#P6417. [COCI 2014/2015 #1] MAFIJA

[COCI 2014/2015 #1] MAFIJA

Description

There are nn people. Some of them are civilians, and some of them are gangsters.

Now the civilians want to find all the gangsters, so each of the nn people has accused one person of being a gangster.

If a person is a civilian, they will accuse someone randomly. Otherwise, they will accuse a civilian.

Find the maximum possible number of gangsters.

Input Format

The first line contains an integer nn.

The next nn lines each contain an integer kk. Line ii means that person ii accused person kk.

Output Format

Output a single integer: the maximum possible number of gangsters.

3
2
1
1

2
3
2
3
1

1

7
3
3
4
5
6
4
4
4

Hint

Sample Explanation

Explanation for Sample Input/Output 1

The gangsters can be person 22 and person 33.

Explanation for Sample Input/Output 2

The gangsters could be everyone, but then there can only be one gangster among them. If there is one more gangster, a gangster would accuse a gangster, which is not allowed.

Constraints

  • For the testdata worth 4040 points, it is guaranteed that n15n\le 15.
  • For the testdata worth 8080 points, it is guaranteed that n2×104n\le 2\times 10^4.
  • For the testdata worth 100%100\% of the testdata, it is guaranteed that 1n5×1051\le n\le 5\times 10^5, 1kn1\le k\le n.

Note

The total score of this problem is 120120 points.

This problem is translated from Croatian Open Competition in Informatics 2014/2015 Contest #1 T4 MAFIJA.

Translated by ChatGPT 5