#include "partition.h"
//#include "grader.cpp"

#include <bits/stdc++.h>

using namespace std;

std::vector<int> solve(std::vector<int> a) {
    int n = a.size();

    map<int, vector<int>> mp;

    for(int i = 0; i < n; i++) {
        mp[a[i]].push_back(i);
    }

    vector<int> ans1, ans2;

    for(auto &[key, val] : mp) {
        for(int i = 0; i < (int)val.size() / 2; i++) {
            ans1.push_back(val[i]);
        }
        for(int i = val.size() / 2; i < (int)val.size(); i++) {
            ans2.push_back(val[i]);
        }
    }

    for(auto &x : ans2) ans1.push_back(x);

    return ans1;
}
