#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll esim = (1 << 30) - 1;
int mp[(1 << 25) + 1];
vector<int> solve(vector<int> A) {
    //vector<ll> a;
    //for (int i = 0; i < (int)A.size(); i++) {
        //a.push_back(((ll)A[i] << 30) ^ i);
    //}
    //sort(a.begin(), a.end());
    for (int i = 0; i <= 25; i++) {
        mp[(1 << i)] = i;
    }
    vector<vector<int>> esim(26);
    int i = 0;
    for (auto &it : A) {
        esim[mp[it]].push_back(i++);
    }
    vector<int> a;
    for (auto &it : esim) {
        for (auto &j : it) {
            a.push_back(j);
        }
    }
    vector<int> ans;
    for (int i = 1; i < (int)a.size(); i += 2) {
        ans.push_back(a[i]);
    }
    if ((int)a.size() % 2 == 1) ans.push_back(a.back());
    for (int i = 0; i < (int)a.size() - 1; i += 2) {
        ans.push_back(a[i]);
    }
    return ans;
}
/*
int main() {
    vector<int> w = { 1, 4, 4, 8, 8, 4, 2 };
    vector<int> q = solve(w);
    for (auto it : q) {
        cout << it << " ";
    }
    cout << "\n";
}
*/