#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
#define ll long long
int last[33554433];
int pr[33554433];
std::vector<int> solve(std::vector<int> A)
{
    vector<int> st, dr;
    for(int i = 0; i < A.size(); i++)
        last[i] = 0;
    int p2 = 1;
    for(int i = 0; i <= 25; i++, p2 <<= 1)
        pr[p2] = i + 1; 
    for(int i = 0; i < A.size(); i++)
    {
        if(last[A[i]])
        {
            st.push_back(last[A[i]] - 1);
            dr.push_back(i);
            last[A[i]] = 0;
        }
        else
            last[A[i]] = i + 1;
    }
    vector<int> rem;
    vector<int> isbit(27, 0);
    for(int i = 0; i <= 25; i++)
        if(last[A[i]])
            isbit[pr[A[i]] - 1] = last[A[i]], last[A[i]] = 0;
    for(int i = 0; i <= 25; i++, p2 <<= 1)
        if(isbit[i])
            rem.push_back(isbit[i] - 1);
    long long sumst = 0, sumdr = 0;
    for(int i = 0; i < (int) rem.size() / 2 - 1; i++)
        st.push_back(rem[i]);
    st.push_back(rem[(int) rem.size() - 1]);
    for(int i = max(0, (int) rem.size() / 2 - 1); i < (int) rem.size() - 1; i++)
        st.push_back(rem[i]);
    for(auto it : dr)
        st.push_back(it);
    return st;
}