#include "partition.h"
#include "bits/stdc++.h"

#define pii pair<int, int>
#define pb push_back
#define ar array
#define ll long long

const ll inf = 1e18 + 7;

using namespace std;

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

    map<int, vector<int>> mp;

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

    vector<int> ret;

    for (auto &[key, val]: mp) {
        int m = val.size();

        while (val.size() > m / 2) {
            ret.pb(val.back());

            val.pop_back();
        }
    }

    for (auto [key, val]: mp) {
        while (val.size()) {
            ret.pb(val.back());

            val.pop_back();
        }
    }

    return ret;
}


