cswork / OAOpen practice workspace

Wells FargoOA #1

Count Operations

Estimated MediumJudge-ready

Topics (AI-labelled)Bits & MathUnion-Find

You are given a 1-based permutation p. One operation sets item i of the new array to item p[i] of the old array. For any array of distinct elements, find the number of repeated operations needed to restore the original array for the first time (at least one operation), modulo 1,000,000,007.

Input

The first line contains n; the second line contains n integers p[i]. Source constraints: 1≤n≤100000, and p is a permutation of 1..n.

Output

Output the minimum number of operations modulo 1,000,000,007.

Example 1

Input:

1
1

Output:

1

Example 2

Input:

2
2 1

Output:

2

Example 3

Input:

3
2 3 1

Output:

3

Editorial

Loading solution…