#include "partition.h"
#include <vector>
#include <iostream>

int rez[2000001];
int vc[2000001];
int v[2000001];
int cnt[2000001];
int n;
int total = 0;

void verificare (int& mini)
{
    int sum1 = 0;
    int sum2 = 0;
    for (int i = 1; i <= n; i++)
    {
        sum1 += cnt[i];
        sum2++;
        if (sum1 >= total / 2)
        {
            break;
        }
    }
    if (abs(sum2 - (n - sum2)) < mini)
    {
        mini = abs(sum2 - n + sum2);
        for (int i = 1; i <= n; i++)
        {
            rez[i] = cnt[i];
        }
    }
}

void bkt (int k , int& mini)
{
    if (k == n + 1)
    {
        verificare(mini);
    }
    else
    {
        for (int i = 1; i <= n; i++)
        {
            if (vc[i] == 0)
            {
                vc[i] = 1;
                cnt[k] = i;
                bkt(k + 1 , mini);
                vc[i] = 0;
            }
        }
    }
}

std::vector<int> solve(std::vector<int> A)
{
    n = A.size();
    for (int i = 0; i <= n; i++)
    {
        total += A[i];
        v[i + 1] = A[i];
    }
    int mini = 10000000;
    bkt(1 , mini);
    std::vector<int> rezz;
    for (int i = 1; i <= n; i++)
    {
        rezz.push_back(rez[i] - 1);
    }
    return rezz;

}
