#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
int t[2000000];
int b[200000];
bool cmp(pair<int,int> x,pair<int,int> y){
    return x.ff>y.ff ||(x.ff == y.ff and x.ss<y.ss);
}
void build(int v, int tl, int tr){
    if(tl == tr){
        t[v] = b[tl];
        return;
    }
    int tm = (tl + tr) / 2;
    build(v + v, tl, tm);
    build(v + v + 1, tm + 1, tr);
    t[v] = min(t[v + v], t[v + v + 1]);
}
int main(){
    int n;
    cin>>n;
    int a[n+2];
    int k = 0;
    int m = n + 1;
    while(m != 1){
        m /= 2;
        k++;
    }
    k--;
    map<int, int> mp;
    set<int> st;
    pair<int, int> dop[1<<k + 3];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mp[a[i]]++;
        st.insert(a[i]);
    }
    if(n == 1){
        cout<<a[1]<<endl;
        return 0;
    }
    int FUK = 1;
    for(auto i:st){
        dop[FUK] = {mp[i], i};
        FUK++;
    }
    sort(dop + 1,dop + 1 + (1<<k), &cmp);
    memset(b, 0, sizeof(b));
    b[1] = dop[1].ss;
    b[(1<<(k - 1)) + 1] = dop[2].ss;
    int cur=3;
	for(int i=2;k-i>=0;i++){
	    int pos=(1<<(k-i))+1;
	    while(pos<=(1<<k)){
	        b[pos]=dop[cur++].ss;
	        pos+=(1<<(k-i+1));
	    }
	}
	build(1, 1, (1<<k));
	map<int, int> mp2;
	for(int i=1;i<=n;i++){
	    mp2[t[i]]++;
	}
    // for(int i=1;i<=(1<<k);i++){
    //     cout<<mp2[i]<<" ";
    // }
    // cout<<endl;
	for(auto i:st){
	    if(mp2[i] != mp[i]){
	        cout<<"-1"<<endl;
	        return 0;
	    }
	}
	for(int i=1;i<=(1<<k);i++){
	    cout<<b[i]<<" ";
	}
	cout<<endl;
	return 0;
}
