#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::vector<int>> m;
    std::vector<int> answer;

    for (int i = 0; i < N; i++) {
        m[A[i]].push_back(i);
    }

    for (const std::pair<int, std::vector<int>> &p : m) {
        for (int i = 0; i < p.second.size() / 2; i++) {
            answer.push_back(p.second[i]);
        }
    }
    
    for (const std::pair<int, std::vector<int>> &p : m) {
        for (int i = p.second.size() / 2; i < p.second.size(); i++) {
            answer.push_back(p.second[i]);
        }
    }
    
    return answer;
}
