#include "partition.h"
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;

vector<int> freq(1000001);
std::vector<int> solve(std::vector<int> A) {
	vector<pair<int, int>> aNorm;
	for (int i = 0; i < A.size(); i++) {
		aNorm.push_back({A[i], i});
	}
	sort(aNorm.begin(), aNorm.end());
	int prev = 0;
	int current = 0;
	std::fill(freq.begin(), freq.begin() + A.size(), 0);
	for (auto &[x, i] : aNorm) {
		if (x != prev) {
			current++;
		}
		prev = x;
		x = current;
		freq[x]++;
	}
	bool allEven = true;
	for (int i = 1; i <= current; i++) {
		if (freq[i] % 2 != 0) {
			allEven = false;
		}
	}
	vector<int> ans;
	if (allEven) {
		for (int i = 0; i < aNorm.size(); i++) {
			freq[aNorm[i].first]--;
			if (freq[aNorm[i].first] % 2 == 0) {
				ans.push_back(aNorm[i].second);
			}
		}
		for (int i = 0; i < aNorm.size(); i++) {
			freq[aNorm[i].first]++;
			if (freq[aNorm[i].first] % 2 == 1) {
				ans.push_back(aNorm[i].second);
			}
		}
	}
	return ans;
}
