#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()

using namespace std;

const long long mod = 1000000007, mod3 = 998244353, inf = (ll)1e15;

struct T{
    ll x, y;
};

ll n;

ll k, a[1000005], b[1000005], t[400005 * 4];

map <ll, ll> used, used2;

ll cnt[500005];

T p[500005];

void build(ll v = 1, ll tl = 1, ll tr = (n + 1) / 2){
    if (tl == tr){
        t[v] = a[tl];

        used2[t[v]]++;

        return;
    }

    ll tm = (tl + tr) >> 1;

    build(v + v, tl, tm);
    build(v + v + 1, tm + 1, tr);

    t[v] = min(t[v + v], t[v + v + 1]);

    used2[t[v]]++;
}
void query(){
    cin >> n;

    set <ll> s;

    for (ll i = 1; i <= n; i++){
        cin >> a[i];

        s.insert(a[i]);

        used[a[i]]++;
    }

    if (s.size() != (n + 1) / 2){
        cout << "-1";

        return;
    }

    ll cur = 0;

    for (auto i : s){
        p[++cur] = {i, used[i]};
    }

    sort (p + 1, p + cur + 1, [](T a, T b){
        if (a.y == b.y) return a.x > b.x;

        return a.y < b.y;
    });

    k = (n + 1) / 2;

    for (auto i : s){
        cnt[used[i]]++;
    }

    ll h = k / 2;
    for (ll i = 1; i < log2(n+1); i++){
        if (cnt[i] != h){
            cout << -1;
            return;
        }
        h /= 2;
    }
    int pos=1;
    for(int i=1; i <= cur; i++){
        if(n < pos)pos = (1<<p[i].y-1);
        a[pos] = p[i].x;
        pos += (1<<p[i].y);
    }
    build();

    for (auto i : s){
        if (used[i] != used2[i]){
            cout << -1;
            return;
        }
    }
    for(int i=1; i <= k; i++){
        cout << a[i] << ' ';
    }

}
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    ll TT = 1;

    //cin >> TT;

    while(TT--){
        query();
    }

    return 0;
}

/**

*/
