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.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/*
public class _520D {

}

 */

public class _520D {
	class pair
	{
		int x;
		int y;
		public pair(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + x;
			result = prime * result + y;
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			pair other = (pair) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (x != other.x)
				return false;
			if (y != other.y)
				return false;
			return true;
		}
		private _520D getOuterType() {
			return _520D.this;
		}
	}

	class node
	{
		int m;
		int p;
		/*public int compareTo(node o) {
			if(this.p == o.p)
			{

			}
			return 0;
		}
		 */
		public node(int m, int p) {
			super();
			this.m = m;
			this.p = p;
		}
	}

	long mod = (long)1e9 + 9;

	public void solve() throws FileNotFoundException {
		InputStream inputStream = System.in;

		InputHelper inputHelper = new InputHelper(inputStream);

		PrintStream out = System.out;

		//actual solution

		int m = inputHelper.readInteger();

		pair[] c = new pair[m];

		Map<pair, Integer> n = new HashMap<_520D.pair, Integer>();

		for(int i = 0; i < m ; i++)
		{
			int x = inputHelper.readInteger();
			int y = inputHelper.readInteger();

			pair pair = new pair(x, y);

			c[i] = pair;

			n.put(pair, i);
		}

		int[] s = new int[m];

		for(int i = 0 ; i < m; i++)
		{
			int x = c[i].x;
			int y = c[i].y;

			if(y == 0)
			{
				s[i] = 5;
			}
			if(n.containsKey(new pair(x  - 1, y + 1)))
			{
				s[n.get(new pair(x  - 1, y + 1))]++;
			}
			if(n.containsKey(new pair(x, y + 1)))
			{
				s[n.get(new pair(x, y + 1))]++;
			}
			if(n.containsKey(new pair(x  + 1, y + 1)))
			{
				s[n.get(new pair(x + 1, y + 1))]++;
			}
		}

		PriorityQueue<node> pqmx = new PriorityQueue<_520D.node>(m, new Comparator<node>() {

			public int compare(node o1, node o2) {
				if(o1.p == o2.p)
				{
					return o2.m - o1.m;
				}
				return o2.p - o1.p;
			}
		});
		PriorityQueue<node> pqmn = new PriorityQueue<_520D.node>(m, new Comparator<node>() {

			public int compare(node o1, node o2) {
				if(o1.p == o2.p)
				{
					return o1.m - o2.m;
				}
				return o2.p - o1.p;
			}
		});

		int[] cp = new int[m];

		for(int i = 0; i < m ; i++)
		{
			int x = c[i].x;
			int y = c[i].y;

			int cm = i;

			int p = 1;

			if(n.containsKey(new pair(x - 1, y + 1)))
			{
				if(s[n.get(new pair(x - 1, y + 1))] <= 1)
					p = 0;
			}
			if(n.containsKey(new pair(x, y + 1)))
			{
				if(s[n.get(new pair(x, y + 1))] <= 1)
					p = 0;
			}
			if(n.containsKey(new pair(x + 1, y + 1)))
			{
				if(s[n.get(new pair(x + 1, y + 1))] <= 1)
					p = 0;
			}

			cp[cm] = p;
			pqmx.add(new node(cm, p));
			pqmn.add(new node(cm, p));
		}

		int[] d = new int[m];

		List<Integer> ans = new ArrayList<Integer>();
		while(ans.size() < m)
		{
			node cn = pqmx.poll();

			while(d[cn.m] == 1 || cp[cn.m] != cn.p)
			{
				cn = pqmx.poll();
			}

			ans.add(cn.m);

			if(ans.size() == m)
				break;

			int cx = c[cn.m].x;
			int y = c[cn.m].y;

			if(n.containsKey(new pair(cx  - 1, y + 1)))
			{
				s[n.get(new pair(cx  - 1, y + 1))]--;
			}
			if(n.containsKey(new pair(cx, y + 1)))
			{
				s[n.get(new pair(cx, y + 1))]--;
			}
			if(n.containsKey(new pair(cx  + 1, y + 1)))
			{
				s[n.get(new pair(cx + 1, y + 1))]--;
			}

			for(int i = cx - 2; i <= cx + 2; i++)
			{
				if(i != cx && n.containsKey(new pair(i, y)))
				{
					int cm = n.get(new pair(i ,y));

					if(d[cm] == 1)
						continue;
					int x = i;
					int p = 1;

					if(n.containsKey(new pair(x - 1, y + 1)))
					{
						if(d[n.get(new pair(x - 1, y + 1))] != 1 && s[n.get(new pair(x - 1, y + 1))] <= 1)
							p = 0;
					}
					if(n.containsKey(new pair(x, y + 1)))
					{
						if(d[n.get(new pair(x, y + 1))] != 1 && s[n.get(new pair(x, y + 1))] <= 1)
							p = 0;
					}
					if(n.containsKey(new pair(x + 1, y + 1)))
					{
						if(d[n.get(new pair(x + 1, y + 1))] != 1 && s[n.get(new pair(x + 1, y + 1))] <= 1)
							p = 0;
					}

					if(cp[cm] != p)
					{
						cp[cm] = p;
						pqmx.add(new node(cm, p));
						pqmn.add(new node(cm, p));
					}
				}
			}
			
			d[cn.m] = 1;
			y--;
			for(int i = cx - 1; i <= cx + 1; i++)
			{
				if(n.containsKey(new pair(i, y)))
				{
					int cm = n.get(new pair(i ,y));

					if(d[cm] == 1)
						continue;
					int x = i;
					int p = 1;

					if(n.containsKey(new pair(x - 1, y + 1)))
					{
						if(d[n.get(new pair(x - 1, y + 1))] != 1 && s[n.get(new pair(x - 1, y + 1))] <= 1)
							p = 0;
					}
					if(n.containsKey(new pair(x, y + 1)))
					{
						if(d[n.get(new pair(x, y + 1))] != 1 && s[n.get(new pair(x, y + 1))] <= 1)
							p = 0;
					}
					if(n.containsKey(new pair(x + 1, y + 1)))
					{
						if(d[n.get(new pair(x + 1, y + 1))] != 1 && s[n.get(new pair(x + 1, y + 1))] <= 1)
							p = 0;
					}

					if(cp[cm] != p)
					{
						cp[cm] = p;
						pqmx.add(new node(cm, p));
						pqmn.add(new node(cm, p));
					}
				}
			}

			cn = pqmn.poll();

			while(d[cn.m] == 1 || cp[cn.m] != cn.p)
			{
				cn = pqmn.poll();
			}

			ans.add(cn.m);

			cx = c[cn.m].x;
			y = c[cn.m].y;

			if(n.containsKey(new pair(cx  - 1, y + 1)))
			{
				s[n.get(new pair(cx  - 1, y + 1))]--;
			}
			if(n.containsKey(new pair(cx, y + 1)))
			{
				s[n.get(new pair(cx, y + 1))]--;
			}
			if(n.containsKey(new pair(cx  + 1, y + 1)))
			{
				s[n.get(new pair(cx + 1, y + 1))]--;
			}

			for(int i = cx - 2; i <= cx + 2; i++)
			{
				if(i != cx && n.containsKey(new pair(i, y)))
				{
					int cm = n.get(new pair(i, y));

					if(d[cm] == 1)
						continue;
					int x = i;
					int p = 1;

					if(n.containsKey(new pair(x - 1, y + 1)))
					{
						if(d[n.get(new pair(x - 1, y + 1))] != 1 && s[n.get(new pair(x - 1, y + 1))] <= 1)
							p = 0;
					}
					if(n.containsKey(new pair(x, y + 1)))
					{
						if(d[n.get(new pair(x, y + 1))] != 1 && s[n.get(new pair(x, y + 1))] <= 1)
							p = 0;
					}
					if(n.containsKey(new pair(x + 1, y + 1)))
					{
						if(d[n.get(new pair(x + 1, y + 1))] != 1 && s[n.get(new pair(x + 1, y + 1))] <= 1)
							p = 0;
					}

					if(cp[cm] != p)
					{
						cp[cm] = p;
						pqmx.add(new node(cm, p));
						pqmn.add(new node(cm, p));
					}
				}
			}

			d[cn.m] = 1;
			y--;
			for(int i = cx - 1; i <= cx + 1; i++)
			{
				if(n.containsKey(new pair(i, y)))
				{
					int cm = n.get(new pair(i ,y));

					if(d[cm] == 1)
						continue;
					int x = i;
					int p = 1;

					if(n.containsKey(new pair(x - 1, y + 1)))
					{
						if(d[n.get(new pair(x - 1, y + 1))] != 1 && s[n.get(new pair(x - 1, y + 1))] <= 1)
							p = 0;
					}
					if(n.containsKey(new pair(x, y + 1)))
					{
						if(d[n.get(new pair(x, y + 1))] != 1 && s[n.get(new pair(x, y + 1))] <= 1)
							p = 0;
					}
					if(n.containsKey(new pair(x + 1, y + 1)))
					{
						if(d[n.get(new pair(x + 1, y + 1))] != 1 && s[n.get(new pair(x + 1, y + 1))] <= 1)
							p = 0;
					}

					if(cp[cm] != p)
					{
						cp[cm] = p;
						pqmx.add(new node(cm, p));
						pqmn.add(new node(cm, p));
					}
				}
			}
		}

		long anss = 0;

		long[] mp = new long[m];

		mp[0] = 1;

		for(int i = 1; i < m; i++)
		{
			mp[i] = (mp[i - 1] * m) % mod;
		}

		for(int i = 0; i < m; i++)
		{
			//System.out.print(ans.get(i));
			anss += ((long)ans.get(i) * mp[m - 1 - i]);
			anss %= mod;
		}

		System.out.println(anss);
		//end here
	}

	public static void main(String[] args) throws FileNotFoundException {
		(new _520D()).solve();
	}

	class InputHelper {
		StringTokenizer tokenizer = null;
		private BufferedReader bufferedReader;

		public InputHelper(InputStream inputStream) {
			InputStreamReader inputStreamReader = new InputStreamReader(
					inputStream);
			bufferedReader = new BufferedReader(inputStreamReader, 16384);
		}

		public String read() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					String line = bufferedReader.readLine();
					if (line == null) {
						return null;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			return tokenizer.nextToken();
		}

		public Integer readInteger() {
			return Integer.parseInt(read());
		}

		public Long readLong() {
			return Long.parseLong(read());
		}
	}
}