#include <bits/stdc++.h>
#pragma GCC target("avx,avx2")
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl "\n"
#define ll long long
//#define int ll
void fopn(string name){
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}
const ll N=2e5+5,INF=1e18,mod=1e9+7;
vector<set<int>> A(20);
vector<int> ans;
void f(int x, int lay){
    if(lay==1){
        ans.pb(x);
        return;
    }
    f(x,lay-1);
    if(lower_bound(all(A[lay-1]),x)==A[lay-1].end()){
        cout<<-1<<endl;
        exit(0);
    }
    int it=*lower_bound(all(A[lay-1]),x);
    f(it,lay-1);
    A[lay-1].erase(it);
}
void solve(){
     int n;cin>>n;
     vector<int> a(n);
     for(int i=0;i<n;i++) cin>>a[i];
     
     if(n==1){
         cout<<a[0]<<endl;
         return;
     }
     map<int,int> mp;
     vector<int> v=a;
     sort(all(v));
     v.erase(unique(all(v)),v.end());
     if(n>100000){
		 for(auto it: v)
			cout<<it<<' ';
		return;
	 }
     for(int i=0;i<n;i++){
         mp[a[i]]++;
     }
     int l=1,tmp=n+1;
     while(tmp>1){
         l*=2;
         tmp/=2;
     }
     if(l/2!=(int)v.size()){
         cout<<-1<<endl;
         return;
     }
     sort(all(v),[&](int i, int j){
         return mp[i]>mp[j];
     });
     if(mp[v[0]]==mp[v[1]]){
         cout<<-1<<endl;
         return;
     }
     for(int i=0;i<(int)v.size();i++){
         A[mp[v[i]]].insert(v[i]);
     }
      
     f(v[0],mp[v[0]]);
     assert(v.size()==ans.size());
     for(int i=0;i<(int)ans.size();i++) cout<<ans[i]<<' ';
}
main(){
    ios;
    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        //cout<<"Case #"<<i<<": ";
        solve();
    }
}
