#include <bits/stdc++.h>
using namespace std;

std::vector<int> solve(std::vector<int> A) {
    bool fl2 = 1;
    int n = A.size();

    if (n <= 7) {
//            cerr << "YES" << endl;
        vector <int> perm(n);
        vector <int> ans(n);
        long long mn = 0, S = 0;
        for (int i = 0; i < n; i++) {
            perm[i] = i;
            ans[i] = i;
            S += A[i];
        }
        mn = S;
        do {
            long long s = 0, c = 0;
            for (int i = 0; i < n; i++) {
                s += A[perm[i]];
                c++;
                if (s * 2 >= S) break;
            }
            if (abs(n - c * 2) < mn) {
                mn = abs(n - c * 2);
                ans = perm;
            }
        } while(next_permutation(perm.begin(), perm.end()));
        return ans;
    }

    vector <pair<int, int>> a(n);
    vector <int> ans;
    vector <int> u(n);
    for (int i = 0; i < n; i++) {
        a[i].first = A[i];
        a[i].second = i;
        if (A[i] != (1ll << i)) fl2 = 0;
    }
    if (fl2) {
//            cerr << "!" << endl;
        for (int i = 0; i < n / 2 - 1; i++)
            ans.push_back(i);
        ans.push_back(n - 1);
        for (int i = n / 2 - 1; i < n; i++)
            ans.push_back(i);
        return ans;
    }

    sort(a.begin(), a.end());
    int c = 1;
    for (int i = 1; i < n; i++) {
        if (a[i].first != a[i - 1].first) {
            int j = i - 1; c /= 2;
            while (c--) {
                ans.push_back(a[j].second);
                u[a[j].second] = 1;
                j--;
            }
            c = 1;
        }
        else c++;
    }
    int j = n - 1; c /= 2;
    while (c--) {
        ans.push_back(a[j].second);
        u[a[j].second] = 1;
        j--;
    }
    for (int i = 0; i < n; i++)
        if (!u[i]) ans.push_back(i);
    return ans;
}