#include "bits/stdc++.h"

using namespace std;

#define int long long

map<int, int> d;
map<int, set<int>> mapa;
vector<pair<int, int>> g;
vector<int> tree;
int n;

void rec(int u, int index) {
    if (index >= n or d[u] <= 0) {
        return;
    }
    tree[index] = u;
    d[u]--;
    if (!mapa[d[u]].empty()){
        int x2 = 0;
        auto x1 = mapa[d[u]].upper_bound(u);
        if (x1 != mapa[d[u]].end()){
            mapa[d[u]].erase(x1);
            x2 = *x1;
        }
        rec(u, index * 2 + 1);
        rec(x2, index * 2 + 2);
    }
}

void solve() {
    cin >> n;
    tree.resize(n,0);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        d[x]++;
    }
    for (auto i: d) {
        g.emplace_back(i.first, i.second);
        mapa[i.second].insert(i.first);
    }

    sort(g.begin(), g.end());

    rec(g.front().first, 0);

    int t = (n + 1) / 2;
    mapa.clear();

    for (int i = n - t; i < n; i++) {
        mapa[tree[i]];
    }

    if (mapa.size() != t) {
        cout << -1;
        return;
    }

    for (int i = n - t; i < n; i++) {
        cout << tree[i] << " ";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
//    cin >> t;

    while (t--) solve();
}
