#include <vector>
using namespace std;

vector<int> f(30000001, -1);

vector<int> solve(vector<int> a){
    vector<int> sol[2];
    for (int i = 0; i < a.size(); i++){
        if (f[a[i]] != -1) sol[0].push_back(f[a[i]]), sol[1].push_back(i), f[a[i]] = -1;
        else f[a[i]] = i;
    }

    int mx = 0, mi = 0;
    for (int i = 0; i < a.size(); i++){
        if (f[a[i]] != -1) mx = max(mx, a[i]);
    }

    int s = 1;
    for (int i = a.size(); i >= 0; i--){
        if (f[a[i]] != -1 && a[i] != mx) sol[s].push_back(i), s = !s;
        if (f[a[i]] != -1 && a[i] == mx) mi = i;
        f[a[i]] = -1;
    }

    sol[0].push_back(mi);

    for (int i : sol[1]){
        sol[0].push_back(i);
    }

    return sol[0];
}
