#include<bits/stdc++.h>

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

using namespace std;

const int N = (int)2e5 + 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 ????
}
vector <int> order;
void dfs(int v, int l, int r, int d) {
    if (l == r) {
        order.push_back(d);
        return;
    }
    int mid = (l + r) / 2;
    dfs(v * 2, l, mid, d + 1), dfs(v * 2 + 1, mid + 1, r, 1);
}
int ans[N];
int check(int l, int r) {
    if (l == r)return ans[l];
    int mid = (l + r) / 2, x = check(l, mid), y = check(mid + 1, r);
    if (x > y)cout << -1, exit(0);
    return x;
}
vector <int> v[20];
int 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);
        v[cnt[a[i]]].push_back(a[i]);
    }
    for (int i = 1;i < 20;i++)reverse(v[i].begin(), v[i].end());
    if (sz(v[k + 1]) != 1)cout << -1, exit(0);
    for (int i = k;i >= 1;i--) {
        if (sz(v[i]) != (1ll << (k - i)))cout << -1, exit(0);
    }//?????
    dfs(1, 1, (1ll << k), 1);
    int pos = 0;
    for (auto kol : order) {
        if (v[kol].empty())cout << -1, exit(0);
        ans[++pos] = v[kol].back(), v[kol].pop_back();
    }
    check(1, (1ll << k));
    for (int i = 1;i <= pos;i++)cout << old[ans[i]] << ' ';
    return 0;
}


