#include "bits/stdc++.h"
#include "partition.h"
// #include "grader.cpp"
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;

vector<int> solve(vector<int> a){
    int n=(int)a.size();
    // assert(n%2==0);
    map<int, int> cnt;
    vector<vector<int>> A(n);
    for(int i = 0; i < n; ++i)
        cnt[a[i]]++, A[a[i]].pb(i);
    sort(all(a));
    a.erase(unique(all(a)), a.end());
    vector<int> ans, anss;
    for(int i = 0; i < (int)a.size(); ++i){
        int ad=cnt[a[i]]/2;
        int ad2=ad;
        while(ad--)
            ans.pb(A[a[i]].back()), A[a[i]].pop_back();
        while(ad2--)
            anss.pb(A[a[i]].back()), A[a[i]].pop_back();
    }
    for(int i = 0; i < (int)anss.size(); ++i)
        ans.pb(anss[i]);
    return ans;
}