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

std::vector<int> solve(std::vector<int> A) {
    bool fl2 = 1;
    int n = A.size();
    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) {
        ans.push_back(n - 1);
        for (int i = 0; i < n - 1; i++) {
            ans.push_back(i);
            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;
}