#P3271. [JLOI2016] 方

    ID: 2320 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016吉林枚举,暴力容斥概率论,统计

[JLOI2016] 方

Description

God said, do not be round, be square; thus this problem.

Since we should be square, and preferably as square as possible, God sent us to find squares. We are placed on a grid with NN rows and MM columns, containing (N+1)×(M+1)(N+1)\times(M+1) grid points. Our task is to count how many squares can be formed such that all four vertices are grid points.

However, the problem is too hard because there are too many points, so God deleted KK of these (N+1)×(M+1)(N+1)\times(M+1) points. With fewer points, the problem becomes easier. Now, how many squares can be formed from the remaining grid points?

Input Format

The first line contains three integers N,M,KN, M, K, representing the number of rows, the number of columns, and the number of vertices that cannot be used. It is guaranteed that N,M1N, M \ge 1, K(N+1)×(M+1)K \le (N+1)\times(M+1).

We number the rows from top to bottom by integers 00 to NN, and the columns from left to right by 00 to MM.

The next KK lines each contain two integers x,yx, y, indicating that the grid point at row xx, column yy is deleted.

It is guaranteed that 0xN1060 \le x \le N \le 10^6, 0yM1060 \le y \le M \le 10^6, K2000K \le 2000, and no grid point is repeated.

Output Format

Output a single positive integer: the number of squares modulo 100000007100000007 (108+710^8 + 7).

2 2 4
1 0
1 2
0 1
2 1
1

Hint

Translated by ChatGPT 5