#include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937_64 rnd(time(0));
#define push_back pb
#define make_pair mp
#define F first
#define S second
#define all(x) x.begin(), x.end()

const ll N = 2e5 + 5;
const ll INF = 1e15;

vector<ll> a;
vector<ll> cnt(N);
map<ll, ll> inv;
vector<ll> ans(N);
vector<bool> used(N);
vector<set<ll>> pick(N);
ll k, len;

void dfs(ll v, ll x, ll dep, ll tl, ll tr) {
    used[x] = true;
    pick[cnt[x]].erase(x);
    if (tl == tr) {
        ans[tl] = x;
        return;
    }
    ll tm = (tl + tr) / 2;
    dfs(2 * v + 1, x, dep - 1, tl, tm);
    if (pick[dep - 1].empty() || *pick[dep - 1].rbegin() <= x) {
        cout << -1 << '\n';
        exit(0);
    }
    ll nxt = *pick[dep - 1].upper_bound(x);
    dfs(2 * v + 2, nxt, dep - 1, tm + 1, tr);
}

void solve() {
    ll n; cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    while ((1ll << (k + 1)) - 1 < n) {
        k++;
    }
    sort(a.begin(), a.end());
    vector<ll> b = a;
    b.erase(unique(b.begin(), b.end()), b.end());
    for (int i = 0; i < n; i++) {
        ll x = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
        inv[x] = a[i];
        a[i] = x;
    }
    for (auto i : a) cnt[i]++;
    for (auto i : a) {
        if (pick[cnt[i]].find(i) == pick[cnt[i]].end()) {
            pick[cnt[i]].insert(i);
        }
    }
    if (cnt[0] != k + 1) {
        cout << -1 << '\n';
        exit(0);
    }
    len = (n + 1) / 2;
    dfs(0, 0, k + 1, 0, len - 1);
    for (int i = 0; i < len; i++) {
        cout << inv[ans[i]] << " ";
    }
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    solve();

    return 0;
}