#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 2e6 + 10;
long long pref_sm[N];
int n;
long long get(int l, int r) {
    if (l <= r) return pref_sm[r] - pref_sm[l - 1];
    return pref_sm[n] - pref_sm[l - 1] + pref_sm[r];
}
vector<int> solve(vector<int> A) {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    long long s = 0;
    for (auto &it : A) {
        s += it;
    }
    n = (int)A.size();
    vector<pair<int, int>> esim(n);
    if (n == 1) return { 0 };
    if (n == 2) {
        if (A[0] > A[1]) return { 0, 1 };
        return { 1, 0 };
    }
    for (int i = 0; i < n; i++) {
        esim[i] = { A[i], i };
    }
    int q = 10;
    while (q--) {
        shuffle(esim.begin(), esim.end(), rng);
        int uzac = (n - 1) / 2;
        for (int i = 1; i <= n; i++) {
            pref_sm[i] = A[esim[i - 1].second];
            pref_sm[i] += pref_sm[i - 1];
        }
        vector<int> ans(n);
        for (int i = 0; i < n; i++) {
            ans[i] = i;
        }
        for (int i = 1; i <= n; i++) {
            if (get(i, i + uzac) * 1ll * 2 >= s && get(i, i + uzac - 1) * 1ll * 2 < s) {
                for (int j = 0; j < n; j++) {
                    ans[j] = esim[(j + i - 1) % n].second;
                }
                return ans;
            }
        }
    }
    return {};
}
/*
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    for (int n = 8; n <= 15; n++) {
        int t = 1000;
        while (t--) {
            vector<int> v(n);
            int s = 0;
            for (auto &it : v) {
                it = rng() % 10 + 1;
                s += it;
            }
            vector<int> ord = solve(v);
            int cur = 0;
            int ind = 0;
            for (int i = 0; i < (int)ord.size(); i++) {
                cur += v[ord[i]];
                if (2 * cur >= s) {
                    ind = i;
                    break;
                }
            }
            if (ind != (n - 1) / 2 && ind != (n - 2) / 2) {
                cout << "! ";
                cout << n << "\n";
                for (auto it : v) {
                    cout << it << " ";
                }
                cout << "\n";
                for (auto it : ord) {
                    cout << it << " ";
                }
                cout << "\n";
                return 0;
            }
        }
    }
}
*/