#include "partition.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
const int NMAX=20;

using namespace std;

vector<int> ansF(NMAX,0);

int fact(int val)
{
    int ans=1;
    for(int i=1;i<=val;i++) ans*=i;
    return ans;
}

vector<int> solve(std::vector<int> v)
{
    vector<int> indexi;
    vector<int> ansF(v.size(),0);
    int sum=0;
    for(int i=0;i<v.size();i++) sum+=v[i];
    for(int i=0;i<v.size();i++) indexi.push_back(i);
    int varPos=fact(v.size()),difMin=1e9;
    for(int i=1;i<=varPos;i++)
    {
        int halfSum=0;
        for(int j=0;halfSum<sum/2+(sum%2==1);j++)
        {
            halfSum+=v[indexi[j]];
        }
        ///cout<<halfSum<<" "<<sum<<endl;
        if(abs((sum-halfSum)-halfSum)<difMin)
        {
            for(int i=0;i<indexi.size();i++)
            {
                ansF[i]=indexi[i];
            }
            difMin=abs((sum-halfSum)-halfSum);
        }
        ///for(auto i:indexi) cout<<i<<" ";
        ///cout<<endl;
        next_permutation(indexi.begin(),indexi.end());
    }
    return ansF;
}

/*1
8
6 6 3 1 1 4 4 3*/
