#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) begin(x), end(x)
using namespace std;

const int N = 2e5 + 1, inf = LLONG_MAX / 2ll ;

 vector <int> pos[N];
void solve() {
    int rz;
    cin >> rz;
    int n = rz/2 + 1;
    int h = log2(n) + 1;
    int a[rz + 1];
    for(int i = 1;i <= rz;i++) cin >> a[i];
    map <int,int> kol;
    for(int i = 1;i <= rz;i++) kol[a[i]]++;
    bool check = false;
    int now = 1;
    for(auto x:kol) {
        pos[x.s].pb(x.f);
    }
    int gg = 0;
    for(int i = h;i >= 1;i--) {
        if(now != sz(pos[i]) + gg) {
            check = true;
        }
        gg+=sz(pos[i]);
        now*=2;
    }
    if(check) {
        cout << -1 << endl;
        exit(0);
    }
    for(int i = 1;i <= h;i++) {
        sort(all(pos[i]));
    }
    vector <int> v;
    v.pb(1);
    set <int> s[h + 1];
    for(int i = 1;i <= h;i++) {
        for(auto x:pos[i]) {
            s[i].insert(x);
        }
    }
    for(int i = h - 1;i >= 1;i--) {
        vector <int> newv;
        int it = 0;
        for(auto x:v) {
            newv.pb(x);
            auto gg = s[i].upper_bound(x);
            if(gg == s[i].end()) {
                cout << -1 << endl;
                return;
            }
            newv.pb(*gg);
            it++;
        }
        v = newv;
    }
    for(auto x:v) cout << x << " ";
}

signed main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);cout.tie(0);
    int T = 1 ;
    while (T--) {
        solve ( ) ;
    }
    return 0 ;
}