#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[n + 1];
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	int col = 0;
	for(int i = 1; i <= 17; i ++){
		if((1 << i) - 1 == n){
			col = i - 1;
			break;
		}
	}
	map<int,int> cnt;
	for(int i = 1; i <= n; i ++){
		cnt[a[i]] ++;
	}
	if(cnt.size() != (1 << col)){
		cout << -1;
		return 0;
	}
	if(n == 1){
		cout << a[1];
		return 0;
	}
	vector<int> x[col + 1];
	int cur = 0, curcnt = 0;
	for(auto i : cnt){
		if(curcnt >= (1 << (cur + 1)) - 1){
			cur ++;
		}
		x[cur].push_back(i.first);
		curcnt++;
	}
	curcnt = 1;
	for(int i = col; i >= 0; i --){
		bool was = 0;
		for(auto j : x[i]){
			if(cnt[j] > curcnt || (cnt[j] == curcnt && was)){
				cout << -1;
				return 0;
			}
			if(cnt[j] == curcnt){
				was = 1;
			}
		}
		curcnt ++;
	}
	for(int i = 0; i <= col; i ++){
		for(auto j : x[i]){
			cout << j << " ";
		}
	}
}
