#include <bits/stdc++.h>

using namespace std;

vector<int> solve(vector<int> a) {
    int n = a.size();

    vector<vector<int>> pos(26);

    for (int i = 0; i < n; i++)
        pos[__lg(a[i])].push_back(i);

    vector<int> ans, r;

    for (int i = 0; i < 26; i++) {
        if (pos[i].size() & 1)
            r.push_back(pos[i][pos[i].size() / 2]);
        for (int x = 0; x < pos[i].size() / 2; x++)
            ans.push_back(pos[i][x]);
    }

    if (!r.empty()) {
        int m = r.size();

        for (int i = 0; i < m / 2; i++)
            ans.push_back(r[i]);

        ans.push_back(r[m - 1]);
        r.pop_back();
        m--;

        for (int i = m / 2; i < m; i++)
            ans.push_back(r[i]);
    }

    for (int i = 0; i < 26; i++) {
        for (int x = (pos[i].size() + 1) / 2; x < pos[i].size(); x++)
            ans.push_back(pos[i][x]);
    }

    return ans;
}