#include <bits/stdc++.h>
#define INF 1000000000
#define fi first
#define se second
#include "partition.h"
//#pragma GCC optimize ("Ofast", "unroll-loops")
//#pragma GCC target ("avx2")
using namespace std;

vector<int> solve(vector<int> a) {
    int tot=0, n=a.size(), minim=INF, i;
    vector<int>ans;
    map<int, int> h;
    h.clear();
    vector<int>v, t;
    v.resize(26);
    int poww=(1<<4), ok=0;
    ans.resize(n);
    int p1=-1, p2=n, j, x;
    for (i=3; i>=0; i--) {
        poww/=2;
        for (auto x:a) {
            if (x==poww) v[i]++;
        }
        int nr=0;
        if (v[i]==0) continue;
        if (v[i]%2==0) {
            for (j=0; j<n; j++) {
                x=a[j];
                if (x==poww) {
                    nr++;
                    if (nr<=v[i]/2) ans[++p1]=j;
                    else ans[--p2]=j;
                }

            }
        }
        else {
            if (ok==0) {
                for (j=0; j<n; j++) {
                    x=a[j];
                    if (x==poww) {
                        nr++;
                        if (nr<=v[i]/2+1) v[++p1]=j;
                        else v[--p2]=j;
                    }

                }
                ok=1;
            }
            else {
                for (j=0; j<n; j++) {
                    x=a[j];
                    if (x==poww) {
                        nr++;
                    }
                    if (nr<=v[i]/2) ans[++p1]=j;
                    else ans[--p2]=j;
                }
            }
        }
    }
    return ans;
}

