Complete Binary Tree
InterviewTime limit1sMemory limit128 MB
Reconstruct each level of a complete binary tree from its inorder visit order.
Problem
Sanggeun is travelling in Donji Andrijevci, a town in Slovenia. The streets of the town form a complete binary tree of depth . A complete binary tree of depth has nodes. Every node carries the number of the building that stands there, and every node outside the last level has one left child and one right child.

Complete binary trees of depth 2 and depth 3
Sanggeun entered every building in the town and wrote the numbers on a sheet of paper in the order he entered them. Back in Korea he tried to draw the town, but he could not remember its shape. He did remember the order in which he walked around.
- Sanggeun starts in front of the building at the root of the tree.
- If he has not entered the building at the left child of the current node, he moves to the left child.
- If the current node has no left child, or he already entered the building at the left child, he enters the building at the current node and writes its number on the paper.
- If he already entered the current building and the node has a right child, he moves to the right child.
- If he already visited the current building and the buildings at both children, he moves to the parent node.
For the tree on the left in the picture Sanggeun entered the buildings in the order 2, 1, 3, and for the tree on the right the order is 1, 6, 4, 3, 5, 2, 7. Given the whole order Sanggeun wrote down, write a program that finds the building numbers on each level.
Input
The first line contains ().
The second line contains the building numbers in the order Sanggeun entered them, separated by spaces. The numbers are distinct and all of them lie in the interval .
Output
Print the answer on lines. On line print the numbers of the buildings on level from left to right, separated by single spaces.