#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6;

int o[MAXN];
vector<int> solve(vector<int> a) {
    int n = a.size();
    vector<vector<int>> z(26);
    for (int i = 0; i < n; i++) {
        z[__lg(a[i])].push_back(i);
    }
    int co = 0;
    for (int j = 25; j >= 0; j--) {
        for (auto &i : z[j]) {
            o[co++] = i;
        }
    }
    co = 0;
    for (int i = (n - 1) / 2 * 2; i >= 0; i -= 2) {
        a[co++] = o[i];
    }
    for (int i = 1; i < n; i += 2) {
        a[co++] = o[i];
    }
    return a;
}