Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the second integer is the XOR sum of the numbers of vertices adjacent to v (if there were no adjacent vertices, he wrote down 0). 

Next day Misha couldn't remember what graph he initially had. Misha has values degreev and sv left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha.

Input

The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph.

The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space.

Output

In the first line print number m, the number of edges of the graph.

Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b).

Edges can be printed in any order; vertices of the edge can also be printed in any order.

Examples

Input

3
2 3
1 0
1 0


Output

2
1 0
2 0


Input

2
1 1
1 0


Output

1
0 1

Note

The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.TreeMap;
import java.util.Vector;
import java.util.concurrent.RecursiveAction;
import java.awt.HeadlessException;
import java.awt.List;
import java.awt.Robot;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import javax.naming.ldap.HasControls;
import javax.swing.tree.TreeNode;

import org.omg.CORBA.FREE_MEM;

public class Main {
	// power
	static double e = 0.00000000000001;

	public static double pow(double a, int n) {
		if (n == 0)
			return 0;
		if (n == 1)
			return a;
		if (n == -1)
			return 1.0 / a;
		double p1 = pow(a, n / 2);
		if ((n & 1) == 0)
			return p1 * p1;
		if (n > 0)
			return p1 * p1 * a;
		else
			return p1 * p1 / a;
	}

	//
	public static double root(double a) {
		double l = 0;
		double r = a;
		while (l <= r) {
			double mid = (l + r) / 2;
			if (Math.abs(mid * mid - a) < e)
				return mid;
			if (mid * mid < a)
				l = mid;
			if (mid * mid > a)
				r = mid;
		}
		return l;
	}

	// to binary
	public static StringBuilder toBinary(int a) {
		StringBuilder rv = new StringBuilder();
		while (a > 0) {
			int rem = a % 2;
			rv.insert(0, rem);
			a /= 2;
		}
		return rv;
	}

	// Quick Sort
	public static int partition(int[] a, int l, int r) {
		int n = r - l + 1;
		Random rn = new Random();
		int pivot = Math.abs(rn.nextInt()) % n;
		int tem = a[pivot];
		int pivotValue = tem;
		a[pivot] = a[r];
		a[r] = tem;
		int currIndex = l;
		for (int i = l; i < r; i++)
			if (a[i] < pivotValue) {
				int te = a[i];
				a[i] = a[currIndex];
				a[currIndex] = te;
				currIndex++;
			}
		tem = a[currIndex];
		a[currIndex] = a[r];
		a[r] = tem;
		return currIndex;
	}

	public static void quickSort(int[] a, int l, int r) {
		if (l >= r)
			return;
		int pivot = partition(a, l, r);
		quickSort(a, l, pivot - 1);
		quickSort(a, pivot + 1, r);
	}

	// Merge Sort
	// merge two sorted arrays
	public static void merge(int[] ar, int firstArrayBegin,
			int secondArrayBegin, int secondArrayEnd) {
		int firstArrayEnd = secondArrayBegin - 1;
		int mergedArraySize = secondArrayEnd - firstArrayBegin + 1;
		int[] merged = new int[mergedArraySize]; // temporary array for merging
		// merging arrays while both pointer are less than arraysEnd
		int currIndexOfMergedArray = 0;
		while (firstArrayBegin <= firstArrayEnd
				&& secondArrayBegin <= secondArrayEnd)
			if (ar[firstArrayBegin] > ar[secondArrayBegin])
				merged[currIndexOfMergedArray++] = ar[secondArrayBegin++];
			else
				merged[currIndexOfMergedArray++] = ar[firstArrayBegin++];

		// there one of the array's last part should copy in merge array
		while (firstArrayBegin <= firstArrayEnd)
			merged[currIndexOfMergedArray++] = ar[firstArrayBegin++];
		while (secondArrayBegin <= secondArrayEnd)
			merged[currIndexOfMergedArray++] = ar[secondArrayBegin++];
		for (int i = mergedArraySize - 1; i >= 0; i--, secondArrayEnd--)
			ar[secondArrayEnd] = merged[i];
	}

