This page is still under construction.

Parts of this page are still being built. What you see may change.

Mafia

Time limit2sMemory limit128 MB

Summary
Each mobster aims at one target; find the minimum and maximum possible number of deaths over all shooting orders.
Level

Medium7 of 10

Topics
Graph, Greedy, Implementation
Solved
No attempts yet

Problem

nn mobsters face off in a tense standoff. Each mobster has drawn a pistol and permanently aims it at exactly one of the nn mobsters (possibly at himself). If the shooting begins, it proceeds under this code of honour:

  • The mobsters fire one at a time, in some order; at any moment at most one shot is fired.
  • No shooter ever misses. The target dies instantly and can no longer fire.
  • Every mobster fires exactly once, unless he is killed before his turn to shoot arrives.
  • A mobster never changes his chosen target. If that target is already dead when he fires, the shot merely hits a corpse and causes no new casualty.

The order in which the mobsters shoot is not fixed, and different orders can lead to a different number of deaths. Knowing only who aims at whom, determine the minimum and the maximum possible number of casualties over all shooting orders.

Input

The first line contains one integer nn (1≤n≤1,000,0001 \le n \le 1{,}000{,}000), the number of mobsters, numbered from 11 to nn.

The second line contains nn integers s1,s2,…,sns_1, s_2, \ldots, s_n (1≤si≤n1 \le s_i \le n), separated by single spaces, where sis_i is the mobster that mobster ii aims at. Note that si=is_i = i is allowed, meaning mobster ii aims at himself.

Output

Print a single line with two integers separated by one space: the minimum and the maximum possible number of casualties.

Examples1

  1. Example 1

    Input
    8
    2 3 2 2 6 7 8 5
    
    Expected output
    3 5