#include <bits/stdc++.h>

// meoowww mrrowww :3
// go play vivid/stasis!!! https://vividstasis.gay

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = []{
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    return 0;
}();

vector<int> solve(vector<int> a) {
    int n = a.size();
    long long total = 0;
    vector<pair<int, int>> b(n); fo(i, 0, n) b[i] = { a[i], i }, total += a[i];
    sort(be(b));

    vector<long long> psum(n + 1);
    fo(i, 0, n) psum[i + 1] = psum[i] + b[i].f;

    int min_diff = n;
    int min_i = 0;
    int min_j = n;

    int i = 0, j = n;
    while ((psum[n] - psum[j]) * 2 < total) j--;
    for (; i <= n && psum[i] * 2 < total; i++) {
        while (j < n && (psum[n] - psum[j + 1]) * 2 >= total) j++;

        int on_left = i + n - j;
        int on_right = n - on_left;

        if (abs(on_left - on_right) < min_diff) {
            min_diff = abs(on_left - on_right);
            min_i = i;
            min_j = j;
        }
    }

    if (abs(2 * i - n) < min_diff) {
        min_i = i;
        min_j = n;
    }

    vector<int> res;
    fo(i, 0, min_i) res.pb(b[i].s);
    fo(i, min_j, n) res.pb(b[i].s);
    fo(i, min_i, min_j) res.pb(b[i].s);

    return res;
}