## problem

$N = 1$のときは頂点数$3$であることや、列は$A_1$から与えられるが$i = 1$は$2$段目を指すことに注意。

## implementation

#include <algorithm>
#include <cstdio>
#include <set>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;

int main() {
// input
int n; scanf("%d", &n);
vector<int> a(n + 1); repeat (i, n) scanf("%d", &a[i + 1]);
// solve
vector<ll> result;
set<ll> used;
repeat_reverse (depth, n + 1) {
ll delta = 1ll << depth;
ll i = 0;
repeat (iteration, a[depth]) {
while (delta) {
if (not used.count(i)) {
result.push_back((1ll << depth) + i);
used.insert(i);
break;
}
i += delta;
if (i == 1ll << depth) {
i = 0;
delta /= 2;
}
}
}
set<ll> next_used;
for (ll i : used) {
next_used.insert(i / 2);
}
used = next_used;
}
// output
whole(sort, result);
for (ll v : result) {
printf("%lld\n", v);
}
return 0;
}