P25376 [AtCoder] Friendly Rabbits
普及-
题目描述

Problem Description

There are $ N $ rabbits. The rabbits are numbered from $ 1 $ to $ N $.

For each $1 \leq i \leq N$, rabbit $ i $ likes rabbit $ a_i $. However, no rabbit likes themselves. That is, $a_i \neq i$.

A pair of rabbits $ (i, j) $ ($ i < j $) is called friendly if the following conditions are met:

  • Rabbit $ i $ likes rabbit $ j $, and rabbit $ j $ likes rabbit $ i $.

Find the number of friendly pairs.

Input Format

The input is given from the standard input in the following format:

$ N $ $ a_1 $ $ a_2 $ $ ... $ $ a_N $

Output Format

Output the number of friendly pairs.

Sample Input and Output

Sample Input #1

4
2 1 4 3

Sample Output #1

2

Sample Input #2

3
2 3 1

Sample Output #2

0

Sample Input #3

5
5 5 5 5 1

Sample Output #3

1

Notes/Hints

Constraints

  • $2 \leq N \leq 10^5$
  • $1 \leq a_i \leq N$
  • $a_i \neq i$

Sample Explanation 1

The friendly pairs are $ (1, 2) $ and $ (3, 4) $, totaling $ 2 $ pairs.

Sample Explanation 2

There are no friendly pairs.

Sample Explanation 3

The friendly pair is $ (1, 5) $, totaling $ 1 $ pair.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 2 1 4 3
样例输出
2