QOJ.ac

QOJ

実行時間制限: 10 s メモリ制限: 256 MB 満点: 100

#15770. Double Cross

統計

In the C tribe, the "double cross" is a very important tribal symbol. A double cross, as shown in the two examples below, consists of two horizontal line segments and one vertical line segment made of "1"s, and must satisfy the following constraints:

  • The two horizontal line segments cannot be in adjacent rows.
  • The top end of the vertical line segment must be strictly above both horizontal line segments, and the bottom end must be strictly below both horizontal line segments.
  • The vertical line segment must strictly divide both horizontal line segments into two equal halves.
  • The upper horizontal line segment must be strictly shorter than the lower horizontal line segment.

Therefore, the example on the right above is the smallest double cross that satisfies the requirements.

Given an $R \times C$ 01 matrix, you are required to calculate how many double crosses exist in this 01 matrix.

For example, in the following case where $R=6$ and $C=8$, the 01 matrix is:

10001011
10111111
10001101
11111110
11111111
11101011

We can find 5 double crosses that satisfy the conditions.

Note that the final result may be very large; you are only required to output the number of double crosses modulo $1,000,000,009$.

Input

The first line of the input contains two space-separated positive integers $R$ and $C$, representing the number of rows and columns of the 01 matrix, respectively. The second line contains a non-negative integer $N$, representing the number of "0"s in the 01 matrix. Each of the following $N$ lines contains two space-separated positive integers $x$ and $y$ ($1 \le x \le R, 1 \le y \le C$), indicating that $(x, y)$ is a "0". It is guaranteed that the coordinates of the $N$ "0"s are distinct. It is guaranteed that $R, C, N \le 10,000$ and $R \times C \le 1,000,000$. For 30% of the data, $R, C \le 50$.

Output

The output file contains only one line, which is the result of $D \pmod{1,000,000,009}$, where $D$ is the number of double crosses in the 01 matrix.

Examples

Input 1

6 8
12
1 2
1 3
1 4
1 6
2 2
3 2
3 3
3 4
3 7
6 4
6 6
4 8

Output 1

5

Figure 1. Two examples of a double cross

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.