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.util.Map;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.util.Collection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
	public void solve(int testNumber, FastScanner in, PrintWriter out) {
		final int MOD = (int)(1e9 + 9);
		final int OFFSET = (int)(1e9);
		final long N = 2*OFFSET + 1;
		int n = in.nextInt();
		long[] pow = new long[n + 1];
		pow[0] = 1;
		for (int i = 1; i < pow.length; i++) {
			pow[i] = n * pow[i - 1] % MOD;
		}
		long ans = 0;
		Map<Long, Cube> cubeByPoint = new HashMap<>();
		for (int i = 0; i < n; i++) {
			int x = in.nextInt() + OFFSET;
			int y = in.nextInt();
			long key = x*N + y;
			Cube c = new Cube();
			c.id = i;
			c.x = x;
			c.y = y;
			cubeByPoint.put(key, c);
		}
		for (Map.Entry<Long, Cube> e : cubeByPoint.entrySet()) {
			long x = e.getKey() / N;
			long y = e.getKey() % N;
			Cube c1 = e.getValue();
			for (int dx = -1; dx <= 1; dx++) {
				long nx = x + dx;
				long ny = y - 1;
				if (nx < 0 || nx > 2*OFFSET || ny < 0 || ny > 2*OFFSET) {
					continue;
				}
				long key = nx*N + ny;
				Cube c2 = cubeByPoint.get(key);
				if (c2 == null) {
					continue;
				}
				c1.cubesBelow.add(c2);
				c2.cubesAbove.add(c1);
			}
		}
		TreeSet<Cube> set1 = new TreeSet<>(new Comparator<Cube>() {
			public int compare(Cube a, Cube b) {
				return b.id - a.id;
			}
		});
		TreeSet<Cube> set2 = new TreeSet<>(new Comparator<Cube>() {
			public int compare(Cube a, Cube b) {
				return a.id - b.id;
			}
		});
		for (Cube c : cubeByPoint.values()) {
			if (c.isSafe()) {
				set1.add(c);
				set2.add(c);
			}
		}
		for (int step = 0; step < n; step++) {
			Cube c;
			if (step % 2 == 0) {
				c = set1.first();
			} else {
				c = set2.first();
			}
			set1.remove(c);
			set2.remove(c);
			cubeByPoint.remove(c.x*N + c.y);
			ans = (ans + pow[n - step - 1] * c.id) % MOD;
			for (Cube cc : c.cubesBelow) {
				if (!cc.cubesAbove.remove(c)) {
					throw new AssertionError();
				}
			}
			for (Cube cc : c.cubesAbove) {
				if (!cc.cubesBelow.remove(c)) {
					throw new AssertionError();
				}
			}
			for (int dx = -2; dx <= 2; dx++) {
				for (int dy = -1; dy <= 0; dy++) {
					long nx = c.x + dx;
					long ny = c.y + dy;
					if (nx < 0 || nx > 2*OFFSET || ny < 0 || ny > 2*OFFSET) {
						continue;
					}
					long key = nx*N + ny;
					Cube cc = cubeByPoint.get(key);
					if (cc == null) {
						continue;
					}
					if (cc.isSafe()) {
						set1.add(cc);
						set2.add(cc);
					} else {
						set1.remove(cc);
						set2.remove(cc);
					}
				}
			}
		}
		out.println(ans);
	}

	class Cube {
		int id;
		int x, y;
		List<Cube> cubesAbove = new ArrayList<Cube>();
		List<Cube> cubesBelow = new ArrayList<Cube>();

		boolean isSafe() {
			for (Cube c : cubesAbove) {
				if (c.cubesBelow.size() == 1) {
					return false;
				}
			}
			return true;
		}

		public boolean equals(Object obj) {
			Cube o = (Cube)obj;
			return id == o.id;
		}
	}
}

class FastScanner {

	private BufferedReader in;
	private StringTokenizer st;

	public FastScanner(InputStream stream) {
		in = new BufferedReader(new InputStreamReader(stream));
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				String rl = in.readLine();
				if (rl == null) {
					return null;
				}
				st = new StringTokenizer(rl);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

}

