#include "partition.h"
#include <vector>
#include <utility>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <iomanip>
#include <random>
#include <chrono>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <cstring>

using namespace std;

#define ll long long
#define pb push_back
#define fr first
#define sc second

const int N = 200005;
const ll oo = 1000000000000000, MOD = 1000000007;

int a[N];

std::vector<int> solve(std::vector<int> A) {
	int n = A.size();
	map<int, vector<int>> ind1;
	vector<int> dis;
	for (int i = 1; i <= n; ++i) {
		a[i] = A[i - 1];
		ind1[a[i]].pb(i);
		if (ind1[a[i]].size() == 1) {
			dis.pb(a[i]);
		}
	}
	vector<int> skizb, verj;
	for (int num : dis) {
		int sz = ind1[num].size();
		for (int i = 0; i < ind1[num].size(); ++i) {
			if (i < sz / 2) {
				skizb.pb(ind1[num][i]);
			}
			else {
				verj.pb(ind1[num][i]);
			}
		}
	}
	vector<int> pat;
	for (int num : skizb) {
		pat.pb(num - 1);
	}
	for (int num : verj) {
		pat.pb(num - 1);
	}
	return pat;
}
