#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <random>
#include <chrono>

using namespace std;

using ll = long long;
using ld = long double;

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

//#define int long long
#define all(x) (x).begin(), (x).end()

vector<vector<int>> s;
vector<int> a;

void rec(int k, int c) {
    if (c != 1 && s[k].size() != c / 2 || c == 1 && s[k].empty()) {
        cout << -1;
        exit(0);
    }
    if (c == 1) {
        a.push_back(s[k].back());
        s[k].pop_back();
    } else {
        vector<int> b;
        while (!s[k].empty()) {
            b.push_back(a.back());
            a.pop_back();
            b.push_back(s[k].back());
            s[k].pop_back();
        }
        a = b;
    }/*
    for (auto i: a) cout << i << ' ';
    cout << endl;*/
    if (k == 1) return;
    rec(k - 1, c * 2);
}

void solve() {
    int n;
    cin >> n;
    vector<int> a1(n);
    map<int, int> cnt;
    for (auto &i: a1) cin >> i, cnt[i]++;
    s.resize(n + 1);
    for (int i = 0; i <= n; i++) s[cnt[i]].push_back(i);
    int k = 1;
    while ((1 << k) < n) k++;
    rec(k, 1);
    for (auto i: a) cout << i << ' ';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll timer = 1;
    // cin >> timer;
    while (timer--) {
        solve();
    }
    return 0;
}

/*
#.#.#.....
.......##.
.#..#.....
.#........
.#..##....
..........
####...#..
.......#..
.......#..
##........

 */