- 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 entries numbered each representing a family member. Each entry has a single number 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 nodes for some such that is the parent of for all and finally is the parent of .
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, , the number of entries in the database.
The second line contains integers, . We have and for all .
Output
Output a single integer, the number of cycles in the given database.
Limits
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 , and .