#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
typedef long long ll;

const int inf=1e9+1;
const int N=4e5+605;

int ori;
int mins[N],t[N*4],ans[N*2];
vt<int>ini,fin;

void build(int tl=0,int tr=ori, int v=0){
    if(tr-tl==1){
        t[v]=ans[tr];
        fin.pb(t[v]);
        return;
    }
    int mid=(tl+tr)>>1;
    build(tl,mid,v+v+1);
    build(mid,tr,v+v+2);
    t[v]=min(t[v+v+1],t[v+v+2]);
    fin.pb(t[v]);
}

void solve(){
    int n;
    cin>>n;
    int a[n+2];
    int k=0;
    int z=n+1,pomni;
    map<int,int>mp;
    for(int i=0; i<N*4; ++i) t[i]=inf;
    while(z!=1){
        z/=2;
        ++k;
    }
    pomni=k;
    ori=(1<<(k-1));
    mins[1]=1;
    mins[2]=1;
    for(int i=4; i<N; i*=2){
        mins[i]=1;
    }
    for(int i=1; i<=n; ++i){
        cin>>a[i];
        ini.pb(a[i]);
        mp[a[i]]--;
    }
    vt<pair<int,int>>v;
    for(auto [x,y]:mp){
        v.pb({y,x});
    }
    sort(all(v));
    int r=n/2,mt=1;
    vt<int>q,dd;
    int bad=0;
    for(auto [x,y]:v){
        //cout<<x<<' '<<y<<' '<<k-1<<endl;
        if(-x!=k){
            cout<<-1<<endl;
            return;
        }
        dd.pb(y);
        k-=mins[mt];//double check
        mt++;
    }
    q.pb(1);
    ans[1]=dd[0];
    bad=1;
    int ura=1;
    r=ori/2;
    //cout<<ori<<endl;
    while(bad){
        if(r==0) break;
        int sz=q.size();
        for(int i=0; i<q.size(); ++i){
            if(q[i]+r<=ori){
                //cout<<q[i]+r<<' '<<dd[ura]<<endl;
                ans[q[i]+r]=dd[ura];
                ++ura;
                q.pb(q[i]+r);
                if(ura==dd.size()){
                    bad=0;
                    break;
                }
            }
            if(i+1==sz){
                r/=2;
                break;
            }
            if(q[i]+r>ori){
                r/=2;
                break;
            }
        }
    }
    //full check
    build();
    sort(all(ini));
    sort(all(fin));
    if(ini!=fin){
        cout<<-1<<endl;
        return;
    }
    for(int i=1; i<=ori; ++i){
        cout<<ans[i]<<' ';
    }
}

int main(){
 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 int tt=1;
 //cin>>tt;
 while(tt--) {
  solve();
 }
}