Permugame
Ksyusha got a great present for her birthday - a "Permugame". Gear for "Permugame" consists of the two permutations of size n: p[i]
, q[i]
and a square board n * n cells. According to the rules cells (i, j) and (a, b) are connected to each other by a tunnel if and only if either (a = i and b = P[j]
) or (a = P[i]
and b = j). The only goal of the game is to find such a minimal integer k (k > 0), that every cell of the board can be painted in one of the k colors. The only restriction is that any two connected cells should have different colors. Ksyusha is too lazy to play "Permugame" so she asked you to figure out the answer.
Input
In the first line you are given a single integer n (1 ≤ n ≤ 100000) - size of the board and permutations p and q. In the next line permutation p[i]
(1 ≤ p[i]
≤ n) is given as a list of integers separated by spaces. In the third line permutation q[i]
(1 ≤ q[i]
≤ n) is given in the same format. It is guaranteed that p[i]
≠ i and q[i]
≠ i for each i in [1, n].
Output
Print the minimal integer k (k > 0) such that every cell of the n * n board can be painted in one of the k colors.