#include "partition.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

vector<int> solve(vector<int> a) {

    vector<pair<int, int>> x;
    int n = (int)a.size();
    for(int i = 0; i < n; i++) x.push_back({a[i], i});
    sort(x.begin(), x.end());
    sort(a.begin(), a.end());
    vector<ll> suff;
    suff.push_back(0ll);
    ll sm = 0;
    for(int i = n - 1; i >= 0; i--) {
        sm += a[i];
        suff.push_back(sm);
    }
    vector<ll> pref(n);
    for(int i = 0; i < n; i++) pref[i] = (i == 0 ? 0 : pref[i - 1]) + a[i];
    ll tar = pref[n - 1] / 2;
    int sz = (n + 1) / 2;
    for(int i = sz - 1; i >= 0; i--) {
        if(pref[i] + suff[sz - (i + 1)] > tar) {
            vector<int> res;
            for(int j = 0; j <= i; j++) {
                res.push_back(x[j].second);
            }
            int L = (n - (sz - (i + 1)));
            for(int j = L; j < n; j++) {
                res.push_back(x[j].second);
            }
            for(int j = i + 1; j < L; j++) {
                res.push_back(x[j].second);
            }
            return res;
        }
    }
    vector<int> res;
    int L = (n - sz);
    for(int j = L; j < n; j++) {
        res.push_back(x[j].second);
    }
    for(int j = 0; j < L; j++) res.push_back(x[j].second);
    return res;


}
