#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;
vector<pair<int, int>> vec;
int ptr = 0;
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) {
		vec.pb({it.second, it.first});
	}
	sort(vec.begin(), vec.end(), [&] (pair<int, int> &x, pair<int, int> &y){
		if(x.first != y.first) return x > y;
		return x.second < y.second;
	});
	int h = 0;
	while((1 << (h + 1)) - 1 <= n) {
		h++;
	}
	queue<array<int, 4>> q;
	q.push({1, 1, h + 1, h});
	while(!q.empty()) {
		array<int, 4> vt = q.front();
		int u = vt[0];
		int l = vt[1], r = vt[2], ht = vt[3];
		q.pop();
		int m = (l + r) / 2;
		if(!tr[u]) {
			if(ptr >= sz(vec)) {
				cout << -1;
				exit(0);
			}
			if(vec[ptr].first != ht) {
				cout << -1;
				exit(0);
			}
			tr[u] = vec[ptr].second;
			ptr++;
		}
		if(l == r) {
			ans[l] = tr[u];
			continue;
		}
		tr[ls] = tr[u];
		q.push({ls, l, m, ht - 1});
		q.push({rs, m + 1, r, ht - 1});
	}
	for(int i = 1; i <= h + 1; i++) {
		cout << ans[i] << ' ';
	}
}
