#include "partition.h"
#include<vector>
#include<map>
using namespace std;
std::vector<int> solve(std::vector<int> a) {
    map<int, vector<int>> ind;
    int n = a.size();
    for (int i = 0; i < n; i++) {
        ind[a[i]].push_back(i);
    }
    vector<int> ans;
    for (auto &[tr, i] : ind) {
        for (int j = 0; j < i.size(); j += 2) {
            ans.push_back(i[j]);
        }
    }
    for (auto &[tr, i] : ind) {
        for (int j = 0; j < i.size(); j += 2) {
            ans.push_back(i[j + 1]);
        }
    }
    return ans;
}
