#include <iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<fstream>
#include<string>
#include<random>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace std;
int main()
{
	ll n;
	cin >> n;
	vector<ll> DO(n);
	ll k = log2(n + 1);
	map<ll, ll> S;
	vector<vector<ll> > sloi(k);
	ll buf;
	for (ll i = 0; i < n; ++i)
	{
		cin >> buf;
		S[buf]++;
	}
	for (auto&y : S)
	{
		if (y.second > k)
		{
			cout << "-1\n";
			return 0;
		}
		ll h = y.second;
		ll pos = k - 1;
		while (h)
		{
			sloi[pos].push_back(y.first);
			--h;
			--pos;
		}
	}
	for (ll i = 0; i < k; ++i)
	{
		if (sloi[i].size() != (1 << i))
		{
			cout << "-1\n";
			exit(0);
		}
	}
	for (auto&y : sloi[k - 1]) {
		cout << y << " ";
	}
	cout << '\n';
	return 0;
}