#P7673. [COCI 2013/2014 #5] OBILAZAK

[COCI 2013/2014 #5] OBILAZAK

Description

You are given a complete binary tree with 2K12^K-1 nodes. The traversal rule of this tree is as follows:

  • The starting point is the only node on the first level of the binary tree.

  • If the left child of the current node has not been recorded yet, record the label of the left child and move to the left child.

  • If the current node has no left child, or its left child has already been recorded, record the label of the current node.

  • If the current node has already been recorded, record the label of the right child and move to the right child.

  • If the current node and both its left and right children have all been recorded, move to the parent of the current node.

Now, you are given the sequence of labels recorded starting from the node on the first level. Please reconstruct the original complete binary tree.

Input Format

The first line contains an integer KK, meaning that this complete binary tree has 2K12^K-1 nodes.

The second line contains 2K12^K-1 integers, representing the sequence of labels recorded starting from the node on the first level.

Output Format

Output KK lines in total, representing the original complete binary tree.

2
2 1 3 
1
2 3 
3
1 6 4 3 5 2 7
3
6 2
1 4 5 7

Hint

Sample Explanation #1

First move to node 11. Seeing that the left child has not been recorded, move to node 22 and record node 22. Then, since node 22 has no children, return to node 11. Seeing that this node has not been recorded, record node 11. Then, seeing that the right child has not been recorded, move to node 33 and record node 33.

Sample Explanation #2

Constraints

For 100%100\% of the testdata, 1K101\le K\le 10.

Notes

The score of this problem follows the original COCI settings. The full score is 8080.

This problem is translated from COCI2013_2014 CONTEST #5 T2 OBILAZAK.

Translated by ChatGPT 5