#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <random>
#include <numeric>
#include <map>
#include <set>
#include <string>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define deb(x) cerr << #x << ":\t" << x << '\n';
#define len(x) (ll) x.size()
#define ff first
#define ss second

const ll INF = 8e18;
const ll MOD = 1e9 + 7;

vector <ll> t;
map <ll, vector <ll>> cntk;
vector <ll> ans;

bool build(ll v, ll l, ll r, ll k) {
    if (r - l == 1) {
        ans[l] = t[v];
        return true;
    }
    t[2 * v + 1] = t[v];
    t[2 * v + 2] = cntk[k].back();
    cntk[k].pop_back();
    ll m = (r + l) / 2;
    if (!build(2 * v + 1, l, m, k - 1))
        return false;
    if (!build(2 * v + 2, m, r, k - 1))
        return false;
    return t[v] == min(t[2 * v + 1], t[2 * v + 2]);
}

void solve() {
    ll n; cin >> n;
    if (n == 1) {
        ll x; cin >> x; cout << x;
        return;
    }
    ll k;
    for (ll p = 0; p < 32; p++) {
        if ((1ll << p) - 1 == n) {
            k = p;
            break;
        }
    }
    vector <ll> a(n);
    map <ll, ll> cntnum;
    for (auto& i : a) {
        cin >> i;
        cntnum[i]++;
    }
    for (auto [x, c] : cntnum) {
        cntk[c].emplace_back(x);
    }
    if (len(cntk[k]) != 1) {
        cout << -1;
        return;
    }
    t.resize(n);
    for (ll p = 1; p < k; p++) {
        if (len(cntk[k - p]) != (1ll << (p - 1))) {
            cout << -1;
            return;
        }
    }
    for (auto& [i, v] : cntk)
        sort(v.rbegin(), v.rend());
    t[0] = cntk[k][0];
    ll sz = (1ll << (k - 1));
    ans.resize(sz);
    if (build(0, 0, sz, k - 1)) {
        for (auto i : ans)
            cout << i << ' ';
    } else {
        cout << -1;
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int T = 1;
//    cin >> T;
//    cout << setprecision(9) << fixed;
    while (T--) {
        solve();
    }
    return 0;
}
