701. Top View of a Binary Tree

0

Medium

The top view of a binary tree refers to the set of nodes that are visible when the tree is viewed from the top. Given a binary tree, the task is to print its top view.

Input Format

The input consists of a single line containing the level order traversal of the binary tree, represented as space-separated integers. In the level order traversal, -1 represents a null child, while any other value represents a node of the tree.

Output Format

The output should be the space-separated values of the nodes that are visible from the top of the binary tree.

Example

Input

1 2 3 -1 -1 -1 -1

Output

2 1 3

Constraints

The number of nodes in the tree must be between 1 and 100,000 (inclusive).
Loading...

View Submissions

Console