Polish version    English version  
  History of OI -> XI OI 2003/2004 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
Schedule
Problems
Stage III - results
Stage II - results
Stage I - results
Stage II
Stage III
Rules
For contestants
Helpful resources
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
XI Olympiad in Informatics 2003/2004

Task: szp

Spies

I stage competition  
Source file: szp.xxx (xxx=pas,c,cpp)
Memory limit: 32 MB

Byteotian Intelligence Agency (BIA) employs many spies. Each of them has duty to shadow exactly one other spy.

King Byteasar wants to entrust as many agents as possible with a top secret operation. However, the operation is so important that each spy taking part has to be traced by at least one agent not involved in the operation (assignment of shadowing BIA spies does not change).

Task

Write a programme that:

  • reads from standard input the description of whom each spy shadows,
  • calculates how many agents can be assigned to the operation in a way that each of them would be spied by at least one agent not taking part in the operation,
  • writes the result to the standard output.

Input

In the first line of the input there is one positive integer written, n - the number of spies, 2 <= n <= 1000000. The spies are numbered from 1 to n. In the following n lines there is a description of whom each agent spies. Each of these lines contains one positive integer. A number ak situated in line no. k + 1 indicates, that the spy no. k shadows the spy no. ak, 1 <= k <= n, 1 <= ak <= n, ak <> k.

Output

Your programme should write one integer in the first line of the output - the maximal number of spies that can be assigned to the secret operation.

Example

For the following input data:

6
2
3
l
3
6
5

the correct answer is:

3

Example




Print friendly version