#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
 
ll n, m, k;
int a[200005], ans[200005], t[200005 * 4], mn;

map < int, int > mp;
set <int> s[200005];

void build(int v, int l, int r, int cnt, int cur){
	t[v] = cur;
	if (l == r) {
		ans[l] = cur;
		return;
	}
	int val;
	if (s[cnt - 1].lower_bound(cur) == s[cnt - 1].end()) {
		cout << -1;
		exit(0);
	}
	val = (*s[cnt - 1].lower_bound(cur));
	s[cnt - 1].erase(val);
	int md = (l + r) / 2;
	build(v * 2, l, md, cnt - 1, cur);
	build(v * 2 + 1, md + 1, r, cnt - 1, val);
}

void solve(){
    cin >> n, m = log2(n) + 1, mn = 1000000000;
    for(int i = 1; i <= n; i++) {
    	cin >> a[i];
    	mn = min(mn, a[i]);
    }
    for(int i = 1; i <= n; i++) mp[a[i]]++;
    if (mp.size() != n / 2 + 1) {
    	cout << -1;
    	return;
    }
    for (int i = 1; i <= n; i++) {
    	if (mp[a[i]] > m) {
    		cout << -1;
    		return;
    	}
    	s[mp[a[i]]].insert(a[i]);
    }
    build(1, 1, mp.size(), m, mn);
    for (int i = 1; i <= mp.size(); i++) {
    	cout << ans[i] << " ";
    }
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}