#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define sz(s) (int)s.size()
#define in insert
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
 
const int MAX=4e5+10;
 
int n;
int a[MAX];
int ans[MAX];
vector<int> v[MAX];
vector<int> qq;
int t[MAX * 4];

void build(int v, int l, int r){
    if(l == r){
        qq.pb(ans[l]);
        t[v] = ans[l];
        return;
    }
    int mid=(l+r)/2;
    build(v+v, l, mid);
    build(v+v+1, mid+1, r);
    t[v] = min(t[v + v], t[v + v + 1]);
    qq.pb(t[v]);
}
 
int main(){
    cin>>n;
    set<int> st;
    map<int,int> cnt,c;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        cnt[a[i]]++;
        st.in(a[i]);
    }
    int n1=(n+1);
    if(sz(st)!=n1/2){
        cout<<-1<<"\n";
        return 0;
    }
    for(int x:st){
        if(cnt[x] >= 30){
            cout<<-1;
            return 0;
        }
    }
    for(int x:st){
        c[cnt[x]]++;
    }
    int x=1;
    int l=0, asd=n;
    while(asd){
        asd /= 2;
        l ++;
    }
    // cout<<l<<' ';
    n1/=2;
    // cout<<l<<"\n";
    for(int i=l;i>=1;i--){
        c[i]+=c[i+1];
    }
    for(int i=1;i<=l;i++){
        if(c[i]==n1){
            n1/=2;
        }
        else{
            cout<<-1<<"\n";
            return 0;
        }
    }
    // cout<<n1<<"\n";
    for(int x:st){
        if(cnt[x] >= 30){
            cout<<-1;
            return 0;
        }
        v[cnt[x]].pb(x);
    }
    set<pii> d;
    if(v[l].size() < 1){
        cout<<-1;
        return 0;
    }
    d.insert({v[l][0], 1});
    ans[1] = v[l][0];
    for(int k=l-1; k>=1; k--){
        set<int> q;
        for(int i=0; i<v[k].size(); i++){
            q.insert(v[k][i]);   
        }
        vector<pii> h;
        for(auto it: d){
            auto s = q.lower_bound(it.first);
            if(s == q.end()){
                cout<<-1;
                return 0;
            }
            // cout<<it.S + (1 << (k-1))<<' '<<k-1<<'\n';
            ans[it.S + (1 << (k-1))] = *s;
            q.erase(s);
            h.pb({*s, it.S + (1 << (k-1))});
        }
        for(int i=0; i<h.size(); i++){
            d.insert(h[i]);
        }
    }
    // for(int i=1;i<=(n+1)/2;i++)cout<<ans[i]<<" ";

    
    build(1, 1, (n + 1) / 2);
    sort(all(qq));
    sort(a + 1, a + 1 + n);
    for(int i=1; i<=n; i++){
        if(qq[i - 1] != a[i]){
            cout<<-1;
            return 0;
        }
    }
    for(int i=1;i<=(n+1)/2;i++)cout<<ans[i]<<" ";
}