#include <bits/stdc++.h>

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define fi first
#define se second
#define pb push_back
#define fr(i, l, r) for (int i = (l); i <= (r); ++i)
#define rf(i, l, r) for (int i = (l); i >= (r); --i)

using namespace std;
typedef long long ll;
const ll N=2e5+100;
set<ll > cnt[N];
map<ll,ll> mp;
ll tree[N];
ll k=0;
vector<pair<ll,ll> > ans;
void build(ll v,ll deep, char napramak){
 if(napramak=='r'){
    if(cnt[deep].empty()){
        cout<<-1<<endl;
        exit(0);
    }
    auto it=cnt[deep].begin();
    tree[v]=*it;
   cnt[deep].erase(it);
 }
 else {
    tree[v]=tree[v>>1];
 }
 if(deep==1){
   ans.pb({v,tree[v]});
   return ;
 }
 build(v<<1,deep-1,'l');
 build(v<<1|1,deep-1,'r');
}
void solve() {
    ll n;
    cin>>n;
    for(int i=0;i<n;i+=1){
        ll x;
        cin>>x;
        mp[x]++;
    }
    for(auto x : mp){
        cnt[x.se].insert(x.fi);
    }
    ll a=1;
    while(a-1!=n){
        a*=2;
        k++;
    }
    build(1,k,'r');
    sort(ans.begin(),ans.end());
    for(auto x : ans)cout<<x.se<<" ";
    cout<<endl;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}
