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

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