#include "partition.h"
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define ll long long
using namespace std;

vector<int> solve(vector<int> a) {
    vector <int> lg;
    for (int &i : a) {
        int x = -1;
        while (i) {
            x++;
            i /= 2;
        }
        lg.pb(x);
    }
    int n = a.size();
    vector <vector <int>> cnt(27);
    for (int i = 0; i < n; i++) {
        cnt[lg[i]].pb(i);
    }
    vector <int> x, y, z;
    for (int i = 0; i <= 26; i++) {
        if (cnt[i].empty()) continue;
        int s = cnt[i].size();
        s /= 2;
        for (int j = 0; j < s; j++) {
            x.pb(cnt[i][j]);
        }
        for (int j = s; j < cnt[i].size() / 2 * 2;j++) {
            y.pb(cnt[i][j]);
        }
        if (cnt[i].size() % 2) z.pb(cnt[i].back());
    }
    n = z.size();
    for (int i = 0; i < ceil(1. * n / 2) - 1; i++) x.pb(z[i]);
    x.pb(z.back());
    for (int i = ceil(1. * n / 2) - 1; i < n - 1; i++) y.pb(z[i]);
    vector <int> ans;
    for (int &i : x) ans.pb(i);
    for (int &i : y) ans.pb(i);
    return ans;
}

