#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<ll> par(n+1);
    for(int i = 1; i <= n; ++i)
        par[i]=par[i-1]+v[i-1].ff;
    vector<int> ans;
    ll mid=(S+1)/2;
    auto f=[&](ll x) -> int {
        int l=1, r=n, ret=-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(par[n]-par[mid-1]>=x)
                l=mid+1, ret=mid;
            else
                r=mid-1;
        }
        return n-ret+1;
    };
    if(n%2==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;
        }
        vector<pii> may;
        int mn=1e9;
        for(int i = n/2-1; i >= 1; --i){
            sm-=v[i].ff;
            may.pb({f(mid-sm)+i, i});
            mn=min(mn, abs(may.back().ff-n/2));
        }
        for(int i = 0; i < (int)may.size(); ++i)
            if(abs(may[i].ff-n/2)==mn){
                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;
    }
    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;
    }
    vector<pii> may;
    int mn=1e9, mn2=1e9;
    for(int i = n/2; i >= 1; --i){
        sm-=v[i].ff;
        may.pb({f(mid-sm)+i, i});
        mn=min(mn, abs(may.back().ff-(n/2+1)));
        mn2=min(mn2, abs(may.back().ff-n/2));
    }
    for(int i = 0; i < (int)may.size(); ++i)
        if(abs(may[i].ff-(n/2+1))==mn or abs(may[i].ff-n/2)==mn2){
            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;
}