#include<iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <algorithm>
#include <map>
#include <deque>
#define int long long
#define double long double
using ll = long long;
using namespace std;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
#define get_time (double)clock() / (double)(CLOCKS_PER_SEC)
#ifndef ONLINE_JUDGE
#define debug(x) cerr << (#x) << ": " << x << endl;
#else
#define debug(x)
#endif
ll max(ll a, ll b) {
    return (a > b) ? a : b;
}
ll min(ll a, ll b) {
    return (a < b) ? a : b;
}
ll bs_sqrt(ll x) {
    ll left = 0, right = 2000000123;
    while (right > left) {
        ll mid = (left + right) / 2;
        if (mid * mid > x) {
            right = mid;
            continue;
        }
        left = mid + 1;
    }
    return left - 1;
}
int gcd(int a, int b) {
    while (a > 0 && b > 0) {
        int c = a;
        a = b % a;
        b = c;
    }
    return a + b;
}
int bin_pow(int a, int n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        ll t = bin_pow(a, n / 2);
        return (t * t);
    }
    else {
        ll t = bin_pow(a, n - 1);
        return (t * a);
    }
}
vector<set<int> > gr;
vector<int> ans;
int all;
void make(int u, int level, int zn) {
    int need = all - level;
    ans[u] = zn;
    if (level == all) return;
    auto cur = gr[need].upper_bound(zn);
    if (cur == gr[need].end()) {
        cout << -1;
        exit(0);
    }
    int news = *cur;
    gr[need].erase(news);
    make(2 * u + 1, level + 1, zn);
    make(2 * u + 2, level + 1, news);
}
void solve() {
    int n, st;
    cin >> n;
    ans = vector<int>(n);
    st = n + 1;
    int l = 0;
    while (st % 2 == 0) {
        l++;
        st /= 2;
    }
    l--;
    all = l;
    debug(l);
    vector<int> a(n);
    gr = vector<set<int> >(n + 1);
    int lit = 1e18;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        lit = min(a[i], lit);
    }
    map<int, int> cnt;
    for (auto c : a) cnt[c]++;
    for (auto c : cnt) {
        gr[c.second].insert(c.first);
    }
    if (cnt[lit] != l + 1) {
        cout << -1;
        return;
    }
    gr[l + 1].erase(lit);
    make(0, 0, lit);
    for (int i = bin_pow(2, l) - 1; i < bin_pow(2, l + 1) - 1; i++) {
        cout << ans[i] << " ";
    }

}
signed main() {
    /*
    #ifdef ONLINE_JUDGE
    freopen("game.in", "r", stdin);
    freopen("game.out", "w", stdout);
    #endif
    */
    cout << fixed << setprecision(20);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}