#include<bits/stdc++.h>
#include "partition.h"
using namespace std;


vector<int> solve(vector<int> a)
{
    vector<int>perm;
    long long s=0,n = a.size();
    for(long long i=0; i<n; i++)
    {
        s+=1LL*a[i];
        perm.push_back(i);
    }
    double trg = (double)(s)/(double)(2);
    long long op,cnt,bb,sz1,sz2;
    long long best = n + 1;
    for(long long b = 0; b<(1<<n); b++)
    {
        op = cnt= 0;
        for(long long i=0; i<n; i++)
        {
            if((bool)(b & (1<<i)) == 1)
            {
                op+=a[i];
                cnt++;
            }
        }
        sz1 = cnt+1;
        sz2 = n - (cnt+1);
        if(op >= trg || abs(sz1-sz2) > best)
            continue;
        bb = -1;
        for(long long i=0; i<n; i++)
        {
            if((bool)(b & (1<<i)) == 0)
            {
                if(op +a[i]>trg)
                {
                    bb = i;
                    break;
                }
            }
        }
        if(bb == -1)
            continue;
        best = abs(sz1-sz2);
        long long id = 0;
        for(long long i=0; i<n; i++)
        {
            if((bool)(b & (1<<i)) == 1)
                perm[id++] = i;
        }
        perm[id++] = bb;
        for(long long i=0; i<n; i++)
        {
            if((bool)(b & (1<<i)) == 0 && i!=bb)
                perm[id++] = i;
        }
    }
    return perm;
}
