Problem: There are n students in Polycarp's class (including himself). A few days ago all students wrote an essay "My best friend". Each student's essay was dedicated to one of the students of class, to his/her best friend. Note that student b's best friend is not necessarily student a, if a's best friend is b.

And now the teacher leads the whole class to the museum of the history of sports programming. Exciting stories of legendary heroes await the students: tourist, Petr, tomek, SnapDragon — that's who they will hear about!

The teacher decided to divide students into pairs so that each pair consisted of a student and his best friend. She may not be able to split all the students into pairs, it's not a problem — she wants to pick out the maximum number of such pairs. If there is more than one variant of doing so, she wants to pick out the pairs so that there were as much boy-girl pairs as possible. Of course, each student must not be included in more than one pair.

Input

The first line contains an integer n (2 ≤ n ≤ 105), n is the number of students per class. Next, n lines contain information about the students, one per line. Each line contains two integers fi, si (1 ≤ fi ≤ n, fi ≠ i, 1 ≤ si ≤ 2), where fi is the number of i-th student's best friend and si denotes the i-th pupil's sex (si = 1 for a boy and si = 2 for a girl).

Output

Print on the first line two numbers t, e, where t is the maximum number of formed pairs, and e is the maximum number of boy-girl type pairs among them. Then print t lines, each line must contain a pair ai, bi (1 ≤ ai, bi ≤ n), they are numbers of pupils in the i-th pair. Print the pairs in any order. Print the numbers in pairs in any order. If there are several solutions, output any of them.

Examples

Input

5
5 2
3 2
5 1
2 1
4 2


Output

2 2
5 3
4 2


Input

6
5 2
3 2
5 1
2 1
4 2
3 1


Output

3 1
4 2
5 1
3 6


Input

8
2 2
3 2
5 1
3 1
6 1
5 1
8 2
7 1


Output

4 1
5 6
3 4
2 1
7 8

Note

The picture corresponds to the first sample. On the picture rhomb stand for boys, squares stand for girls, arrows lead from a pupil to his/her best friend. Bold non-dashed arrows stand for pairs in the answer. 

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int pos[100005][3];
int f[100005][3];
int d[100005][3];
int last[100005];
int sex[100005];
int pre[200005];
int e[200005];
int h[100005];
int n, m, l, r, curp;
vector<pair<int, int> > res;
void dfs(int x, int par) {
  int i;
  h[x] = 1;
  for (i = last[x]; i != 0; i = pre[i])
    if (h[e[i]] == 0)
      dfs(e[i], x);
    else if (e[i] != par) {
      l = x, r = e[i];
      if (i % 2 == 0) swap(l, r);
    }
}
void ms(int x) {
  int i, j, k;
  f[x][0] = f[x][1] = d[x][0] = d[x][1] = pos[x][0] = pos[x][1] = 0;
  for (i = last[x]; i != 0; i = pre[i])
    if (i % 2 != 0 && e[i] != r) {
      ms(e[i]);
      f[x][0] += f[e[i]][2];
      d[x][0] += d[e[i]][2];
    }
  for (i = last[x]; i != 0; i = pre[i])
    if (i % 2 != 0 && e[i] != r && e[i] != curp) {
      j = f[x][0] - f[e[i]][2] + f[e[i]][0] + 1;
      k = d[x][0] - d[e[i]][2] + d[e[i]][0] + (sex[x] != sex[e[i]]);
      if (j > f[x][1] || (j == f[x][1] && k > d[x][1])) {
        f[x][1] = j;
        d[x][1] = k;
        pos[x][1] = e[i];
      }
    }
  if (x == curp) f[x][1] = -1;
  f[x][2] = max(f[x][0], f[x][1]);
  if (f[x][0] > f[x][1] || (f[x][0] == f[x][1] && d[x][0] > d[x][1])) {
    d[x][2] = d[x][0];
    pos[x][2] = 0;
  } else {
    d[x][2] = d[x][1];
    pos[x][2] = 1;
  }
}
void recans(int x, int type) {
  int i;
  if (type == 2) type = pos[x][2];
  if (type == 1 && pos[x][1]) res.push_back(make_pair(x, pos[x][1]));
  for (i = last[x]; i != 0; i = pre[i])
    if (i % 2 != 0 && e[i] != r)
      if (type == 1 && pos[x][1] == e[i])
        recans(e[i], 0);
      else
        recans(e[i], 2);
}
void work() {
  int i, c1, c2, cur, ans, cp;
  ans = cp = 0;
  for (i = 1; i <= n; ++i)
    if (h[i] == 0) {
      dfs(i, 0);
      curp = 0, ms(r);
      cur = f[r][2];
      c1 = d[r][2], c2 = pos[r][2];
      curp = l, ms(r);
      if (f[r][0] + 1 > cur ||
          f[r][0] + 1 == cur && d[r][0] + (sex[l] != sex[r]) > c1) {
        cur = f[r][0] + 1;
        c1 = d[r][0] + (sex[l] != sex[r]);
        c2 = 2;
      }
      if (c2 == 2) {
        res.push_back(make_pair(l, r));
        c2 = 0;
      } else {
        curp = 0;
        ms(r);
        c2 = pos[r][2];
      }
      recans(r, c2);
      ans += cur, cp += c1;
    }
  printf("%d %d\n", ans, cp);
  for (i = 0; i < res.size(); ++i)
    printf("%d %d\n", res[i].first, res[i].second);
}
int main() {
  int i, x;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", &x, &sex[i]);
    (e[++m] = i, pre[m] = last[x], last[x] = m),
        (e[++m] = x, pre[m] = last[i], last[i] = m);
  }
  work();
  return 0;
}