#include <bits/stdc++.h>

using namespace std;
using ll = long long;


signed main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);


    ll n;
    cin >> n;

    map <ll, ll> d;

    for(ll i = 0; i < n; i++) {
        ll t;
        cin >> t;

        d[t]++;
    }

    map <ll, set <ll>> a;

    for(auto i : d){
        a[i.second].insert(i.first);
    }

    if(n == 1){
        cout << *a[1].begin();
        return 0;
    }

    ll p = 1;

    ll h = log2(n + 1);

    auto it = a.find(h);
    if(it == a.end() || it->second.size() != p) {
        cout << -1;
        return 0;
    }

    for(ll i = h - 1; i > 0; i--){
        auto it = a.find(i);
        if(it == a.end() || it->second.size() != p){
            cout << -1;
            return 0;
        }
        p *= 2;
    }

    vector <ll> ans((n + 1) / 2);
    ans[0] = *a[h].begin();
    ans[ans.size() / 2] = *(a[h-1].begin());

    if(ans[0] > ans[ans.size() / 2]){
        cout << -1;
        return 0;
    }

    ll y = ans.size() / 4;
    ll x = ans.size() - y;




    for(ll i = h - 2; i > 0; i--){
        for(auto it = a[i].rbegin(); it != a[i].rend(); it++){
            if(ans[x - y] > *it){
                cout << -1;
                return 0;
            }

            ans[x] = *it;
            x -= y * 2;
        }

        y /= 2;
        x = ans.size() - y;

    }

    for(auto i : ans)
        cout << i << " ";

    return 0;
}