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

std::vector<int> solve(std::vector<int> A){
    int N = A.size();
    vector<int> ans(N);
    map<int, vector<int>> mp;
    for(int i = 0; i < N; i++){
        mp[A[i]].push_back(i);
    }
    int pos = 0;
    for(auto x : mp){
        for(int j = 0; j < x.second.size() / 2; j++){
            ans[pos] = x.second[j];
            pos++;
        }
    }
    for(auto x : mp){
        for(int j = x.second.size() / 2; j < x.second.size(); j++){
            ans[pos] = x.second[j];
            pos++;
        }
    }
    return ans;
}
/*int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        vector<int> ANS = solve(a);
        for(int i = 0; i < n; i++){
            cout << ANS[i] << " ";
        }
        cout << "\n";
    }
}*/
