#codefestival2016qualAb. [codefestival_2016_qualA_b]Friendly Rabbits

[codefestival_2016_qualA_b]Friendly Rabbits

Problem Statement

There are NN rabbits, numbered 11 through NN.

The ii-th (1iN1≤i≤N) rabbit likes rabbit aia_i. Note that no rabbit can like itself, that is, aiia_i≠i.

For a pair of rabbits ii and jj (iji<j), we call the pair (iji,j) a friendly pair if the following condition is met.

  • Rabbit ii likes rabbit jj and rabbit jj likes rabbit ii.

Calculate the number of the friendly pairs.

Constraints

  • 2N1052≤N≤10^5
  • 1aiN1≤a_i≤N
  • aiia_i≠i

Input

The input is given from Standard Input in the following format:

NN a1a_1 a2a_2 ...... aNa_N

Output

Print the number of the friendly pairs.


Sample Input 1

4
2 1 4 3

Sample Output 1

2

There are two friendly pairs: (12)(1,2) and (34)(3,4).


Sample Input 2

3
2 3 1

Sample Output 2

0

There are no friendly pairs.


Sample Input 3

5
5 5 5 5 1

Sample Output 3

1

There is one friendly pair: (15)(1,5).