QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 256 MB مجموع النقاط: 100

#1414. Mascots

الإحصائيات

JOI-chan was playing with mascots with her friends. The fun time passed in the blink of an eye, and now that her friends have gone home, it is time to clean up.

JOI-chan has $R \times C$ mascots, and she uses a rectangular area of $R$ rows and $C$ columns for cleaning up. One mascot is placed in each cell. We denote the cell in the $A$-th row from the top and $B$-th column from the left as $(A, B)$. At the stage when cleaning begins, $N$ mascots are already placed. When she starts cleaning, there is at least one cell where no mascot is placed.

JOI-chan cleans up by placing the mascots one by one. JOI-chan becomes "a little happy" if, when she places a new mascot, the set of all cells containing mascots forms a single rectangle (excluding the case where the set of cells containing mascots already formed a single rectangle in the initial state). The set of cells containing mascots forms a single rectangle if there exist four integers $r_1, r_2, c_1, c_2$ ($1 \le r_1 \le r_2 \le R$ and $1 \le c_1 \le c_2 \le C$) such that every cell $(i, j)$ satisfying $r_1 \le i \le r_2$ and $c_1 \le j \le c_2$ contains a mascot, and no other cell contains a mascot. The more times she becomes "a little happy," the more soundly JOI-chan can sleep tonight.

When placing mascots, the types of mascots are not distinguished. How many ways are there to place the remaining mascots such that the number of times she becomes "a little happy" is maximized?

Input

Read the following from standard input:

  • The first line contains two integers $R$ and $C$ separated by a space. $R$ represents the number of rows and $C$ represents the number of columns in the area where mascots are placed.
  • The second line contains an integer $N$, representing the number of mascots already placed when cleaning begins.
  • The following $N$ lines contain information about the initially placed mascots. The $i$-th of these lines contains two integers $A_i$ and $B_i$ separated by a space, indicating that a mascot is initially placed at cell $(A_i, B_i)$. These pairs of numbers are distinct.

Output

Output the number of ways to place the mascots such that the number of times she becomes "a little happy" is maximized, modulo $1\,000\,000\,007$.

Constraints

All input data satisfies the following conditions:

  • $2 \le R \le 3\,000$
  • $2 \le C \le 3\,000$
  • $1 \le N \le 100\,000$

Subtasks

Subtask 1 [10 points]

  • $R \le 3$
  • $C \le 3$

Subtask 2 [30 points]

  • $R \le 50$
  • $C \le 50$

Subtask 3 [60 points]

  • No additional constraints.

Examples

Input 1

2 3
2
1 2
2 2

Output 1

8

Note

In the initial state, the 6 cells are as follows ($\triangle$ represents a cell where a mascot is already placed):

Of the 6 cells, $(1, 2)$ and $(2, 2)$ already have mascots. The maximum number of times she becomes "a little happy" is 2. There are 8 ways to place the remaining mascots such that she becomes "a little happy" 2 times (the numbers represent the order in which the new mascots are placed):

In all 8 examples, when the 2nd mascot is placed, the cells with mascots form a $2 \times 2$ rectangle, and when the 4th mascot is placed, the cells with mascots form a $2 \times 3$ rectangle, making JOI-chan "a little happy" 2 times in total.

Input 2

3 3
2
1 1
3 3

Output 2

5040

Note

No matter the order of placement, the number of times she becomes "a little happy" is 1.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.