public class haha {
public haha(int tree[]) {
int p = 0;
int k = 0;
while(k != tree.length){
if(p < tree.length){
System.out.print(tree[p]+" ");
p = 2*p+1;
k++;
}
else {
p = p/2;
if(p%2==0){
p=p/4-1;
p = 2*p+2;
}
else { p =p+1;
if(p >= tree.length)
p = 2*p+1;
}
}
}
}
public static void main (String[] args) {
int tree[] = {1,2,3,4,5,6,7,8};
new haha(tree);
}
}