    #pragma GCC optimize("O3")
    #include <bits/stdc++.h>
    #define int long long
    #define ll long long
    #define f first
    #define s second
    #define pb push_back
    #define sz(x) (int) x.size()
    #define all(x) begin(x), end(x)
    using namespace std;

    const int N = 2e5 + 1, inf = LLONG_MAX / 2ll ;

    void solve() {
        int n; cin >> n;
        unordered_map<int, set<ll>> vals;
        unordered_map<ll, int> cnt;
        auto add = [&](ll x) {
            int cur_cnt = cnt[x];
            vals[cur_cnt].erase(x);
            cur_cnt = ++cnt[x];
            vals[cur_cnt].insert(x);
        };
        auto del = [&](ll x) {
            int cur_cnt = cnt[x];
            vals[cur_cnt].erase(x);
            cur_cnt = --cnt[x];
            vals[cur_cnt].insert(x);
        };
        for(int i = 0; i < n; i++) {
            ll x; cin >> x; add(x);
        }       
        int m = (n + 1) / 2;
        int height = __lg(m) + 1;
        vector<ll> a(m, -1);
        bool ok = true;
        function<void(ll, ll, int, int, int)> solve = [&](ll more, ll must, int level, int lx, int rx) {
            if(rx - lx == 1) {
                if(must != -1) {
                    if(cnt[must] != 1) ok = false;
                    else {
                        del(must);
                        a[lx] = must;
                    }
                } else {
                    auto it = vals[height - level].upper_bound(more);
                    if(it == vals[height - level].end()) ok = false;
                    else {
                        ll x = *it;
                        del(x);
                        a[lx] = x;
                    }
                }
                return;
            }
            int mx = (lx + rx) / 2;
            if(must == -1) { 
                if(vals[height - level].size() != 1) ok = false;
                else {
                    auto it = vals[height - level].upper_bound(more);
                    if(it == vals[height - level].end()) ok = false;
                    else {
                        ll x = *it;
                        del(x);
                        solve(more, x, level + 1, lx, mx);
                        solve(x, -1, level + 1, mx, rx);
                    }
                }
            } else {
                del(must);
                solve(more, must, level + 1, lx, mx);
                solve(must, -1, level + 1, mx, rx);
            }
        };
        solve(-1, -1, 0, 0, m);
        if(!ok) {
            cout << -1;
        } else {
            for(auto i : a) cout << i << ' ';
        }
        return ;
    }

    signed main() {
        ios_base::sync_with_stdio(NULL);
        cin.tie(0);cout.tie(0);
        int T = 1 ;
        while (T--) {
            solve ( ) ;
        }
        return 0 ;
    }