#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<iomanip>
using namespace std;
using ll = long long;
vector<int>ans;

void f(int v, int l, int r, set<pair<int, int>>x) {
    auto [c1, a1] = *x.begin();
    //cout << l << ' ' << r << ' ' << a1 << ' ' << c1 << "\n";
    if (x.size() == 1) {
        ans[l] = a1;
        return;
    }
    x.erase(x.begin());
    auto [c2, a2] = *x.begin();
    x.erase(x.begin());
    set<pair<int, int>>x1, x2;
    x1.insert({ c1 + 1, a1});
    x2.insert({ c2 + 1, a2 });
    for (auto [c, a] : x) {
        if (a > a2) {
            x2.insert({ c, a });
        }
        else {
            x1.insert({ c, a });
        }
    }
    f(2 * v + 1, l, (l + r) / 2, x1);
    f(2 * v + 2, (l + r) / 2, r, x2);
}
void solve()
{
    int n;
    cin >> n;
    vector<int>tree(n);
    map<int, int>cnt;
    set<pair<int, int>>cntx;
    for (int i = 0; i < n; ++i) {
        cin >> tree[i];
        cnt[tree[i]]++;
    }
    for (auto [x, y] : cnt) {
        cntx.insert({ -y, x });
    }
    int n1 = (n + 1) / 2;
    if (n1 != cnt.size()) {
        cout << "-1\n";
        return;
    }
    ans.resize(n1);
    
    f(0, 0, n1, cntx);
    vector<int>fintree(2 * n1 - 1);
    for (int i = 0; i < n1; ++i) {
        fintree[n1 + i - 1] = ans[i];
    }
    for (int i = n1 - 2; i >= 0; --i) {
        fintree[i] = min(fintree[2 * i + 1], fintree[2 * i + 2]);
    }
    sort(fintree.begin(), fintree.end());
    sort(tree.begin(), tree.end());
    //for (auto x : ans) cout << x << ' ';
    if (tree == fintree) {

        for (auto x : ans) {
            cout << x << ' ';
        }
    }
    else cout << "-1\n";
}
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cout.tie(0)->sync_with_stdio(0);
    int t = 1;
    //cin>>t;
    while (t--) {
        solve();
    }
}