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
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.geom.Point2D;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    static int m;
    static Map<Point2D,Integer> cubesInFigure = new HashMap<Point2D,Integer>();
    static Point2D[] cubesIndexes;
    static TreeSet<Integer> removableCubes = new TreeSet<Integer>();
    static List<Integer> removedCubes;
    static final long MOD = 1000000009L;
    
    public static int numParentCubes(Point2D child) {
        int numParents = 0;
        
        for (long i = (long)child.getX()-1; i <= child.getX()+1; i++) {
            Point2D parentP = new Point2D.Double(i,child.getY()-1);
            if (cubesInFigure.get(parentP) != null) {
                numParents++;
            }
        }
        
        return numParents;
    }
    
    public static boolean canRemoveCube(int i) {
        Point2D p = cubesIndexes[i];
        for (long j = (long)p.getX()-1; j <= p.getX()+1; j++) {
            Point2D childP = new Point2D.Double(j,p.getY()+1);
            if (cubesInFigure.get(childP) != null) {
                if (numParentCubes(childP) == 1) return false;
            }
        }
        return true;
    }
    
    public static void updateRemovableSet(Point2D p) {
        for (long i = (long)p.getX()-2; i <= p.getX()+2; i++) {
            for (long j = (long)p.getY()-2; j <= p.getY()+2; j++) {
                Point2D neighborCube = new Point2D.Double(i,j);
                Integer neighborIdx = cubesInFigure.get(neighborCube);
                if (neighborIdx != null) {
                    if (canRemoveCube(neighborIdx)) {
                        removableCubes.add(neighborIdx);
                    } else {
                        removableCubes.remove(neighborIdx);
                    }
                }
            } 
        }
    }
    
    public static long mod(long num, long pow, long mod) {
        long num1 = num, currVal, currPow;
        
        num1 %= mod;
        currVal = 1;
 
        for (currPow = 0; currPow < pow; currPow++) {
            currVal = (currVal * num1) % mod;   
            // num = (num * num) % mod;
        }
        return currVal;
    }
    
    public static long processNumber(List<Integer> cubesNumber, int radix) {
        long number = 0, factor = 1, cubeNum;
        
        for (int i = cubesNumber.size()-1; i >= 0; i--) {
            int cube = cubesNumber.get(i);
            // System.out.println("Cube: " + cube);
            // System.out.println("Exponent = " + factor);
            cubeNum = (((cube)*factor)%MOD);
            // System.out.println("Cube Number = " + cubeNum);
            number = (number+cubeNum)%MOD;
            // System.out.println("Cube Number Sum = " + number);
            factor = (factor*m)%MOD;
        }
        return number;
    }
    
    public static void main (String[] args) throws java.lang.Exception
    {
        long x, y;
    
        Scanner s = new Scanner(System.in);
        
        m = s.nextInt();
        
        removedCubes = new ArrayList<Integer>(m);
        cubesIndexes = new Point2D[m];
        
        for (int i = 0; i < m; i++) {
            x = s.nextLong();
            y = s.nextLong();
            
            // System.out.println("x = " + x + ", y = " + y);
            
            Point2D p = new Point2D.Double(x,y);
            cubesInFigure.put(p,i);
            cubesIndexes[i] = p;
        }
        
        for (int i = 0; i < m; i++) {
            if (canRemoveCube(i)) {
                removableCubes.add(i);
            }
        }
        
        int removedCube;
        
        for (int i = 0; i < m; i++) {
            if (i%2 == 0) {
                //Player 1
                removedCube = removableCubes.last();
            } else {
                //Player 2
                removedCube = removableCubes.first();
            }
            
            // System.out.println("Removed cube: " + removedCube);
            
            Point2D p = cubesIndexes[removedCube];
            cubesInFigure.remove(p);
            removableCubes.remove(removedCube);
            updateRemovableSet(p);
            removedCubes.add(removedCube);
        }
        // System.out.println("RemovedCubes:\n" + removedCubes);
            
        System.out.println(processNumber(removedCubes,m));
    }
}