// Bolatulu
#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define int long long
#define kanagattandirilmagandiktarinizdan ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define F first
#define S second
#define md (tl+tr)/2
#define TL tl,md,v+v
#define TR md+1,tr,v+v+1

#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

using namespace std;

int binpow(int a,int n,int M) {
    if (n==0)
        return 1;
    if (n%2!=0)
        return (a * binpow(a,n-1,M))%M;
    int z=binpow(a,n/2,M);
    return (z*z)%M;
}

const ll INF = 1e18;
const int N =  1e6+7;
const int M = 1e9+7;
const ll HZ = 1e5;
const int MAX = INT_MAX;
const int MIN = INT_MIN;
const db pi = 3.141592653;
const int P=31;

int n,m,a[N],k,t[N],b[N];
set <int> st[N];
map <int,int> cnt;

void build(int tl,int tr,int v,int d) {
    if (tl==tr) {
        b[tl]=t[v];
        return;
    }
    t[v+v]=t[v], build(TL,d-1);
    auto z=st[d-1].upper_bound(t[v]);
    if (z==st[d-1].end()) {
        cout << -1;
        exit(0);
    }
    t[v+v+1]=*z, st[d-1].erase(z), build(TR,d-1);
}

void solve() {
    cin >> n;
    m=n/2+1;
    int z=m;
    while (z) {
        k++;
        z/=2;
    }
    set <int> s;
    for (int i=1;i<=n;i++)
        cin >> a[i], cnt[a[i]]++, s.insert(a[i]);
    if (s.size()!=m or cnt[*s.begin()]!=k) {
        cout << -1;
        return;
    }
    for (auto now : s)
        st[cnt[now]].insert(now);
    t[1]=*s.begin();
    build(1,m,1,k);
    for (int i=1;i<=m;i++)
        cout << b[i] << ' ';
}

signed main() {
    // freopen("lca.in", "r", stdin);
    // freopen("lca.out", "w", stdout);
    kanagattandirilmagandiktarinizdan
    int test = 1, count = 1;
    // cin >> test;
    while (test--) {
        // cout << "Case " << count << ":\n";
        solve();
        if (test)
            // cout << '\n';
            count++;
    }
    return 0;
}