#include "partition.h"
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

vector<int> acp;

void chk(vector<int> ord)
{
    ll s = 0;
    for (auto it : acp)
        s += it;
    ll sm = 0;
    int x = 0;
    for (auto it : ord)
    {
        sm += acp[it];
        x++;
        if (2ll * sm >= s)
            break;
    }
    int y = acp.size() - x;
    if (abs(x - y) > 1)
        assert(false);
}

vector<int> solve(vector<int> A)
{
    acp.clear();
    vector<pair<int, int>> a(A.size());
    for (int i = 0; i < A.size(); i++)
        a[i].first = A[i], a[i].second = i;
    //sort(a.begin(), a.end());
    acp = A;
    ll s = 0;
    for (auto it : A)
        s += it;
    vector<ll> sp(A.size());
    sp[0] = A[0];
    for (int i = 1; i < sp.size(); i++)
        sp[i] = sp[i - 1] + a[i].first;
    int nec = 0;
    ll sm = 0;
    for (int i = -1; i < (int)A.size(); i++)
    {
        if (i != -1)
            sm += a[i].first;
        if (2ll * sm >= s)
        {
            int x = i + 1, y = A.size() - x;
            if (abs(x - y) <= 1)
            {
                vector<int> ha(A.size());
                for (int j = 0; j < A.size(); j++)
                    ha[j] = a[j].second;
                return ha;
            }
            break;
        }
        else
        {
            while (nec + 1 < (int)A.size())
            {
                if (2ll * (sm + sp[A.size() - 1] - sp[nec]) >= s)
                    nec++;
                else
                    break;
            }
            //cout << i << ' ' << nec << endl;
            int x = i + 1 + (int)A.size() - nec;
            int y = (int)A.size() - x;
            if (abs(x - y) <= 1)
            {
                vector<int> ord;
                for (int j = 0; j <= i; j++)
                    ord.push_back(a[j].second);
                for (int j = nec; j < A.size(); j++)
                    ord.push_back(a[j].second);
                for (int j = i + 1; j < nec; j++)
                    ord.push_back(a[j].second);
                //chk(ord);
                return ord;
            }
        }
    }
    assert(false);
}
