#include<bits/stdc++.h>

#define ll long long
#define int ll
#define sz(v) v.size()

using namespace std;

const int N = (int)1e6 + 7;
const long long INF = (long long)1e18 + 7;

int n, a[N], cnt[N], old[N];
void f() {
    vector <int> v;
    for (int i = 1;i <= n;i++)v.push_back(a[i]);
    sort(v.begin(), v.end());
    map <int, int> id;
    int cur = 0;
    for (int i = 0;i < v.size();i++) {
        if (i > 0 && v[i - 1] == v[i])continue;
        id[v[i]] = ++cur, old[cur] = v[i];
    }
    for (int i = 1;i <= n;i++)a[i] = id[a[i]];
}
bool cmp(int x, int y) {
    return (cnt[x] < cnt[y]) || (cnt[x] == cnt[y] && x < y);//x > y ????
}
int ans[N];
vector <int> order;
multiset <int> st[20];
int dfs(int l, int r, int d, int limit) {
    if (l == r) {
        auto it = st[d].upper_bound(limit);
        //cout << l << ':' << d << ' ' << limit << '\n';
        if (it == st[d].end())cout << -1, exit(0);
        ans[l] = *it, st[d].erase(it);
        cnt[ans[l]]--;
        return ans[l];
    }
    int mid = (l + r) / 2, x;
    limit = dfs(l, mid, d + 1, 0), x = dfs(mid + 1, r, 1, limit);
    assert(limit <= x);
    if (limit > x)cout << -1, exit(0);
    cnt[limit]--;
    return limit;
}
signed main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cin >> n;
    int k = 0;
    for (int i = 1;i < 20;i++) {
        if ((1ll << i) - 1 == n)k = i;
    }
    k--;//???
    for (int i = 1;i <= n;i++)cin >> a[i];
    f();
    for (int i = 1;i <= n;i++)cnt[a[i]]++;
    sort(a + 1, a + n + 1, cmp);
    vector <int> val;
    for (int i = 1;i <= n;i++) {
        if (i > 1 && a[i] == a[i - 1])continue;
        //if (cnt[a[i]] >= 20)cout << -1, exit(0);
        st[cnt[a[i]]].insert(a[i]);
    }
    dfs(1, (1ll << k), 1, 0);
    for (int i = 1;i <= n;i++) {
        if (cnt[a[i]] != 0)cout << -1, exit(0);
    }
    for (int i = 1;i <= (1ll << k);i++)cout << old[ans[i]] << ' ';
    return 0;
}
