CSES - Permutation Rounds
  • Time limit: 1.00 s
  • Memory limit: 512 MB

There is a sorted array [1,2,,n][1,2,\dots,n] and a permutation p1,p2,,pnp_1,p_2,\dots,p_n. On each round, all elements move according to the permutation: the element at position ii moves to position pip_i.

After how many rounds is the array sorted again for the first time?

Input

The first line has an integer nn.

The next line contains nn integers p1,p2,,pnp_1,p_2,\dots,p_n.

Output

Print the number of rounds modulo 109+710^9+7.

Constraints

  • 1n21051 \le n \le 2 \cdot 10^5

Example

Input:

8
5 3 2 6 4 1 8 7

Output:

4

Explanation: The array changes as follows after the rounds:

  • Round 1: [6,3,2,5,1,4,8,7][6,3,2,5,1,4,8,7]
  • Round 2: [4,2,3,1,6,5,7,8][4,2,3,1,6,5,7,8]
  • Round 3: [5,3,2,6,4,1,8,7][5,3,2,6,4,1,8,7]
  • Round 4: [1,2,3,4,5,6,7,8][1,2,3,4,5,6,7,8]