Problems

# Permutation Representation

# Permutation Representation

A permutation is a bijection from a set \textbf{X} onto itself. If \textbf{X} is finite, the elements of \textbf{X} are often numbered \textbf{1},\textbf{ 2}, \textbf{3}, ..., \textbf{n}. A permutation of a set with five elements is often denoted by
\includegraphics{https://static.e-olymp.com/content/35/3544691a1352a2a38ed8a1c3188ec77f479ea904.jpg}
meaning the element \textbf{1} is mapped to the element \textbf{3} of the set, the element \textbf{2} is mapped to the element \textbf{2} and so on and so forth. Another way of denoting permutations is to use cycle notation. Cycle notation is not necessarily unique. The following cycle
\textbf{(2 4 7)}
means that the element \textbf{2} is mapped to the element \textbf{4}, the element \textbf{4} is mapped to the element \textbf{7} and the element \textbf{7} is mapped to the element 2. The cycle above could also be written
\textbf{(7 2 4)}
The product of several cycles is evaluated from right to left. The above permutation can be written as
\textbf{(5 3) (5 1) (5 4)}
\textbf{(1 3 5 4) (1)}
\textbf{(1) (1 3 5 4)}
A permutation can be written uniquely as the product of cylces
\includegraphics{https://static.e-olymp.com/content/32/32b3606583a7678f37fd0f5dfaa2eee8e321d356.jpg}
if \textbf{0} ≤ \textbf{a_i} ≤ \textbf{i-1} holds for each exponent \textbf{a_i}. The example permutation can be uniquely written as
\includegraphics{https://static.e-olymp.com/content/9e/9ec5c9f183fab3e67a14cc29d5afd046e80665d0.jpg}
Your task is to compute the \textbf{a_i}'s of a given permutation.
\InputFile
The input consists of several test cases. Each test case consists of three lines. The first line contains the number \textbf{n} (\textbf{1} ≤ \textbf{n }≤ \textbf{200000}). The second line contains the elements from \textbf{1} to \textbf{n}. The third line contains a mapping for every element from the second line.
\OutputFile
For each test case there should be one line of output. Print all the \textbf{a_i}'s on a single line separated by one space in the order \textbf{a_1 ... a_n}.

Input example #1

5 1 2 3 4 5 3 2 5 1 4 4 1 2 3 4 3 4 1 2

Output example #1

0 1 2 2 2 0 0 0 2