#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
//#pragma startup st_point /* start some function before main*/
//#pragma exit /* start some function after main */
//#pragma warn -rvl /* No return value, + do opposite*/
//#pragma warn -par /* Parameter not used, + do opposite */
//#pragma warn - rch /* Unreachable code, + do opposite */
/*
attribute((constructor)) acts like #pragma startup
attribute((destructor)) acts like #pragma exit
*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
#define F first
#define S second
#define left(v) (v) + (v)
#define right(v) (v) + (v) + 1
#define ll long long
#define int long long
using namespace std;
using namespace __gnu_pbds;
///using ll = long long;
//using ull = unsigned long long;
const int MAXN = 2e5 + 5;
const int inf = 4e9;
const long long INF = 4e18;
//const int M = ((ll)1 << (ll)32);
const int P = 191;
const int P2 = 191;
const double EPS = 1e-6;
void D_BASE(string name = "") {
    if (sz(name)) {
        freopen((name + ".in").c_str(), "r", stdin);
     freopen((name + ".out").c_str(), "w", stdout);
    }
    ios_base::sync_with_stdio(0);
     cin.tie(0);
    cout.tie(0);
}
int n, a[MAXN], b[MAXN];
vector<int> g[MAXN];
void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a + 1, a + 1 + n);
    vector<pair<int, int> > v;
    for (int i = 1; i <= n; ++i) {
     int cur = a[i];
     int ct = 0;
     while (i <= n && cur == a[i]) {
      ct++;
      i++;
  }
  i--;
  v.pb(mp(ct, cur));
 }
 sort(all(v));
 int m = (n + 1) / 2;
 int cur = m / 2;
 int val = 1;
 int cnt = 0;
 for (int i = 0; i < sz(v); ++i) {
  if(cnt == cur) {
   cur /= 2;
   if(!cur) cur = 1;
   val++;
   cnt = 0;
  }
  if(v[i].F != val) {
   cout << "-1";
   return;
  }
  cnt++;
 }
 int pos = 0;
 for (int i = 0; i < sz(v); ++i) {
  if(!i || v[i].F != v[i - 1].F) pos++;
  g[pos].pb(v[i].S);
 }
 vector<int> p;
 int ps = 1;
 b[1] = g[pos][0];
 for (int i = pos - 1; i > 0; --i) {
  int nwpos = ps + 1;
  for (int j = ps - sz(g[i]) + 1; j <= ps; ++j) {
   b[nwpos] = b[j];
   b[nwpos + 1] = g[i][j - (ps - sz(g[i]) + 1)];
   if(b[nwpos] >= b[nwpos + 1]) {
    cout << "-1";
    return;
   }
   nwpos += 2;
  }
  ps = nwpos - 1;
 }
 for (int i = ps - m + 1; i <= ps; ++i) cout << b[i] << ' ';
}
signed main() {
    D_BASE("");
 int tt = 1, ct = 0;
    //cin >> tt;
    while (tt--) {
        //cout << "Case " << ++ct << ": ";
  solve();
    }
 return 0;
}
