#include "partition.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> solve6sau2(vector<int> vec) {
    vector<int> ans(n);

    int minn = 500, sol;
    long long sum = 0;

    for(int i : vec)
        sum += 2ll * i;

    for(int mask = 0; mask < (1 << n); mask++) {
        long long localsum = 0;
        int minim = 2e9, unu = 0, zero = n;
        bool ok = 1;

        for(int bit = 0; bit < n; bit++) {
            if((1 << bit)&mask) {
                unu++;
                zero--;

                if(localsum >= sum / 2) {
                    ok = 0;
                    break;
                }

                localsum += 2ll * vec[bit];
                minim = min(minim, vec[bit]);
            }
        }

        if(!ok)
            continue;

        if(minn > abs(unu - zero)) {
            minn = abs(unu - zero);
            sol = mask;
        }
    }

    int poz = 0, last = n - 1;

    for(int i = 0; i < n; i++) {
        if((1 << i)&sol)
            ans[poz++] = i;
        else
            ans[last--] = i;
    }

    return ans;
}
vector<int> solve4(vector<int> vec) {
    vector<int> ans(n + 1, 0);

    int poz = 0;

    for(int i = 0; i < n; i += 2) {
        ans[i] = n - poz - 1;
        ans[i + 1] = poz;
        poz++;
    }

    ans.pop_back();

    return ans;
}
vector<int> solve5(vector<int> vec) {
    vector<int> seven(n);
    vector<int> ans(n);

    long long sum = 0;

    for(int i : vec)
        sum += 2ll * i;

    for(int i = 0; i < n; i++)
        seven[i] = i;

    int prod = 1;

    for(int i = 2; i <= n; i++)
        prod *= i;

    int minn = 10;

    for(int i = 0; i < prod / 3; i++) {
//        if(i < 10) {
//            for(int dick : seven)
//                cout << dick << " ";
//
//            cout << "\n";
//        }

        long long localsum = 0;
        int last = 0;

        for(int j = 0; j < n; j++) {
            localsum += 2ll * vec[seven[j]];

            if(localsum >= sum / 2) {
                last = j;
                break;
            }
        }

        int dif = max((last + 1) - (n - 1 - last), (n - 1 - last) - (last + 1));

//        cout << i << " " << dif << "\n";

        if(dif < minn) {
            ans = seven;
            minn = dif;
        }

        if(dif == 0)
            break;

        next_permutation(seven.begin(), seven.end());
    }

    return ans;
}
std::vector<int> solve(std::vector<int> A) {
    n = A.size();
    vector<int> ans(n);
    ans = solve6sau2(A);
    return ans;
}
