Binary Search Tree#3096

Binary Search Tree

1 second
128 megabytes
Easy

A binary search tree is a binary tree that satisfies the following properties:

prb3096

Pre-order traversal (Root-Left-Right) visits the root node, then the left subtree, and then the right subtree, outputting node keys in this order. Post-order traversal (Left-Right-Root) visits the left subtree, then the right subtree, and finally the root node, outputting their keys. For example, the results of pre-order and post-order traversals of the binary tree shown above are:

Pre-order: 50 30 24 5 28 45 98 52 60

Post-order: 5 28 24 45 30 60 52 98 50

Given the pre-order traversal of a binary search tree, find its post-order traversal.

Input

The keys of all nodes in the binary search tree are given in the order of pre-order traversal. Each node's key is a positive integer less than 10^6. All keys are given in separate lines (one number per line). The tree has no more than nodes and does not contain duplicate keys.

Output

Print the post-order traversal of the tree. Output one key per line.

Examples

Example 1

Loading
Loading