#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define kchau ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;
const ll SP = 2e5 + 7;
const ll N = 1e6 + 7;

using namespace std;

ll a[SP], d[SP];

ll tree[SP * 2];

void build(ll v, ll tl, ll tr){
  if(tl == tr){
    tree[v] = d[tl];
    return;
  }
  ll tm = (tl + tr) / 2;
  build(v * 2, tl, tm);
  build(v * 2 + 1, tm + 1, tr);
  tree[v] = min(tree[v * 2], tree[v * 2 + 1]);
}

int main(){
  // freopen("txt.in", "r", stdin);
  // freopen("txt.out", "w", stdout);
  kchau
  ll n; cin >> n;
  map<ll, ll> mp;
  map<ll, vector<ll>> mm;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    if(n == 1) return cout << a[i], 0;
    mp[a[i]]++;
  }
  ll m = mp.size();
  ll k = 1;
  while(m / 2 != 1 && m != 1){
    m /= 2;
    k++;
  }
  m = mp.size();
  vector<ll> x, y;
  for(auto it : mp){
    mm[it.S].pb(it.F);
    x.pb(it.S);
  }
  ll cnt = k + 1, ct = 1;
  y.pb(cnt);
  for(int i = 1; i <= k; i++){
    cnt--;
    for(int j = 1; j <= ct; j++){
      y.pb(cnt);
    }
    ct *= 2;
  }
  // for(int i = 1; i <= k + 1; i++){
  //   sort(rall(mm[i]));
  // }
  sort(rall(x));
  sort(rall(y));
  if(x.size() != y.size()) return cout << -1, 0;
  for(int i = 0; i < x.size(); i++){
    if(x[i] != y[i]) return cout << -1, 0;
    // cout << x[i] << " " << y[i] << '\n';
  }
  // for(auto it : mm){
  //   cout << it.F << '\n';
  //   for(auto itt : it.S){
  //     cout << itt << " ";
  //   }
  //   cout << '\n';
  // }
  bool c[SP];
  ll count = m;
  for(int i = 1; i <= k + 1; i++){
    // cout << k - i + 2 << " " << count << " ya tut " << "\n";
    ll q = 0;
    for(int j = 1; j <= m; j += count){
      if(!c[j]){
        c[j] = 1;
        d[j] = mm[k - i + 2][q];
        // cout << mm[k - i + 2][q] << " " << q << "\n";
        q++;
      }
    }
    if(count != 1) count /= 2;
  }
  build(1, 1, m);
  vector<ll> z;
  for(int i = 1; i <= n; i++){
    z.pb(tree[i]);
  }
  sort(all(z));
  sort(a + 1,a + 1 + n);
  for(int i = 0; i < n; i++){
    if(a[i + 1] != z[i]) return cout << -1, 0;
  }
  for(int i = 1; i <= m; i++){
    cout << d[i] << " ";
  }
  return 0;
}