#include "partition.h"
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

// #define int long long

vector <int> ind[(int)3e7 + 1];

std::vector<signed> solve(std::vector<signed> A) {
    for (int i = 0; i < A.size(); i++)
        ind[A[i]].emplace_back (i);

    vector <int> ans1;
    vector <int> ans2;
    for (int i = 0; i < 3e7 + 1; i++)
        if (!ind[i].empty()) {
            for (int j = 0; j < ind[i].size() / 2; j++)
                ans1.emplace_back (ind[i][j]);
            for (int j = ind[i].size() / 2; j < ind[i].size(); j++)
                ans2.emplace_back (ind[i][j]);
        }

    vector <int> ans;
    for (auto&& e : ans1)
        ans.emplace_back (e);
    for (auto&& e : ans2)
        ans.emplace_back (e);
    return ans;
}
