#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const ll inf = 998244353;
#define all(a) a.begin(), a.end()

map<int, set<int>> m;
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;
    }
    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);
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        cnt[a[i]]++;
    }
    sort(all(a));
    while((1 << k) - 1 != n)k++;
    for(auto it : cnt){
        if(it.second > k){
            cout << "-1\n";
            return;
        }
        m[it.second].insert(it.first);
    }
    //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() != (1 << k - 1)){
        cout << "-1\n";
        return;
    }
    for(int i = 0; i < (1 << k - 1); ++i){
        s.insert(ans[i]);
    }
    if(s.size() != (1 << k - 1))cout << "-1\n";
    else{
        for(int i : ans)cout << i << ' ';
        cout << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k = 1;
    //cin >> k;
    for (int i = 0; i < k; ++i) {
        solve();
    }
}
