12062 - DS_2018Fall_Quiz3   

Description

Given the preorder traversal sequence and inorder traversal sequence of a tree, your task is to print the postorder traversal sequence of the tree.

 

 

 

 

 

Input

Two string sequences in two lines,

the first line is the preorder traversal sequence, 

and the second line is the inorder traversal sequence.

Keys in the sequences are separated by the comma. 

1<= key <=100,000

Note:
1) Multiple instances are given in the same test case. That is, the 1st and 2nd lines are the preorder and inorder sequences of the first tree, and the 3rd and 4th lines are the sequences of the second tree and so on.

2) Each tree does not contain duplicate keys.

3) The number of nodes in each tree is in the range: [1, 100000].

 

Output

The postorder traversal sequence of the tree, separated by commas.

Note:
1) You need to output '\n' at the end of the line.

    (newline)

2) If there are n lines of inputs, there will be n/2 lines of output.

Sample Input  Download

Sample Output  Download

Tags




Discuss