
#include <bits/stdc++.h>

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

#define fi first
//#define second secondcond
#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;
typedef long double ld;
const ll N=2e5+100;
map<ll,ll> mp,mp2;
set<ll> cnt[N];
vector<ll > ans;
ll tree[N*4];
ll tr[N*4];
void build(ll v,ll deep){
if(cnt[deep].empty()){

    cout<<-1<<endl;
    exit(0);
}
auto it=cnt[deep].begin();
tree[v]=*it;
cnt[deep].erase(it);
cnt[deep-1].insert(tree[v]);
if(deep==1){
  ans.pb(tree[v]);
  return ;
}
build(v<<1,deep-1);
build(v<<1|1,deep-1);
}
void build2(ll v,ll l,ll r){
if(l==r){
    tr[v]=ans[l];
    mp2[tr[v]]++;
    return ;
}
ll m=(l+r)>>1;
build2(v<<1,l,m);
build2(v<<1|1,m+1,r);
tr[v]=min(tr[v<<1],tr[v<<1|1]);
mp2[tr[v]]++;
}
void solve() {
   ll n;
   cin>>n;
   for(int i=0;i<n;i+=1){
    ll x;
    cin>>x;
    mp[x]++;
   }
   for(auto i : mp){
    cnt[i.second].insert(i.fi);
   }
   ll a=1,k=0;
   while(a-1!=n){
    a*=2;
    k++;
   }
   build(1,k);
   build2(1,0,ans.size()-1);
   for(auto x : ans){
    if(mp[x]!=mp2[x]){
        cout<<-1<<endl;
      return ;
    }
   }
   for(auto x : ans)cout<<x<<" ";
   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;
}

