Choose but not both

2.8

13 votes
Algorithms, Depth First Search, Dynamic Programming, Graphs, Trees
Problem

The alone Y has another array a1,a2,...,an that 1ain. this time Y wants to choose some numbers from 1 to n that there is no i that both i and ai is chosen.

What is the maximum amount of numbers that Y can choose?

Input

First line contains only n, legnth of array.

Second line contains the array elements a1,a2,...,anseparated by space.

1n3×105

1ain

Output

The only line of output contains an integer, maximum amount of numbers that Y can choose.

Sample Input
3
3 1 3
Sample Output
1
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Y cannot choose 3 because a3=3.

Y cannot choose both 1 and 2 because a2=1 so Y can choose only one number (either 1 or 2).

Editor Image

?