#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

std::vector<int> solve(std::vector <int> a){
    ll n = a.size();
    vector <pair <ll,ll> > b(n);
    ll sum = 0;
    ll ok = 1;
    for (int i = 0; i < n; i++){
         b[i] = {a[i], i};
         sum += a[i];
         if(a[i] != i + 1)
            ok = 0;
    }
    if(ok == 1){
        reverse(b.begin(), b.end());
    }
    else
    sort(b.rbegin(), b.rend());
    ll so =10e12;
    vector <int> perm;
    vector <int> p;
    vector <int> p1;
    ll s = 0, s1 = 0;
    for (int j = 1; j < n; j++){
        if(p.size() == p1.size()){
                if(2*(s + b[j].first) <= sum)
                {
                    p.push_back(b[j].second);
                    s += b[j].first;
                }
                else {
                    s1 += b[j].first;
                    p1.push_back(b[j].second);
                }
            }
            else {
                if(2*(s1 + b[j].first) <= sum)
                {
                    p1.push_back(b[j].second);
                    s1 += b[j].first;
                }
                else {
                    s += b[j].first;
                    p.push_back(b[j].second);
                }
            }
        }
        if(p.size() > p1.size()){
            for (auto u : p1)
            perm.push_back(u);
        perm.push_back(b[0].second);
        for (auto u : p)
            perm.push_back(u);

        }
        else {
        for (auto u : p)
            perm.push_back(u);
        perm.push_back(b[0].second);
        for (auto u : p1)
            perm.push_back(u);
        }
    return perm;
}