- Time limit: 1.00 s
- Memory limit: 512 MB
There is a sorted array and a permutation . On each round, all elements move according to the permutation: the element at position moves to position .
After how many rounds is the array sorted again for the first time?
Input
The first line has an integer .
The next line contains integers .
Output
Print the number of rounds modulo .
Constraints
Example
Input:
8 5 3 2 6 4 1 8 7
Output:
4
Explanation: The array changes as follows after the rounds:
- Round 1:
- Round 2:
- Round 3:
- Round 4: