#include "partition.h"
#include<iostream>
#include<vector>
#include <math.h>
#include <algorithm>
#include <numeric>
std::vector<int> solve(std::vector<int> A) {
    int sum = accumulate(A.begin(), A.end(), 0);
    std::vector<std::vector<int>> cnt(sum);

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

    for (int i = 0; i < A.size(); i++) {
        int cntr = cnt[i].size() - 1;
        for (int j = 0; j < cnt[i].size(); j += 2) {
            std::cout << cnt[i][cntr--] << " ";
            cnt[i].pop_back();
        }
    }
for (int i = 0; i < A.size(); i++) {
        int cntr = cnt[i].size() - 1;
        for (int j = 0; j < cnt[i].size(); j += 2) {
            std::cout << cnt[i][cntr--] << " ";
            cnt[i].pop_back();
        }
    }

    return {};
}
