Time limit
1s
Memory limit
128 MB
There is a rectangular sheet of magic colored paper marked with horizontal and vertical grid lines at intervals of 1. At first, the sheet consists of one white piece. Points are then given in order. For each point, cut the current piece containing that point according to the color of that piece.
You are given the width and height of the initial sheet, followed by the points used for cutting in order. After all points have been processed, find the areas of the largest and smallest pieces that remain.
No two given points lie on the same horizontal line or on the same vertical line. No given point lies on the boundary of the initial sheet.
The width and height of the sheet are positive integers. Each point is given by two integers: its horizontal distance and vertical distance from the lower-left corner of the initial sheet. In the figures below, point 1 is located at (5, 4).
Suppose the sheet has width 8 and height 7, and the points are given in the order (5, 4), (2, 3), (3, 1), (7, 6), (6, 2). Processing the first point divides the sheet into two black pieces, as shown in Figure 1.

Figure 1
The second point lies in the lower black piece from Figure 1, so that piece is divided into two white pieces as shown in Figure 2.

Figure 2
Processing the remaining points in the same way produces the state shown in Figure 3. In this case, the largest piece has area 21 and the smallest piece has area 3.

Figure 3
The first line contains two positive integers, the width and height of the sheet, separated by a space. Both values are at most 40,000.
The second line contains a positive integer N, the number of points used for cutting. N is at most 30,000.
Each of the next N lines contains one point in processing order. Each point is given as two space-separated integers: the horizontal distance followed by the vertical distance.
Print two integers on the first line: the largest area and the smallest area among all pieces after every cut, separated by a space.