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 n, x[200011], Nxt[200011], head[100011], Cnt, sex[100011];
bool visit[100011], insta[100011];
inline void link(int A, int B) {
  x[++Cnt] = B;
  Nxt[Cnt] = head[A];
  head[A] = Cnt;
}
void init() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1, A; i <= n; ++i) {
    cin >> A >> sex[i];
    link(i, A);
    link(A, i);
  }
}
int c[100011], cc;
bool onc[100011];
bool dfs(int u, int pre = 0) {
  static int flag = 0;
  static int start = 0;
  if (flag) flag = 0;
  insta[u] = 1;
  for (int i = head[u]; i; i = Nxt[i]) {
    int v = x[i];
    if (v == pre) continue;
    if (insta[v])
      return cc = 0, flag = 1, start = v, c[++cc] = u, onc[u] = 1, 1;
    dfs(v, u);
    if (flag) {
      if (flag == 1) c[++cc] = u, onc[u] = 1;
      if (start == u) flag = 2;
      return 1;
    }
  }
  insta[u] = 0;
  return 0;
}
struct status {
  int a, b;
  status() {}
  status(int _a, int _b) : a(_a), b(_b) {}
} f[100011], g[100011];
status outs[100011];
int couts, rec;
inline bool operator<(const status &A, const status &B) {
  return (A.a < B.a) || (A.a == B.a && A.b < B.b);
}
inline status operator+(const status &A, const status &B) {
  return status(A.a + B.a, A.b + B.b);
}
int p[100011];
void treeDP(int u, int pre = 0) {
  if (visit[u]) return;
  visit[u] = 1;
  f[u] = status(-1000000, 0);
  g[u] = status(0, 0);
  for (int i = head[u]; i; i = Nxt[i]) {
    int v = x[i];
    if (v == pre || onc[v]) continue;
    treeDP(v, u);
    if (f[u] + max(g[v], f[v]) < g[u] + g[v] + status(1, sex[u] != sex[v]))
      f[u] = g[u] + g[v] + status(1, sex[u] != sex[v]), p[u] = v;
    else
      f[u] = f[u] + max(g[v], f[v]);
    g[u] = g[u] + max(f[v], g[v]);
  }
}
bool used[100011];
void record(int u, int pre = 0) {
  if (g[u] < f[u] && p[u] && !used[u] && !used[p[u]])
    outs[++couts] = status(u, p[u]), used[u] = used[p[u]] = 1,
    rec += sex[u] != sex[p[u]];
  for (int i = head[u]; i; i = Nxt[i]) {
    int v = x[i];
    if (v == pre || onc[v]) continue;
    record(v, u);
  }
}
status f1[100011], g1[100011], f2[100011], g2[100011];
int p1[100011], p2[100011];
void circleDP() {
  memset(p1, 0, sizeof(p1));
  memset(p2, 0, sizeof(p2));
  f1[1] = f[c[1]], g1[1] = g[c[1]];
  for (int i = 2; i <= cc; ++i) {
    if (max(f1[i - 1], g1[i - 1]) + max(f[c[i]], g[c[i]]) <
        g1[i - 1] + g[c[i]] + status(1, sex[c[i]] != sex[c[i - 1]]))
      f1[i] = g1[i - 1] + g[c[i]] + status(1, sex[c[i]] != sex[c[i - 1]]),
      p1[i] = i - 1;
    else
      f1[i] = max(f1[i - 1], g1[i - 1]) + max(f[c[i]], g[c[i]]);
    g1[i] = max(g1[i - 1], f1[i - 1]) + g[c[i]];
  }
  f2[0] = f[c[cc]], g2[0] = g[c[cc]];
  c[0] = c[cc];
  for (int i = 1; i <= cc - 1; ++i) {
    if (max(f2[i - 1], g2[i - 1]) + max(f[c[i]], g[c[i]]) <
        g2[i - 1] + g[c[i]] + status(1, sex[c[i]] != sex[c[i - 1]]))
      f2[i] = g2[i - 1] + g[c[i]] + status(1, sex[c[i]] != sex[c[i - 1]]),
      p2[i] = i - 1 == 0 ? cc : i - 1;
    else
      f2[i] = max(f2[i - 1], g2[i - 1]) + max(f[c[i]], g[c[i]]);
    g2[i] = max(g2[i - 1], f2[i - 1]) + g[c[i]];
  }
  if (max(g1[cc], f1[cc]) < max(g2[cc - 1], f2[cc - 1])) {
    for (int i = cc - 1; i >= 1; --i)
      if (g2[i] < f2[i] && p2[i] && !used[c[i]] && !used[c[p2[i]]])
        outs[++couts] = status(c[i], c[p2[i]]), used[c[i]] = used[c[p2[i]]] = 1,
        rec += sex[c[i]] != sex[c[i - 1]];
  } else {
    for (int i = cc; i > 1; --i)
      if (g1[i] < f1[i] && p1[i] && !used[c[i]] && !used[c[p1[i]]])
        outs[++couts] = status(c[i], c[p1[i]]), used[c[i]] = used[c[p1[i]]] = 1,
        rec += sex[c[i]] != sex[c[i - 1]];
  }
  for (int i = 1; i <= cc; ++i) record(c[i]);
}
void work() {
  for (int i = 1; i <= n; ++i)
    if (!visit[i]) {
      if (dfs(i)) {
        for (int j = 1; j <= cc; ++j) treeDP(c[j]);
        circleDP();
      } else {
        treeDP(i);
        record(i);
      }
    }
  cout << couts << ' ' << rec << endl;
  for (int i = 1; i <= couts; ++i)
    cout << outs[i].a << ' ' << outs[i].b << endl;
}
int main() {
  init();
  work();
  return 0;
}