#include "partition.h"
#include <map>
using namespace std;

std::vector<int> solve(std::vector<int> A) {
    map<int, int> unique;
    vector<int> res;

    for (int i = 0; i < A.size(); i++) {
        unique[A[i]]++;
    }   

    for (auto& [k, v] : unique) {
        v /= 2;
    }

    for (int i = 0; i < A.size(); i++) {
        if (unique[A[i]]) {
            res.push_back(i);
            unique[A[i]]--;
        }
    }

    for (int i = 0; i < A.size(); i++) {
        unique[A[i]]++;
    }   

    for (auto& [k, v] : unique) {
        v /= 2;
    }

    for (int i = A.size() - 1; i >= 0; i--) {
        if (unique[A[i]]) {
            res.push_back(i);
            unique[A[i]]--;
        }
    }
    
    return res;
}
