#include <bits/stdc++.h>
#define ll long long
using namespace std;

vector<int> ids[26];

vector<int> solve(vector<int> v){
    for(int i = 0; i < 26; i++) ids[i].clear();
    int n = v.size();
    for(int i = 0; i < n; i++){
        int lg = 0;
        while(v[i] > 1){
            lg++;
            v[i] /= 2;
        }
        ids[lg].push_back(i);
    }
    vector<pair<int, int>> ramas;
    for(int i = 0; i < 26; i++){
        if(ids[i].size() & 1){
            ramas.push_back({ids[i].back(), i});
        }
    }
    vector<int> ans;
    for(int i = 0; i < 26; i++){
        for(int j = 0; j < ids[i].size() / 2; j++){
            ans.push_back(ids[i][j]);
        }
    }
    //acum punem "ramas"
    if(ramas.size() & 1){
        //cineva are cu 1 mai mult
        for(int i = 0; i < (ramas.size() - 1) / 2; i++){
            ans.push_back(ramas[i].first);
        }
        ans.push_back(ramas.back().first);
    }
    else if(ramas.size() != 0){
        for(int i = 0; i < ramas.size() / 2 - 1; i++){
            ans.push_back(ramas[i].first);
        }
        ans.push_back(ramas.back().first);
    }
    //acum pun ce ia a doua
    if(ramas.size() & 1){
        for(int i = (ramas.size() - 1) / 2; i < ramas.size() - 1; i++){
            ans.push_back(ramas[i].first);
        }
    }
    else if(ramas.size() != 0){
        for(int i = ramas.size() / 2 - 1; i < ramas.size() - 1; i++)
            ans.push_back(ramas[i].first);
    }
    //pun dublurile initiale
    for(int i = 0; i < 26; i++){
        for(int j = ids[i].size() / 2; j < ids[i].size() - (ids[i].size() % 2); j++){
            ans.push_back(ids[i][j]);
        }
    }
    return ans;
}
