#include "bits/stdc++.h"
#include "partition.h"
// #include "grader.cpp"
#define pb push_back
#define all(v) v.begin(), v.end()
#define ll long long
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;

vector<int> solve(vector<int> a){
    int n=(int)a.size();
    ll S=0;
    vector<pii> v;
    for(int i = 0; i < n; ++i)
        S+=a[i], v.pb({a[i], i});
    sort(all(v));
    vector<int> ans;
    ll mid=(S+1)/2;
    if(n%2==0){
        int id=0;
        ll sm=0;
        for(int i = 0; i < n/2; ++i)
            sm+=v[i].ff;
        if(sm>=mid){
            for(int i = 0; i < n/2; ++i)
                ans.pb(v[i].ss);
            for(int i = n/2; i < n; ++i)
                ans.pb(v[i].ss);
            return ans;
        }
        auto f=[&](ll x) -> int {
            for(int i = n-1; i >= 0; --i){
                x-=v[i].ff;
                if(x<=0)
                    return n-i;
            }
            assert(false);
        };
        vector<pii> may;
        bool did=0;
        for(int i = n/2-1; i >= 1; --i){
            sm-=v[i].ff;
            // printf("%lld ", sm);
            may.pb({f(mid-sm)+i, i});
            did|=(may.back().ff==n/2);
        }
        // puts("");
        assert(did);
        // for(int i = 0; i < (int)may.size(); ++i)
        //     printf("%d %d\n", may[i].ff, may[i].ss);
        // return {};
        for(int i = 0; i < (int)may.size(); ++i)
            if(may[i].ff==n/2){
                // printf("%d %d\n", may[i].ff, may[i].ss);
                for(int j = 0; j < may[i].ss; ++j)
                    ans.pb(v[j].ss);
                int galdy=n/2-may[i].ss;
                for(int j = n-1; j >= n-galdy; --j)
                    ans.pb(v[j].ss);
                for(int j = may[i].ss; j < n-galdy; ++j)
                    ans.pb(v[j].ss);
                break;
            }
        return ans;
    }
    int id=0;
    ll sm=0;
    for(int i = 0; i <= n/2; ++i)
        sm+=v[i].ff;
    if(sm>=mid){
        for(int i = 0; i <= n/2; ++i)
            ans.pb(v[i].ss);
        for(int i = n/2+1; i < n; ++i)
            ans.pb(v[i].ss);
        return ans;
    }
    auto f=[&](ll x) -> int {
        for(int i = n-1; i >= 0; --i){
            x-=v[i].ff;
            if(x<=0)
                return n-i;
        }
        assert(false);
    };
    vector<pii> may;
    bool did=0;
    for(int i = n/2; i >= 1; --i){
        sm-=v[i].ff;
        may.pb({f(mid-sm)+i, i});
        did|=(may.back().ff==n/2+1);
    }
    assert(did);
    for(int i = 0; i < (int)may.size(); ++i)
        if(may[i].ff==n/2+1){
            for(int j = 0; j < may[i].ss; ++j)
                ans.pb(v[j].ss);
            int galdy=n/2+1-may[i].ss;
            for(int j = n-1; j >= n-galdy; --j)
                ans.pb(v[j].ss);
            for(int j = may[i].ss; j < n-galdy; ++j)
                ans.pb(v[j].ss);
            break;
        }
    return ans;
}