#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sqr(x) abs((x) * (x))
#define sume(a) (accumulate(all(a), 0ll))
#define mine(a) (*min_element(all(a)))
#define maxe(a) (*max_element(all(a)))
bool getbit (int mask, int bit) {return (mask & (1 << bit));}
bool is_sqrt (int a) {double x = sqrt(a); if (x == (int)x) return 1; return 0;}
typedef long long ll;
typedef long double ld;
typedef void hahahahahaha;
ll lcm (ll a, ll b) {return (a / __gcd(a, b) * b);}
typedef unsigned long long ull;
const unsigned long long MOD = 1e9 + 7;
const ull N = 2e5 + 5;
const ll dx[]={-1, 1, -1, 1};  
const ll dy[]={-1, 1, 1, -1};
ll binpow (ll a, ll n) { if (n == 0) return 1; if (n % 2 == 1) return binpow (a, n-1) % MOD * a % MOD;else {ll b = binpow (a, n / 2);return b % MOD * b % MOD;}}
//vector <ll> g[N];int used[N];ll d[N];int p[N];
//char c[N][N];
//void ptt (int x, int y) {g[x].pb(y);g[y].pb(x);}
bool cmp (pair <int, int> a, pair <int, int> b) {
	if (a.first < b.first) return 1;
	else if (a.first > b.first) return 0;
	return a.second < b.second;
}
hahahahahaha hahahahahah () {
	int n; cin >> n;
	vector <int> a;
	map <int, int> mp;
	set <int> st;
	int x;
	for (int i = 0; i < n; i ++) {
		cin >> x;
		st.insert(x);
		mp[x] ++;
	}
	for (int c : st) {
		a.pb(c);
	}
	sort(all(a));
	x = __builtin_popcount(n);
	n = (int)a.size();
	int mx = 0;
	for (int i = 0; i < n; i ++) {
		mx = max(mx, mp[a[i]]);
	}
	if (mx != x) {
		cout << -1;
		return;
	}
	vector <pair <int, int> > b;
	for (auto c : mp) {
		b.pb({c.second, c.first});
	}
	sort(rall(b), cmp);
	n = (int)b.size();
	int l = 0, r = n - 1;
	vector <int> ans (n);
	bool q = 0;
	for (int i = 0; i < n; i ++) {
		if (!q) {
			ans[i] = b[l].second, l ++, q = 1;
		}
		else {
			ans[i] = b[r].second, r --, q = 0;
		}
	}
	//for (auto c : b) cout << c.second << " --> " << c.first << '\n';
	st.clear();
	for (int c : ans) st.insert(c);
	if ((int)st.size() != n) {
		cout << -1;
		return;
	}
	for (int c : ans) cout << c << ' ';
}

int main() {
	//freopen("hps.in", "r", stdin); freopen("hps.out", "w", stdout);
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cout.setf(ios::fixed);cout.precision(10);
    int hahahahaha = 1; //cin >> hahahahaha;
    //int cnt = 1;
	while (hahahahaha --) {
		//cout << "Case " << cnt++ << ": ";
		hahahahahah();
		cout << '\n';
	}
	return 0;
}
	
