#include <bits/stdc++.h>
#define endl '\n'
#define int ll
#define ve vector
#define pb push_back
#define all(x) x.begin() , x.end()
#define pii pair <int , int>
#define F first
#define S second
#define bpp __builtin_popcount

using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 2e5 + 10;

vector < int > ver[N];

vector < int > my[N];
int ind[N], sz[N];
map < int, int > mp, re;
int a[N];

int fnd(int x){
    if(ind[x] == x) return x;
    else return ind[x] = fnd(ind[x]);
}

void unt(int v, int u){
    v = fnd(v);
    u = fnd(u);

    if(sz[v] < sz[u]) swap(u, v);

    ind[u] = v;
    sz[v] += sz[u];

    for(auto to : my[u])
        my[v].pb(to);

    my[u].clear();
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt" , "r" , stdin);
        freopen("output.txt" , "w" , stdout);
    #endif // LOCAL


    int n;
    cin >> n;

    int k = bpp(n);

    map < int, int > cnt;



    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);

    int num = 1;
    for(int i = 1; i <= n; i++){
        if(!mp.count(a[i])) mp[a[i]] = num++;
        re[mp[a[i]]] = a[i];
        a[i] = mp[a[i]];
        cnt[a[i]]++;
    }

//    cout << (1 << (k - 1)) << ' ' << cnt.size() << endl;
    if(cnt.size() != (1 << (k - 1))){
        cout << -1;
        return 0;
    }

    for(auto to : cnt){
        ver[to.S].pb(to.F);
        ind[to.F] = to.F, sz[to.F] = 1;
        my[to.F].pb(to.F);
    }

    for(int high = 1; high < k; high++){
        vector < int > need;

        for(int h = high + 1; h <= k; h++)
            for(auto to : ver[h])
            need.pb(to);

        if(ver[high].size() != need.size()){
//            cout << "OK " << high << endl;
            cout << -1;
            return 0;
        }

        sort(need.begin(), need.end());

        for(int i = 0; i < (int)(need.size()); i++){
            if(need[i] > ver[high][i]){
                cout << -1;
                return 0;
            }

            unt(need[i], ver[high][i]);
        }

    }

    int root = fnd(a[1]);
    for(auto to : my[root])
        cout << re[to] << ' ';







    return 0;

}
