#include<bits\stdc++.h>
#define ll long long
#define ls u << 1
#define rs u << 1 | 1
#define sz(x) (int) x.size()
#define pb push_back
using namespace std;
const int N = 2e5 + 15;
int n, a[N], ans[N], tr[N];
map<int, int> cnt;
set<int> st[N];
int ptr = 0;
void check(int u, int l, int r) {
	if(l == r) {
		return;
	}
	if(min(tr[ls], tr[rs]) != tr[u]) {
		cout << "-1";
		exit(0);
	}
	int m = (l + r) / 2;
	check(ls, l, m);
	check(rs, m + 1, r);
}
int main() {
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	for(auto it : cnt) {
		st[it.second].insert(it.first);
	}
	int h = 0;
	while((1 << (h + 1)) - 1 <= n) {
		h++;
	}
	priority_queue<pair<pair<int, int>, pair<int, int>>> q;
	q.push({{h, 1}, {1, (1 << (h - 1))}});
	while(!q.empty()) {
		pair<pair<int, int>, pair<int, int>> vt = q.top();
		int u = vt.first.second;
		int l = vt.second.first, r = vt.second.second, ht = vt.first.first;
		q.pop();
		int m = (l + r) / 2;
		if(!tr[u]) {
			int mn = (u == 1 ? 0 : tr[(int) u / 2]);
			if(sz(st[ht]) == 0) {
				cout << "-1";
				exit(0);
			}
			auto it = st[ht].lower_bound(mn);
			if(it == st[ht].end()) {
				cout << "-1";
				exit(0);
			}
			tr[u] = *it;
			st[ht].erase(it);
		}
		if(l == r) {
			ans[l] = tr[u];
			continue;
		}
		tr[ls] = tr[u];
		q.push({{ht - 1, ls}, {l, m}});
		q.push({{ht - 1, rs}, {m + 1, r}});
	}
	check(1, 1, (1 << (h - 1)));
	for(int i = 1; i <= (1 << (h - 1)); i++) {
		cout << ans[i] << ' ';
	}
}
