#include <bits/stdc++.h>
using namespace std;

std::vector<int> solve(std::vector<int> A){
    int n = A.size();
    vector<int> a(n, -1);
    map<int,int> mp, m1, m2, ms; 
    for(auto &i : A) mp[i]++;
    int cur = 0;
    for(int i= 0 ; i < n; i++){
        if(m1[A[i]] < (mp[A[i]]/2)){
            a[i] = cur;
            cur++;
            m1[A[i]]++;
        }
    }
    for(auto &i : a){
        if(i == -1){
            i = cur;
            cur++;
        }
    }
    return a;
}
