#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define inf (int)1e9
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")

bool comp(pair<int, int> a, pair<int, int> b) {
    if (a.first > b.first) return true;
    if (b.first > a.first) return false;
    if (a.second < b.second) return true;
    return false;
}

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

    int n;
    cin >> n;
    int k2 = (n + 1) / 2;
    vector<int> a(n);
    for (auto& i : a) cin >> i;

    sort(a.begin(), a.end());
    vector<pair<int, int>> dif;
    for (auto i : a) {
        if (dif.size() == 0 || i != dif[dif.size() - 1].second) {
            dif.push_back({1, i});
        } else {
            ++dif[dif.size() - 1].first;
        }
    }

    if (dif.size() == k2) {
        sort(dif.begin(), dif.end(), comp);
        vector<int> t(n, -1);
        queue<int> q;
        q.push(0);
        for (int i = 0; i < k2; ++i) {
            int v = q.front();
            q.pop();
            if (2 * v + 1 < n) q.push(2 * v + 1);
            if (2 * (2 * v + 2) + 1 < n) q.push(2 * (2 * v + 2) + 1);
            if (v >= n) {
                cout << "-1\n";
                return 0;
            }
            while (true) {
                t[v] = dif[i].second;
                --dif[i].first;
                v = 2 * v + 2;
                if (v >= n) break;
            }
            if (dif[i].first != 0) {
                cout << "-1\n";
                return 0;
            }
        }
        for (int i = 0; i < n - k2; ++i) {
            if (t[i] > t[2 * i + 1] || t[i] > t[2 * i + 2]) {
                cout << "-1\n";
                return 0;
            }
        }

        for (auto i : dif) cout << i.second << " ";
    } else {
        cout << "-1\n";
    }
    return 0;
}
