#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9;
//using ld = long double;

struct segtree {
    vector<ll> tree;
    int size;

    void init(int n) {
        size = 1;
        while (size < n) size *= 2;
        tree.assign(2 * size - 1, inf);
    }

    void upd(int i, ll v, int x, int lx, int rx) {
        if (rx - lx == 1) {
            tree[x] = min(tree[x], v);
            return;
        }
        int m = (lx + rx) >> 1;
        if (i < m) upd(i, v, 2 * x + 1, lx, m);
        else upd(i, v, 2 * x + 2, m, rx);
        tree[x] = min(tree[2 * x + 1], tree[2 * x + 2]);
    }

    void upd(int i, ll v) {
        upd(i, v, 0, 0, size);
    }

    ll get(int l, int r, int x, int lx, int rx) {
        if (l >= rx or lx >= r) return inf;
        if (l <= lx and rx <= r) return tree[x];
        int m = (lx + rx) >> 1;
        return min(get(l, r, 2 * x + 1, lx, m), get(l, r, 2 * x + 2, m, rx));
    }

    ll get(int l, int r) {
        return get(l, r + 1, 0, 0, size);
    }
};


vector<int>ans;


int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n,mn=inf; cin >> n;
    map<int,int> mp;
    vector<int> ch;
    for(int i = 0; i <n; i ++){
        int x; cin >> x; mp[x] ++;
        mn=min(mn,x);
    }

    vector<pair<int,int>> v;
    int k = __builtin_popcount(n);
    if(mp.size() != k+1){
        cout << -1; return  0;
    }
    vector<int>cnt(k+1,0);
    for(auto [a, b] : mp){
        v.push_back({b, a});
        cnt[b]++;
    }

    if(cnt[k]!=1){
        cout<<-1;
        return 0;
    }
    int h=1;
    for(int i=k-1;i>=1;i--){
        if(cnt[i]!=h) return cout<<-1,0;
        h*=2;
    }

    int N=(n+1)/2;
    ans.resize(N);

    sort(v.begin(), v.end(),[&](pair<int,int> a, pair<int,int> b){
        if(a.first == b.first) return a.second < b.second;
        return a.first > b.first;
    });

    if(v[0].second!=mn){
        return cout<<-1,0;
    }


    queue<pair<int,int>>g;
    int i=0;
    g.push({1,i});
    while(!g.empty()){
        auto [x,y]=g.front();
        g.pop();
        if(x>=N) ans[x-N]=v[y].second;
        else{
            g.push({2*x,y});
            g.push({2*x+1,++i});
        }
    }

    auto cop = ans;
    auto check = [&]() {
        map<int, int> mp2;
        while (ans.size() > 1) {
            vector<int> vec;
            for (int i = 1; i < ans.size(); i += 2) {
                mp2[ans[i - 1]]++;
                mp2[ans[i]]++;
                vec.emplace_back(min(ans[i - 1], ans[i]));
            }
            ans = vec;
        }
        mp2[ans[0]]++;
        return mp == mp2;
    };
    if (!check()) {
        cout << -1;
        return 0;
    }

    for(int z:cop) cout<<z<<' ';

}