Permutation Representation

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 () 12345 32514 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 (247) 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 (724) The product of several cycles is evaluated from right to left. The above permutation can be written as (53)(51)(54) (1354)(1) (1)(1354) A permutation can be written uniquely as the product of cylces () () 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 12...n b1 b2 ... bn =(1)a1(12)a2(123)a3(1234)a4 ...(1...n)an if 0 ≤ ai ≤ i − 1 holds for each exponent ai. The example permutation can be uniquely written as 12345 32514 = (1)0(12)1(123)2(1234)2(12345)2 Your task is to compute the ai’s of a given permutation. Input

2/2 Sample Input 5 12345 32514 4 1234 3412 Sample Output 01222 0002