#include <iostream>
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#include "partition.h"
using namespace std;

const int MAXN = 3e6 + 10, BUCKET = 1024;
int top[MAXN], value[MAXN], to[MAXN], a[MAXN];

int cnt[32][MAXN];
int g[32];

vector <int> solve(vector <int> v) {
    int n = v.size();
    
    for (int i = 0; i < n; i++) {
        int x = __builtin_clz(v[i]);
        cnt[x][g[x]] = i + 1;
        g[x]++;
    }

    int g = 0;
    
    for (int b = 31; b >= 0; b--) {
        for (int i = 0; cnt[b][i]; i++) {
            a[g++] = cnt[b][i] - 1;
            cnt[b][i] = 0;
        }

        ::g[b] = 0;
    }

    vector <int> ans;
    ans.reserve(n);

    if (n % 2) {
        for (int i = 0; i < n; i += 2) {
            ans.push_back(a[i]);
        }
    
        for (int i = 1; i < n; i += 2) {
            ans.push_back(a[i]);
        }

        return ans;
    }
    
    for (int i = 1; i < n; i += 2) {
        ans.push_back(a[i]);
    }

    for (int i = 0; i < n; i += 2) {
        ans.push_back(a[i]);
    }

    return ans;
}
/**
1
9
5 6 6 3 1 1 4 4 3
 */