#include <bits/stdc++.h>
using namespace std;

    typedef long long ll;
    typedef long double ld;
vector<ll> A;
ll op(ll a, ll b) {
    return max(a, b);
}
void build(ll n) {
    for (ll x = n - 1; x >= 0; x--) {
        A[x] = op(A[2 * x + 1], A[2 * x + 2]) + 1;
    }
}
void build1(ll n) {
    for (ll x = 0; x <= n - 1; x++) {
        A[2 * x + 1] = A[x];
    }
}
void solve() {
    ll n;
    cin >> n;
    A.assign(n, 1);
    build(log2(n + 1));
    /*for (ll i = 0; i < n; i++) {
        cout << A[i] << ' ';
    }
    cout << '\n';*/
    build1(log2(n + 1));
    /*for (ll i = 0; i < n; i++) {
        cout << A[i] << ' ';
    }*/
    map<ll, ll> B;
    for (ll i = 0; i < n; i++) {
        ll a;
        cin >> a;
        B[a]++;
    }
    vector<set<ll>> C(n + 1);
    for (auto i : B) {
        C[i.second].insert(i.first);
    }
    vector<ll> Ans;
    for (ll i = log2(n + 1); i < n; i++) {
        if (C[A[i]].size() == 0) {
            cout << -1 << '\n';
            return;
        }
        Ans.push_back(*C[A[i]].begin());
        C[A[i]].erase(C[A[i]].begin());
    }
    for (ll i = 0; i < n; i++) {
        if (C[i].size() != 0) {
            cout << -1 << '\n';
            return;
        }
    }
    for (ll i : Ans) {
        cout << i << ' ';
    }
}

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

    int t = 1;
    //cin >> t;

    while (t--) {
        solve();
    }
}
