#include "bits/stdc++.h"

using namespace std;

#define int unsigned long long

map<int, int> d;
map<int, set<int>> mapa;
vector<int> s;
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 ans = 0;
//        for (auto i: mapa[d[u]]){
//            if (i > u and d[i] > 0){
//                ans = i;
//                break;
//            }
//        }

        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);
    }
    return;

}

void solve() {
    cin >> n;
    s.resize(n);
    tree.resize(n);
    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(), [](pair<int, int> a, pair<int, int> b) {
        return a.second > b.second or a.second == b.second and a.first < b.first;
    });

    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() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;

    while (t--) solve();
}
