#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

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);
    }

    int bf = (n + 1) / 2;
    vector<vector<int>> res(k + 10, vector<int>(bf * 2));

    fill(all(res[0]), 2e9);

    for (int i = 1; i <= k; ++i)
    {
        if (cur[i].size() != (bf + 1) / 2)
        {
            cout << "-1\n";
            return 0;
        }
        sort(all(cur[i]));

        if (i == k)
        {
            if (max(res[i - 1][0], res[i - 1][1]) < cur[i][0])
            {
                cout << "-1\n";
                return 0;
            }
            else
                res[i][0] = cur[i][0];
        }

        else
        {
            for (int l = 0; l < cur[i].size(); l++)
            {
                int j = l * 2;
                if (max(res[i - 1][j * 2], res[i - 1][j * 2 + 1]) > cur[i][l])
                {
                    res[i][j] = cur[i][l];
                }
                else if (max(res[i - 1][(j + 1) * 2], res[i - 1][(j + 1) * 2 + 1]) > cur[i][l])
                    res[i][j + 1] = cur[i][l];
                else
                {
                    // cout << cur[i][l] << " " << max(res[i - 1][(j + 1) * 2], res[i - 1][(j + 1) * 2 + 1]) << " " << max(res[i - 1][j * 2], res[i - 1][j * 2 + 1]) << "\n";
                    cout << "-1\n";
                    return 0;
                }
            }
        }
        bf /= 2;
    }

    // for (int i = k; i >= 1; --i)
    //     cout << res[i] << "\n";

    int bbf = 1;
    for (int i = k; i > 1; --i)
    {
        for (int j = 0; j < bbf; ++j)
        {
            if (!res[i - 1][j * 2])
                res[i - 1][j * 2] = res[i][j];
            else
                res[i - 1][j * 2 + 1] = res[i][j];
        }
        bbf *= 2;
    }

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