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

#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi2,fma")

using namespace std;
//using namespace __gnu_pbds;

//gp_gash_table<int,int>mp;
#define ll long long
#define pb push_back
#define ld long double
#define endl '\n'
#define all(a) a.begin(), a.end()

const ll INF = 2e18, MOD = 1e9 + 7, MAXN = 2e5;

vector<int> t;
map<int, set<int>> mp;

void vvv(int l, int r, int sz, int chislo, int type) {
    int ff;
    if (type == 0) {
        ff = chislo;
        if (l == r)
            t.pb(chislo);
    } else {
        auto it = mp[sz].upper_bound(chislo);
        if (it == mp[sz].end()) {
            cout << -1;
            exit(0);
        } else {
            if (l == r)
                t.pb(*it);
            ff = *it;
            mp[sz].erase(it);

        }
    }
    if (l == r) {
        return;
    }
    int m = (l + r) / 2;
    vvv(l, m, sz-1, ff, 0);
    vvv(m + 1, r, sz-1, ff, 1);
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> gg;
    int mn = 1e9;
    for (ll i = 0 ; i< n; i++) {
        cin >> a[i];
        gg[a[i]]++;
        mn = min(mn, a[i]);
    }
    for (auto e : gg) {
        mp[e.second].insert(e.first);
    }
    int m = (n+1) / 2;
    int lg = (int) log2(n + 1);
    if (mp[lg].find(mn) == mp[lg].end()) {
        cout << -1;
        return;
    } else {
        mp[lg].erase(mn);
    }
    vvv(0, m-1, lg, mn, 0);
    if (t.size() * 2 - 1 != n) {
        cout << -1;
        return;
    }
    for (auto e : mp) {
        if (e.second.size() > 0) {
            cout << e.first << " " << e.second.size()<< endl;
            cout << -1;
            return;
        }
    }
    for (ll i : t) {
        cout << i << " ";
    }
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    // cin >> t;
    while(t--) {
        solve();
    }
}