#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 1e7 + 7;
const int L = 20;

// short int lg[(1 << 25) + 1];

short int lg[MAXN];
short int prec[(1 << L) + 1];
int ord[MAXN];
ll pref[MAXN];
int cnt[30], pos[30];

bool FIRST_TIME = 0;

vector<int> solve(vector<int> A) {
    if (FIRST_TIME == 0) {
        for (int i = 2; i <= (1 << L); ++i) {
            prec[i] = prec[i / 2] + 1;
        }
        FIRST_TIME = 1;
    }
    ll sum = 0;
    int n = A.size();
    for (int i = 0; i < n; ++i) {
        sum += A[i];
        if (A[i] > (1 << L)) {
            lg[i] = L + prec[A[i] / (1 << L)];
        } else {
            lg[i] = prec[A[i]];
        }
        ++cnt[lg[i]];
    }
    int kek = 0;
    for (int i = 0; i < 30; ++i) {
        pos[i] = kek;
        kek += cnt[i];
    }
    for (int i = 0; i < n; ++i) {
        int v = lg[i];
        ord[pos[v]] = i;
        ++pos[v];
    }
    
    int ans = 1e9;
    int whol, whor;
    ll s = 0;
    int r = 0;
    for (int l = 0; l < n && l < n / 2 + 10; ++l) {
        while (r < n && s < (sum + 1) / 2) s += A[ord[r]], ++r;
        int x = r - l;
        int y = n - x;
        if (s >= (sum + 1) / 2) {
            if (ans > abs(x - y)) {
                ans = abs(x - y);
                whol = l;
                whor = r - 1;
                if (ans < 2 || n - l < n / 2 && 2 * l - n < ans) break;
            }
        } else {
            break;
        }
        s -= A[ord[l]];
    }
    vector<int> sol(n);
    int id = 0;
    for (int i = whol; i <= whor; ++i) sol[id++] = ord[i];
    for (int i = 0; i < whol; ++i) sol[id++] = ord[i];
    for (int i = whor + 1; i < n; ++i) sol[id++] = ord[i];
    for (int i = 0; i < 30; ++i) cnt[i] = 0;
    return sol;
}

/*
8
2 2 3 2 3 2 2 3
X X   X   X X
6 5 3 1 0 2 4 7 


*/

// int main() {
//     ios::sync_with_stdio(0); 
//     cin.tie(0); cout.tie(0);
//     int n; cin >> n;
//     vector<int> A(n);
//     for (int i = 0; i < n; ++i) cin >> A[i];
//     auto res = solve(A);
//     for (auto x : res) cout << x << " ";
//     cout << "\n";
//     return 0;
// }