	// merge sort
	public static void mergeSort(int[] ar, int l, int r) {
		if ((r - l) < 1)
			return;
		int midle = (l + r) / 2;
		mergeSort(ar, l, midle);
		mergeSort(ar, midle + 1, r);
		merge(ar, l, midle + 1, r);
	}

	// SYBSEEEET
	ArrayList<ArrayList<Integer>> getSubsets(ArrayList<Integer> set, int index) {
		ArrayList<ArrayList<Integer>> allsubsets;
		if (set.size() == index) {
			allsubsets = new ArrayList<ArrayList<Integer>>();
			allsubsets.add(new ArrayList<Integer>()); // Empty set
		} else {
			allsubsets = getSubsets(set, index + 1);
			int item = set.get(index);
			ArrayList<ArrayList<Integer>> moresubsets = new ArrayList<ArrayList<Integer>>();
			for (ArrayList<Integer> subset : allsubsets) {
				ArrayList<Integer> newsubset = new ArrayList<Integer>();
				newsubset.addAll(subset); //
				newsubset.add(item);
				moresubsets.add(newsubset);
			}
			allsubsets.addAll(moresubsets);
		}
		return allsubsets;
	}

	
	
	// PERMUTATION
	public static ArrayList<String> getPerms(String s) {
		ArrayList<String> permutations = new ArrayList<String>();
		if (s == null) { // error case
			return null;
		} else if (s.length() == 0) { // base case
			permutations.add("");
			return permutations;
		}
		char first = s.charAt(0); // get the first character
		String remainder = s.substring(1); // remove the first character
		ArrayList<String> words = getPerms(remainder);
		for (String word : words) {
			for (int j = 0; j <= word.length(); j++) {
				permutations.add(insertCharAt(word, first, j));
			}
		}
		return permutations;
	}
	public static String insertCharAt(String word, char c, int i) {
		String start = word.substring(0, i);
		String end = word.substring(i);
		return start + c + end;
	}
	static class CC implements Comparable<CC>{
		int deg;
		int xor;
		int ind;
		public CC(int val,int xor,int ind) {
			this.deg=val;
			this.xor=xor;
			this.ind=ind;
		}
		@Override
		public int compareTo(CC o1) {
			if(this.deg>o1.deg) return 1;
			if(this.deg<o1.deg) return -1;
			return 0;
		}
		
	}
	public static void main(String[] args) throws IOException{
		int[] a = { 5, 4, 3, 2, 1 };
		// squickSort(a, 0, 4);
		// Integer x=new Integer(37);
		// Integer nx=new Integer(-17);
		// System.out.println(Integer.toBinaryString(x));
		// System.out.println(Integer.toBinaryString(nx));
		// System.out.println(Integer.toBinaryString(x));
		// Integer op=new Integer(x & (x+(1<<0)));
		// System.out.println(Integer.toBinaryString(op));
		// System.out.println(op);
		// int[] ar=new int[10];
		// System.out.println(ar.length);
		//CC x1=new CC(1); pq.add(x1);
		//CC x2=new CC(9); pq.add(x2);
		//CC x3=new CC(7); pq.add(x3);
		//CC x4=new CC(8); pq.add(x4);
		//x2.val=5;
		PriorityQueue<CC> pq=new PriorityQueue<>();
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		CC[] ar=new CC[n];
		long answ=0;
		for(int i = 0; i<n; i++)
		{
			int deg=sc.nextInt();
			int xor=sc.nextInt();
			CC t=new CC(deg,xor,i);
			ar[i]=t;
			answ+=deg;
			if(deg==1)
				pq.add(t);
		}
		System.out.println(answ/2);
		while(!pq.isEmpty())
		{
			CC cur=pq.poll();
			if(cur.deg==1)
			{
				int sec=cur.xor;
				System.out.print(cur.ind);
				System.out.print(" ");
				System.out.println(sec);
				ar[sec].deg--;
				ar[sec].xor=ar[sec].xor^cur.ind;
				if(ar[sec].deg==1)
					pq.add(ar[sec]);
			}
		}
	}
}
