#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
#include<unordered_set>
#include<unordered_map>
#include<queue>
#include<stack>
#include<deque>
using namespace std;
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()

void solve() {
	int x, mx, k=0;
	cin >> mx;
	while ((1 << k) < mx) k++;
	k--;
	map<int, int> mp;
	for (int i = 0; i < mx; ++i) {
		cin >> x;
		mp[x]++;
	}
	vector<vector<int>> pos(100);
	pos[0].push_back(0);
	vector<int> t(mx);
	for (auto p : mp) {
		int val = p.first;
		int cnt = p.second;
		if ((k + 1) - cnt < 0 || pos[(k + 1) - cnt].empty()) {
			cout << "-1\n";
			return;
		}
		int v = pos[(k + 1) - cnt].back(), depth = (k + 1) - cnt;
		pos[(k + 1) - cnt].pop_back();
		while (v < mx) {
			t[v] = val;
			pos[depth + 1].push_back(2 * v + 2);
			depth++;
			v = 2 * v + 1;
		}
	}
	for (int i = mx - (1 << k); i < mx; ++i) {
		cout << t[i] << ' ';
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}