#include <bits/stdc++.h>
using namespace std;
vector<int> solve(vector<int> A){
    map<int, int> cnt;
    map<int,int> needcnt;
    vector<int> first, second;
    for(auto x : A){
        cnt[x]++;
    }
    for(auto [x,y] : cnt){
        needcnt[x]=y/2;
    }
    vector<int> ans;
    for(int i=0; i<A.size(); i++){
        int x = A[i];
        if(cnt[x]>needcnt[x]){
            first.push_back(i);
            cnt[x]--;
        }
        else{
            second.push_back(i);
        }
    }
    for(auto x : first){
        ans.push_back(x);
    }
    for(auto x : second){
        ans.push_back(x);
    }
    return ans;
}
/*int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t ;
    for (int test=1; test<=t; test++) {
        int n;
        cin >> n ;
        vector <int> a(n);
        for (int i=0; i<n; i++) {
            cin >> a[i] ;
        }

        for (auto ind : solve(a)) {
            cout << ind << " ";
        }
        cout << endl ;
    }
    cout << endl ;
    return 0;
}*/
