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.*;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class B {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    private static final int MOD = 1000 * 1000 * 1000 + 9;

    class Vertex implements Comparable<Vertex> {
        int x;
        int y;
        int index;

        Vertex(int x, int y, int index) {
            this.x = x;
            this.y = y;
            this.index = index;
        }

        public int compareTo(Vertex o) {
            return this.index - o.index;
        }
    }

    void solve() throws IOException {
        int t = 1;
        while (t-- > 0) {
            solveTest();
        }
    }

    private void solveTest() throws IOException {
        int n = readInt();
        Vertex[] vertexes = new Vertex[n];
        Map<Integer, Map<Integer, Vertex>> map = new HashMap<Integer, Map<Integer, Vertex>>();
        for(int i = 0; i < n; i++) {
            vertexes[i] = new Vertex(readInt(), readInt(), i);
            add(map, vertexes[i]);
        }
        TreeSet<Vertex> q = new TreeSet<Vertex>();
        for(Vertex v: vertexes) {
            if(isSafe(map, v)) {
                q.add(v);
            }
        }
        long[] res = new long[n];
        boolean[] used = new boolean[n];
        for(int i = 0; i < n; i++) {
            Vertex cur;
            if(i % 2 == 0) {
                cur = q.pollLast();
            } else {
                cur = q.pollFirst();
            }
            res[i] = cur.index;
            remove(map, cur);
            used[cur.index] = true;
            for(int dx = -2; dx <= 2; dx++) {
                for(int dy = -1; dy <= 0; dy++) {
                    Vertex next = get(map, cur.x + dx, cur.y + dy);
                    if (next == null) continue;
                    if (used[next.index]) continue;
                    if (isSafe(map, next)) {
                        q.add(next);
                    } else {
                        q.remove(next);
                    }
                }
            }
        }

        long curPow = 1;
        long resNum = 0;
        for(int i = n-1; i >= 0; i--) {
            resNum += res[i] * curPow;
            resNum %= MOD;
            curPow *= n;
            curPow %= MOD;
        }
        out.println(resNum);
    }

    boolean isSafe(Map<Integer, Map<Integer, Vertex>> map, Vertex v) {
        boolean res = true;
        for(int dx = -1; dx <= 1; dx++) {
            if(count(map, v.x + dx, v.y + 1) == 1) {
                res = false;
            }
        }
        return res;
    }

    int count(Map<Integer, Map<Integer, Vertex>> map, int x, int y) {
        int res = 0;
        Vertex v = get(map, x, y);
        if(v == null) return res;
        for(int dx = -1; dx <= 1; dx++) {
            if(get(map, v.x + dx, v.y - 1) != null) {

                res++;
            }
        }
        return res;
    }

    Vertex get(Map<Integer, Map<Integer, Vertex>> map, int x, int y) {
        Map<Integer, Vertex> yMap = map.get(x);
        if(yMap == null) return null;
        return yMap.get(y);
    }

    void add(Map<Integer, Map<Integer, Vertex>> map, Vertex v) {
        if(!map.containsKey(v.x)) {
            map.put(v.x, new HashMap<Integer, Vertex>());
        }
        map.get(v.x).put(v.y, v);
    }

    void remove(Map<Integer, Map<Integer, Vertex>> map, Vertex v) {
        map.get(v.x).remove(v.y);
    }

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " .");
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

    public static void main(String[] args) {
        new B().run();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}