영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
시간 제한 1초 · 메모리 제한 512 MB
Problem
There is a sorted array [1,2,…,n] and a permutation p_1,p_2,…,p_n. On each round, all elements move according to the permutation: the element at position i moves to position p_i.
After how many rounds is the array sorted again for the first time?
Input
The first line has an integer n.
The next line contains n integers p_1,p_2,…,p_n.
Output
Print the number of rounds modulo 10^9+7.
Constraints
- 1 ≤ n ≤ 2 · 10^5
Example
Explanation: The array changes as follows after the rounds:
- Round 1: [6,3,2,5,1,4,8,7]
- Round 2: [4,2,3,1,6,5,7,8]
- Round 3: [5,3,2,6,4,1,8,7]
- Round 4: [1,2,3,4,5,6,7,8]
예제
예제 1
8 5 3 2 6 4 1 8 7
4