#include "bits/stdc++.h"
#include "partition.h"
// #include "grader.cpp"
using namespace std;

#define ll long long

ll n, ans, S, s;
vector <int> v[30];

vector <int> solve(vector<int> A) {
    ios::sync_with_stdio(0);cin.tie(0);
    n = (int)A.size();
    vector <int> a = {};
    priority_queue <pair <ll,ll>> q;
    S = s = 0;
    for(int i = 0; i < n; i++) {
        S += A[i];
        for(int j = 25; j >= 0; j--) {
            if(A[i] == (1<<j)) {
                v[j].push_back(i);
            }
        }
    }
    for(int i = 0; i <= 25; i++) {
        for(auto j : v[i]) {
            a.push_back(j);
            if((int)a.size() < n / 2) s += (1<<i);
        }
    }
    int i = n - 1, j = max((n / 2) - 1, 0ll);
    while(s * 2 < S && i >= (n / 2) && j >= 0) {
        s -= A[a[j]];
        s += A[a[i]];
        swap(a[j], a[i]);
        i--;
        j--;
    }
    return a;
}