#include "partition.h"
#include <bits/stdc++.h>
using namespace std;

std::vector<int> solve(std::vector<int> A) {
    int n = A.size();
    vector<vector<int>>mp(30);
    for(int i = 0;i<n;i++){
		int cnt = 0;
		while(A[i] > 1){
			cnt += 1;
			A[i] /= 2;
		}
		mp[cnt].push_back(i);
	}
	
	vector<int>res, ans, ans2;
	long long sum = 0;
	for(int i = 0;i<=25;i++){
		if(mp[i].size() % 2 == 1){
			res.push_back(mp[i].back());
			//~ sum += mp[i].back();
		}
		for(int j = 1;j<mp[i].size();j+=2){
			ans.push_back(mp[i][j-1]);
			ans2.push_back(mp[i][j]);
		}
	}
	
	if(!res.empty()){
		for(int i = 0;i<(int)(res.size()-1)/2;i++){
		ans.push_back(res[i]);
		}
		ans.push_back(res.back());

		for(int i = (res.size()-1)/2;i<(int)res.size()-1;i++){
			ans2.push_back(res[i]);
		}
	}
	
	vector<int>u;
	for(auto to : ans)u.push_back(to);
	for(auto to : ans2)u.push_back(to);
	
	return u;
	
	
}
