///@author: suuuiii
//#pragma GCC target("avx2")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define int128 __int128
#define int long long
#define ll long long
#define ld long double
#define ve vector
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define eb emplace_back
#define INF1 INT32_MAX
#define INF2 INT64_MAX
#define sz(x) (int)(x).size()


using namespace std;
using namespace __gnu_pbds;
random_device rd;
mt19937 rnd(rd());


int rand(int l, int r) {
    return l + rnd() % (r - l + 1);
}

template<typename key, typename cmp = less<key>>
using pbds = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

const int Size = (1ll << 3), maxn = (int)1e5*2+1;


void solve() {
    int n; cin >> n;
    ve<int> a(n);

    map<int, int> mp;
    for (int &i : a) cin >> i, mp[i]++;
    sort(all(a));

    ve<pair<int, int>> mas;

    for (auto[l, r] : mp) {
        mas.eb(r, l);
    }

    deque<int> L, R;

    int k = __lg(n+1)-1;
    if (sz(mp) != (1 << k)) {
        cout << -1;
        return;
    }
    sort(all(mas), [](auto l, auto r) {
        if (l.first == r.first) return l.second < r.second;
        return l.first > r.first;
    });
    if (mas[0].first > k+1) {
        cout << -1;
        return;
    }

    k = (1 << k);
    ve<int> op(k);

    deque<pair<int, int>> q;

    q.eb(0, k);
    ve<int> v;

    while (!q.empty()) {
        auto[lx, rx] = q.front();
        q.pop_front();

        if (rx-lx==1) continue;

        v.eb(lx);
        v.eb(rx-1);

        q.eb(lx, (rx+lx)/2);
        q.eb((rx+lx)/2, rx);
    }
    set<int> used;

    ve<int> vp;

    for (int i : v) {
        if (!used.count(i)) {
            used.insert(i);
            vp.eb(i);
        }
    }

    int j = 0;
    for (auto[l, r] : mas) {
        op[vp[j]] = r;
        ++j;
    }

    ve<int> ap;

    ve<int> tree(2*k-1);
    for (int i = k-1; i < 2*k-1; ++i) tree[i] = op[i-k+1], ap.eb(tree[i]);
    for (int i = k-2; i >= 0; --i) {
        tree[i] = min(tree[i*2+1], tree[i*2+2]), ap.eb(tree[i]);
    }

    sort(all(ap));
    if (ap != a) cout << -1;
    else {
        for (int i : op) cout << i << " ";
    }

}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
//    cout << setprecision(8);
//    cin >> tt;
    while (tt--){
        solve();
    }
}