#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define double long double
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
    tree_order_statistics_node_update> ordered_set;
const int mod= 1e9 +7;
const int N=1e5;
  
int binpow (int a, int n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1)
        return binpow (a, n-1) * a;
    else {
        int b = binpow (a, n/2);
        return b * b;
    }
}
int t[N*4];
vector<int> ans(N);
map<int,int>mps;
void build(int tl,int tr,int v){
    if(tr==tl){
        t[v]=ans[tl];
    }
    else {
        int tm=(tl+tr)/2;
        build(tl,tm,v*2);
        build(tm+1,tr,v*2+1);
        t[v]=min(t[v*2],t[v*2+1]);
    }
}
//-------------------seg------------------------------- 
  
void solve(){
      
    int n;
    cin >> n;
    map<int,int> mp;
    int lg = __lg(n+1);
    int a[n];
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    
    if(mp.size() != (n+1)/2){
        cout << "-1";
        return;
    }
    vector<int> v[lg+1];
    for(auto [i,cnt] : mp){
        v[cnt].pb(i);
    }
    int sum = 1,sum2 = 0;
     for(int i = lg ; i >= 1 ; i--){
        if(v[lg].size() + sum2 != sum){
            cout << "-1";
            return;
        }
        sum2 += sum;
        sum *= 2;
    }
    
    int cnt = (n + 1) / 2;
    while(cnt >= 1){
        sort(rall(v[lg]));
        for(int i = 1 ; i <= mp.size() ; i += cnt){
            if(ans[i] == 0){
                ans[i] = v[lg].back();
                v[lg].pop_back();
            }
        }
        cnt /= 2;
        lg--;
    }
     
    build(1,mp.size(),1);
 
    for(int i=1;true;i++){
        if(t[i]==0)break;
        mps[t[i]]++;
    }
     
    for(auto to:mp){
        if(to.s!=mps[to.f]){
            cout<<-1<<endl;
            return;
        }
    }
    set<int>st;
     
    for(int i =1;i<=mp.size();i++){
        st.insert(ans[i]);
    }
    if(st.size()!=mp.size()){
        cout<<-1<<endl;
        return;
    }
    for(int i = 1 ; i <= mp.size() ; i++){
        cout << ans[i] << ' ';
     }
}
  
 signed main()
{
//  freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    int cnt=0;
    int tt=1;
    while(tt--)solve();
  
}