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

using namespace std;

vector<int> solve(vector<int> A)
{
    vector<int> ans;
    long long i,cnt,masca,solutie,mini,y,s,suma;
    bool ok;
    solutie=(1LL<<A.size())-1;
    mini=A.size();
    suma=0;
    for(auto x:A)
        suma+=x;
    for(masca=0;masca<(1LL<<A.size());masca++)
    {
        cnt=__builtin_popcount(masca);
        if(abs(2*cnt-(long long)A.size())>=abs(2*mini-(long long)A.size()))
            continue;
        s=y=0;
        ok=true;
        for(i=0;i<A.size();i++)
        {
            if(masca&(1LL<<i))
            {
                s+=A[i];
                y++;
            }
            if(2*s>=suma && y<cnt)
            {
                ok=false;
                break;
            }
        }
        if(2*s>=suma && ok==true)
        {
            solutie=masca;
            mini=cnt;
        }
    }
    //cerr<<solutie<<" "<<mini<<endl;
    for(i=0;i<A.size();i++)
    {
        if(solutie&(1LL<<i))
            ans.push_back(i);
    }
    for(i=0;i<A.size();i++)
    {
        if((solutie&(1LL<<i))==0)
            ans.push_back(i);
    }
    /*s=0;
    cerr<<"VERIF: ";
    for(i=0;i<ans.size();i++)
    {
        s+=A[ans[i]];
        cerr<<s<<" ";
    }
    cerr<<endl;*/
    return ans;
}
/*
2
9
5 6 6 3 1 1 4 4 3
8
2 2 3 2 3 2 2 3
*/
