#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9;
//using ld = long double;

struct segtree {
    vector<ll> tree;
    int size;

    void init(int n) {
        size = 1;
        while (size < n) size *= 2;
        tree.assign(2 * size - 1, inf);
    }

    void upd(int i, ll v, int x, int lx, int rx) {
        if (rx - lx == 1) {
            tree[x] = min(tree[x], v);
            return;
        }
        int m = (lx + rx) >> 1;
        if (i < m) upd(i, v, 2 * x + 1, lx, m);
        else upd(i, v, 2 * x + 2, m, rx);
        tree[x] = min(tree[2 * x + 1], tree[2 * x + 2]);
    }

    void upd(int i, ll v) {
        upd(i, v, 0, 0, size);
    }

    ll get(int l, int r, int x, int lx, int rx) {
        if (l >= rx or lx >= r) return inf;
        if (l <= lx and rx <= r) return tree[x];
        int m = (lx + rx) >> 1;
        return min(get(l, r, 2 * x + 1, lx, m), get(l, r, 2 * x + 2, m, rx));
    }

    ll get(int l, int r) {
        return get(l, r + 1, 0, 0, size);
    }
};


vector<int>ans;


int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> v(n), a;
    map<int, int> mp, connect;
    for (int &x: v) cin >> x;
    for (int x: v) mp[x]++;
    for (auto &it: mp) a.emplace_back(it.first);
    vector<vector<int>> all;
    if (mp.size() != __builtin_popcount(n) + 1) {
        cout << -1;
        return 0;
    }
    while (a.size() > 1) {
        vector<int> del, oth;
        for (int i = 0; i < a.size(); i++) {
            if (mp[a[i]] == 1) del.emplace_back(a[i]);
            else oth.emplace_back(a[i]);
            mp[a[i]]--;
        }
        sort(del.begin(), del.end());
        sort(oth.begin(), oth.end());
        if (del.size() != oth.size()) {
            cout << -1;
            return 0;
        }
        all.emplace_back(del);
        for (int i = 0; i < del.size(); i++) {
            if (oth[i] > del[i]) {
                cout << -1;
                return 0;
            }
            connect[del[i]] = oth[i];
        }
        a = oth;
    }
    reverse(all.begin(), all.end());
    for (auto &v: all) {
        map<int, int> pos;
        vector<int> nw(2 * a.size());
        for (int i = 0; i < a.size(); i++) pos[a[i]] = i;
        for (int i = 0; i < a.size(); i++) nw[i * 2] = a[i];
        for (int i = 0; i < v.size(); i++) {
            nw[pos[connect[v[i]]] * 2 + 1] = v[i];
        }
        a = nw;
    }
    for (int x: a) cout << x << ' ';
}