LogiQuest

377. Postorder Traversal

EasyBinary TreeDFS

Print the postorder traversal (left, right, node).

Input format

Line 1: n (number of level-order entries) Line 2: the values in level order, -1 for a missing child

Output format

The values in postorder.

Example 1

Input

7
4 2 6 1 3 5 7

Output

1 3 2 5 7 6 4

Example 2

Input

1
5

Output

5

Constraints

1 ≤ nodes ≤ 10⁴

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…