//#pragma GCC optimaze("O3")
//#pragma GCC optimaze("Ofast")
//#pragma GCC optimaze("unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#include <bits/stdc++.h>

#define int int64_t
#define ll long long

const int MOD = 1e9 + 7;

using namespace std;
vector<int> t;
int sz;
int aa[100000];
void build(int p=0,int l=0,int r=sz){
    if(r-l==1){
        t[p]=aa[l];
        return;
    }
    int m=(r+l)/2;
    build(p*2+1,l,m);
    build(p*2+2,m,r);
    t[p]=min(t[p*2+1],t[p*2+2]);
}
void solve(){
    int n;
    cin>>n;
    t.resize(n);
    sz=0;
    for(int i=n;i>0;i/=2,sz++){
        int rrrrrrrr = sz + 1;
    }
    sz--;
    sz=(1<<sz);
    map<int,int>cnt;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        cnt[x]++;
    }
    set<pair<int,int>>scs;
    for(auto[a,b] : cnt){
        scs.emplace(-b,a);
    }
    set<int>nms;
    for(int i=0;i<n;i++){
        nms.insert(i);
    }
    vector<int> rt(n);
    while(!scs.empty()){
        auto[sc,x]=*scs.begin();
        scs.erase(scs.begin());
        sc=-sc;
        int c=*nms.begin();
        rt[c]=x;
        nms.erase(nms.begin());
        while(c<n){
            rt[c]=x;
            nms.erase(c);
            sc--;
            c=c*2+1;
        }
        if(sc){
            cout<<-1;
            return;
        }
    }
    for(int i=n-sz;i<n;i++){
        aa[i-n+sz]=rt[i];
    }
    build();
    for(int i=0;i<n;i++){
        if(t[i]!=rt[i]){
            cout<<-1;
            return;
        }
    }
    for(int i = 0; i < sz; ++i){
        cout<< aa[i]<<' ';
    }
}

signed main() {
    int t=1;
    //cin >> t;
    for(int i = 0; i < t; ++i){
        solve();
    }
    return 0;
}
/*
7
2 3 1 1 4 1 3
 */