#include "partition.h"
#include "bitset"
#include "iostream"

std::vector<int> solve(std::vector<int> A) {

    std::vector<int> rez(A.size());

    int stot = 0;
    for (auto x:A) stot += x;

    int n2 = A.size(),mmin = stot*2;

    for (int mask=0; mask<=(1<<n2); mask++) {
        std::bitset<32> x = mask;
        int sum = 0;
        for (int i=0; i<A.size(); i++) {
            if (x[i]) sum += A[i];
        }

        //std::cout<<x<<" "<<sum<<" "<<stot<<" "<<mmin<<"\n";

        if (std::abs(2*sum-stot) < mmin) {
            mmin = std::abs(2*sum-stot);
            if (sum > stot/2 || (sum == stot/2 && stot%2 == 0)) {
                int st = 0;
                for (int i=0; i<A.size(); i++) {
                    if (x[i]) rez[st++] = i;
                }

                for (int i=0; i<A.size(); i++) {
                    if (!x[i]) rez[st++] = i;
                }
            }
            else {
                int st = 0;
                for (int i=0; i<A.size(); i++) {
                    if (!x[i]) rez[st++] = i;
                }

                for (int i=0; i<A.size(); i++) {
                    if (x[i]) rez[st++] = i;
                }
            }
        }
    }

    return rez;
}