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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.AbstractQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pradyumn Agrawal coderbond007  PLEASE!! PLEASE!! HACK MY SOLUTION!!
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        static Cube[] c;
        static Set<Integer>[] child;
        static Set<Integer>[] parent;
        static int[] ans;
        static int m;
        static PriorityQueue<Integer> minq;
        static PriorityQueue<Integer> maxq;
        static boolean[] rem;
        static boolean[] added;

        public void solve(int testNumber, FastReader in, PrintWriter w) {
            m = in.nextInt();

            c = new Cube[m];
            ans = new int[m];
            child = new Set[m];
            parent = new Set[m];

            for (int i = 0; i < m; i++) {
                int x = in.nextInt();
                int y = in.nextInt();
                c[i] = new Cube(x, y, i);
                child[i] = new TreeSet();
                parent[i] = new TreeSet();
            }

            Arrays.sort(c);

            for (int i = 0; i < m; i++) {
                if (c[i].y != 0) {
                    int i1 = bS(c[i].x - 1, c[i].y - 1);
                    if (i1 != -1) {
                        child[c[i].v].add(c[i1].v);
                        parent[c[i1].v].add(c[i].v);
                    }
                    i1 = bS(c[i].x, c[i].y - 1);
                    if (i1 != -1) {
                        child[c[i].v].add(c[i1].v);
                        parent[c[i1].v].add(c[i].v);
                    }
                    i1 = bS(c[i].x + 1, c[i].y - 1);
                    if (i1 != -1) {
                        child[c[i].v].add(c[i1].v);
                        parent[c[i1].v].add(c[i].v);
                    }
                }
            }

            minq = new PriorityQueue(m);
            maxq = new PriorityQueue(m, Collections.reverseOrder());
            added = new boolean[m];

            for (int i = 0; i < m; i++) {
                if (parent[i].size() == 0) {
                    minq.add(i);
                    added[i] = true;
                } else {
                    int s = parent[i].size();
                    boolean canAdd = true;
                    Iterator<Integer> it = parent[i].iterator();
                    for (int j = 0; j < s; j++)
                        if (child[it.next()].size() < 2)
                            canAdd = false;
                    if (canAdd) {
                        added[i] = true;
                        minq.add(i);
                    }
                }
            }

            maxq.addAll(minq);

            rem = new boolean[m];
            boolean turn = false;

            for (int i = 0; i < m; i++) {
                int curr = -1;
                if (turn) {
                    curr = minq.remove();
                    while (rem[curr] || !check(curr)) {
                        if (!check(curr))
                            added[curr] = false;
                        curr = minq.remove();
                    }
                } else {
                    curr = maxq.remove();
                    while (rem[curr] || !check(curr)) {
                        if (!check(curr))
                            added[curr] = false;
                        curr = maxq.remove();
                    }
                }

                rem[curr] = true;
                turn = !turn;

                Iterator<Integer> it = parent[curr].iterator();
                while (it.hasNext())
                    child[it.next()].remove(curr);

                it = child[curr].iterator();
                while (it.hasNext()) {
                    int nx = it.next();
                    parent[nx].remove(curr);
                    if (added[nx] == false && check(nx)) {
                        minq.add(nx);
                        maxq.add(nx);
                        added[nx] = true;
                    }
                }

                ans[i] = curr;
            }

            w.println(getAns());

        }

        public static boolean check(int curr) {
            Iterator<Integer> it = parent[curr].iterator();
            while (it.hasNext()) {
                int nx = it.next();
                if (child[nx].size() < 2)
                    return false;
            }
            return true;
        }

        public static long getAns() {
            long f = 1;
            long answer = 0;
            long mod = (long) (1e9 + 9);

            for (int i = m - 1; i >= 0; i--) {
                answer = (answer + (f * ans[i]) % mod) % mod;
                f = (f * m) % mod;
            }

            return answer;
        }

        public static int bS(int x, int y) {
            int sy = bSyFirst(y);
            if (sy == -1)
                return -1;
            int ey = bSyLast(y);
            return bSx(x, sy, ey + 1);
        }

        public static int bSyFirst(int key) {
            int start = 0, end = c.length;
            int ret = -1;
            while (true) {
                if (start == end) return ret;
                int mid = (start + end) / 2;
                if (key == c[mid].y) ret = mid;
                if (end - start == 1) return ret;
                if (key <= c[mid].y) end = mid;
                else start = mid + 1;
            }
        }

        public static int bSyLast(int key) {
            int start = 0, end = c.length;
            int ret = -1;
            while (true) {
                if (start == end) return ret;
                int mid = (start + end) / 2;
                if (key == c[mid].y) ret = mid;
                if (end - start == 1) return ret;
                if (key < c[mid].y) end = mid;
                else start = mid + 1;
            }
        }

        public static int bSx(int key, int start, int end) {
            while (true) {
                if (start == end) return -1;
                int mid = (start + end) / 2;
                if (key == c[mid].x) return mid;
                if (end - start == 1) return -1;
                if (key < c[mid].x) end = mid;
                else start = mid + 1;
            }
        }

        class Cube implements Comparable<Cube> {
            int x;
            int y;
            int v;

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


            public int compareTo(Cube arg0) {
                if (y < arg0.y)
                    return -1;
                if (y > arg0.y)
                    return 1;
                if (x < arg0.x)
                    return -1;
                if (x > arg0.x)
                    return 1;
                return 0;
            }

        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;
        private FastReader.SpaceCharFilter filter;

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

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

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

        private boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

        private interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

