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

#define pb push_back
#define ll long long
#define pii pair<int, int>
#define fr first
#define sc second

using namespace std;

const ll inf = 1e9 + 7;

vector<int> solve(vector<int> a) {
    int n = a.size();

    vector<pii> b;

    for (int i = 0; i < n; i++) {
        b.pb({a[i], i});
    }

    ll s = accumulate(a.begin(), a.end(), 0ll), oksum = 0;

    int ans = inf, indi, indj;

    for (int i = 0; i < n; i++) {
        int sum = (oksum += b[i].fr);

        for (int j = 0; j <= i; j++) {
            int x;

            if (!j) {
                x = b[i].fr;
            }
            else {
                x = b[n - 1].fr;
            }

            if (sum * 2 >= s && (sum - x) * 2 < s) {
                if (ans > abs(i + 1 - (n - i - 1))) {
                    ans = abs(i + 1 - (n - i - 1));

                    indi = i, indj = j;
                }
            }

            sum -= b[i - j].fr;
            sum += b[n - j - 1].fr;
        }
    }

    vector<int> ret;

    for (int i = 0; i <= indi - indj; i++) {
        ret.pb(b[i].sc);
    }

    for (int i = n - 1; i >= n - indj; i--) {
        ret.pb(b[i].sc);
    }

    for (int i = indi - indj + 1; i < n - indj; i++) {
        ret.pb(b[i].sc);
    }

    return ret;
}
/*int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t ;
    for (int test=1; test<=t; test++) {
        int n;
        cin >> n ;
        vector <int> a(n);
        for (int i=0; i<n; i++) {
            cin >> a[i] ;
        }

        for (auto ind : solve(a)) {
            cout << ind << " ";
        }
        cout << endl ;
    }
    cout << endl ;
    return 0;
}*/
