#include "partition.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX = 3e7 + 5;
const int maxn = 2e6 + 5;

int n;
int a[maxn];
vector<int> positions[MAX];

void reset()
{
    for (int i = 1; i <= n; ++i)
    {
        positions[a[i]].clear();
    }
}

std::vector<int> solve(std::vector<int> A)
{
    reset();
    n = A.size();
    for (int i = 0; i < n; ++i)
    {
        a[i + 1] = A[i];
    }

    int mx = 0;

    for (int i = 1; i <= n; ++i)
    {
        mx = max(mx, a[i]);
        positions[a[i]].push_back(i);
    }

    vector<int> ans(n);
    int l = 0, r = n - 1;

    for (int i = 1; i <= n; ++i)
    {
        if (positions[a[i]].empty()) continue;

        for (int j = 0; j < positions[a[i]].size(); j += 2)
        {
            ans[l++] = positions[a[i]][j];
            ans[r--] = positions[a[i]][j + 1];
        }

        positions[a[i]].clear();
    }

    for (int i = 0; i < n; ++i)
    {
        --ans[i];
    }

    return ans;
}
