#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> ind;
    ind.reserve(n);
    vector<vector<int> > buk(26);
    for (int i = 0; i < n; i++) buk[__lg(a[i])].push_back(i);
    for (int i = 0; i <= 25; i++) for (int x : buk[i]) ind.push_back(x);


    int len = n >> 1;
    long long sum = 0;
    vector<bool> left(n);
    for (int i = 0; i < len; i++) sum += a[ind[i]], left[ind[i]] = 1;
    for (int i = 0; i < len; i++) {
        if ((sum << 1) >= S) break;
        left[ind[i]] = 0;
        left[ind[n - i - 1]] = 1;
        sum -= a[ind[i]];
        sum += a[ind[n - i - 1]];
    }
    vector<int> ans;
    ans.reserve(n);
    for (int i = 0; i < n; i++) if (left[ind[i]]) ans.push_back(ind[i]);
    for (int i = 0; i < n; i++) if (!left[ind[i]]) ans.push_back(ind[i]);
    return ans;
}
