Codeforces Round 295 (Div. 2)
D
Cubes
Codeforces
2100
原题
← CE →
翻译中…

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 $10^{9} + 9$.

翻译中…

Input

翻译中…

The first line contains number $*m*$ ($2 ≤ *m* ≤ 10^{5}$).

翻译中…

The following $*m*$ lines contain the coordinates of the cubes $*x*_{*i*}, *y*_{*i*}$ ($- 10^{9} ≤ *x*_{*i*} ≤ 10^{9}$, $0 ≤ *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.

翻译中…

Output

翻译中…

In the only line print the answer to the problem.

翻译中…

样例

Input #1
3
2 1
1 0
0 1
Output #1
19
InputCopy OutputCopy
Input #2
5
0 0
0 1
0 2
0 3
0 4
Output #2
2930
InputCopy OutputCopy
题目信息
题号
520D
时间限制
3 s
内存限制
256 MB
标签
博弈论
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。