Circular Rotation Check
Easy1s time · 256MB memory · arrays, simulation
A carousel of numbered seats spins one step. Formally, rotate the array one position to the left: the new array b is defined by bᵢ = aᵢ₊₁ for i < n, and bₙ = a₁. The score is the number of positions that then contain their own 1-based index, i.e. positions i with bᵢ = i.
Input
The first line contains one integer n.
The second line contains n integers a₁ … aₙ.
Output
Print the score after the rotation.
Constraints
- 1 ≤ n ≤ 2·10⁴
- 1 ≤ aᵢ ≤ n
Samples
Input 1
5 5 1 2 4 3
Output 1
3
Input 2
5 1 2 5 4 3
Output 2
0
Sign in (top right) to run or submit.