#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

#define int long long

struct Pa{
    int x, cnt;

    bool operator<(const Pa& obj) const {
        return x < obj.x;
    }
};

bool comp(const pair<int, int>& obj1, const pair<int, int>& obj2) {
    if (obj1.first == obj2.first) {
        obj1.second > obj2.second;
    } else {
        return obj1.first > obj2.first;
    }
}

void solve() {
    int n;
    cin >> n;
    vector <int> a(n);
    set <Pa> st;
    int cnt;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (st.find({a[i], 1}) == st.end()) {
            st.insert({a[i], 1});
        } else {
            cnt = st.find({a[i], 1})->cnt;
            st.erase(st.find({a[i], 1}));
            st.insert({a[i], cnt + 1});
        }
    }




    int m = st.size();
    int k = log2(m);
    k++;

    vector<pair<int, int>> arr;
    for (Pa a: st) {
        arr.push_back({a.cnt, a.x});
    }
    sort(arr.begin(), arr.end(), comp);


    bool f = true;
    if (arr.back().first != k) {
        f = false;
        cout << "here1";
    }
    k--;
    int b = 1;
    for (int i = m - 2; i >= 0 and f;) {
        for (int q = 0; q < b and f; q++) {
            if (i < 0 or arr[i].first != k) {
                f = false;
                cout << "here2";
            }
            i--;
        }
        b *= 2;
        k--;
    }

    if (!f) {
        cout << -1;
    } else {
        reverse(arr.begin(), arr.end());
        int* t = new int[n + 1];
        t[1] = arr[0].second;
        int ptr = 1;
        for (int i = 1; ptr < m and f; i++) {
            t[i * 2] = t[i];
            t[i * 2 + 1] = arr[ptr].second;
            if (t[i * 2 + 1] < t[i]) {
                f = false;
                cout << t[i * 2 + 1] << ' ' << t[i];
            }
            ptr++;
        }
        if (!f) {
            cout << -1;
            return;
        }
        for (int i = n - m + 1; i <= n; i++) {
            cout << t[i] << ' ';
        }
    }
}

signed main()
{
    int t = 1;
    //cin >> t;
    //freopen("input.in", "r", stdin);
    while (t--) {
        solve();
    }
    return 0;
}
