#include <bits/stdc++.h>

#define fi first
#define se second

#define pw(x) (1LL << x)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(x) (int)(x).size()

using namespace std;

template < typename T >
bool umn (T& a, T  b) {return a > b ? a = b, 1 : 0;}
template < typename T >
bool umx (T& a, T  b) {return a < b ? a = b, 1 : 0;}

using ll = long long;
using ld = long double;

const int N = 1e6 + 5;

int n, a[N], k, t[N];
set < int > st;
vector < int > vec;
map < int , int > mp;
vector < int  > ve[N];

void update (int v, int val, int sz) {
    if (v > n) return;

//    cout << v << endl;

    t[v] = val;
    if (sz) ve[sz - 1].pb (v << 1 | 1);

    update (v << 1, val, sz - 1);
}

void calc (int v) {
    if ((v << 1) > n) {
        vec.pb (t[v]);
        return;
    }

    calc (v << 1);
    calc (v << 1 | 1);
    if (t[v] != min (t[v << 1], t[v << 1 | 1])) {
        cout << -1 << "\n";
        exit(0);
    }
}

int main() {
#ifdef localy
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
#endif // localy
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> a[i], ++ mp[a[i]];

    int sum = 0;
    k = 0;
    while (sum < n) {
        sum += pw(k);
        k++;
    }
    int k1 = k;
    k = pw (k - 1);
    if (sz(mp) != k) {

        cout << -1 << "\n";
        return 0;
    }

//    cout << k << "\n";

    ve[k1].pb (1);
    for (auto& it : mp) {
//            cout << it.fi << endl;
        if (!sz(ve[it.se])) {
//            cout << "sas\n";
            cout << -1 << "\n";
            return 0;
        }

        update (ve[it.se][0], it.fi, it.se);
        swap (ve[it.se][0], ve[it.se].back());
        ve[it.se].pop_back();
    }

    calc (1);
    for (auto& it : vec) cout << it << " ";
    cout << "\n";
    return 0;
}
