#include "partition.h"
#include <bits/stdc++.h>
using namespace std;

std::vector<int> solve(std::vector<int> A)
{
    int n = A.size();

    map<int, vector<int> > m;

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

    vector<int> v1, v2;

    for(pair<int, vector<int> > p : m)
    {
        for(int i=0;                 i<p.second.size() / 2; i++)v1.push_back(p.second[i]);
        for(int i=p.second.size()/2; i<p.second.size();     i++)v2.push_back(p.second[i]);
    }

    vector<int> v = v1;
    for(int &num : v2)v.push_back(num);

    return v;
}