#include "partition.h"

#pragma GCC optimize("O3")
#pragma GCC target("avx2,bmi2,popcnt,lzcnt")

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

std::vector<int> solve(std::vector<int> A) {
  int n = A.size();
  vector <pair <int, int>> a;
  a.reserve(n);
  int mx = 0;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, A[i]);
  }
  int idx = 0;
  for (int i = 0; i < n; i++) {
    if (A[i] == mx) idx = i;
  }
  for (int i = 0; i < n; i++) {
    sum += A[i];
  }
  for (int i = 0; i < n; i++) {
    if (i != idx) {
      a.push_back({A[i], i});
    }
  }
  a.push_back({mx, idx});
  for (int i = 0; i < n-1; i += 2) {
    if (a[i].first > a[i+1].first) {
      swap(a[i], a[i+1]);
    }
  }
  vector <int> f, s;
  f.reserve(n/2);
  s.reserve(n/2);
  ll cur = 0;
  for (int i = 0; i < n; i += 2) {
    cur += a[i].first;
  }
  int i = n - 2 - n % 2;
  while (cur * 2 < sum) {
    cur += a[i+1].first - a[i].first;
    i -= 2;
  }
  i += 2;
  for (int j = 0; j < i; j += 2) {
    f.push_back(a[j].second);
  }
  for (int j = 1; j < i; j += 2) {
    s.push_back(a[j].second);
  }
  for (int j = i; j < n-n%2; j += 2) {
    s.push_back(j);
  }
  for (int j = i+1; j < n; j += 2) {
    f.push_back(j);
  }
  if (n % 2 == 1) f.push_back(a.back().second);
  vector <int> ans;
  ans.reserve(n);
  for (int i : f) {
    ans.push_back(i);
  }
  for (int i : s) {
    ans.push_back(i);
  }
  return ans;
}
