#include<bits/stdc++.h>
#define int int64_t
using namespace std;

const int N = 1e5 + 10,inf = 1e18;

int t[4 * N],A[N];

map<int,vector<int>>pos;
map<int,int>used;
unordered_map<int,int>mp,mpcnt;
int st;

void build(int v,int tl,int tr,int k,int H){
    t[v] = k;
    used[k] = 1;
    if(tl == tr)return;
    int mid = (tl + tr) >> 1;
    int h = st - H;
//    cerr << v << ' ' << H  << ' ' << tl << ' ' << tr << '\n';
    int l = 0 , r = pos[h].size() - 1,ans = 0;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(used[pos[h][mid]] == 1){
            l = mid + 1;
        }
        else {
            r = mid - 1;
            ans = mid;
        }
    }
    used[pos[h][ans]] = 1;
    used[k] = 1;
    build(v * 2,tl,mid,k, H + 1);
    build(v * 2 + 1,mid + 1,tr,pos[h][ans],H + 1);
}

void solve(){
    int n;
    cin >> n;
    vector<int>a(n);
    int mn = inf;
    for(int i = 0; i < n; ++ i){
        cin >> a[i];
        mn = min(mn,a[i]);
        mp[a[i]] ++ ;
    }
    if(n == 1){
        cout << a[0] << '\n';
        return;
    }
    st = __lg(n) + 1;
    for(auto [x,y] : mp){
        mpcnt[y]++;
        if(y > st){
            cout << "-1\n";
            return;
        }
    }
    vector<int>ans;
    for(int i = 0; i < st; ++ i){
        if(i == 0){
            if(mpcnt[st] != 1){
                cout << "-1\n";
                return;
            }
        }
        else {
            if(mpcnt[st - i] != (1ll << (i - 1))){
//                cerr << "! " << mp[st - i] << ' ' << i << '\n';
                cout << "-1\n";
                return;
            }
        }
    }
    vector<array<int,2>>v;
    for(auto [x,y] : mp){
        pos[y].push_back(x);
        v.push_back({x,y});
    }
    for(int i = 1; i <= st; ++ i){
        sort(pos[i].rbegin(),pos[i].rend());
    }
    sort(v.begin(),v.end(),[&](auto x,auto y){
        if(x[1] == y[1])return x[0] < y[0];
        return x[1] > y[1];
    });
    int mid = v.size() / 2,i = 0;
//    for(auto to : v){
//        cout << to[0] << ' ' << to[1] << '\n';
//    }
    ans.push_back(v[i][0]);
    ans.push_back(v[mid][0]);
    if(v[0][0] != mn){
        cout << "-1\n";
        return;
    }
    vector<int>res((1ll << (st - 1)));
    for(int i = st; i >= 1; -- i){
        int e = (1ll << (i - 1));
//        cerr << "! " << i << ' ' << e << '\n';
        int p = e;
        for(auto to : pos[i]){
            res[p - 1] = to;
            p += e * 2;
        }
    }
    for(auto to : res){
        cout << to << ' ';
    }
    cout << '\n';
}

int32_t main(){
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int Q = 1;
//    cin >> Q;
    while(Q -- )solve();
    return 0;
}
