/*
It is code Zhanabergen Abdurroshid :))))
*/
//#pragma GCC "unroll-loop, 0fast"
#include<bits/stdc++.h>
#define ll long long
//#define int ll
#define double long double
#define m_p make_pair
#define p_b push_back
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<ll>
#define vii vector<pii>
#define viii vector<pair<int,pii> >
#define si set<int>
#define sii set<pii>
#define siii set<pair<int,pii> >
#define F first
#define S second
#define pre precision
#define n_per next_permutation
#define sz size()
#define all(x) x.begin(),x.end()
#define RUN ios_base::sync_with_stdio(false);cin.tie(0);
#define OPEN freopen("unionday.in","r",stdin);freopen("unionday.out","w",stdout)
using namespace std;
int fl(){
	int a;
	cin>>a;
	return a;
}
const int N = 4e5+1, INF = 1e9+9, k = 3;
int ans[N];
main(){
	RUN;
	int n = fl();
	int a[n + 9];
	for(int i=1;i<=n;i++){
		a[i] = fl();
	}
	if(n==1){
		cout<<a[1];
		return 0;
	}
	sort(a+1,a+n+1);
	int col = 1, cnt = 1;
	vii v;
	for(int i=2;i<=n;i++){
		if(a[i]==a[i-1])cnt++;
		else{
			col++;
			v.p_b({cnt,a[i-1]});
			cnt = 1;
		}
	}
	v.p_b({cnt,a[n]});
	int k = 0, x = n+1;
	while(x){
		x/=2;
		k++;
	}
	k--;
	vi p;
	queue<piii>q;
	q.push({1,{1,n/2+1}});
	while(q.sz){
		int tp = q.front().F, tl = q.front().S.F, tr = q.front().S.S;
		q.pop();
		if(tp==1)p.p_b(tl);
		if(tl==tr)continue;
		int tm = (tl+tr)>>1;
		q.push({0,{tl,tm}});
		q.push({1,{tm+1,tr}});
	}
	bool yes = 1;
	int nxt = 2, ct = 1;
	for(int i=v.sz-1;i>=0;i--){
		int len = v.sz-i;
		if(len==nxt){
			nxt*=2;
			ct++;
		}
		if(ct<v[i].F)yes = 0;
		//cout<<v[i].F<<"-"<<v[i].S<<":"<<ct<<" ";
	}
	sort(all(v));
	reverse(all(v));
	if(!yes||col!=n/2+1||v[0].F==v[1].F||v[0].F!=k){
		cout<<-1;
		return 0;
	}
	int id = 1;
	ans[1] = v[0].S;
	cnt = 1;
	int two = 1;
	k--;
	for(int i=1;i<v.sz;i++){
		bool ok = 1;
		for(int j=i;j<i+two;j++){
			if(j>=v.sz)break;
			if(v[j].F!=k)ok = 0;
			ans[p[id]] = v[j].S;
			id++;
		}
		if(!ok){
			cout<<-1;
			return 0;
		}
		k--;
		i+=two-1;
		two*=2;
	}
	for(int i=1;i<=n/2+1;i++)cout<<ans[i]<<" ";
	return 0;
}
/*
15
1 1 1 1 6 6 6 3 3 5 5 2 4 7 8
*/
