#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
template<typename T>void re(T&x){x = 0; int sign = 1; char c; do{c = getchar(); if (c == '-') sign = -1;}while(!isdigit(c)); do{x = x * 10 + c - '0'; c = getchar();}while(isdigit(c)); x *= sign;}
void write(int x){if (x < 0) putchar('-'); else if (x < 10) putchar(x + '0'); else write(x /10), putchar(x % 10 + '0');}
const int N = 1e7 + 1000;
ll n, a[N], root;
map<ll, ll> t;
ll deep = 1;
void build(ll x){
ll now = 1, dep = 1;
if (root == 0){ root = 1, t[1] = x; return;}
else {
while (t[now]){
if (x <= t[now]){
now *= 2;
dep ++;
}else {
now = now * 2 + 1;
dep ++;
}
}
deep = max(deep, dep);
t[now] = x;
}
return;
}
void dfs(ll id){
if (t[id * 2]) dfs(id * 2);
if (t[id * 2 + 1]) dfs(id * 2 + 1);
write(t[id]);
printf("\n");
}
int main(){
re(n);
for (int i = 1; i <= n; i ++) re(a[i]);
build(a[1]);
for (int i = 2; i <= n; i ++){
build(a[i]);
}
printf("deep=%d\n", deep);
dfs(1);
return 0;
}