Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower left corner, these coordinates are integers for each cube.

The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates (x, y) either y = 0, or there is a cube with coordinates (x - 1, y - 1), (x, y - 1) or (x + 1, y - 1).

Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the m-ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.

Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo 109 + 9.

Input

The first line contains number m (2 ≤ m ≤ 105).

The following m lines contain the coordinates of the cubes xi, yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ 109) in ascending order of numbers written on them. It is guaranteed that the original figure is stable.

No two cubes occupy the same place.

Output

In the only line print the answer to the problem.

Examples

Input

3
2 1
1 0
0 1


Output

19


Input

5
0 0
0 1
0 2
0 3
0 4


Output

2930
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;




import java.util.Arrays;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;



public final class CF_Cubes_v4{

	void log(int[] X){
		int L=X.length;
		for (int i=0;i<L;i++){
			logWln(X[i]+" ");
		}
		log("");
	}


	void log(long[] X){
		int L=X.length;
		for (int i=0;i<L;i++){
			logWln(X[i]+" ");
		}
		log("");
	}
	void log(Object[] X){
		int L=X.length;
		for (int i=0;i<L;i++){
			logWln(X[i]+" ");
		}
		log("");
	}


	void log(Object o){
		logWln(o+"\n");
	}

	void logWln(Object o){
		System.out.print(o);
		//	outputWln(o);

	}
	void info(Object o){
		System.out.println(o);
		//output(o);
	}

	void output(Object o){

		outputWln(""+o+"\n");

	}

	void outputWln(Object o){
		// System.out.print(o);

		try {
			out.write(""+ o);
		} catch (Exception e) {

		}
	}


	boolean isOk(int v){

		int n=0;
		for (int delta=-1;delta<=1;delta++)
			if (nb[v][0][1+delta]>=0)
				n++;
		//	log("Checking is is ok for v:"+v+" //"+(n>=2));
		return (n>=2);
	}

	static int DOWN=0,UP=2,SAME=1;
	static int LEFT=0,RIGHT=2,CENTER=1;

	void updateImpact(Integer v){
		Integer w,z;

		for (int delta=LEFT-1;delta<=RIGHT-1;delta++){
			// le bas
			if ((w=nb[v][DOWN][delta+1])>=0){
				//log("Step 1");
				nb[w][UP][-delta+1]=-1;
				checkDependers(w);
			}
			// le haut
			if ((w=nb[v][UP][delta+1])>=0){
				//log("Step 2");
				nb[w][0][-delta+1]=-1;
			}
		}


		boolean ul=false,ur=false;
		if ((w=nb[v][UP][LEFT])>=0) {
			ul=true;
			if ((z=nb[w][DOWN][CENTER])>=0)
				checkDependers(z);
			if ((z=nb[w][DOWN][LEFT])>=0)
				checkDependers(z);
		}

		if ((w=nb[v][UP][RIGHT])>=0) {
			ur=true;
			if ((z=nb[w][DOWN][CENTER])>=0)
				checkDependers(z);
			if ((z=nb[w][DOWN][RIGHT])>=0)
				checkDependers(z);
		}

		if ((w=nb[v][UP][CENTER])>=0) {
			if (!ul)
				if ((z=nb[w][DOWN][LEFT])>=0)
					checkDependers(z);
			if (!ur)
				if ((z=nb[w][DOWN][RIGHT])>=0)
					checkDependers(z);
		}



		// la map des latéraux
		for (int delta=LEFT-1;delta<=RIGHT-1;delta+=2){
			if ((w=nb[v][SAME][1+delta])>=0){
				//	log("Step 3");
				nb[w][1][1-delta]=-1;
			}
		}

	}

	void checkDependers(Integer v){
		//log("Check dependers for v:"+v+" x:"+x[v]+" y:"+y[v]);
		int last=nsup[v];
		nsup[v]=0;
		for (int delta=-1;delta<=1;delta++){
			int w;
			if ((w=nb[v][2][1+delta])>=0){
				//	log("w:"+w);
				if (!isOk(w))
					nsup[v]++;
			}
			//	supports[i][nsup[i]++]=find(a+delta,b+1);
		}
		//log("nsup:"+nsup[v]);
		if (nsup[v]==0 && last!=0) {
			//log("Adding:"+i);
			pq.add(v);
			//pqLo.add(v);
			//pqHi.add(-v);
			//			submitted[i]=true;
			return;
		}
		if (last==0 && nsup[v]>0){
			pq.remove(v);
			//pqLo.remove(v);
			//pqHi.remove(-v);

		}
		return;

	}



	HashMap<String,Integer> hm;

	int XMAX,YMAX;
	int[] max;
	int[] nsup;
	//PriorityQueue<Integer> pqLo,pqHi;
	TreeSet<Integer> pq;
	int[][][] nb;

	class Composite implements Comparable<Composite> {
		int x;
		int y;
		int m;

		public int compareTo(Composite X){
			if (y!=X.y)
				return y-X.y;
			return x-X.x;
		}

		public Composite(int x,int y,int m){
			super();
			this.x=x;
			this.y=y;
			this.m=m;
		}

		public int hashCode(){
			long w=(31*x+y);
			if (w>Integer.MAX_VALUE)
				w=w%Integer.MAX_VALUE;
			return (int)w;
		}

		public boolean equals(Object O){
			Composite X=(Composite)O;
			return (X.x==x && X.y==y);
		}

	}


