LearnPy Hub
← Arena
IntermediateRating 1200

Longest Cycle

The list is a permutation of 0 … n−1. Starting at index i, jump to a[i], then a[a[i]], and so on until you come back. Print the length of the longest such cycle.

Input

n, then the permutation.

Output

One integer.

Sample 1

Input
7
5 4 0 3 1 6 2
Output
4

Sample 2

Input
3
0 1 2
Output
1
solution.py
Output appears here
Longest Cycle · Python Arena problem · LearnPy Hub