CSES - E4590 2020 4 - Freshman's Database
  • Time limit: 2.00 s
  • Memory limit: 256 MB

Teemu is an assistant at the course CS-A1150 - Databases. One of the tasks on the course is to create a family database.

A family database consists of nn entries numbered 1,2,3,n1, 2, 3, \ldots n each representing a family member. Each entry ii has a single number pip_i pointing to the parent of the entry.

As we all know nobody can be their own ancestor. Still many of the students have managed to create databases with cycles. A cycle is a set of kk nodes {a1,a2,,ak}\{a_1, a_2, \dotsc, a_k\} for some k2k\ge 2 such that ai+1a_{i+1} is the parent of aia_i for all i=1,2,,k1i = 1, 2, \dotsc, k-1 and finally a1a_1 is the parent of aka_k.

As the assistant of the course, Teemu needs your help to count cycles in the students' databases.

Input

The first line contains a single integer, nn, the number of entries in the database.

The second line contains nn integers, p1,p2,,pnp_1, p_2, \ldots, p_n. We have 1pin1 \le p_i \le n and piip_i \ne i for all ii.

Output

Output a single integer, the number of cycles in the given database.

Limits

  • 2n1062 \le n \le 10^6

Example 1

Input:

16
2 3 4 5 6 1 4 7 7 4 12 11 14 15 13 13

Output:

3

Explanation: Cycles in the input are {1,2,3,4,5,6}\{1, 2, 3, 4, 5, 6\}, {11,12}\{11, 12\} and {13,14,15}\{13, 14, 15\}.