#include "partition.h"
#include <bits/stdc++.h>
using namespace std;
const int N=3e7+1;
vector<int> solve(vector<int> A) {
    bool b[N];
    for (int i=0; i<N; i++) {
        b[i] = false;
    }
    bool bl=true;
    for (int i=0; i<A.size(); i++) {
        if (A[i]!=(1<<i)) {
            bl=false;
            break;
        }
    }
    vector<int> cur1, cur2, v;
    if (bl) {
        for (int i=A.size()-2; i>=0; i--) {
            v.push_back(i);
        }
        v.push_back(A.size()-1);
        return v;
    }


    for (int i=0; i<A.size(); i++) {
        if (b[A[i]]) {
            b[A[i]] = false;
            cur1.push_back(i);
        }else {
            b[A[i]] = true;
            cur2.push_back(i);
        }
    }
    for (auto it : cur2)  v.push_back(it);
    for (auto it: cur1) v.push_back(it);
    return v;
}
