#include <bits/stdc++.h>
using namespace std;
int n, k;
int par[1000010];
void init() {
  memset(par, 0, sizeof(par));
  for (int i = 0; i < 1000010; i++) {
    par[i] = i;
  }
}
int fin(int x) {
  while (x != par[x]) x = par[x] = par[par[x]];
  return x;
}
void unite(int x, int y) {
  x = fin(x);
  y = fin(y);
  par[x] = y;
}
int Size[1000010], cnt;
int w[400 + 10], w2[1000010];
map<int, int> ma;
int main() {
  init();
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int tmp;
    scanf("%d", &tmp);
    int fa1 = fin(i);
    int fa2 = fin(tmp);
    unite(fa1, fa2);
  }
  for (int i = 1; i <= n; i++) {
    if (ma[fin(i)]) {
      Size[ma[fin(i)]]++;
    } else {
      ma[fin(i)] = (++cnt);
      Size[cnt] = 1;
    }
  }
  sort(Size + 1, Size + 1 + cnt);
  int maxx = 0;
  int tmpk = k;
  if (cnt >= k)
    maxx = k * 2;
  else {
    int tmp = 0;
    for (int i = cnt; i >= 1; i--) {
      if (k - Size[i] / 2 >= 0) {
        if (Size[i] % 2) tmp++;
        maxx += Size[i] / 2 * 2;
        k -= Size[i] / 2;
      } else if (k - Size[i] / 2 < 0) {
        maxx += (k * 2);
        k = 0;
        break;
      }
    }
    if (k != 0) maxx += min(k, tmp);
  }
  k = tmpk;
  int cnt2 = 0;
  for (int i = 1; i <= cnt; ++i) {
    if (Size[i] > 400)
      w2[++cnt2] = Size[i];
    else
      w[Size[i]]++;
  }
  bitset<1000010> dp;
  dp[0] = 1;
  for (int i = 1; i <= cnt2; ++i) dp |= dp << (w2[i]);
  for (int i = 1; i <= 400; ++i) {
    if (!w[i]) continue;
    for (int j = 1; j <= w[i]; j <<= 1) {
      dp |= dp << (i * j);
      w[i] -= j;
    }
    if (w[i]) dp |= dp << (w[i] * i);
  }
  if (dp[k] == 1)
    printf("%d %d\n", k, maxx);
  else
    printf("%d %d\n", k + 1, maxx);
}

### Prompt

Please create a solution in cpp to the following problem:

It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i.

Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold: 

  1. Ball number i will bring the present he should give. 
  2. Ball x such that px = i will bring his present. 



What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs?

Input

The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents. 

The second line contains the permutation p of integers from 1 to n, where pi is the index of Ball who should get a gift from the i-th Ball. For all i, pi ≠ i holds.

Output

You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order.

Examples

Input

5 2
3 4 1 5 2


Output

2 4

Input

10 1
2 3 4 5 6 7 8 9 10 1


Output

2 2

Note

In the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
int par[1000010];
void init() {
  memset(par, 0, sizeof(par));
  for (int i = 0; i < 1000010; i++) {
    par[i] = i;
  }
}
int fin(int x) {
  while (x != par[x]) x = par[x] = par[par[x]];
  return x;
}
void unite(int x, int y) {
  x = fin(x);
  y = fin(y);
  par[x] = y;
}
int Size[1000010], cnt;
int w[400 + 10], w2[1000010];
map<int, int> ma;
int main() {
  init();
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int tmp;
    scanf("%d", &tmp);
    int fa1 = fin(i);
    int fa2 = fin(tmp);
    unite(fa1, fa2);
  }
  for (int i = 1; i <= n; i++) {
    if (ma[fin(i)]) {
      Size[ma[fin(i)]]++;
    } else {
      ma[fin(i)] = (++cnt);
      Size[cnt] = 1;
    }
  }
  sort(Size + 1, Size + 1 + cnt);
  int maxx = 0;
  int tmpk = k;
  if (cnt >= k)
    maxx = k * 2;
  else {
    int tmp = 0;
    for (int i = cnt; i >= 1; i--) {
      if (k - Size[i] / 2 >= 0) {
        if (Size[i] % 2) tmp++;
        maxx += Size[i] / 2 * 2;
        k -= Size[i] / 2;
      } else if (k - Size[i] / 2 < 0) {
        maxx += (k * 2);
        k = 0;
        break;
      }
    }
    if (k != 0) maxx += min(k, tmp);
  }
  k = tmpk;
  int cnt2 = 0;
  for (int i = 1; i <= cnt; ++i) {
    if (Size[i] > 400)
      w2[++cnt2] = Size[i];
    else
      w[Size[i]]++;
  }
  bitset<1000010> dp;
  dp[0] = 1;
  for (int i = 1; i <= cnt2; ++i) dp |= dp << (w2[i]);
  for (int i = 1; i <= 400; ++i) {
    if (!w[i]) continue;
    for (int j = 1; j <= w[i]; j <<= 1) {
      dp |= dp << (i * j);
      w[i] -= j;
    }
    if (w[i]) dp |= dp << (w[i] * i);
  }
  if (dp[k] == 1)
    printf("%d %d\n", k, maxx);
  else
    printf("%d %d\n", k + 1, maxx);
}

```