#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pii pair<long long, long long>

const int N = 2e5 + 10;

int n;

int t[N];

int d[N], arr[N / 2], pos[N];

unordered_map < int, set < int > > v;

int Build(int x, int lx, int rx) {
    if (lx == rx) {
        d[x] = 1;
        v[d[x]].insert(x);
        pos[x] = lx;

        return 1;
    } else {
        int m = (lx + rx) / 2;

        int mx = Build(x + x, lx, m) + 1;

        Build(x + x + 1, m + 1, rx);

        d[x] = mx;
        v[d[x]].insert(x);

        return mx;
    }
}

int Update(int x, int &k) {
    v[d[x]].erase(x);

    d[x] = -1;
    t[x] = k;

    if (x + x > n)
        return pos[x];

    if (d[x + x] != -1 && t[x + x] > k && t[x + x + 1] > k)
        return Update(x + x, k);
    else if (d[x + x + 1] != -1 && t[x + x] > k && t[x + x + 1] > k)
        return Update(x + x + 1, k);
    else {
        cout << "-1\n";
        exit(0);
    }
}

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

    cin >> n;

    for (int i = 1; i <= n; i++)
        t[i] = INT_MAX;

    set < int > s;
    unordered_map < int, int > cnt;

    for (int i = 0, x; i < n; i++)
        cin >> x, cnt[x]++, s.insert(x);

    Build(1, 0, n / 2);

    for (auto x : s) {
        if (v[cnt[x]].empty()) {
            cout << "-1\n";
            return 0;
        }

        if (t[*v[cnt[x]].begin() / 2] > x) {
            cout << "-1\n";
            return 0;
        }

        int id = Update(*v[cnt[x]].begin(), x);

        arr[id] = x;
    }

    for (int i = 1; i <= n; i++)
        if (d[i] > -1) {
            cout << "-1\n";
            exit(0);
        }

    for (int i = 0; i <= n / 2; i++)
        cout << arr[i] << " ";
}
