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

std::vector<int> solve(std::vector<int> A){
    using ll = long long;
    ll n = A.size();
    vector<ll> a(n, -1);
    map<ll,ll> mp, m1, m2, ms; 
    for(auto &i : A) mp[i]++;
    ll cur = 0;
    for(ll 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++;
        }
    }
    vector<int> ans;
    for(auto &i : a) ans.push_back(i);
    return ans;
}
