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;
const int maxN = 100005;
const int inf = 214748364;
struct edge {
  int a, l;
} e[maxN];
int sex[maxN], start[maxN], p[maxN], q[maxN], ans[maxN][2];
int n, t, tot, k, root, fa[maxN];
bool bo[maxN], flag;
struct Node {
  int x, y;
  Node() {}
  Node(int x1, int y1) {
    x = x1;
    y = y1;
  }
  bool operator>(const Node &o) const {
    return x > o.x || (x == o.x && y > o.y);
  }
  Node operator+(const Node &o) { return Node(x + o.x, y + o.y); }
} f[maxN][2], g[maxN], tmp, cnt;
void add(int x, int y) {
  e[++tot].l = start[x];
  e[tot].a = y;
  start[x] = tot;
}
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", fa + i, sex + i);
    add(fa[i], i);
  }
}
void dfs(int x) {
  bo[x] = 1;
  for (int i = start[x]; i; i = e[i].l)
    if (e[i].a != root) dfs(e[i].a);
  t = 0;
  for (int i = start[x]; i; i = e[i].l)
    if (e[i].a != root) q[++t] = e[i].a;
  tmp = g[t + 1] = Node(0, 0);
  for (int i = t; i; --i)
    g[i] =
        g[i + 1] + ((f[q[i]][0]) > (f[q[i]][1]) ? (f[q[i]][0]) : (f[q[i]][1]));
  f[x][0] = g[1];
  f[x][1] = Node(-inf, 0);
  p[x] = 0;
  for (int i = 1; i <= t; ++i) {
    cnt = tmp + g[i + 1] + f[q[i]][0] + Node(1, sex[x] != sex[q[i]]);
    if (q[i] == fa[root] && flag) cnt = Node(-inf, 0);
    if (cnt > f[x][1]) {
      f[x][1] = cnt;
      p[x] = q[i];
    }
    tmp = tmp + ((f[q[i]][0]) > (f[q[i]][1]) ? (f[q[i]][0]) : (f[q[i]][1]));
  }
  if (flag && x == fa[root]) f[x][1] = Node(-inf, 0);
}
void get(int x, bool flag) {
  if (flag == 1) f[x][1] = Node(-inf, 0);
  if (f[x][0] > f[x][1])
    p[x] = 0;
  else {
    ++k;
    ans[k][0] = x;
    ans[k][1] = p[x];
  }
  for (int i = start[x]; i; i = e[i].l)
    if (e[i].a != root) get(e[i].a, e[i].a == p[x]);
}
void work() {
  int x, old;
  Node best, tmp, cnt;
  best = Node(0, 0);
  for (int i = 1; i <= n; ++i)
    if (!bo[i]) {
      x = i;
      old = k;
      while (!bo[x]) bo[x] = 1, x = fa[x];
      root = x;
      flag = 0;
      dfs(x);
      cnt = ((f[x][0]) > (f[x][1]) ? (f[x][0]) : (f[x][1]));
      get(x, 0);
      flag = 1;
      dfs(x);
      tmp = f[x][0] + Node(1, sex[x] != sex[fa[x]]);
      if (tmp > cnt) {
        cnt = tmp;
        k = old;
        get(x, 1);
        ++k;
        ans[k][0] = x;
        ans[k][1] = fa[x];
      }
      best = best + cnt;
    }
  printf("%d %d\n", best.x, best.y);
  for (int i = 1; i <= k; ++i) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main() {
  init();
  work();
  return 0;
}