#include <bits/stdc++.h>
#include "partition.h"
using namespace std;
using ll = int;
vector<int> solve(vector<int> a)
{
    ll tsum, minraz, ms = a.size();
    vector<pair<int, int>> v = a;
    vector<int> ans;
    for(ll i = 0; i < v.size(); i++)
    {
        tsum += a[i];
        v[i].first() = a[i];
        v[i].second() = i;
    }
    sort(v.begin(), v.end());
    minraz = tsum;
    for(ll i = 0; i < v.size(); i++)
    {
        vector<int> locans1;
        vector<int> locans2;
        ll sum1 = 0, sum2 = 0;
        for(ll j = v.size() - i - 1; j >= 0; j++)
        {
            if(sum1 <= sum2)
            {
                sum1 += v[j].first();
                locans1.insert(locans1.begin(), v[j].second());
            }
            else
            {
                sum2 += v[j].first();
                locans2.insert(locans2.begin(), v[j].second());
            }
        }
        if(sum1 >= sum2 && (sum1 - sum2 < minraz || (sum1 - sum2 == minraz && max(locans1.size(), locans2.size()) - min(locans1.size(), locans2.size()) < ms)))
        {
            minraz = sum1 - sum2;
            ms = max(locans1.size(), locans2.size()) - min(locans1.size(), locans2.size());
            ans = locans1;
            ans.insert(ans.end(), locans2.begin(), locans2.end());
        }
        else if(sum2 > sum1 && (sum2 - sum1 < minraz || (sum2 - sum1 == minraz && max(locans1.size(), locans2.size()) - min(locans1.size(), locans2.size()) < ms)))
        {
            minraz = sum2 - sum1;
            ms = max(locans1.size(), locans2.size()) - min(locans1.size(), locans2.size());
            ans = locans2;
            ans.insert(ans.end(), locans1.begin(), locans1.end());
        }
    }
    return ans;
}
