#include "partition.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;

std::vector<int> solve(std::vector<int> A) {
  int n = A.size();
  vector <int> f, s;
  gp_hash_table <int, int> buff;
  for (int i = 0; i < n; i++) {
    if (buff.find(A[i]) == buff.end()) {
      buff[A[i]] = i + 1;
    } else {
      f.push_back(buff[A[i]] - 1);
      s.push_back(i);
      buff.erase(A[i]);
    }
  }
  vector <pair <int, int>> a;
  for (auto& [x, i] : buff) {
    a.emplace_back(x, i - 1);
  }
  sort(a.begin(), a.end());
  ll sum = 0;
  for (auto [x, i] : a) {
    sum += x;
  }
  if (a.size() % 2 == 1) {
    for (int i = 0; i < (int)a.size(); i++) {
      if (i % 2 == 0) f.push_back(a[i].second);
      else s.push_back(a[i].second);
    }
  } else {
    ll cur = 0;
    for (int i = 0; i < (int)a.size(); i += 2) {
      cur += a[i].first;
    }
    int i = (int)a.size() - 2;
    while (cur * 2 < sum) {
      cur += a[i+1].first - a[i].first;
      i -= 2;
    }
    i += 2;
    for (int j = 0; j < (int)a.size(); j++) {
      if (j % 2 == (j >= i)) {
        f.push_back(a[j].second);
      } else {
        s.push_back(a[j].second);
      }
    }
  }
  vector <int> ans;
  for (int i : f) {
    ans.push_back(i);
  }
  for (int i : s) {
    ans.push_back(i);
  }
  return ans;
}
