#include "partition.h"

#pragma GCC optimize("O3,unroll-loops")
#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 <int> f, s;
  vector <int> idx(26, -1);
  for (int i = 0; i < n; i++) {
    int x = __builtin_ctz(A[i]);
    if (idx[x] != -1) {
      f.push_back(idx[x]);
      s.push_back(i);
      idx[x] = -1;
    } else {
      idx[x] = i;
    }
  }
  vector <pair <int, int>> a;
  for (int i = 0; i <= 25; i++) {
    if (idx[i] != -1) {
      a.emplace_back(1 << i, idx[i]);
    }
  }
  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;
}
