#include <bits/stdc++.h>
using namespace std;
vector <long long> res,niz;
long long N,k;
long long dir[2000045],br[2000023];
vector<long long> solve(vector<long long> A){
    N=A.size();
    for(int i=0;i<N;i++){
        dir[A[i]]++;
    }
    for(int i=0;i<N;i++){
        if(dir[A[i]]>(br[A[i]]*2)){
            res.push_back(i);
            br[A[i]]++;
        }
    }
    cout << endl;
    for(int i=N-1;i>=0;i--){
        if(br[A[i]]<dir[A[i]]){
            res.push_back(i);
            br[A[i]]++;
        }
    }

    return res;
}