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>
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int N;
int T[100005];
struct E {
  int V, Next;
} Edge[200005];
int EdgeTop;
int Head[100005];
void Add(int U, int V) {
  Edge[++EdgeTop] = (E){V, Head[U]};
  Head[U] = EdgeTop;
}
int V[100005];
void Init() {
  Get(N);
  for (int i = 1; i <= N; i++) {
    Get(V[i]);
    Get(T[i]);
    if (i != V[i] && V[V[i]] != i) {
      Add(i, V[i]);
      Add(V[i], i);
    }
  }
}
int Fa[100005];
long long F[100005][5];
long long BestF[100005];
int BestFID[100005];
int FromF[100005][5];
long long G[100005][5];
long long BestG[100005];
int BestGID[100005];
long long H[100005][5];
long long BestH[100005];
int BestHID[100005];
void Rec(int Y, int X) {
  for (int i = Y;; i = Fa[i]) {
    G[i][0] = H[i][0] = F[i][0];
    G[i][1] = H[i][1] = F[i][1];
    BestG[i] = BestH[i] = BestF[i];
    BestGID[i] = BestHID[i] = BestFID[i];
    if (i == X) break;
  }
  G[Y][1] = G[Y][0];
  G[Y][0] = 0xc0c0c0c0c0c0c0c0ll;
  for (int i = Y;; i = Fa[i]) {
    if (i == X) break;
    G[Fa[i]][0] += G[i][1];
    if (BestG[Fa[i]] < G[i][0] + (1000000ll + (T[Fa[i]] != T[i])) - G[i][1]) {
      BestG[Fa[i]] = G[i][0] + (1000000ll + (T[Fa[i]] != T[i])) - G[i][1];
      BestGID[Fa[i]] = i;
    }
    G[Fa[i]][1] = G[Fa[i]][0] + BestG[Fa[i]];
    H[Fa[i]][0] += H[i][1];
    if (BestH[Fa[i]] < H[i][0] + (1000000ll + (T[Fa[i]] != T[i])) - H[i][1]) {
      BestH[Fa[i]] = H[i][0] + (1000000ll + (T[Fa[i]] != T[i])) - H[i][1];
      BestHID[Fa[i]] = i;
    }
    H[Fa[i]][1] = H[Fa[i]][0] + BestH[Fa[i]];
  }
  G[X][1] = G[X][0] + (1000000ll + (T[X] != T[Y]));
  BestGID[X] = Y;
}
int Low[100005];
int DFN[100005];
int Time;
void DFS(int X) {
  DFN[X] = Low[X] = ++Time;
  BestF[X] = 0;
  for (int i = Head[X]; i; i = Edge[i].Next) {
    if (Fa[X] != Edge[i].V) {
      if (DFN[Edge[i].V] == 0) {
        Fa[Edge[i].V] = X;
        DFS(Edge[i].V);
        if (Low[X] > Low[Edge[i].V]) Low[X] = Low[Edge[i].V];
        if (Low[Edge[i].V] > DFN[X]) {
          F[X][0] += F[Edge[i].V][1];
          if (BestF[X] < F[Edge[i].V][0] +
                             (1000000ll + (T[X] != T[Edge[i].V])) -
                             F[Edge[i].V][1]) {
            BestF[X] = F[Edge[i].V][0] + (1000000ll + (T[X] != T[Edge[i].V])) -
                       F[Edge[i].V][1];
            BestFID[X] = Edge[i].V;
          }
        }
      } else {
        if (Low[X] > DFN[Edge[i].V]) Low[X] = DFN[Edge[i].V];
      }
    }
  }
  F[X][1] = F[X][0] + BestF[X];
  for (int i = Head[X]; i; i = Edge[i].Next)
    if (DFN[Edge[i].V] > DFN[X] && Fa[Edge[i].V] != X) {
      Rec(Edge[i].V, X);
      if (F[X][0] < G[X][0]) {
        F[X][0] = G[X][0];
        FromF[X][0] = 1;
      }
      if (F[X][0] < H[X][0]) {
        F[X][0] = H[X][0];
        FromF[X][0] = 2;
      }
      if (F[X][1] < G[X][1]) {
        F[X][1] = G[X][1];
        FromF[X][1] = 1;
      }
      if (F[X][1] < H[X][1]) {
        F[X][1] = H[X][1];
        FromF[X][1] = 2;
      }
    }
}
int Ans2[5][100005];
int AnsTop2;
bool End[100005];
void Solu(int Type, int i, int j) {
  int FGH = FromF[i][j];
  if (Type == 0) Type = FGH;
  if (j == 1) {
    if (Type == 0 && Fa[BestFID[i]] != i && BestFID[i] != 0) {
      Ans2[1][++AnsTop2] = i;
      Ans2[2][AnsTop2] = BestFID[i];
      End[BestFID[i]] = 1;
      j = 0;
    } else if (Type == 1 && Fa[BestGID[i]] != i && BestGID[i] != 0) {
      Ans2[1][++AnsTop2] = i;
      Ans2[2][AnsTop2] = BestGID[i];
      End[BestGID[i]] = 1;
      j = 0;
    } else if (Type == 2 && Fa[BestHID[i]] != i && BestHID[i] != 0) {
      Ans2[1][++AnsTop2] = i;
      Ans2[2][AnsTop2] = BestHID[i];
      End[BestHID[i]] = 1;
      j = 0;
    }
  }
  if (End[i] == 1) j = 0;
  for (int k = Head[i]; k; k = Edge[k].Next) {
    int j0 = j;
    if (j == 0)
      j0 = 1;
    else {
      if (Type == 0 && BestFID[i] == Edge[k].V) {
        j0 = 0;
        Ans2[1][++AnsTop2] = i;
        Ans2[2][AnsTop2] = Edge[k].V;
      }
      if (Type == 1 && BestGID[i] == Edge[k].V) {
        j0 = 0;
        Ans2[1][++AnsTop2] = i;
        Ans2[2][AnsTop2] = Edge[k].V;
      }
      if (Type == 2 && BestHID[i] == Edge[k].V) {
        j0 = 0;
        Ans2[1][++AnsTop2] = i;
        Ans2[2][AnsTop2] = Edge[k].V;
      }
    }
    if (Fa[Edge[k].V] == i) {
      if (Low[i] == Low[Edge[k].V])
        Solu(Type, Edge[k].V, j0);
      else
        Solu(0, Edge[k].V, j0);
    }
  }
}
long long Ans;
void Work() {
  for (int i = 1; i <= N; i++) {
    if (DFN[i] == 0) {
      DFS(i);
      if ((F[i][0] > F[i][1])) {
        Ans += F[i][0];
        Solu(0, i, 0);
      } else {
        Ans += F[i][1];
        Solu(0, i, 1);
      }
    }
  }
}
void Output() {
  puts("");
  printf("%I64d %I64d\n", Ans / 1000000ll, Ans % 1000000ll);
  for (int i = 1; i <= AnsTop2; i++) printf("%d %d\n", Ans2[1][i], Ans2[2][i]);
}
int main() {
  Init();
  Work();
  Output();
  return 0;
}