#include<bits/stdc++.h>
#include"partition.h"
using namespace std;
vector<int> solve(vector<int> A){
    int N=A.size();
    deque<int> res;
    map<int,vector<int>> f;
    for(int i=0;i<N;i++) f[A[i]].push_back(i);
    for(auto [x,v]:f){
        for(int i=0;i<v.size()/2;i++) res.push_back(v[i]);
        for(int i=v.size()/2;i<v.size();i++) res.push_front(v[i]);
    }
    vector<int> ans;
    for(auto d:res) ans.push_back(d);
    return ans;
}