#include "partition.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn = 2e6 + 10;
//vector < pair < int, int > > g;
long long total = 0;
int n, used[maxn];

long long psum[maxn];
long long get(int l, int r)
{
    if(l > r)return 0;
    long long ans = psum[r];
    if(l > 0)ans -= psum[l-1];
    return ans;
}
std::vector<int> solve(std::vector<int> A)
{

    n = A.size();

    vector < pair < long long, int > > g;
    for (int i = 0; i < n; ++ i)
    {
        g.pb(make_pair(A[i], i));
    }
    sort(g.begin(), g.end());
    g.pb(make_pair(0, n));
    for (int i = 0; i < n; ++ i)
    {
        psum[i] = psum[i-1] + g[i].first;
    }
    vector < int > res;
    total = 0;
    for (int i = 0; i < n; ++ i)
        total += A[i];

    int mindif = n+1;
    res.pb(0);

    long long pretook = 0;
    for (int takepref = 0; takepref < n/2; ++ takepref)
    {
        long long took = get(0, takepref - 1);
        if(pretook * 2 >= total)break;
        int lt = takepref, rt = n-1, mid, ans = n; /// nai poslednoto koeto da napravi >= total
        while(lt <= rt)
        {
            mid = (lt + rt)/2;
            if((took + get(mid, n-1))* 2 >= total)
            {
                ans = mid;
                lt = mid + 1;
            }
            else rt = mid - 1;
        }
        if((get(0, takepref-1) + get(ans, n-1)) * 2 >= total)
        {
            int cntis = takepref + max(0, n - 1 - ans + 1);
            int cntisnt = n - cntis;
            if(mindif > abs(cntis - cntisnt))
            {
                vector < int > curr;
                for (int i = 0; i < takepref; ++ i)
                    curr.pb(g[i].second);
                for (int i = ans; i < n; ++ i)
                    curr.pb(g[i].second);
                for (int i = takepref; i < ans; ++ i)
                    curr.pb(g[i].second);
                res = curr;
                mindif = abs(cntis - cntisnt);
            }
        }
        pretook = took;
    }
  //  cout << mindif << endl;
    return res;
}
