题目描述
Problem Description
Takahashi is playing a certain game. The game is played on an infinite grid of squares in both vertical and horizontal directions. Each square is shaped like a square, with each side parallel to either the east-west or north-south direction. One of the squares is assigned the coordinate pair (0, 0). From this square, moving east by x squares (or west by -x squares when x is negative) and north by y squares (or south by -y squares when y is negative) leads to a square assigned the coordinate pair (x, y).
On the grid, there are W × H gold nuggets. These nuggets are placed one each on all squares (p, q) where 1 ≦ p ≦ W and 1 ≦ q ≦ H. Additionally, exactly N squares with nuggets have gold collection devices. The devices are numbered from 1 to N. For any two squares (a, b) and (c, d), if both have a device, then a ≠ c and b ≠ d. Also, no multiple devices are on the same square. Initially, none of the gold collection devices are activated.
When a gold collection device is activated, it first collects the nugget on its square. Then, it can extend cranes in the east, west, north, and south directions to collect more nuggets. Due to the nature of the cranes, they must be placed where there is no nugget, and the area they collect must have consecutive nuggets. That is, if the square with the crane is (x, y), the cranes can be placed and collect nuggets only under the following conditions:
- East direction collection: Choose an integer p that satisfies the following condition. Then, collect all nuggets on squares (i, y) where x+1 ≦ i ≦ p-1.
- Condition: p > x+1, all squares (i, y) where x+1 ≦ i ≦ p-1 have nuggets, and the square (p, y) has no nugget.
West direction collection: Choose an integer p that satisfies the following condition. Then, collect all nuggets on squares (i, y) where p+1 ≦ i ≦ x-1.
Condition: p < x-1, all squares (i, y) where p+1 ≦ i ≦ x-1 have nuggets, and the square (p, y) has no nugget.
South direction collection: Choose an integer q that satisfies the following condition. Then, collect all nuggets on squares (x, j) where q+1 ≦ j ≦ y-1.
Condition: q < y-1, all squares (x, j) where q+1 ≦ j ≦ y-1 have nuggets, and the square (x, q) has no nugget.
North direction collection: Choose an integer q that satisfies the following condition. Then, collect all nuggets on squares (x, j) where y+1 ≦ j ≦ q-1.
Condition: q > y+1, all squares (x, j) where y+1 ≦ j ≦ q-1 have nuggets, and the square (x, q) has no nugget.
For each direction, if there is no integer p or q that satisfies the condition, the crane cannot be extended in that direction.
Takahashi plans to activate all devices in some order. The order of activation might change the number of nuggets collected in the end. Takahashi loves gold nuggets and wants to maximize the number of nuggets collected in the end.
You are asked to write a program to calculate the maximum number of nuggets that can be collected on behalf of Takahashi.
Input Format
The input is given from the standard input in the following format:
W H N X_1 Y_1 X_2 Y_2 : X_N Y_N
- The first line contains two integers W (1 ≦ W ≦ 10^6) and H (1 ≦ H ≦ 10^6) separated by a space, representing the number of nuggets and their layout.
- The second line contains an integer N (1 ≦ N ≦ 30), representing the number of gold collection devices.
- The next N lines, the i-th line (1 ≦ i ≦ N) contains two integers X_i (1 ≦ X_i ≦ W) and Y_i (1 ≦ Y_i ≦ H) separated by a space, indicating that the i-th device is on square (X_i, Y_i).
Additionally, the input satisfies the following condition:
- For any two integers i, j (1 ≦ i, j ≦ N), X_i ≠ X_j and Y_i ≠ Y_j.
Output Format
Output the maximum number of nuggets that can be collected. Ensure a newline at the end of the output.
Sample Input and Output
Sample Input #1
6 4
3
2 4
3 1
4 3
Sample Output #1
19
Sample Input #2
3 3
3
1 1
2 3
3 2
Sample Output #2
9
Sample Input #3
15 10
8
7 10
12 8
4 4
5 7
9 9
1 6
6 5
3 2
Sample Output #3
112
Notes/Hints
Partial Points
This problem has partial points.
- If you solve the dataset 1 where N ≦ 8, W ≦ 80, H ≦ 80, you get 80 points.
- If you solve the dataset 2 where W ≦ 80, H ≦ 80, you get an additional 19 points, totaling 99 points.
- If you solve the dataset 3 without additional constraints, you get an additional 1 point, totaling 100 points.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分