#pragma GCC optimize("Ofast")

#include "partition.h"
#include <iostream>
#include <vector>

using namespace std;

vector<int> solve(vector<int> a) {
    int n = (int)a.size();
    long long S = 0;
    for (int i : a) S += i;

    vector<int> b(n);

    vector<vector<int> > buk(26);
    for (int i = 0; i < n; i++) buk[__lg(a[i])].push_back(i);
    int now = 0;
    for (int i = 0; i <= 25; i++) for (int j = 0; j < buk[i].size(); j++) b[now++] = i;

    int len = n >> 1;
    long long sum = 0;
    vector<bool> left(n);
    for (int i = 0; i < len; i++) sum += 1 << b[i], left[i] = 1;
    for (int i = 0; i < len; i++) {
        if ((sum << 1) >= S) break;
        left[i] = 0;
        left[n - i - 1] = 1;
        sum -= 1 << b[i];
        sum += 1 << b[n - i - 1];
    }
    vector<int> ans(n);
    now = 0;
    vector<int> rn(26);
    for (int i = 0; i < n; i++) if (left[i]) ans[now++] = buk[b[i]][rn[b[i]]++];
    for (int i = 0; i < n; i++) if (!left[i]) ans[now++] = buk[b[i]][rn[b[i]]++];
    return ans;
}
