#include <bits/stdc++.h>
#include "partition.h"
using namespace std;
vector<int> solve2(vector<int> v)
{
    vector<int>ans;
    int n=v.size();
    for(int i=0;i<(n-1)/2;i++)
    {
        ans.push_back(v[i]);
    }
    for(int i=n-1;i>=(n-1)/2;i--)
    {
        ans.push_back(v[i]);
    }
    return ans;
}
vector<int> solve(vector<int> a)
{
    map<int,int>m;
    int n=a.size();
    vector<int>res1,res2,res3;
    for(int i=0;i<n;i++)
    {
        if(m[a[i]]==0)
        {
            m[a[i]]=i+1;
        }
        else
        {
            res1.push_back(m[a[i]]-1);
            res2.push_back(i);
            m[a[i]]=0;
        }
    }
    vector<int>v2;
    int k=1;
    for(int i=0;i<=25;i++)
    {
        if(m[k]!=0)v2.push_back(m[k]-1);
        k=k*2;
    }
    res3=solve2(v2);
    for(auto i:res3)res1.push_back(i);
    for(auto i:res2)res1.push_back(i);
    return res1;
}
