문제: https://www.acmicpc.net/problem/2263
import sys
sys.setrecursionlimit(10**6)
read = lambda : sys.stdin.readline().strip()
n = int(read())
inorder = list(map(int, read().split()))
postorder = list(map(int, read().split()))
position = {}
for i in range(n):
position[inorder[i]] = i
def solve(in_start, in_end, post_start, post_end):
if in_start > in_end or post_start > post_end: return
root = postorder[post_end]
print(root, end=' ')
p = position[root]
left = p - in_start
solve(in_start, p-1, post_start, post_start+left-1)
solve(p+1, in_end, post_start+left, post_end-1)
solve(0, n-1, 0, n-1)