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 = 100000 + 10;
struct Graph {
  int id, next;
  bool pre[2], sel;
} g[MAXN * 2];
int st[MAXN], n, frb[MAXN], vis[MAXN], TT;
pair<int, int> f[MAXN][2];
bool sex[MAXN], rcd;
vector<pair<int, int> > CC;
void Add(int tot, int first, int second) {
  g[tot].id = second, g[tot].next = st[first], st[first] = tot;
}
void init() {
  scanf("%d", &n);
  memset(st, -1, sizeof(st));
  for (int i = 1; i <= n; ++i) {
    int first, second;
    scanf("%d%d", &first, &second);
    Add(i * 2, first, i), Add(i * 2 + 1, i, first);
    sex[i] = second - 1;
  }
}
int BP1, BP2;
int Find_bp(int first, int fa) {
  vis[first] = TT;
  for (int i = st[first]; i != -1; i = g[i].next)
    if (g[i].id != fa) {
      if (vis[g[i].id] == TT) {
        BP1 = first, BP2 = g[i].id;
        return first;
      }
      int second = Find_bp(g[i].id, first);
      if (second != -1) return second;
    }
  return -1;
}
pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> operator+=(pair<int, int>& a, const pair<int, int>& b) {
  a = a + b;
  return a;
}
pair<int, int> operator-(const pair<int, int>& a, const pair<int, int>& b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<int, int> Tree_dp(int first, int fa) {
  vis[first] = TT;
  f[first][0] = f[first][1] = make_pair(0, 0);
  pair<int, int> delta = make_pair(-MAXN, -MAXN);
  int ref = 0;
  bool flag = false;
  for (int i = st[first]; i != -1; i = g[i].next)
    if (g[i].id != fa && vis[g[i].id] != TT) {
      Tree_dp(g[i].id, first);
      if (f[g[i].id][1] > f[g[i].id][0]) {
        f[first][0] += f[g[i].id][1];
        if (!flag && f[g[i].id][0] - f[g[i].id][1] +
                             make_pair(1, sex[first] ^ sex[g[i].id]) >
                         delta)
          delta = f[g[i].id][0] - f[g[i].id][1] +
                  make_pair(1, sex[first] ^ sex[g[i].id]),
          ref = i;
        f[first][1] += f[g[i].id][1];
        if (rcd) g[i].pre[0] = g[i].pre[1] = 1;
      } else {
        flag = true;
        if (make_pair(1, sex[first] ^ sex[g[i].id]) > delta)
          delta = make_pair(1, sex[first] ^ sex[g[i].id]), ref = i;
        f[first][0] += f[g[i].id][0], f[first][1] += f[g[i].id][0];
        if (rcd) g[i].pre[0] = g[i].pre[1] = 0;
      }
    }
  if (!frb[first]) {
    f[first][1] += delta;
    if (rcd) g[ref].pre[1] = 0, g[ref].sel = true;
  } else
    f[first][1] = f[first][0], f[first][0] = make_pair(-MAXN, -MAXN);
  return max(f[first][0], f[first][1]);
}
void Construct(int first, int k) {
  vis[first] = TT;
  for (int i = st[first]; i != -1; i = g[i].next)
    if (vis[g[i].id] != TT) {
      if (k && g[i].sel && !frb[first] && !frb[g[i].id])
        CC.push_back(make_pair(first, g[i].id));
      Construct(g[i].id, g[i].pre[k]);
    }
}
int cnt = 0;
void solve() {
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      TT = 1;
      rcd = false;
      Find_bp(i, 0);
      TT = 2;
      pair<int, int> f1 = Tree_dp(i, 0);
      TT = 3;
      frb[BP1] = 1;
      frb[BP2] = 2;
      pair<int, int> f2 = Tree_dp(i, 0) + make_pair(1, sex[BP1] ^ sex[BP2]);
      frb[BP1] = frb[BP2] = 0;
      TT = 4;
      rcd = true;
      if (f1 > f2) {
        cnt += f1.second, Tree_dp(i, 0);
        int id = 0;
        if (f[i][1] > f[i][id]) id = 1;
        TT = 5;
        Construct(i, id);
      } else {
        cnt += f2.second, frb[BP1] = 1;
        frb[BP2] = 2;
        CC.push_back(make_pair(BP1, BP2));
        Tree_dp(i, 0);
        TT = 5;
        Construct(i, 1);
      }
    }
  cout << CC.size() << " " << cnt << endl;
  for (int i = 0; i < (int)CC.size(); ++i)
    cout << CC[i].first << " " << CC[i].second << endl;
}
int main() {
  init();
  solve();
  fclose(stdin);
  fclose(stdout);
  return 0;
}