#include "partition.h"
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const ll N=2e6;
ll m[50];
std::vector<int> solve(std::vector<int> A) {
    vector <int> ans;
	ans.clear();
	vector <int> ans1;
	ans1.clear();
    pair <int,int> p[N+5];
    ll n=A.size();
    for (int i=0; i<A.size(); i++){
    	p[i]=make_pair(A[i],i);
    	ll z=log2(A[i]);
    	m[z]++;
	}
	sort(p,p+n);
	for (int i=n-1; i>=0; i--){
		ll z=log2(p[i].f);
		if (m[z]%2==0){
			ll x=m[p[i].f]; ll z=0;ll ind=i;
			while (z<x/2){
				z++;
				ans.pb(p[ind].s); ind--;
			}
			z=0;
			while (z<x/2){
				z++;
				ans1.pb(p[ind].s); ind--;
			}
			i=ind;
		} else {
			n=i+1; break;
		}
	}
	for (int i=0; i<(n-1)/2; i++) ans.pb(p[i].s);
	ans.pb(p[n-1].s);
	for (int i=(n-1)/2; i<n-1; i++) ans.pb(p[i].s); 
	for (int i=0; i<ans1.size(); i++) ans.pb(ans1[i]);
	return ans;
}
