14308 - 2024_IDS_Spring_Quiz2_Preorder   

Description

You are given the postorder and inorder traversal of a binary tree. Your job is to reconstruct the tree and print the preorder traversal of the tree.

Note

  • Each vertex of the tree is labeled 1 ~ n distinctly.

Input

Each input is given in three lines.

The first line contains an integer n: The number of vertices of the binary tree.

The second line is the postorder traversal of the tree.

The last line is the inorder traversal of the tree.

Note

  • For both traversals, each vertex is seperated by an empty space.

Restriction

  • 1 ≤ n ≤ 2∗105

 

Output

Output should be printed in one line. Containing the preorder traversal of the tree. Each vertex of the traversal should be seperated with an empty space.

Remember to print a ‘\n’ at the end of the output.

Do not include any spaces at the "end of line".

Sample Input  Download

Sample Output  Download

Tags




Discuss