Permutation Representation

 Permutation Representation 

Time-Limit: 5 second(s)

A permutation is a bijection from a set $ X$ onto itself. If $ X$ is finite, the elements of $ X$ are often numbered 1,2,3,...n. A permutation of a set with five elements is often denoted by

\begin{displaymath}
\left(
\begin{array}{c c c c c}
1 & 2 & 3 & 4 & 5 \\
3 & 2 & 5 & 1 & 4
\end{array}\right)
\end{displaymath}

meaning the element 1 is mapped to the element 3 of the set, the element 2 is mapped to the element 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

$\displaystyle (2 4 7) $

means that the element 2 is mapped to the element 4, the element 4 is mapped to the element 7 and the element 7 is mapped to the element 2. The cycle above could also be written

$\displaystyle (7 2 4) $

The product of several cycles is evaluated from right to left. The above permutation can be written as

$\displaystyle (5 3) (5 1) (5 4)$

$\displaystyle (1 3 5 4) (1)$

$\displaystyle (1) (1 3 5 4)$

A permutation can be written uniquely as the product of cylces

\begin{displaymath}
\left(
\begin{array}{c c c c}
1 & 2 & \ldots & n \\
b_1 & b...
...)^{a_2} (1 2 3)^{a_3} (1 2 3 4)^{a_4}\ldots (1 \ldots n)^{a_n} \end{displaymath}

if $ 0 \leq a_i \leq i - 1$ holds for each exponent ai. The example permutation can be uniquely written as

\begin{displaymath}\left(
\begin{array}{c c c c c}
1 & 2 & 3 & 4 & 5 \\
3 & 2 &...
...array}\right)
= (1)^0(1 2)^1(1 2 3)^2(1 2 3 4)^2(1 2 3 4 5)^2
\end{displaymath}

Your task is to compute the ai's of a given permutation.



Input
The input consists of several test cases. Each test case consists of three lines. The first line contains the number n, 1 ≤ n ≤ 200000. The second line contains the elements from $ 1$ to $ n$. The third line contains a mapping for every element from the second line.

Output
For each test case there should be one line of output. Print all the ai's on a single line separated by one space in the order a1...an

Sample Input


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

 


Sample Output


0 1 2 2 2
0 0 0 2