DWITE Online Computer Programming Contest
February 2011
Problem 2
Safe from Rooks

In chess, a rook is a piece that can move to any other square on the row or column it is on. So, we say that it threatens all the squares on the row and column it is on (because it can threaten to capture any of the opponent's piece on these squares; if there are multiple pieces in a row, the threat upon the further piece is known as skewer or an x-ray attack /chess-trivia). Given the positions of rooks on a chess board, whose dimensions aren't necessarily 8 by 8, determine the number of squares that are not threatened by rooks.

The input file DATA2.txt will contain 5 test cases. The first line of each test case contains three numbers, R, C and Ro (1 <= R, C <= 31000, 1 <= Ro <= 20) representing the number of rows and the number of columns on our chess board (where the rows are numbered bottom up, and the columns are numbered left to right) and the number of rooks on the board respectively. The next Ro lines each contain two numbers X and Y (1 <= X <= R, 1 <= Y <= C) representing the position of a rook on the board.

The output file OUT2.txt should contain 5 lines, where each line represents the number of squares on the chessboard that are not being threatened by rooks.

Sample Input (first two cases shown):
3 3 1
2 2
8 8 3
1 1
5 5
8 8
Sample Output (first two cases shown):
Explanation of first case:
There is only a single Rook in the very centre at (2,2). It does not threaten squares marked by . periods.