CF520D.Cubes

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Once Vasya and Petya assembled a figure of mm cubes, each of them is associated with a number between 00 and m1m-1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OXOX is the ground, and the OYOY 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)(x,y) either y=0y=0 , or there is a cube with coordinates (x1,y1)(x-1,y-1) , (x,y1)(x,y-1) or (x+1,y1)(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 mm -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+910^{9}+9 .

输入格式

The first line contains number mm ( 2<=m<=1052<=m<=10^{5} ).

The following mm lines contain the coordinates of the cubes xi,yix_{i},y_{i} ( 109<=xi<=109-10^{9}<=x_{i}<=10^{9} , 0<=yi<=1090<=y_{i}<=10^{9} ) in ascending order of numbers written on them. It is guaranteed that the original figure is stable.

No two cubes occupy the same place.

输出格式

In the only line print the answer to the problem.

输入输出样例

  • 输入#1

    3
    2 1
    1 0
    0 1
    

    输出#1

    19
    
  • 输入#2

    5
    0 0
    0 1
    0 2
    0 3
    0 4
    

    输出#2

    2930
    
首页