#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ld = long double;
using ui = unsigned int;
using ull = unsigned long long;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &i : a) cin >> i;
    if (n == 1) {
        cout << a[0];
        return 0;
    }
    sort(a.begin(), a.end());
    map<int, int> cnts;
    int k = 0;
    while ((1 << k) < n) {
        k++;
    }
    map<int, vector<int>> elems;
    for (int i = 0; i < n; i++) {
        cnts[a[i]]++;
    }
    for (auto [x, y] : cnts) {
        elems[y].push_back(x);
    }
    for (auto [x, y] : elems) {
        sort(elems[x].rbegin(), elems[x].rend());
    }
    if (cnts.begin()->second != k) {
        cout << -1;
        return 0;
    }
    vector<int> ans((1 << (k - 1)));
    ans[0] = a[0];
    elems[cnts[a[0]]].pop_back();
    if (!elems[cnts[a[0]]].empty() || cnts.size() != (1 << (k - 1))) {
        cout << -1;
        return 0;
    }
    vector<int> maxes;
    maxes.push_back(k);
    vector<bool> used((1 << k) - 1, false);
    int v = 0;
    while (v < used.size()) {
        used[v] = true;
        v *= 2;
        v++;
    }
    int el = 2;
    int op = 0;
    for (int i = 0; i < ((1 << (k - 1))) - 1; i++) {
        int y = (1 << k) + i;
        int x = 1;
        used[y] = true;
        while (!used[y / 2 - (y % 2 == 0)]) {
            int ny = y / 2 - (y % 2 == 0);
            x++;
            y = ny;
            used[ny] = true;
        }
        if (elems[x].empty()) {
            cout << -1;
            return 0;
        }
        ans[i + 1] = elems[x].back();
        elems[x].pop_back();
    }
    for (int i : ans) {
        cout << i << " ";
    }
    return 0;
}