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

std::vector<int> solve(std::vector<int> A) {

    const int N = A.size();

    std::unordered_map<int, std::pair<int, int>> m;
    std::vector<int> answer;

    for (int i = 0; i < N; i++) {
        if (m.find(A[i]) == m.end()) {
            m[A[i]].first = i;
            answer.push_back(i);
        } else {
            m[A[i]].second = i;
        }
    }

    for (const std::pair<int, std::pair<int, int>> &p : m) {
        answer.push_back(p.second.second);
    }

    return answer;
}
