#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int n1=n+1;
    int col=0;
    while(n1>1){
        ++col;
        n1=n1/2;
    }
    vector<int> a(n);
    for (int i=0; i<n; ++i){
        cin>>a[i];
    }
    map<int, int> pod;
    for (int i=0; i<n; ++i){
        ++pod[a[i]];
    }
    vector<vector<int>> b(col+1);
    for (auto i: pod){
        if(i.second>col){
            cout<<-1;
            return 0;
        }
        b[i.second].push_back(i.first);
    }
    if(b[col].size()!=1){
        cout<<-1;
        return 0;
    }
    int st=1;
    for(int i=col-1; i>0; --i){
        if(b[i].size()!=st ){
            cout<<-1;
            return 0;
        }
        st=st*2;
    }
    for (int i=1; i<=col; ++i){
        sort(b[i].begin(), b[i].end());
    }
    vector<vector<int>> s(col);
    s[0]={b[col][0]};

    for (int i=1; i<col; ++i){
        for (int j=0; j<s[i-1].size(); ++j){
            s[i].push_back(s[i-1][j]);
            s[i].push_back(b[col-i][j]);
            if(b[col-i][j]<=s[i-1][j]){
                cout<<-1;
                return 0;
            }
        }
    }
    for (int i: s.back()){
        cout<<i<<" ";
    }
    return 0;
}
