/*#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")*/
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define str string
#define pii pair<int,int>
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define mii map<int,int>
#define mll map<ll,ll>
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yess cout<<"Yes\n";
#define noo cout<<"No\n";
using namespace std;
 
const str num1[10]={"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"};
const int num2[10]={0,1,2,3,4,5,6,7,8,9};
 
const int dx[8] = {1, -1, 0, 0,1,-1,-1,1};
const int dy[8] = {0, 0, -1, 1,1,-1,1,-1};
 
const ll mod=1000000007;
const ll oo=9000000000000000000;
 
ll binmod(int n,int m){if(m==0){return 1;}if(m==1){return n;}if(m%2==1){return n*(binmod(n,m-1))%mod;}int c=binmod(n,m/2);return c*c%mod;}
ll bin(int n,int m){if(m==0){return 1;}if(m==1){return n;}if(m%2==1){return n*(bin(n,m-1));}int c=bin(n,m/2);return c*c;}
 
int ss(int x){
  int ans=0;
  while(x!=0){
    x/=2;
    ans++;
  }
  return ans-1;
}
 
vector <int>d[200001];
 
void solve(){
  int n;
  cin>>n;
  set <int>s;
  map<int ,int>pp;
  int a[n+1];
  int mx=-1;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    pp[a[i]]++;
    s.insert(a[i]);
    mx=max(mx,pp[a[i]]);
  }
  if(bin(2,ss(s.size())+1)-1!=n){
    cout<<-1;
    return ;
  }
  for(auto it : s){
    d[pp[it]].pb(it);
  }
  n=bin(2,ss(s.size()));
  //cout<<n<<"\n";
  //cout<<mx<<" "<<n<<"\n";
  if(mx!=ss(s.size())+1){
      //cout<<1<<"\n";
      cout<<-1;
      return;
  }
  a[1]=d[mx][0];
  int o=2,l=0,k=1;
  for(int j=1;j<=n;j*=2){
    for(int i=1+j;i<=n;i+=o)
	{
      if(l>=d[k].size())
	  {
        cout<<-1;
        return;
      }
      a[i]=d[k][l];
      l++;
    }
    k++;
    l=0;
    o*=2;
  }
  vi z,x;
  for(int i=1;i<=n;i++){
      z.pb(a[i]);
  }
  int h=0;
  for(int iii=1;iii<=ss(n);iii++){
      if(h==0){
          for(int i=0;i<z.size();i+=2){
              if(z[i]<z[i+1]){
                  x.pb(z[i]);
              }
              else{
                  cout<<-1;
                  return;
              }
          }
          z.clear();
      }
      else{
          for(int i=0;i<x.size();i+=2){
              if(x[i]<x[i+1]){
                  z.pb(x[i]);
              }
              else{
                  cout<<-1;
                  return;
              }
          }
          x.clear();
      }
      h=1-h;
       
  }
  for(int i=1;i<=n;i++){
      cout<<a[i]<<" ";
  }
}
 
signed main(){
  //ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  //srand( time(0));
  //rand()
  //freopen("sum.in", "r", stdin);
  //freopen("sum.out", "w", stdout);
    int tests=1;
    //cin>>tests;
    for(int i=1;i<=tests;i++){
    //cout<<"TEST CASE : "<<i<<"\n";
    solve();
  }
}
