#include <bits/stdc++.h>
using namespace std;

#define pii pair<long long, long long>

int n;

int arr[200001];

unordered_map < int, set < int > > v;

inline void Build(int x, int lx, int rx, int num, int k) {
    if (lx == rx) {
        arr[lx] = num;
    } else {
        int m = (lx + rx) / 2;

        Build(x + x, lx, m, num, k - 1);

        if (!v.count(k - 1) || v[k - 1].empty()) {
            cout << "-1\n";
            exit(0);
        }

        auto nxt = v[k - 1].upper_bound(num);

        if (nxt == v[k - 1].end()) {
            cout << "-1\n";
            exit(0);
        }

        int num2 = *nxt;

        v[k - 1].erase(num2);

        Build(x + x + 1, m + 1, rx, num2, k - 1);
    }
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);

    cin >> n;

    unordered_map < int, int > cnt;

    for (int i = 0, x; i < n; i++)
        cin >> x, cnt[x]++;    

    for (auto [x, y] : cnt)
        v[y].insert(x);

    if (!v.count(__lg(n + 1)) || v[__lg(n + 1)].empty()) {
        cout << "-1\n";
        return 0;
    }

    int first = *v[__lg(n + 1)].begin();
    v[__lg(n + 1)].erase(first);

    Build(1, 0, n / 2, first, __lg(n + 1));

    for (int i = 0; i <= n / 2; i++)
        cout << arr[i] << " ";
}
