#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int k = 0;
    while ((1 << k) - 1 != n) {
        k++;
    }
    unordered_map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    vector<vector<int>> a(k + 1);
    for (auto el : cnt) {
        if (el.second > k) {
            cout << -1;
            return 0;
        }
        a[el.second].push_back(el.first);
    }
    vector<vector<int>> tree(k + 1);
    if (a[k].size() != 1) {
        cout << -1;
        return 0;
    }
    tree[k].push_back(a[k][0]);
    for (int d = k - 1; d >= 1; d--) {
        if (tree[d + 1].size() != a[d].size()) {
            cout << -1;
            return 0;
        }
        vector<pair<int, int>> pred;
        for (int i = 0; i < tree[d + 1].size(); i++) {
            pred.push_back({ tree[d + 1][i], i });
        }
        sort(pred.begin(), pred.end());
        sort(a[d].begin(), a[d].end());
        tree[d].resize(tree[d + 1].size() * 2);
        for (int i = 0; i < a[d].size(); i++) {
            if (pred[i].first < a[d][i]) {
                tree[d][2 * pred[i].second] = pred[i].first;
                tree[d][2 * pred[i].second + 1] = a[d][i];
            } else {
                cout << -1;
                return 0;
            }
        }
    }
    for (int el : tree[1]) {
        cout << el << ' ';
    }
}

