#include <bits/stdc++.h>
#define ll long long
#define int ll
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define in insert
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define deb(x) cout << #x << " = " << x << '\n';
#define file(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
using namespace std;
 
// const int dx[] = {0, 1, 0, -1};
// const int dy[] = {1, 0, -1, 0};
 
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int a[N],cnt[N],n; 
 set <pii> st;
 set <int> ss;
 map <int,int> mp;

void dfs(pii v,int tt = 1){
	if (tt==__lg(n+1)){
		return;
	}
	// cout << v.S << '\n';
	// for (auto it : st){
	// 	cout << it.F << ' ' << it.S << '\n';
	// }
	if (st.empty()){
		return;
	}
	if (sz(st) < 2){
		cout << -1;
		exit(0);
	}
	pii u1 = *st.begin();
	st.erase(st.begin());
	pii u2 = *st.begin();
	st.erase(st.begin());
	int mn = min(u1.S, u2.S);
	if (u1.F!=u2.F || mn!=v.S){
		cout << -1;
		exit(0);
	}
	if (-u1.F > 1)st.insert({u1.F+1, u1.S});
	if (-u2.F > 1)st.insert({u2.F+1, u2.S});
	// cout << u1.S << ' ' << u2.S << '\n';
	dfs(u1,tt+1);
	dfs(u2,tt+1);
} 

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		ss.insert(a[i]);
	}
	int c = 0;
	for (int it: ss) {
		mp[it] = ++c;
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) {
		a[i] = mp[a[i]];
		cnt[a[i]]++;
	}
	if (cnt[1]!=__lg(n+1)){
		cout << -1;
		return;
	}
	cnt[1]--;
	for (int i = 1; i <= n; i++) {
		st.insert({-cnt[a[i]], a[i]});
	}
	pii v = *st.begin();
	dfs(v);
	for (auto it : ss){
		cout << it << ' ';
	}
}
 
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int TT = 1;
    // cin >> TT;
    while(TT--) {
        solve();
    }
    return 0;
}