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

using namespace std;
using namespace __gnu_pbds;

#define str string
#define ldb long double
#define ll long long
#define db double
#define ull unsigned long long
#define ss second
#define ff first
#define pob pop_back
#define pub push_back
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
const ll INF18 = 2e18;
const int INF9 = 2e9;
const db PI = acos(-1);
const db EPS = 1e-5;
mt19937 rnd(time(0));
template <typename T, typename TT>
ostream& operator<<(ostream& out, pair<T, TT> &a) {
    out << "{" << a.ff << ' ' << a.ss << '\n';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> &a) {
    for (auto it : a)
        out << it << ' ';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, set<T> &a) {
    for (auto it : a)
        out << it << ' ';
    return out;
}
#define print(...) cout << #__VA_ARGS__ << " = " << __VA_ARGS__ << '\n'
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int ll

map <int, int> cnt;

map <int, set <int>> q;

vector <int> ans;

void build(int v, int l, int r, int h, int last = -1, int need = -1) {
    if (need == -1) {
        auto it = q[h].lower_bound(last);
        if (it == q[h].end()) {
            cout << -1 << '\n';
            exit(0);
        }
        last = *it;
        q[h].erase(it);
    }
    if (l + 1 == r) {
        ans[l] = last;
        return;
    }
    int m = (l + r) / 2;
    build(2 * v + 1, l, m, h - 1, last, 0);
    build(2 * v + 2, m, r, h - 1, last, -1);
}

signed main() {
    fast
    int n;
    cin >> n;
    vector <int> a(n);
    ans.resize(n);
    set <int> m;
    for (auto &i : a) {
        cin >> i;
        m.insert(i);
        cnt[i]++;
    }
    for (auto [x, y] : cnt) {
        q[y].insert(x);
    }
    int k = 1 << __lg(n), h = __lg(n) + 1;
    if (m.size() != k) {
        cout << -1 << '\n';
        return 0;
    }
    build(0, 0, k, h);
    for (int i = 0; i < k; ++i) {
        cout << ans[i] << " ";
    }
    return 0;
}
