#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#define int long long
using namespace std;
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    int k = 1;
    while ((1ll << (k)) - 1 < n) k++;
    map<int, int> cnt;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (auto x : a) cnt[x]++;
    if (cnt.size() != (1ll << (k - 1))) {
        cout << -1;
        return 0;
    }
    vector<vector<int>> sk(k + 1);
    for (auto [u, v]: cnt) {
        sk[v].push_back(u);
    }
    int m = (1ll << (k - 1));
    vector<int> ans(m, -1);
    int g = m;
    reverse(sk.begin(), sk.end());
    for (auto x : sk) {
        int q = 0;
        for (auto y : x) {
            for (; q < m; q += g) {
                if (ans[q] == -1) {
                    ans[q] = y;
                    break;
                }
            }
        }
        g =g / 2;
    }
    for (int j = 1; j <= m; j *= 2) {
        for (int i = 0; i < m; i += j) {
            cnt[ans[i]]--;
        }
        for (int i = 0; i + 2 * j < m; i += (2 * j)) {
            ans[i] = min(ans[i], ans[i + 2 * j]);
        }
    }
    for (auto [u, v]: cnt) {
        if (v != 0) {
            cout << -1;
            return 0;
        }
    }
    for (auto x : ans) cout << x << ' ';
    return 0;
}
