#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>

using namespace std;
#define int long long

const int N = 40 + 5;
set<int> m[N];
map<int, int> cnt;
int k = 1;
vector<int> ans;

void dfs(int d, int x){
    if(d == k - 1){
        ans.push_back(x);
        return;
    }
    if(k - d - 1 < 0)return;
    dfs(d + 1, x);
    if(m[k - d - 1].empty()){
        cout << "-1\n";
        exit(0);
    }
    auto it = m[k - d - 1].upper_bound(x);
    if(m[k - d - 1].end() == it){
        cout << "-1\n";
        exit(0);
    }
    m[k - d - 1].erase(it);
    dfs(d + 1, *it);
    return;
}

void solve() {
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        cnt[x]++;
    }
    while((1 << k) - 1 != n)k++;
    for(auto it : cnt){
        if(it.second > k){
            cout << "-1\n";
            return;
        }
        m[it.second].insert(it.first);
    }
    cnt.clear();
    int sz = (1 << k - 1);
    //cout << k << '\n';
    if(m[k].size() != 1){
        cout << "-1\n";
        return;
    }
    for(int i = 0; i < k - 1; ++i){
        if(m[k - i - 1].size() != (1 << i)){
            cout << "-1\n";
            return;
        }
    }
    //cout << a[0] << '\n';
    dfs(0, *m[k].begin());
    set<int> s;
    if(ans.size() != sz){
        cout << "-1\n";
        return;
    }
    for(int i = 0; i < sz; ++i){
        s.insert(ans[i]);
    }
    if(s.size() != sz)cout << "-1\n";
    else{
        for(int i = 0; i < sz; ++i)cout << ans[i] << ' ';
        cout << '\n';
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}
