G. Graph of Love
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Luiz Eduardo is one of the last remnants of an almost extinct race on Earth: the romantics. He believes that everyone in the world will eventually find their one and only true love, whoever they may be (in fact, their true love could even be themselves!).

He took a sabbatical year and traveled the world, talking to people and hearing about their true loves. Carrying his notebook, he wrote down the names of the people he spoke to or heard about and the corresponding name of their true love. After his long journey, he showed his notes to his colleague Iasmim (to protect people's privacy, he replaced names with numbers).

Iasmim did not find Luiz's notes very interesting, so she decided to turn them into something nicer: a graph! More specifically, she constructed a graph where there is a directed edge from $$$A$$$ to $$$B$$$ if and only if person $$$A$$$ truly loves person $$$B$$$.

She then challenged Luiz with a problem: what is the maximum number of partially happy monogamous marriages (P.H.M.M.s) that could happen simultaneously in this graph? A P.H.M.M. consists of two people, $$$A$$$ and $$$B$$$, such that:

  • $$$A \neq B$$$
  • There is an edge in Iasmim's graph from $$$A$$$ to $$$B$$$ or from $$$B$$$ to $$$A$$$.
  • Neither $$$A$$$ nor $$$B$$$ are in another P.H.M.M.

Both Luiz and Iasmim have terrible memories of the last time they heard the words marriage and graph in the same sentence. Therefore, help them solve this problem.

Input

The first line of the input contains the number $$$N$$$, the number of people in Luiz's notes ($$$1 \leq N \leq 10^5$$$).

The second line of the input contains $$$N$$$ integers $$$A_i$$$, each representing the true love of person $$$i$$$ ($$$1 \leq i, A_i \leq N$$$, it is possible that $$$A_i = i$$$).

Output

Print a single integer: the maximum number of partially happy monogamous marriages (P.H.M.M.s) that could happen simultaneously in Iasmim's graph.

Example
Input
12
4 1 5 1 9 7 9 12 9 11 12 10
Output
5
Note

In the sample test case, to generate the maximum number of P.H.M.M.s, one of multiple possibilities is to pair the people in the following marriages: $$$(1,4),(3,5),(6,7),(8,12),(10,11)$$$.

Although person $$$2$$$ and person $$$9$$$ remain outside of P.H.M.M.s, it is not possible to pair them because there are no edges between them. It can be verified that it is not possible to generate more than $$$5$$$ P.H.M.M.s simultaneously.