#include<bits/stdc++.h>
#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
using namespace std;
#define int long long
const int N = 2e5 + 7;
int a[N], n, k, tr[4 * N], cnt[N];
void ex() {
    cout << "-1\n";
    exit(0);
}
signed main() { 
    ios_base::sync_with_stdio(false);    
    cin.tie(nullptr);
    cin>>n;
    int x = n + 1;
    while(x % 2 == 0)x /= 2, k ++;
    map<int, int> mp;
    set<int> st;
    for(int i = 1; i <= n; i++) {
        cin>>a[i];
        st.insert(a[i]);
        mp[a[i]] ++;
    }
    vector<pair<int, int> > v;
    for(auto j : st) {
        if(++cnt[mp[j]] > k)ex();
        v.push_back({-mp[j], j});
    }
    int xx = 1;
    for(int j = k; j >= 1; j--) {
        if(j == k) {
            if(cnt[j] != 1)ex();
            continue;
        }
        if(cnt[j] != xx)ex();
        xx *= 2;
    }
    sort(v.begin(), v.end());
    int l = 0;
    for(int i = 1; i <= n; i++) {
        if(i % 2 == 1) {
            tr[i] = v[l].second;
            l ++;
        }else {
            tr[i] = tr[i / 2];
        }
    }
    for(int i = 1; i <= n; i++) {
        if(i >= (1 << (k - 1)))continue;
        if(tr[i] != min(tr[i + i], tr[i + i + 1]))ex();
    }
    for(int i = (1 << (k - 1)); i < (1 << k); i++)cout << tr[i] << ' ';
    cout << '\n';
}

