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

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

    if (n <= 20) {
//            cerr << "!" << endl;
        int mn = n, msk = (1ll << n) - 1;
        long long S = 0;
        for (int i = 0; i < n; i++)
            S = S + A[i];

        for (int mask = 0; mask < (1ll << n); mask++) {
            long long s = 0;
            int cnt = 0;
            bool fl = 0;
            for (int i = 0; i < n; i++) {
                if (!((mask >> i) & 1)) continue;
                if (s * 2 >= S) fl = 1;
                s = s + A[i];
                cnt++;
            }
            if (!fl && s * 2 >= S) {
                int cur = abs(n - cnt * 2);
                if (cur < mn) {
                    mn = cur;
                    msk = mask;
                }
            }
        }
//    cerr << "   " << mn << endl;
        for (int i = 0; i < n; i++)
            if ((msk >> i) & 1) ans.push_back(i);
        for (int i = 0; i < n; i++)
            if (!((msk >> i) & 1)) ans.push_back(i);
        return ans;
    }

    vector <pair<int, int>> a(n);
    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) {
        if (n == 1) return {0};
        if (n == 2) return {1, 0};
//            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 - 1; 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;
}