#include <bits/stdc++.h>
//#include "grader.cpp"
//#include "partition.h"
using namespace std;

// maxsum

std::vector<int> solve(std::vector<int> A)
{
    const int maxN = 1e5 + 5;
    vector <int> ans;
    vector <int> can(maxN);
    vector <int> br(maxN);
    vector <bool> used(maxN);
    //sort(A.rbegin(), A.rend());
    int Rsum = 0, n = A.size(), sum = 0;
    can[0] = true;
    for (int i = 0; i < n; i++)
    {
        for (int j = Rsum; j >= 0; j--)
        {
            if (can[j] != 0 && can[j + A[i]] == 0)
            {
                can[j + A[i]] = i;
            }
        }
        Rsum += A[i];
        sum += A[i];
    }
    int ind = ceil(sum / 2.0);
    while (ind < sum)
    {
        if (can[ind] != 0)
        {
            break;
        }
        ind++;
    }
    //cout << "1: " << ind << endl;
    //cout << "2: " << sum - ind << endl;
    int sum1 = 0;
    while (ind >= 0)
    {
        if (can[ind] != 0)
        {
            break;
        }
        ind--;
    }
    for (int j = ind; j > 0; )
    {
        if (can[j] != 0)
        {
            used[can[j]] = true;
            ans.push_back(can[j]);
            //ans.push_back(A[can[j]]);
            j -= A[can[j]];
        }
        else
        {
            j--;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (!used[i])
        {
            ans.push_back(i);
            //ans.push_back(A[i]);
        }
    }
    return ans;
}
