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 main() {
  int n;
  scanf("%d", &n);
  vector<int> f(n), s(n);
  vector<vector<int>> g(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &f[i], &s[i]);
    --f[i];
    --s[i];
    g[f[i]].push_back(i);
  }
  vector<vector<pair<int, int>>> dp(n, vector<pair<int, int>>(2));
  vector<int> match(n, -1);
  vector<bool> was(n);
  function<void(int, const int&)> dfs = [&](int v, const int& root) {
    dp[v][0] = dp[v][1] = make_pair(0, 0);
    was[v] = true;
    match[v] = -1;
    for (int to : g[v]) {
      if (to == root) {
        continue;
      }
      dfs(to, root);
      dp[v][0].first += dp[to][1].first;
      dp[v][0].second += dp[to][1].second;
      auto t = make_pair(1 - dp[to][1].first + dp[to][0].first,
                         (s[v] != s[to]) - dp[to][1].second + dp[to][0].second);
      if (dp[v][1] < t) {
        dp[v][1] = t;
        match[v] = to;
      }
    }
    dp[v][1].first += dp[v][0].first;
    dp[v][1].second += dp[v][0].second;
  };
  function<void(int, int, vector<pair<int, int>>&, const int&)> go =
      [&](int v, int matched, vector<pair<int, int>>& vect, const int& root) {
        for (int to : g[v]) {
          if (to == root) {
            continue;
          }
          if (matched == 0 || to != match[v]) {
            go(to, 1, vect, root);
          } else {
            vect.emplace_back(v, to);
            go(to, 0, vect, root);
          }
        }
      };
  vector<pair<int, int>> select;
  pair<int, int> ans(0, 0);
  auto solve = [&](int v) {
    while (!was[v]) {
      was[v] = true;
      v = f[v];
    }
    pair<int, int> add(0, 0);
    vector<pair<int, int>> vect;
    for (int t = 0; t < 2; ++t) {
      dfs(v, v);
      if (dp[v][1] > add) {
        add = dp[v][1];
        vect.clear();
        go(v, 1, vect, v);
      }
      v = f[v];
    }
    ans.first += add.first;
    ans.second += add.second;
    for (auto x : vect) {
      select.push_back(x);
    }
  };
  for (int i = 0; i < n; ++i) {
    if (!was[i]) {
      solve(i);
    }
  }
  printf("%d %d\n", ans.first, ans.second);
  for (auto p : select) {
    printf("%d %d\n", p.first + 1, p.second + 1);
  }
  return 0;
}