# include <bits/stdc++.h>

# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
# define pii pair <int, int>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 2e5 + 7;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll a[maxn] , ans[maxn] , sz[maxn] , n;
deque <ll> g[maxn];
vector<ll> ob;
map<ll,ll> mp;
void precalc(int v){
  sz[v] = 1;
  if(v*2 <= n) precalc(v*2);
  if(v*2+1 <= n) precalc(v*2+1);
  sz[v] = sz[v*2]+1;
}
void dfs(int v , int num){
  ans[v] = num;
  mp[ans[v]]--;
  if(mp[ans[v]] < 0){
    cout << "-1";
    exit(0);
  }
  if(v*2 <= n) dfs(v*2,num);
  if(v*2+1 <= n){
    if(g[sz[v*2+1]].size() == 0){
      cout << "-1";
      exit(0);
    }
    int nw = g[sz[v*2+1]].front();
    g[sz[v*2+1]].pop_front();
    dfs(v*2+1,nw);
  }
  if(v*2 > n){
    ob.push_back(ans[v]);
  }
}
void ma1n () {
   cin >> n;
   for(int i = 1; i <= n; i++) {
     cin >> a[i];
     mp[a[i]]++;
   }
   sort(a+1,a+1+n);
   mp[a[1]] = 0;
   for(int i = 1; i <= n; i++) {
     if(mp[a[i]] > 0){
       g[mp[a[i]]].push_back(a[i]);
      mp[a[i]] = 0;
     } 
   }
   for(int i = 1; i <= n; i++) mp[a[i]]++;
   precalc(1);
   dfs(1,a[1]);
   for(int i = 1; i <= n; i++) {
     if(mp[a[i]] > 0){
       cout << "-1";
       return;
     }
   }
   for(int x : ob) cout << x <<" ";
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test) {
//      cout << "Case " << test << ":" << '\n';
        ma1n();
    }
    return 0;
}
