#include <bits/stdc++.h>

namespace operators
{
    template <typename T1, typename T2>
    std::istream &operator>>(std::istream &in, std::pair<T1, T2> &x)
    {
        in >> x.first >> x.second;
        return in;
    }

    template <typename T1, typename T2>
    std::ostream &operator<<(std::ostream &out, std::pair<T1, T2> &x)
    {
        out << x.first << " " << x.second;
        return out;
    }

    template <typename T1>
    std::istream &operator>>(std::istream &in, std::vector<T1> &x)
    {
        for (auto &i : x)
            in >> i;
        return in;
    }

    template <typename T1>
    std::ostream &operator<<(std::ostream &out, std::vector<T1> &x)
    {
        for (auto &i : x)
            out << i << " ";
        return out;
    }

    template <typename T1>
    std::ostream &operator<<(std::ostream &out, std::set<T1> &x)
    {
        for (auto &i : x)
            out << i << " ";
        return out;
    }
}
using namespace std;
using namespace operators;

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define uint unsigned int
#define all(vc) vc.begin(), vc.end()

// #define int ll

struct segTree
{
    struct Node
    {
        int val, op;
    };

    int sz = 1;
    vector<Node> tree;

    void init(int n)
    {
        sz = 1;
        while (sz < n)
            sz *= 2;
        tree.resize(sz + sz - 1, {(int)2e9, 0});
    }

    void push(int v, int lv, int rv)
    {
        if (rv - lv == 1 or tree[v].op == 0)
            return;
        tree[v * 2 + 1].val = tree[v * 2 + 2].val = tree[v].op;
        tree[v * 2 + 1].op = tree[v * 2 + 2].op = tree[v].op;
        tree[v].op = 0;
    }

    void set(int l, int r, int val, int v, int lv, int rv)
    {
        push(v, lv, rv);
        if (l <= lv and rv <= r)
        {
            tree[v].op = tree[v].val = val;
            return;
        }
        if (r <= lv or rv <= l)
            return;
        int m = (lv + rv) >> 1;
        set(l, r, val, v * 2 + 1, lv, m);
        set(l, r, val, v * 2 + 2, m, rv);
        tree[v].val = min(tree[v * 2 + 1].val, tree[v * 2 + 2].val);
    }

    void set(int l, int r, int val)
    {
        set(l, r, val, 0, 0, sz);
    }

    int get(int l, int r, int v, int lv, int rv)
    {
        push(v, lv, rv);
        if (l <= lv and rv <= r)
        {
            return tree[v].val;
        }
        if (r <= lv or rv <= l)
            return (int)2e9;
        int m = (lv + rv) >> 1;
        return min(get(l, r, v * 2 + 1, lv, m), get(l, r, v * 2 + 2, m, rv));
    }

    int get(int l, int r)
    {
        return get(l, r, 0, 0, sz);
    }
};

main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    if (n == 1)
    {
        cout << a << "\n";
        return 0;
    }

    int k = __lg(n + 1);
    map<int, int> cnt;

    for (int i = 0; i < n; ++i)
        cnt[a[i]]++;

    vector<vector<int>> cur(k + 1);

    for (auto [x, c] : cnt)
    {
        if (c > k)
        {
            cout << "-1\n";
            return 0;
        }
        cur[c].pb(x);
    }

    segTree tree;
    tree.init((n + 1) / 2);

    int bf = (n + 1) / 2;
    int len = 2;
    vector<int> res((n + 1) / 2);
    for (int i = 1; i <= k; ++i)
    {
        if (i == k)
        {
            if (cur[i].size() != 1)
            {
                cout << "-1\n";
                return 0;
            }
            res[((n + 1) / 2) - 1] = cur[i][0];
            tree.set(((n + 1) / 2) - 1, ((n + 1) / 2), cur[i][0]);
        }
        else
        {
            if (cur[i].size() != bf / 2)
            {
                cout << "-1\n";
                return 0;
            }

            sort(all(cur[i]));
            if (i == 1)
                reverse(all(cur[i]));
            int id = 0;
            for (int j = 0; j < (n + 1) / 2; j += len)
            {
                res[j + len / 2 - 1] = cur[i][id];
                tree.set(j + len / 2 - 1, j + len / 2, cur[i][id]);
                id++;
            }
        }
        len *= 2;
        bf /= 2;
    }

    sort(all(a));
    vector<int> K;
    for (auto [v, op] : tree.tree)
    {
        K.pb(v);
    }
    sort(all(K));
    if (K != a)
    {
        cout << "-1\n";
    }
    else
        cout << res << "\n";
}