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.List;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.TreeSet;
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;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    int MOD = (int) 1e9 + 9;
    static class Cube implements Comparable<Cube> {
        int x;
        int y;
        int num;
        List<Cube> dependents = new ArrayList<Cube>();
        List<Cube> supports = new ArrayList<Cube>();

        public Cube(int num, int x, int y) {
            this.num = num;
            this.x = x;
            this.y = y;
        }

        public int compareTo(Cube o) {
            return this.num - o.num;
        }

        boolean is_removable() {
            boolean has_super_dependent = false;
            for (Cube dependent: this.dependents) {
                if (dependent.supports.size() == 1) {
                    has_super_dependent = true;
                    break;
                }
            }
            return !has_super_dependent;
        }
    }

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int m = in.readInt();
        Cube[] cubes = new Cube[m];

        HashMap<Integer, Integer>[] sets = new HashMap[(int) m + 5];
        for (int i = 0; i < sets.length; ++i) {
            sets[i] = new HashMap<Integer, Integer>();
        }

        for (int i = 0; i < m; i++) {
            int x = in.readInt();
            int y = in.readInt();
            cubes[i] = new Cube(i, x, y);
            sets[y].put(x, i);
        }
        for (int i = 0; i < m; i++) {
            int x = cubes[i].x;
            int y = cubes[i].y;
            if (y == 0) continue;

            for (int j = -1; j <= 1; ++j) {
                if (sets[y - 1].containsKey(x + j)) {
                    int supporter_id = sets[y - 1].get(x + j);
                    cubes[supporter_id].dependents.add(cubes[i]);
                    cubes[i].supports.add(cubes[supporter_id]);
                }
            }
        }


        TreeSet<Cube> removable = new TreeSet<Cube>(new Comparator<Cube>() {
            public int compare(Cube o1, Cube o2) {
                return o1.num - o2.num;
            }
        });
        for (Cube cube : cubes) {
            if (cube.is_removable()) {
                removable.add(cube);
            }
        }
        long res = 0;
        for (int turn = 0; turn < m; turn++) {
            if (turn % 2 == 0) {
                Cube cube = removable.last();
                res = (res * m + cube.num) % MOD;
                for (Cube dependent : cube.dependents) {
                    if (dependent.is_removable()) removable.remove(dependent);
                    dependent.supports.remove(cube);
                    if (dependent.supports.size() == 1) {
                        removable.remove(dependent.supports.get(0));
                    }
                    if (dependent.is_removable()) removable.add(dependent);
                }
                for (Cube support : cube.supports) {
                    if (support.is_removable()) removable.remove(support);
                    support.dependents.remove(cube);
                    boolean is_removable_after = support.is_removable();
                    if (support.is_removable()) removable.add(support);
                }
                removable.remove(cube);
            } else {
                Cube cube = removable.first();
                res = (res * m + cube.num) % MOD;
                for (Cube dependent : cube.dependents) {
                    if (dependent.is_removable()) removable.remove(dependent);
                    dependent.supports.remove(cube);
                    if (dependent.supports.size() == 1) {
                        removable.remove(dependent.supports.get(0));
                    }
                    if (dependent.is_removable()) removable.add(dependent);
                }
                for (Cube support : cube.supports) {
                    if (support.is_removable()) removable.remove(support);
                    support.dependents.remove(cube);
                    boolean is_removable_after = support.is_removable();
                    if (support.is_removable()) removable.add(support);
                }
                removable.remove(cube);
            }
        }
        out.println(res);
    }
}

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

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

    public int read() {
        // InputMismatchException -> UnknownError
        if (numChars == -1)
            throw new UnknownError();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new UnknownError();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        } else if (c == '+') {
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

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

}

