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

using namespace std;

using ll = long long;

vector<int> solve(vector<int> 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];
    int nec = 0;
    ll sm = 0;
    for (int i = 0; i < A.size(); i++)
    {
        sm += A[i];
        if (sm >= s / 2)
        {
            int x = i, y = A.size() - i;
            if (abs(x - y) <= 1)
            {
                vector<int> ha;
                for (int j = 0; j < A.size(); j++)
                    ha.push_back(j);
                return ha;
            }
            break;
        }
        else
        {
            while (nec + 1 < A.size())
            {
                if (sm + sp[A.size() - 1] - sp[nec] >= s / 2)
                    nec++;
                else
                    break;
            }
            //cout << i << ' ' << nec << endl;
            int x = i + 1 + A.size() - nec;
            int y = A.size() - x;
            if (abs(x - y) <= 1)
            {
                vector<int> ord;
                for (int j = 0; j <= i; j++)
                    ord.push_back(j);
                for (int j = nec; j < A.size(); j++)
                    ord.push_back(j);
                for (int j = i + 1; j < nec; j++)
                    ord.push_back(j);
                return ord;
            }
        }
    }
    assert(false);
}
