#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) (x).begin(),(x).end()

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
// #define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int, int>;
using tii = tuple<int, int, int>;

std::vector<int> solve(std::vector<int> A) {
	if(sz(A) == 1) {
		return {0};
	}
	ll N = sz(A);
	vector<ll> idx(N);
	iota(all(idx), 0);
	// sort(all(idx), [&](int a, int b) { return A[a] < A[b]; });
	
	ll totalsum = accumulate(all(A), 0ll);
	ll sum;
	ll r, l;
	
	Restart:
	sum = 0;
	r = sz(A), l = 0;
	while(sum * 2 < totalsum) sum += A[idx[--r]];
	// cerr << r << ' ' << N - r << ' ' << N / 2 << '\n';
 	if((N - r) > N / 2) {
		reverse(all(idx));
		sum = 0;
		goto Restart;
	}
	
	while(l + (N - r) < N / 2) {
		sum -= A[idx[r++]];
		while(sum * 2 < totalsum) sum += A[idx[l++]];
	}
	l = min(l, r - 1);
	// cerr << l << ' ' << r << '\n';
	
	vector<int> rez;
	rez.reserve(N);
	for(int i = N - 1; i >= r; i--) rez.emplace_back(idx[i]);
	for(int i = 0; i < l; i++) rez.emplace_back(idx[i]);
	if(sz(rez) != N / 2)
		rez.insert(begin(rez) + N / 2 - 1, idx[r - 1]);
	else
		r++;
	for(int i = l; i < r - 1; i++) rez.emplace_back(idx[i]);
	
	return rez;
}
