#include <bits/stdc++.h>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define WHAT ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define cin(x, N) for(int i = 1; i <= N; i ++) cin >> x[i]
#define reset(x, N) for(int i = 1; i <= N; i ++) x[i] = 0;
#define sortvec(x) sort(x.begin(), x.end())
#define open_file(intput, output) freopen("input","r",stdin);freopen("output","w",stdout)
 
int n,m;
int main(){
    WHAT
    int N;
    cin >> N;
    int a[N + 1];
    map <int, int> mp;
    for(int i = 1; i <= N; i ++){
        cin >> a[i];
        if(mp.count(a[i]) == 0) mp[a[i]] = 1;
        else mp[a[i]] ++;
    }
    int ans = log2(N + 1);
    if(mp.size() != N / 2 + 1){
        cout << -1;
        exit(0);
    }
    //mp1 - элементы
    //mp2 - количество элементов
    //sizes1 - количество элементов 
    //sizes2 - количество количества элементов
    map <int, int> sizes;
    map <int, int> :: iterator it = mp.begin();
    while(it != mp.end()){
        if(sizes.count(it->second) == 0) sizes[it->second] = 1;
        else sizes[it->second] ++;
        it ++;
    }
    if(sizes.size() != ans){
        cout << -1;
        exit(0);
    }
    for(int i = 1; i <= ans; i ++){
        if(sizes.count(ans) == 0){
            cout << -1;
            exit(0);
        }
    }
    if(sizes[ans] != 1){
        cout << -1;
        exit(0);
    }
    int pos[N + 1];
    for(int i = 1; i <= ans + 1; i ++){
        int k = N / pow(2, i - 1);
        int l = pow(2, i - 1);
        for(int j = 1; j <= k; j ++){
            pos[(j - 1) * l + 1] = i;
        }
    }
    set <int> q[ans + 1];
    it = mp.begin();
    while(it != mp.end()){
        if(sizes[it->second] == 0){
            cout << -1;
            exit(0);
        }
        q[it->second].insert(it->first);
        mp[it->second] --;
        it ++;
    }
    for(int i = 1; i <= N / 2 + 1; i ++){
        int k = *q[pos[i]].begin();
        q[pos[i]].erase(k);
        cout << k << " ";
    }
}
//15 
//1 1 5 1 3 5 7 1 2 3 4 5 6 7 8 
//1 2 3 4 5 6 7 8 
//4 1 2 1 3 1 2 1
//1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
//5 1 2 1 3 1 2 1 4 1  2  1  3  1  2  1