#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl "\n"
#define ll long long
//#define int ll
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll N=2e5+5,INF=1e18,mod=1e9+7;
vector<set<int>> A(30);
vector<int> ans,tmp;
int n;
int get(int x, int l, int r, vector<int> &a){
	//cout<<x<<' '<<l<<' '<<r<<endl;
	if(l==r){
		//cout<<"AAAA"<<endl;
		tmp.pb(a[l]);
		return a[l];
	}
	int md=(l+r)/2;
	int cur=min(get(2*x,l,md,a),
			   get(2*x+1,md+1,r,a));
	tmp.pb(cur);
	return cur;
}
bool check(vector<int> a, vector<int> b){
	tmp.clear();
	get(1,0,(int)a.size()-1,a);
	sort(all(tmp));
	sort(all(b));
	
	/*for(auto it: tmp) cout<<it<<' ';
	cout<<endl;*/
	return b==tmp;
}
void dfs(int x=1, int v=1){
	if(x>n) return;
	if(2*x>n) ans.pb(v);
	dfs(x*2,v+1);
	dfs(2*x+1,1);
}
void solve(){
	 cin>>n;
	 vector<int> a(n);
	 for(int i=0;i<n;i++) cin>>a[i];
	 dfs();
	 /*for(int i=0;i<(int)ans.size();i++)
		cout<<ans[i]<<' ';
	 cout<<endl;*/
	 if(n==1){
		 cout<<a[0]<<endl;
		 return;
	 }
	 map<int,int> mp;
	 vector<int> v=a;
	 sort(all(v));
	 v.erase(unique(all(v)),v.end());
	 for(int i=0;i<n;i++){
		 mp[a[i]]++;
	 }
	 int l=n+1;
	 if(l/2!=(int)v.size()){
		 cout<<-1<<endl;
		 return;
	 }
	 
	 for(int i=0;i<(int)v.size();i++){
		 A[mp[v[i]]].insert(v[i]);
	 }
	 
	 vector<int> res;
	 vector<int> last(30);
	 for(int i=0;i<(int)ans.size();i++){
		 
		 if(A[ans[i]].empty()){
			 cout<<-1<<endl;
			 return;
		 }
		 last[ans[i]]=i;
		 if(i==0){
			res.pb(*A[ans[i]].begin());
			A[ans[i]].erase(A[ans[i]].begin());
		 }
		 else{
			 int id=0;
			 for(int j=ans[i]+1;j<30;j++) id=max(id,last[j]);
			 auto it=lower_bound(all(A[ans[i]]),res[id]);
			 if(it==A[ans[i]].end()){
				 cout<<-1<<endl;
				 return;
			 }
			 res.pb(*it);
			 A[ans[i]].erase(it);
		 }
		
	 }
	 //cout<<endl;
	 if(!check(res,a)){
		 cout<<-1<<endl;
		 return;
	 }
	 for(auto it: res)
		cout<<it<<' ';
}
main(){
	ios;
	int T=1;
	//cin>>T;
	for(int i=1;i<=T;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


