#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
/*std::vector<int> solve(
std::vector<std::pair<int, int>> R,
std::vector<long long> D,
std::vector<int> S,
std::vector<int> T,
std::vector<bool> I
) {
    for (auto &[i, j] : R) i++, j++;
    for (auto &i : S) i++;
    for (auto &i : T) i++;
    long long n = R.size() + 1;
    vector<long long> g[n + 1];
    for (auto [i, j] : R) {
        g[i].push_back(j);
        g[j].push_back(i);
    }
    vector<long long> tin(n + 1), tout(n + 1);
    long long timer = 0;
    vector<vector<long long>> up(20, vector<long long>(n + 1));
    function<void(long long, long long)> dfs = [&](long long v, long long p) {
        tin[v] = timer++;
        up[0][v] = p;
        for (long long lg = 1; lg < 20; ++lg) {
            up[lg][v] = up[lg - 1][up[lg - 1][v]];
        }
        for (auto to : g[v]) {
            if (to == p) continue;
            dfs(to, v);
        }
        tout[v] = timer++;
        return;
    };
    dfs(1, 0);
    auto parent = [&](long long u, long long v) {
        return tin[u] <= tin[v] && tout[v] <= tout[u];
    };
    auto lca = [&](long long u, long long v) {
        if (parent(u, v)) return u;
        if (parent(v, u)) return v;
        for (long long lg = 19; lg >= 0; --lg) {
            if (up[lg][u] != 0 && parent(up[lg][u], v) == false) {
                u = up[lg][u];
            }
        }
        return up[0][u];
    };
    cc_hash_table<long long, vector<pair<long long, long long>>> mp;
    long long m = S.size();
    vector<int> ans(m);
    for (long long i = 0; i < m; ++i) {
        long long st = S[i], fn = T[i];
        //cout << "!" << st << ' '<< fn << '\n';
        long long l = lca(st, fn);
        vector<long long> way, tmp;
        while (true) {
            way.push_back(st);
            if (st == l) break;
            st = up[0][st];
        }
        while (true) {
            if (fn == l) break;
            tmp.push_back(fn);
            fn = up[0][fn];
        }
        reverse(tmp.begin(), tmp.end());
        for (auto z : tmp) way.push_back(z);

        for (long long j = 0; j < way.size(); ++j) {
            mp[j + D[i]].push_back({way[j], i});
        }
    }
    cc_hash_table<long long, bool> mapa;
    for (auto [key, vec] : mp) {
        long long sum = 0;
        mapa.clear();
        for (auto [ver, idx] : vec) {
            mapa[ver] = mapa[ver] | I[idx];
        }
        for (auto [ver, idx] : vec) {
            if (mapa[ver]) I[idx] = true;
            ans[idx] += I[idx];
        }
    }
    return ans;

    //cout << 2 * 3 * 4 * 5 * 6 * 7 << endl;
}*/
std::vector<int> solve(std::vector<int> A) {
    int n = A.size();
    bool dp[(1 << n)]; memset(dp, false, sizeof dp);
    int sum[(1 << n)]; memset(sum, 0, sizeof sum);
    int from[(1 << n)]; memset(from, 0, sizeof from);
    dp[0] = true;
    for (int mask = 0; mask < n; ++mask) {
        for (int i = 0; i < n; ++i) {
            if (mask & (1 << i)) sum[mask] += A[i];
        }
    }
    int s = 0;
    for (auto i : A) s += i;
    int delta_min = 1e9;
    int tmask = -1;
    for (int mask = 0; mask < (1 << n); ++mask) {
        if (2 * sum[mask] >= s) {
            int f1 = sum[mask], f2 = s - sum[mask];
            if (delta_min > abs(f1 - f2)) {
                delta_min = abs(f1 - f2);
                tmask = mask;
            }
            continue;
        }
        for (int i = 0; i < n; ++i) {
            if (!(mask & (1 << i))) {
                dp[mask | (1 << i)] = true;
                from[mask | (1 << i)] = i;
            }
        }
    }

    vector<int> ans;
    vector<bool> used(n);
    while (tmask != 0) {
        used[from[tmask]] = true;
        ans.push_back(from[tmask]);
        tmask ^= (1 << from[tmask]);
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < n; ++i) {
        if (!used[i]) ans.push_back(i);
    }
    return ans;
}