#include "partition.h"
#include<iostream>
#include<vector>
#include <map>
using namespace std;
vector<int>sol;
int p,x,i1,a[100100];
int f[30010000];
vector<int> solve(vector<int> A)
{
    while (A.size())
    {
        p++;
        x=A.back();
        A.pop_back();

        if (f[x]) sol.push_back(p-1),a[++i1]=f[x],f[x]=0;
        else f[x]=p;
    }

    for (int i=1; i<=i1; i++)
    sol.push_back(a[i]-1);

    return sol;
}/*

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t ;
    for (int test=1; test<=t; test++) {
        int n;
        cin >> n ;
        vector <int> a(n);
        for (int i=0; i<n; i++) {
            cin >> a[i] ;
        }

        for (auto ind : solve(a)) {
            cout << ind << " ";
        }
        cout << endl ;
    }
    cout << endl ;
    return 0;
}*/
