#include <bits/stdc++.h>
using namespace std;
vector<int> solve(vector<int> a) {
    int n = a.size();
    map<int, int> cnt;
    for (int i : a) {
        if (cnt.count(i)) {
            cnt[i]++;
        } else {
            cnt[i] = 1;
        }
    }
    for (auto& [nm, c] : cnt) {
        c /= 2;
    }
    vector<int> ans;
    ans.reserve(n);
    for (int i = 0; i < n; i++) {
        if (cnt[a[i]] > 0) {
            ans.insert(ans.begin(), i);
            cnt[a[i]]--;
        } else {
            ans.push_back(i);
        }
    }
    return ans;
}