题目描述
Problem Description
Little S is playing a mini-game. The game features a $n \times m$ chessboard with $k$ stars placed on it. Initially, there is a catcher at position $(x, y)$. In each move, you can move the catcher to any position in the same row or column, ensuring that the new position $(x', y')$ is different from the original and satisfies $1 \leq x' \leq n$, $1 \leq y' \leq m$. The catcher will capture all stars on the path from $(x, y)$ to $(x', y')$. Once a star is captured, it disappears.
The goal of the game is to capture as many stars as possible in exactly two moves. However, Little S doesn't know how to play optimally, so he randomly chooses a new position to move to. For the $(n+m-2)^2$ different possible moves Little S can make, calculate the total number of stars captured, modulo $10^9+7$.
Input Format
The first line contains three positive integers $n, m, k$, representing the size of the chessboard and the number of stars.
The second line contains two positive integers $x, y$, indicating the initial position of the catcher.
The next $k$ lines each contain two positive integers, representing the positions $(p, q)$ of the stars. Multiple stars can be at the same position.
Output Format
A single line containing a non-negative integer, representing the total number of stars Little S can capture for the $(n+m-2)^2$ different move combinations, modulo $10^9+7$.
Sample Input and Output
Sample Input #1
3 3 4
2 2
1 1
1 2
1 3
3 1
Sample Output #1
11
Sample Input #2
5 8 9
2 7
1 7
2 2
4 7
4 5
4 7
2 8
5 2
1 7
1 7
Sample Output #2
153
Notes
【Sample Explanation #1】
In the grid, a valid sequence of moves for the catcher is:
$$(2,2) \to (1,2) \to (1,3)$$
In this sequence, the catcher captures one star at position $(1,2)$ and one star at position $(1,3)$.
【Data Range】
This problem is bundled with subtasks.
| Subtask # | Points | $n \leq$ | $m \leq$ |
|---|---|---|---|
| 1 | 5 | 50 | 50 |
| 2 | 10 | 1000 | 1000 |
| 3 | 20 | $10^5$ | $10^5$ |
| 4 | 25 | $10^5$ | $10^9$ |
| 5 | 25 | $10^9$ | $10^9$ |
| 6 | 15 | $10^{18}$ | $10^{18}$ |
For $100\%$ of the data, $1 \leq k \leq 10^5$, $1 \leq n, m \leq 10^{18}$, $1 \leq x, p \leq n$, $1 \leq y, q \leq m$, $(x, y) \neq (p, q)$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分