#include <bits/stdc++.h>
using namespace std;
const long inf = (1 << 28);
long c[100000][2], p[100000], k1[100000], k2[100000], k3[100000], tot, root;
long b[100000];
void rorate(long x, long f) {
  long y = p[x];
  p[c[x][f]] = y;
  c[y][!f] = c[x][f];
  p[x] = p[y];
  if (p[x]) c[p[x]][c[p[y]][1] == y] = x;
  p[y] = x;
  c[x][f] = y;
}
void splay(long x, long goal) {
  long y, f;
  while (p[x] != goal) {
    if (p[p[x]] == goal) {
      rorate(x, c[p[x]][0] == x);
      break;
    }
    y = p[x];
    f = c[p[y]][0] == y;
    if (c[y][f] == x)
      rorate(x, !f);
    else
      rorate(y, f);
    rorate(x, f);
  }
  if (!goal) root = x;
}
long find(long x, long f) {
  long y;
  if (!f) {
    if (c[x][0]) {
      y = c[x][0];
      while (c[y][1]) y = c[y][1];
    } else {
      y = p[x];
      while (c[y][0] == x) {
        x = y;
        y = p[x];
      }
    }
  } else {
    if (c[x][1]) {
      y = c[x][1];
      while (c[y][0]) y = c[y][0];
    } else {
      y = p[x];
      while (c[y][1] == x) {
        x = y;
        y = p[x];
      }
    }
  }
  return (y);
}
long findval0(long val) {
  long x = root, y;
  while (x)
    if (k2[x] <= val) {
      y = x;
      x = c[x][1];
    } else
      x = c[x][0];
  return (y);
}
void newnode(long &x, long p1, long p2, long p3) {
  x = ++tot;
  c[x][0] = c[x][1] = p[x] = 0;
  k1[x] = p1;
  k2[x] = p2;
  k3[x] = p3;
}
void Insert(long p1, long p2, long p3) {
  long x = findval0(p2);
  splay(x, 0);
  x = c[x][1];
  while (c[x][0]) x = c[x][0];
  splay(x, root);
  newnode(c[c[root][1]][0], p1, p2, p3);
  p[c[c[root][1]][0]] = c[root][1];
}
void Delete(long x) {
  long y = find(x, 0), z = find(x, 1);
  splay(y, 0);
  splay(z, root);
  c[c[root][1]][0] = 0;
}
void work(long x) {
  long y = find(x, 0), z = find(x, 1);
  splay(y, 0);
  splay(z, root);
}
void init() {
  root = tot = 0;
  c[0][0] = c[0][1] = p[0] = k1[0] = k2[0] = k3[0] = 0;
  newnode(root, 0, -inf, 0);
  newnode(c[root][1], 0, inf, 0);
  p[2] = 1;
  p[1] = 0;
}
int main() {
  long i, j, n, bs = 0, bsi, val;
  init();
  scanf("%ld", &n);
  for (i = 0; i <= n - 1; i++) {
    scanf("%ld%ld", &bsi, &val);
    Insert(val, bsi, i);
    b[i] = tot;
    bs += bsi;
  }
  printf("%ld\n", bs / 2);
  for (i = 1; i <= n; i++) {
    long x = root, y, z, u, v;
    while (c[x][0]) x = c[x][0];
    x = find(x, 1);
    if (k2[x]) {
      u = k3[x];
      v = k1[x];
      printf("%ld %ld\n", u, v);
      y = b[v];
      work(y);
      c[c[root][1]][0] = 0;
      k2[y]--;
      k1[y] ^= u;
      z = findval0(k2[y]);
      splay(z, 0);
      z = c[z][1];
      while (c[z][0]) z = c[z][0];
      splay(z, root);
      p[y] = c[root][1];
      c[c[root][1]][0] = y;
    }
    Delete(x);
  }
  return 0;
}
