题目描述
Background
sxz is not good at socializing, so he usually likes to sit in secluded places. Today, sxz came to the cafeteria, and he still wants to find a secluded spot to sit, maximizing the sum of his Manhattan distances to all other people.
Problem Description
The seating in the cafeteria can be seen as a rectangle divided into $n \times m$ grids, with length $n$ and width $m$. Each grid $(i, j) (i \in [1, n], j \in [1, m])$ (where $i, j$ are integers) represents a seat.
Currently, there are $k$ people in the cafeteria, with the $i$-th person (where $1 \leq i \leq k$) sitting at $(x_i, y_i)$. sxz wants to find a seat such that the sum of his Manhattan distances to these $k$ people is maximized. Please help him find this maximum value, and leave the rest to sxz!
Suppose sxz sits at point $(a, b)$, then the sum of his Manhattan distances to the $k$ people is $\sum_{i=1}^{k} |a - x_i| + |b - y_i|$.
Obviously, sxz cannot sit at the same place as any of the $k$ people.
Input Format
The first line contains three integers $n, m, k$.
The next $k$ lines, each containing two integers, describe $x_i, y_i$.
Output Format
A single line containing one integer, representing this value. Note that it may be very large.
Sample Input and Output
Sample Input #1
2 5 3
1 1
1 3
1 4
Sample Output #1
10
Sample Input #2
7 4 9
1 4
2 3
4 1
6 2
7 1
5 2
3 4
1 1
7 4
Sample Output #2
38
Notes
Sample Explanation 1
The best position is $(2, 5)$, with Manhattan distances to the $3$ people being $5, 3, 2$ respectively.
Data Size and Constraints
This problem uses subtask testing.
+ Subtask 0 (15 pts): $n, m \leq 100$.
+ Subtask 1 (25 pts): $n, m \leq 10000$.
+ Subtask 2 (20 pts): $k = 3$.
+ Subtask 3 (40 pts): No special restrictions.
For all data, $1 \leq n, m \leq 10^9$, $1 \leq k \leq \min\{4 \times 10^5, n \times m - 1\}$, $1 \leq x_i \leq n$, $1 \leq y_i \leq m$, and all $(x_i, y_i)$ are guaranteed to be unique.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分