cho.sh
Notes
Loading...

Recover Tree Preorder

Time limit

5s

Memory limit

128 MB

Problem

A binary tree has n vertices labeled with distinct integers from 1 to n. You are given the tree's inorder traversal and postorder traversal. Print the preorder traversal of the same tree.

Input

The first line contains n (1 <= n <= 100,000), the number of vertices.

The second line contains n integers, the inorder traversal.

The third line contains n integers, the postorder traversal of the same tree.

Output

Print the preorder traversal on one line, with values separated by spaces.