539. Binary Tree Zigzag Traversal

0

Medium

Given a binary tree, output the values in a zigzag level order. The zigzag order means that odd levels should be printed from left to right, while even levels should be printed from right to left.

Input Format

Enter the values of all the nodes in the binary tree in pre-order format. Use 'true' to indicate the presence of a node and 'false' to indicate a NULL node.

Output Format

Display the values in zigzag level order, with each value separated by a space.

Example

Input

10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false

Output

10 30 20 40 50 60 73

Constraints

None
Loading...

View Submissions

Console