12405 - Construct tree by inorder and postorder   

Description

We will give you the "inorder" and "postorder" of a tree.

You need to print the "preorder" of this tree we give you.

Notice that the the final testcase has small memory limit. If you don't free your tree you will get memory limit exceeded

 

 

 

 

 

(The tree for sample input 1)

(The tree for sample input 2)

Input

There are multiple testcases. The testcases will end with EOF.

Each testcase contains three lines.

First line only contains one integer n(1 <= n <= 100) which means the number of nodes in the tree.

Second line contains n integers which in the range of int. Standing for the "inorder".

Third line contains n integers which in the range of int. Standing for the "postorder".

Output

For each testcase output the "preorder" of the tree.

You have to output in this form:

testcase<id>: <preorder sequence>

Replace <id> and <preorder sequence> into the i-th testcase and the correct preorder sequence.

Each number in preorder sequence should be followed by a single blank(even the last number).

If you have further questions, please refer to sample output.

Sample Input  Download

Sample Output  Download

Tags




Discuss