#include <bits/stdc++.h>

using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 5e5 + 9 , mod = 1e9 + 7;
ll   a[N] = {}, b[N] , c[N] , d[N] , dp[N] , le[2 * N] , ri[2 * N] , ans[N];

set<int>kol[50];

void build(int i , int x , int y){
    int m = (x + y) / 2;
    le[i] =  x;
    ri[i] =  y;
    if(x == y)
        return;
    build(2 * i , x , m);
    build(2 * i + 1 , m + 1 , y);
}



void solve()
{
    ll q , i , j , m ,n, z ,s = 0 , f  = 0, l , r , k , x , y , mn  = 1e18 , mx = 0;
    cin>>m;
    set<int>st ;
    map<int,int>mp;
    for(i = 1; i <= m; i++){
        cin>>a[i];
        mp[a[i]]++;
        st.insert(a[i]);
    }
    k = log2(m + 1)  + 1;
    for(auto it : st){
        if(mp[it] > k){
            cout<<-1<<"\n";
            return;
        }
        kol[mp[it]].insert(it);
    }
    n = m / 2 + 1;
    if(st.size() != n){
        cout<<-1<<"\n";
        return;
    }
    build(1 , 1 , n);
    vector<pair<int,int>>v;
    for(i = 1; i <= n; i++){
        y = (n - 1) + i;
        s = 0;
        k = 0;
        while(y != 0){
            k = le[y];
            if(le[y] != i)
                break;
            s++;
            y /= 2;
        }
        c[i] = s;
        if(i == 1)
            b[i] = 0;
        else
            b[i] = k;
        v.pb({c[i] , i});
    }
    sort(rall(v));
    for(auto to : v){
        if(kol[to.fi].size() == 0){
            cout<<-1<<"\n";
            return;
        }
        x = ans[b[to.se]];
        auto it = kol[to.fi].lower_bound(x);
        if(it == kol[to.fi].end()){
            cout<<-1<<"\n";
            return;
        }
        ans[to.se] = *it;
        kol[to.fi].erase(it);
    }
    for(i = 1; i <= n; i++)
        cout<<ans[i]<<" ";
}

int main(){

int t = 1;
//cin>>t;
while(t--)
     {
     solve();
     }
}
// Author : حسن
