#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define in insert
#define ld long double
#define all(x) (x).begin(), (x).end()
#define len(x) (int)x.size()
#define deb(x) cout << #x << " = " << x << '\n';
#define file(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
using namespace std;

// const int dx[] = {0, 1, 0, -1};
// const int dy[] = {1, 0, -1, 0};

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int a[N], cnt[N], nxt[N];
set <int> s[N];

void solve() {
  set <int> st;
  map <int, int> mp;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    st.insert(a[i]);
  }
  for (int it: st) {
    mp[it] = len(mp) + 1;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = mp[a[i]];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    s[cnt[a[i]]].insert(a[i]);
  }
  int k = __lg(n) + 1;
  vector <int> v;
  for (int i = k, j = 1; i; i--) {
//    cout << i << ' ' << k << ' ' << len(s[i]) << ' ' << j << '\n';
    if (len(s[i]) != j) {
//      cout << i << ' ' << len(s[i]) << ' ' << j << '\n';
      cout << -1;
      return;
    }
    if (i == k) {
      v.pb(*s[i].begin());
      continue;
    }
    vector <int> cur, now;
    set <int> by;
    for (int it: s[i]) cur.pb(it);
    for (int it: v) {
      by.insert(it);
    }
    for (int it: cur) {
      int cv = *by.begin();
      if (cv > it) {
        cout << -1;
        return;
      }
      nxt[cv] = it;
      by.erase(by.begin());
    }
    for (int it: v) {
      now.pb(it);
      now.pb(nxt[it]);
    }
    for (int i = 0; i <= n; i++) {
      nxt[i] = 0;
    }
    v = now;
    if (i < k) j *= 2;
  }
  for (int it: v) cout << it << ' ';
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int TT = 1;
	// cin >> TT;
	while(TT--) {
		solve();
	}
	return 0;
}