#include <bits/stdc++.h>
#pragma GCC optimize("O3", "Ofast", "unroll-loops")
#pragma GCC target("avx2")
long long lim[2];
long long add[2];
std::vector<int> solve(std::vector<int> a) {
  add[0] = add[1] = 0;
  std::vector<bool> type(a.size());
  std::vector<std::vector<int>> idx(26);
  long long s = 0;
  for( int i = 0; i < a.size(); i++ ) {
    int lg = 0;
    while((1 << lg) < a[i])
      lg++;
    idx[lg].push_back(i);
    s += a[i];
  }
  std::vector<std::pair<int, int>> v;
  for( int lg = 0; lg <= 25; lg++ ) {
    for( int i = 0; i < idx[lg].size(); i++ )
      v.push_back({(1 << lg), idx[lg][i]});
  }
  int n = a.size();
  int half = (n + 1) / 2;
  long long currs = 0;
  for( int i = 0; i < half; i++ ) {
    currs += v[i].first;
  }
  int idx1 = half - 1, idx2 = n - 1;
  while(currs < (s + 1) / 2) {
    currs = currs - v[idx1].first + v[idx2].first;
    std::swap(v[idx1], v[idx2]);
    idx1--;
    idx2--;
  }


  std::vector<int> ret;
  for( int i = 0; i < n; i++ ) {
    ret.push_back(v[i].second);
  }
  return ret;
}
