#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define endl '\n'
#define fr first
#define sc second
#define ld long double
 
template <typename _T>
bool chmin(_T &a, const _T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename _T>
bool chmax(_T &a, const _T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
 
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const double eps = 1e-6;
const double EPS = 1e-9;
const int N = 2e5 + 5 ;
 
vector<ll> t(N*4);
ll ans[N];
map<ll,ll> mp2;
void build(ll v,ll tl,ll tr){
  if(tl==tr){
    t[v]=ans[tl];
    mp2[t[v]]++;
    return;
  }
  ll tm=(tl+tr)/2;
  build(v*2,tl,tm);
  build(v*2+1,tm+1,tr);
  t[v]=min(t[v*2],t[v*2+1]);
  mp2[t[v]]++;
}
 
void solve() {
  ll n,m,i,j;
  ll b,c;
  cin>>n;
  m=(n+1)/2;
  map<ll,ll> mp;
  vector <ll> vv;
  for(i=0;i<n;i++){
    cin>>b;
    if(mp[b]==0)vv.pb(b);
    mp[b]++;
  }
  vector <pair<ll,ll>> v2;
  vector <ll> vec;
  vector <set<ll>> v(40);
  for(i=0;i<m;i++){
    v[mp[vv[i]]].insert(vv[i]);
    vec.pb(vv[i]);
  }
  m=(n+1)/2;
  for(i=1;i<=m;i++){
    c=0;
    for(j=0;j<=log2(m);j++){
      if(i%(1ll<<j)==1){
        c++;
      }
    }
    v2.pb({c,-i});
  }
  sort(rall(v2));
  for(i=0;i<(ll)v2.size();i++){
    ll a=v2[i].fr,b=-v2[i].sc;
    if(i==0){
      ans[b]=*v[a+1].begin();
      continue;
    }
    auto low=lower_bound(all(v[a+1]),ans[b-(1ll<<a)]);
    if(low==v[a+1].end()){
      cout<<-1<<endl;
      return;
    }
    ans[b]=*low;
    v[a+1].erase(low);
  }
  build(1,1,m);
  bool flag=true;
  for(i=0;i<m;i++){
    if(mp[vec[i]]!=mp2[vec[i]])flag=false;
  }
  if(!flag){
    cout<<-1<<endl;
    return;
  }
  for(i=1;i<=m;i++) cout<<ans[i]<<' ';
  cout<<endl;
}
 
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while(tt--) {
    solve();
  }
}
