QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#340. Square

Statistics

God said, no circles, only squares, and thus this problem was born.

Since we should be square, and preferably as square as possible, God sent us to find squares. God sent us to a grid with $N$ rows and $M$ columns, which contains a total of $(N + 1) \times (M + 1)$ grid points. We need to find how many squares are formed by these grid points (in other words, all four vertices of the square are grid points).

However, this problem is too difficult for us because there are too many points. So, God deleted $K$ points from the $(N + 1) \times (M + 1)$ grid. Since there are fewer points, the problem becomes simpler. How many squares are formed by the remaining grid points?

Input

The first line of the input file square.in contains three integers $N, M, K$, representing the number of rows, columns, and the number of points that cannot be selected, respectively. It is guaranteed that $N, M \geq 1$ and $K \leq (N + 1) \times (M + 1)$.

The grid points in each row are indexed from $0$ to $N$ from top to bottom, and the grid points in each column are indexed from $0$ to $M$.

The next $K$ lines each contain two integers $X, Y$, representing that the grid point at row $X$ and column $Y$ has been deleted. It is guaranteed that $0 \leq X \leq N$, $0 \leq Y \leq M$, and no duplicate grid points appear.

Output

The output file square.out contains a single integer, representing the number of squares modulo $100000007$ ($10^8 + 7$).

Examples

Input 1

2 2 4
1 0
1 2
0 1
2 1

Output 1

1

Note 1

As shown in the figure, we deleted four of the grid points, so the only remaining square is the largest $2 \times 2$ square.

Input 2

7 10 5
2 3
1 5
6 2
3 5
2 6

Output 2

429

Input 3

2 2 4
0 0
2 2
0 2
2 0

Output 3

1

Note 3

There remains one square with side length $\sqrt{2}$.

Subtasks

Test Case ID $N, M$ $K$
1, 2 $\leq 5$ No special restrictions
3, 4 $\leq 50$ $\leq 50$
5, 6 $\leq 10^6$ $= 0$
7, 8 $\leq 10^6$ $\leq 50$
9, 10 $\leq 10^6$ $\leq 200$
11, 12 $\leq 10^3$ $\leq 2 \times 10^3$
13~20 $\leq 10^6$ $\leq 2 \times 10^3$

Figure 1. Illustration of the grid with deleted points for Note 1

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.