#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e16;
const int mod = 1e9+7;
const int maxn = 2e5 + 12;
int k = 0, p;
map<int, int> m;
queue<int> t[20];
int out[maxn], cmp[maxn * 4];
void go(int v, int l, int r) {
	//cout << cmp[v] << ' ';
	if(l + 1 == r) {
		out[l] = cmp[v];
		return;
	}
	go(v * 2 + 1, l, (l + r) / 2);
	go(v * 2 + 2, (l + r) / 2, r);
	if(cmp[v * 2 + 1] > cmp[v * 2 + 2]) {
		cout << "-1";
		exit(0);
	}
	cmp[v] = cmp[v * 2 + 1];
}
void solve() {
	int n;
	cin >> n;
	p = (n + 1) / 2;
	while(p) p /= 2, k++;
	int a[n];
	multiset<int> ms;
	p = (n + 1) / 2;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		m[a[i]]++;
	}
	for(auto i : m) {
		ms.insert(i.ss);
		if(i.ss > k) {
			cout << "-1";
			return;
		}
		t[i.ss].push(i.ff);
	}
	pair<int, string> srt[p];
	int kk = 0;
	for(int i = 0; i < p; i++) {
		string tot = "";
		int I = i;
		for(int j = 0; j < k - 1; j++) {
			if(I & 1) {
				tot += '1';
			}
			else {
				tot += '0';
			}
			I >>= 1;
		}
		if(kk == i)kk = max(kk * 2, 1);
		srt[i] = {kk, tot};
	}
	sort(srt, srt + p);
	for(int i = 0; i < p; i++) {
		int v = 0;
		if(ms.empty()) {
			cout << "-1";
			return;
		}
		int it = *ms.rbegin();
		if(t[it].empty()) {
			cout << "-1";
			return;
		}
		int xx = it;
		int x = t[it].front();
		t[it].pop();
		ms.erase(--(ms.end()));	
		int iii = 0;
		for(int j = 0; j < k - 1; j++) {
			if((srt[i].ss)[j] == '1')iii += (1 << j);
		}
		for(int j = 0; j < k - 1; j++){
			if(iii & 1) {
				v = v * 2 + 2;
			}
			else {
				v = v * 2 + 1;
			}
			iii >>= 1;
			if(iii == 0){
				cmp[v] = x;
				xx--;
			}
		}
		if(i == 0)cmp[0] = x, xx--;
		if(xx != 0) {
			cout << "-1";
			return;
		}
	}
	go(0, 0, p);
	for(int i = 0; i < p; i++) {
		cout << out[i] << ' ';
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int times = 1;
	//cin >> times;
	for(int i = 1; i <= times; i++) {
		solve();
	}
	return 0;
}
