#abc047b. [abc047_b]Snuke's Coloring 2 (ABC Edit)

[abc047_b]Snuke's Coloring 2 (ABC Edit)

Problem Statement

There is a rectangle in the xyxy-plane, with its lower left corner at (0,0)(0, 0) and its upper right corner at (W,H)(W, H). Each of its sides is parallel to the xx-axis or yy-axis. Initially, the whole region within the rectangle is painted white.

Snuke plotted NN points into the rectangle. The coordinate of the ii-th (1iN1 ≦ i ≦ N) point was (xi,yi)(x_i, y_i).

Then, he created an integer sequence aa of length NN, and for each 1iN1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

  • If ai=1a_i = 1, he painted the region satisfying x<xix < x_i within the rectangle.
  • If ai=2a_i = 2, he painted the region satisfying x>xix > x_i within the rectangle.
  • If ai=3a_i = 3, he painted the region satisfying y<yiy < y_i within the rectangle.
  • If ai=4a_i = 4, he painted the region satisfying y>yiy > y_i within the rectangle.

Find the area of the white region within the rectangle after he finished painting.

Constraints

  • 1W,H1001 ≦ W, H ≦ 100
  • 1N1001 ≦ N ≦ 100
  • 0xiW0 ≦ x_i ≦ W (1iN1 ≦ i ≦ N)
  • 0yiH0 ≦ y_i ≦ H (1iN1 ≦ i ≦ N)
  • WW, HH (21:32, added), xix_i and yiy_i are integers.
  • aia_i (1iN1 ≦ i ≦ N) is 1,2,31, 2, 3 or 44.

Input

The input is given from Standard Input in the following format:

WW HH NN x1x_1 y1y_1 a1a_1 x2x_2 y2y_2 a2a_2 :: xNx_N yNy_N aNa_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.


Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

e19e673abcd0882783f635cce9d2f94d.png

First, as (x1,y1)=(2,1)(x_1, y_1) = (2, 1) and a1=1a_1 = 1, he paints the region satisfying x<2x < 2 within the rectangle:

f25cd04bbac23c4e5426d70511a9762f.png

Then, as (x2,y2)=(3,3)(x_2, y_2) = (3, 3) and a2=4a_2 = 4, he paints the region satisfying y>3y > 3 within the rectangle:

46b0c06fd9eee4f148e1f441f7abca53.png

Now, the area of the white region within the rectangle is 99.


Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.


Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64