#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin >> n;

    vector<int> a(n);
    set<int> uniq;
    map<int, int> count;
    map<int, set<int>> elems;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        uniq.insert(a[i]);
        count[a[i]]++;
    }
    if (uniq.size() * 2 != n + 1) {
        cout << -1;
        return 0;
    }
    for (const auto& [key, val] : count)
        elems[val].insert(key);

    vector<int> st(n + 1);
    int len = (int) log2(uniq.size()) + 1;
    if (elems[len].empty()) {
        cout << -1;
        return 0;
    }
    st[1] = *(elems[len].begin());
    int v = 2;
    for (int level = 1; level < len; ++level)
        for (int i = 0; i < pow(2, level); ++i) {
            if ((v & 1) == 0)
                st[v] = st[v / 2];
            else {
                auto it = elems[len - level].upper_bound(st[v / 2]);
                if (it == elems[len - level].end()) {
                    cout << -1;
                    return 0;
                }
                st[v] = *it;
                elems[len - level].erase(it);
            }
            v++;
        }

    for (int i = (int) uniq.size(); i < st.size(); ++i)
        cout << st[i] << " ";
}