#include "partition.h"
#include<iostream>
#include<vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
int long long x,nr,n,p,i1,i2,a[1100000],b[1100000],ok,c[50],i3,fr[50];
short int f[100001000];

vector<int> solve(vector<int> A)
{
    for (int i=0; i<=25; i++)
    f[(int)pow(2,i)]=i+1;

    vector<int>sol;
    p=0;
    sol.clear();
    n=A.size();
    i1=i2=i3=0;
    while (A.size())
    {
        x=A.back();
        A.pop_back();
        p++;
        nr=f[x];
        if (fr[nr]) a[++i1]=n-p+1,b[++i2]=n-fr[nr]+1,fr[nr]=0;
        else fr[nr]=p;
    }

    for (int i=1; i<=26; i++)
    if (fr[i]) c[++i3]=fr[i],fr[i]=0;


    for (int i=1; i<i3/2; i++)
    a[++i1]=n-c[i]+1;
    if (i3)
    {
        a[++i1]=n-c[i3]+1;
        if (i3>1)
        for (int i=i3/2; i<i3; i++)
        b[++i2]=n-c[i]+1;
    }

    for (int i=1; i<=i1; i++)
    sol.push_back(a[i]-1);

    for (int i=1; i<=i2; i++)
    sol.push_back(b[i]-1);

    return sol;
}
/*
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t ;
    for (int test=1; test<=t; test++) {
        int n;
        cin >> n ;
        vector <int> a(n);
        for (int i=0; i<n; i++) {
            cin >> a[i] ;
        }

        for (auto ind : solve(a)) {
            cout << ind << " ";
        }
        cout << endl ;
    }
    cout << endl ;
    return 0;
}
*/
