#define fi first
#define se second
#include "partition.h"

using namespace std;

int S = 0,n;
bool loob = 0;

bool Comp(pair <int,int> a,pair <int,int> b){
    return a.fi>b.fi;
}

int Diff(vector<int> A,vector<int> B){
    int s = 0;
    int ind = 0;
    while (s<S/2){
        s += A[B[ind]];
        ind++;
    }
    return s-(S-s);
}

std::vector<int> solve(std::vector<int> A){
    bool issubtask2 = 1;
    bool issubtask4 = 1;
    vector <int> ans;
    n = A.size();
    S = 0;
    for (int i=0;i<n;++i){
        S += A[i];
        if (n>25 or A[i]!=(1<<i)) issubtask2 = 0;
        if (A[i]!=i+1) issubtask4 = 0;
    }
    if (issubtask2){
        for (int i=n-1;i>=0;--i) ans.push_back(i);
        return ans;
    }
    if (issubtask4){
        if (n%2==0){
            for (int i=0;i<n;++i){
                ans.push_back(i);
                ans.push_back(n-1-i);
            }
        }else{
            ans.push_back(0);
            for (int i=1;i<n;++i){
                ans.push_back(i);
                ans.push_back(n-i);
            }
        }
        return ans;
    }
    if (n<=25){
        vector <int> B;
        for (int i=0;i<n;++i) B.push_back(i);
        int Min = 1e9;
        do{
            int loc = Diff(A,B);
            if (Min>loc){
                Min = loc;
                ans = B;
            }
        }while(next_permutation(B.begin(),B.end()));
        return ans;
    }
    assert(0);
}