#P8075. King Expansion
King Expansion
King Expansion
Mirko and Slavko are playing a game on an $R \times C$ chessboard. Each player places a number of kings on the board. A king can move one step in any of the $8$ possible directions.
The distance between two kings is defined as the minimum number of moves required for one king to reach the cell of the other. In other words, if two kings are positioned at $(r_1, c_1)$ and $(r_2, c_2)$, their distance is given by $\max(|r_1 - r_2|, |c_1 - c_2|)$. The expansion of a player is the sum of distances for every distinct pair of kings placed by that player.
Your task is to calculate the expansion for both Mirko and Slavko given the board dimensions and the positions of their kings.
inputFormat
The input consists of the following lines:
- The first line contains two integers $R$ and $C$, representing the number of rows and columns of the chessboard.
- The second line contains an integer $m$, the number of kings placed by Mirko. The next $m$ lines each contain two integers $r$ and $c$, representing the row and column of a king placed by Mirko.
- The following line contains an integer $n$, the number of kings placed by Slavko. The next $n$ lines each contain two integers $r$ and $c$, representing the row and column of a king placed by Slavko.
outputFormat
Output two integers separated by a space: the expansion of Mirko followed by the expansion of Slavko.
sample
3 3
2
1 1
3 3
2
1 3
3 1
2 2