eolymp
bolt
Try our new interface for solving problems
Problems

Degree of a permutation

Degree of a permutation

Find the degree of a permutation $p$. A permutation of $n$ elements is an ordered set of $n$ distinct numbers from $1$ to $n$. The degree of a permutation $p$ is a minimal positive integer $k$ such that $p^k = ε$, where $ε$ is an identity permutation $(1, 2, ..., n)$. \InputFile The first line contains the order $n~(0 < n \le 100)$ of a permutation $p$. The second line contains the permutation $p$ itself. \OutputFile Print the degree of the given permutation.
Time limit 1 second
Memory limit 128 MiB
Input example #1
6
4 3 2 5 1 6
Output example #1
6
Input example #2
9
4 3 6 8 9 7 2 1 5
Output example #2
12