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

#ifdef ORD_SET
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    template<typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif
#ifdef ROPE
    #include <ext/rope>
    using namespace __gnu_cxx;
#endif

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using ll = long long;
using ld = long double;
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define sp " "
#define en "\n"
#define bg begin()
#define ed end()
// #define sz size()
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void EvrazGold() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }
const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const ll mod = 1e9+7, N = 3e5+5;

ll n, a[N], k, sz;
map<ll, ll> cnt;
set<ll> g[N];
vector<ll> v[N];
set<ll> st;



void psycho() {
    cin>>n;
    sz = (n + 1) / 2, k = log2(n + 1);
    ll mn = inf;
    for(int i = 1; i <= n; i ++) {
        cin>>a[i];
        mn = min(mn, a[i]);
        st.insert(a[i]);
        cnt[a[i]] ++;
    }
    for(auto x : cnt) {
        if(x.ff == mn) continue;
        g[x.ss].insert(x.ff);
    }
    if(st.size() != sz) {
        cout<<-1;
        return;
    }
    v[k].pb(mn);
    ll cnt = 1;
    for(int d = k - 1; d >= 1; d --) {
        if(g[d].empty() || g[d].size() != cnt) {
            cout<<-1;
            return;
        }
        int id = 0;
        for(auto to : v[d + 1]) {
            auto get = g[d].lower_bound(to);
            if(get == g[d].end()) {
                cout<<-1;
                return;
            }
            v[d].pb(to);
            v[d].pb(*get);
            g[d].erase(get);
        }
        cnt *= 2;
    }
    bool ok = 1;
    for(int d = 2; d <= k; d ++) {
        int id = 0;
        for(auto x : v[d]) {
            if(min(v[d - 1][id], v[d - 1][id + 1]) != x) {
                cout<<-1;
                return;
            }
            id += 2;
        }
    }
    for(auto x : v[1]) cout<<x<<" ";

    return;
}

signed main(/*Nurmyrza, Beibarys, Amir*/) {
    // freopen("");
    EvrazGold();
    ll tt = 1;
    // cin>>tt;
    for(ll i=1; i<=tt; i++) {
        psycho();
    }
}
