QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#11876. Spies

統計

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).

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 ≤ 1\,000\,000$. 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 $a_k$ situated in line no. $k+1$ indicates, that the spy no. $k$ shadows the spy no. $a_k$, $1 ≤ k ≤ n$, $1 ≤ a_k ≤ n$, $a_k \ne 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

Input

6
2
3
1
3
6
5

Output

3
problem_11876_1.gif

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.