#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<iomanip>
using namespace std;
using ll = long long;
using db = double;

bool cmp(pair<int, int>a, pair<int, int>b) {
	return a.first > b.first || a.first == b.first && a.second < b.second;
}
void solve()
{
	int N;
	cin >> N;
	
	vector<int>tree(N);
	for (int i = 0; i < N; ++i) {
		cin >> tree[i];
	}
	if (N == 1) {
		cout << tree[0] << "\n";
		return;
	}
	int h = 0;
	while ((1 << h) < N) ++h;
	vector<pair<int, int>>a;
	map<int, int>cnt;
	for (int i = 0; i < N; ++i) {
		cnt[tree[i]] ++;
	}
	if (cnt.size() != (N + 1) / 2) {
		cout << "-1\n";
		return;
	}
	for (auto [x, y] : cnt) {
		a.push_back({ y, x });
	}
	sort(a.begin(), a.end(), cmp);
	int n = (N + 1) / 2;
	vector<int>ans1(n);
	int cur = 1;
	for (int i = 0; i < h; ++i) {
		int v = (n / (1 << i)) % n;
		for (int j = v; j < n; j += 2 * n / (1 << i)) {
			ans1[j] = cur; cur++;
		}
	}
	vector<int>fin(ans1.size());
	for (int i = 0; i < n; ++i) {
		fin[i] = a[ans1[i] - 1].second;
	}
	int l = 0, r = n;
	vector<int>fintree(2 * n - 1);
	for (int i = 0; i < n; ++i) {
		fintree[n + i - 1] = fin[i];
	}
	for (int i = n - 2; i >= 0; --i) {
		fintree[i] = min(fintree[2 * i + 1], fintree[2 * i + 2]);
	}
	sort(fintree.begin(), fintree.end());
	sort(tree.begin(), tree.end());
	if (tree == fintree) {

		for (auto x : fin) {
			cout << x << ' ';
		}
	}
	else cout << "-1\n";
}

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0)->sync_with_stdio(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}