QOJ.ac

QOJ

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

#11060. Mafia

الإحصائيات

Mob feud rages in Equatorial Byteotia. The mob bosses have come to the country's capital, Byteburg, to settle the dispute. Negotiations were very tense, and at one point the trigger-happy participants drew their guns. Each participant aims at another with a pistol. Should they go on a killing spree, the shooting will go in accordance with the following code of honour:

  • the participants shoot in a certain order, and at any moment at most one of them is shooting,
  • no shooter misses, his target dies instantly, hence he may not shoot afterwards,
  • everyone shoots once, provided he had not been shot before he has a chance to shoot,
  • no participant may change his first target of choice, even if the target is already dead (then the shot causes no further casualties).

An undertaker watches from afar, as he usually does. After all, the mobsters have never failed to stimulate his business. He sees potential profit in the shooting, but he would like to know tight estimations. Precisely he would like to know the minimum and maximum possible death rate. The undertaker sees who aims at whom, but does not know the order of shooting. You are to write a programme that determines the numbers he is so keen to know.

Write a programme that:

  • reads from the standard input what target each mobster has chosen,
  • determines the minimum and maximum number of casualties,
  • writes out the result to the standard output.

Input

The first line of the standard input contains the number of participants $n$ ($1 ≤ n ≤ 1\,000\,000$). They are numbered from $1$ to $n$. The second line contains $n$ integers $s_1,s_2,…,s_n$, separated by single spaces, $1 ≤ s_i ≤ n$. $s_i$ denotes the number of ith participant's target. Note that it is possible that $s_i=i$ for some $i$ (the nerves, you know).

Output

Your programme should write out two integers separated by a single space in the first and only line of the standard output. These numbers should be, respectively, the minimum and maximum number of casualties resulting from the shooting.

Example

Input

8
2 3 2 2 6 7 8 5
problem_11060_1.gif

Output

3 5

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.