	void solve(){

		//	XMAX=compress(x);
		//	YMAX=compress(y);

		long res=0;

		nb=new int[M][3][3];

		boolean[] friendy=new boolean[M];


		Composite[] list=new Composite[M];
		for (int i=0;i<M;i++){
			list[i]=new Composite(x[i],y[i],i);
		}
		Arrays.sort(list);


		for (int i=0;i<M;i++)
			for (int j=0;j<3;j++)
				Arrays.fill(nb[i][j],-1);

		for (int i=0;i<M;i++){
			int a=x[i];
			int b=y[i];
			for (int delta=-1;delta<=1;delta++){
				int Z;
				Z=Arrays.binarySearch(list,new Composite(a+delta,b+1,0));
				if (Z>-1) {
					nb[i][2][delta+1]=list[Z].m;
					friendy[i]=true;
				}
				Z=Arrays.binarySearch(list,new Composite(a+delta,b-1,0));
				//Z=hm.get((a+delta)+" "+(b-1));
				if (Z>-1) {
					nb[i][0][delta+1]=list[Z].m;
					friendy[i]=true;
				}
				if (delta!=0) {
					Z=Arrays.binarySearch(list,new Composite(a+delta,b,0));
					//		Z=hm.get((a+delta)+" "+(b));
					if (Z>-1) {
						nb[i][1][delta+1]=list[Z].m;
						friendy[i]=true;
					}
				}
			}
		}


		/*
		for (int i=0;i<M;i++) {
			for (int u=0;u<3;u++){
				for (int v=0;v<3;v++)
					logWln(nb[i][v][2-u]+" ");
				log("");

			}
			log("///");
		}
		 */


		//	////log("Solving");

		// on commence pareil

		// mais ensuite on fait le graphe

		//int[][] depends=new int[M][3];
		//int[][] supports=new int[M][3];
		//int[] ndep=new int[M];
		nsup=new int[M];
		Arrays.fill(nsup,-1);

		//boolean[] submitted=new boolean[M];

		pq=new TreeSet<Integer>();


		//pqLo=new PriorityQueue<Integer>();
		//pqHi=new PriorityQueue<Integer>();




		for (int i=0;i<M;i++){

			checkDependers(i);

			/*

			for (int delta=-1;delta<=1;delta++){
				nb[i][0][delta+1]=find(a+delta,b-1);
				nb[i][2][delta+1]=find(a+delta,b+1);
			}

			for (int delta=-1;delta<=1;delta++){
				if (!isOk(a+delta,b+1)){
					nsup[i]++;
					//	supports[i][nsup[i]++]=find(a+delta,b+1);
				}
			}




			if (nsup[i]==0) {
				//log("Adding:"+i);
				pqLo.add(i);
				pqHi.add(-i);
				//			submitted[i]=true;

			}

			 */

			/*
			for (int delta=-1;delta<=1;delta++){
				if (!isEmpty(a+delta,b+1)){
					depends[i][ndep[i]++]=find(a+delta,b-1);
				}
			}
			 */



		}
		int d=0;
		while (d<M) {

			/*
			//log("///");
			log(pqLo);
			log(pqHi);
			//log("////");
			 */
			if (d%2==0){
				Integer v=pq.pollLast();
				//Integer v=-pqHi.poll();
				//log("using v:"+v);


				//	pqLo.remove(v);
				//	hm.remove(x[v]+" "+y[v]);

				if (friendy[v])
					updateImpact(v);

				/*
				update(x[v]+1,y[v]);
				update(x[v]-1,y[v]);
				update(x[v]+2,y[v]);
				update(x[v]-2,y[v]);

				update(x[v]-1,y[v]-1);
				update(x[v]+1,y[v]-1);
				update(x[v],y[v]-1);
				 */

				res*=M;
				if (res>=MOD)
					res%=MOD;
				res+=v;
				if (res>=MOD)
					res%=MOD;
			} else {

				//Integer v=pqLo.poll();

				Integer v=pq.pollFirst();

				//log("using v:"+v);
				//pqHi.remove(-v);
				//hm.remove(x[v]+" "+y[v]);
				if (friendy[v])
					updateImpact(v);

				/*
				update(x[v]+1,y[v]);
				update(x[v]-1,y[v]);
				update(x[v]+2,y[v]);
				update(x[v]-2,y[v]);

				update(x[v]-1,y[v]-1);
				update(x[v]+1,y[v]-1);
				update(x[v],y[v]-1);
				 */


				res*=M;
				if (res>=MOD)
					res%=MOD;
				res+=v;
				if (res>=MOD)
					res%=MOD;

			}
			d++;
		}
		System.out.println(res);
	}




	// Global vars
	StringTokenizer st;
	BufferedReader in;
	BufferedWriter out;
	static long MOD=1000000009;

	int[] x,y;
	int M;



	void process() throws Exception {



		//	out = new BufferedWriter(new OutputStreamWriter(System.out));
		//	in=new BufferedReader(new InputStreamReader(System.in));


		InputReader reader = new InputReader(System.in);

		M=reader.readInt();
		x=new int[M];
		y=new int[M];
		for (int i=0;i<M;i++){
			x[i]=reader.readInt();
			y[i]=reader.readInt();
		}


		solve();

		try {
			out.close();
		}
		catch (Exception e){}


	}



	public static void main(String[] args) throws Exception {
		CF_Cubes_v4 J=new CF_Cubes_v4();


		J.process();


	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}


		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res=new StringBuilder();
			do {
				res.append((char)c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}


		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}



}