#include <bits/stdc++.h>
 
using namespace std;
 
#define speed ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define F first
#define S second
#define nl '\n'
// #define int long long 
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;
 
const int N = 2e5 + 1;
const int inf = 1e9+123;
const ll INF = 1e15 + 5;
const int mod = 1e9 + 7;
const int P = 31;

int lg[N];
vector<vector <int> > cnt(N);
int pat[30];

void solve(){
    int n;
    cin >> n;
    int mxd = lg[n] + 1;
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        mp[x]++;
    }
    for(auto u : mp){
        cnt[u.S].pb(u.F);
    }
    for(int i = 1; i <= mxd; i++)
        sort(all(cnt[i]));
    int pat[mxd + 1];
    pat[mxd] = 1;
    pat[mxd - 1] = 1;
    for(int i = mxd - 2; i >= 1; i--)
        pat[i] = pat[i + 1] * 2;
    bool ok = true;
    for(int i = 1; i <= mxd; i++){
        if(pat[i] != sz(cnt[i]))
            ok = false;
    }
    if(!ok){
        cout << -1 << '\n';
        return;
    }
    int t[n + 1];
    t[1] = cnt[mxd][0];
    vector<int> cur = {1};
    for(int d = mxd - 1; d >= 1; d--){
        for(auto e : cur)
            t[2 * e] = t[e];
        vector<pii> ihv;
        for(auto e : cur)
            ihv.pb({t[e], e});
        sort(all(ihv));
        for(int i = 0; i < sz(ihv); i++){
            int e = ihv[i].S;
            t[2 * e + 1] = cnt[d][i];
        }
        vector<int> nw;
        for(auto e : cur)
            nw.pb(2 * e), nw.pb(2 * e + 1);
        cur = nw;
    }
    for(auto e : cur){
        cout << t[e] << ' ';
    }
}

signed main() {
    //speed;
    lg[1] = 0;
    for(int i = 2; i < N; i++)
        lg[i] = lg[i / 2] + 1;
    int T = 1;
    // cin >> T;
    while(T--)
        solve();
}