There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.
Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).
Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:
 - If a_i = 1, he painted the region satisfying x < x_i within the rectangle.
 - If a_i = 2, he painted the region satisfying x > x_i within the rectangle.
 - If a_i = 3, he painted the region satisfying y < y_i within the rectangle.
 - If a_i = 4, he painted the region satisfying y > y_i within the rectangle.
Find the area of the white region within the rectangle after he finished painting.

-----Constraints-----
 - 1 ≦ W, H ≦ 100
 - 1 ≦ N ≦ 100
 - 0 ≦ x_i ≦ W (1 ≦ i ≦ N)
 - 0 ≦ y_i ≦ H (1 ≦ i ≦ N)
 - W, H (21:32, added), x_i and y_i are integers.
 - a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

-----Input-----
The input is given from Standard Input in the following format:
W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

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

-----Sample Input-----
5 4 2
2 1 1
3 3 4

-----Sample Output-----
9

The figure below shows the rectangle before Snuke starts painting.
First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:
Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:
Now, the area of the white region within the rectangle is 9.

Difficulty: EASY

Solutions:
(W, H, N) = list(map(int, input().split()))
Black = [[True for _ in range(W)] for i in range(H)]
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	for j in range(H):
		for k in range(W):
			if a == 1:
				if k < x:
					Black[j][k] = False
			elif a == 2:
				if k >= x:
					Black[j][k] = False
			elif a == 3:
				if j < y:
					Black[j][k] = False
			elif a == 4:
				if j >= y:
					Black[j][k] = False
c = 0
for i in range(H):
	c += Black[i].count(True)
print(c)


(W, H, N) = map(int, input().split())
(x, y) = (0, 0)
for _ in range(N):
	(xi, yi, a) = map(int, input().split())
	if a == 1:
		x = max(x, xi)
	elif a == 2:
		W = min(xi, W)
	elif a == 3:
		y = max(y, yi)
	else:
		H = min(H, yi)
print(0 if x >= W or y >= H else (W - x) * (H - y))


(W, H, N) = list(map(int, input().split()))
(bl_x, tr_x, bl_y, tr_y) = (0, W, 0, H)
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		bl_x = max(bl_x, x)
	elif a == 2:
		tr_x = min(tr_x, x)
	elif a == 3:
		bl_y = max(bl_y, y)
	elif a == 4:
		tr_y = min(tr_y, y)
print(max(tr_x - bl_x, 0) * max(tr_y - bl_y, 0))


(W, H, N) = map(int, input().split())
X = [0, W]
Y = [0, H]
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		X[0] = max(x, X[0])
	elif a == 2:
		X[1] = min(x, X[1])
	elif a == 3:
		Y[0] = max(y, Y[0])
	else:
		Y[1] = min(y, Y[1])
if X[1] - X[0] <= 0 or Y[1] - Y[0] <= 0:
	area = 0
else:
	area = max(0, (X[1] - X[0]) * (Y[1] - Y[0]))
print(area)


(w, h, n) = map(int, input().split())
x1 = 0
x2 = w
y1 = 0
y2 = h
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		x1 = max(x1, x)
	if a == 2:
		x2 = min(x2, x)
	if a == 3:
		y1 = max(y1, y)
	if a == 4:
		y2 = min(y2, y)
if x2 < x1 or y2 < y1:
	print(0)
else:
	print((x2 - x1) * (y2 - y1))


(W, H, N) = map(int, input().split())
(u, U, v, V) = (0, W, 0, H)
for _ in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		u = max(u, x)
	if a == 2:
		U = min(U, x)
	if a == 3:
		v = max(v, y)
	if a == 4:
		V = min(V, y)
f = lambda x: x if x > 0 else 0
print(f(U - u) * f(V - v))


(w, h, n) = map(int, input().split())
a = [[int(i) for i in input().split()] for i in range(n)]
(x, y) = (0, 0)
for (s, t, u) in a:
	if u == 1:
		x = max(x, s)
	elif u == 2:
		w = min(w, s)
	elif u == 3:
		y = max(y, t)
	else:
		h = min(h, t)
height = max(0, h - y)
width = max(0, w - x)
print(height * width)


(w, h, n) = map(int, input().split())
b = c = 0
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		b = max(b, x)
	if a == 2:
		w = min(w, x)
	if a == 3:
		c = max(c, y)
	if a == 4:
		h = min(h, y)
print(max(0, w - b) * max(0, h - c))


(W, H, N) = map(int, input().split())
xya = []
l = 0
r = W
u = H
d = 0
for _ in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		l = max(l, x)
	elif a == 2:
		r = min(r, x)
	elif a == 3:
		d = max(d, y)
	else:
		u = min(u, y)
print(max(0, u - d) * max(0, r - l))


(W, H, N) = map(int, input().split())
w = 0
h = 0
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		w = max(w, x)
	elif a == 2:
		W = min(W, x)
	elif a == 3:
		h = max(h, y)
	else:
		H = min(H, y)
print(max(0, W - w) * max(0, H - h))


(w, h, n) = map(int, input().split())
ow = 0
oh = 0
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1 and ow < x:
		ow = x
	if a == 2 and w > x:
		w = x
	if a == 3 and oh < y:
		oh = y
	if a == 4 and h > y:
		h = y
if w > ow and h > oh:
	print((w - ow) * (h - oh))
else:
	print(0)


(w, h, n) = map(int, input().split())
(l, r, u, d) = (0, w, h, 0)
for _ in [0] * n:
	(x, y, a) = map(int, input().split())
	l = max(l, x) if a == 1 else l
	r = min(r, x) if a == 2 else r
	d = max(d, y) if a == 3 else d
	u = min(u, y) if a == 4 else u
print(max(0, r - l) * max(0, u - d))


(xmax, ymax, N) = map(int, input().split())
xmin = 0
ymin = 0
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		xmin = max(xmin, x)
	elif a == 2:
		xmax = min(xmax, x)
	elif a == 3:
		ymin = max(ymin, y)
	else:
		ymax = min(ymax, y)
print(max(0, xmax - xmin) * max(0, ymax - ymin))


(W, H, N) = map(int, input().split())
p = 0
q = W
r = 0
s = H
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		p = max(p, x)
	elif a == 2:
		q = min(q, x)
	elif a == 3:
		r = max(r, y)
	else:
		s = min(s, y)
print(max(q - p, 0) * max(s - r, 0))


(W, H, N) = map(int, input().split())
XW = [1] * W
YW = [1] * H
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		XW[:x] = [0] * x
	elif a == 2:
		XW[x:] = [0] * (W - x)
	elif a == 3:
		YW[:y] = [0] * y
	elif a == 4:
		YW[y:] = [0] * (H - y)
print(sum(XW) * sum(YW))


import numpy as np
(W, H, N) = map(int, input().split())
X = Y = 0
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		X = max(X, x)
	elif a == 2:
		W = min(W, x)
	elif a == 3:
		Y = max(Y, y)
	else:
		H = min(H, y)
S = max(W - X, 0) * max(H - Y, 0)
print(S)


(H, W, N) = map(int, input().split())
(sita, hidari) = (0, 0)
(ue, migi) = (W, H)
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		hidari = max(x, hidari)
	elif a == 2:
		migi = min(migi, x)
	elif a == 3:
		sita = max(sita, y)
	else:
		ue = min(ue, y)
print(max(0, migi - hidari) * max(0, ue - sita))


wo = 0
ho = 0
(w, h, n) = map(int, input().split())
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		wo = max(wo, x)
	if a == 2:
		w = min(w, x)
	if a == 3:
		ho = max(ho, y)
	if a == 4:
		h = min(h, y)
ans = (w - wo) * (h - ho)
if wo >= w or ho >= h:
	print(0)
else:
	print(ans)


(w, h, n) = map(int, input().split())
l = 0
r = w
d = 0
u = h
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		l = max(l, x)
	if a == 2:
		r = min(r, x)
	if a == 3:
		d = max(d, y)
	if a == 4:
		u = min(u, y)
ans = max(0, r - l) * max(0, u - d)
print(ans)


(w, h, n) = map(int, input().split())
(i, j) = (0, 0)
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		i = max(i, x)
	elif a == 2:
		w = min(w, x)
	elif a == 3:
		j = max(j, y)
	else:
		h = min(h, y)
print((w - i) * (h - j) if w > i and h > j else 0)


(w, h, n) = map(int, input().split())
(x1, x2, y1, y2) = (0, 0, 0, 0)
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		x1 = max(x1, x)
	if a == 2:
		x2 = max(x2, w - x)
	if a == 3:
		y1 = max(y1, y)
	if a == 4:
		y2 = max(y2, h - y)
w -= x1 + x2
h -= y1 + y2
if w > 0 and h > 0:
	print(w * h)
else:
	print(0)


(W, H, N) = map(int, input().split())
w = W * [1]
h = H * [1]
for n in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		w[:x] = x * [0]
	elif a == 2:
		w[x:] = (W - x) * [0]
	elif a == 3:
		h[:y] = y * [0]
	else:
		h[y:] = (H - y) * [0]
print(w.count(1) * h.count(1))


(hw, hh, n) = map(int, input().split())
lw = lh = 0
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		lw = max(lw, x)
	elif a == 2:
		hw = min(hw, x)
	elif a == 3:
		lh = max(lh, y)
	else:
		hh = min(hh, y)
print(max(hh - lh, 0) * max(hw - lw, 0))


(W, H, N) = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
wl = 0
wr = W
hd = 0
hu = H
for (x, y, a) in xya:
	if a == 1:
		wl = max(wl, x)
	elif a == 2:
		wr = min(wr, x)
	elif a == 3:
		hd = max(hd, y)
	else:
		hu = min(hu, y)
ans = max(wr - wl, 0) * max(hu - hd, 0)
print(ans)


(W, H, N) = map(int, input().split())
b = c = 0
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		b = max(b, x)
	elif a == 2:
		W = min(W, x)
	elif a == 3:
		c = max(c, y)
	elif a == 4:
		H = min(H, y)
print(max(W - b, 0) * max(H - c, 0))


(W, H, N) = map(int, input().split())
(L, D) = (0, 0)
for _ in [0] * N:
	(x, y, a) = map(int, input().split())
	if a == 1:
		L = max(L, x)
	elif a == 2:
		W = min(W, x)
	elif a == 3:
		D = max(D, y)
	else:
		H = min(H, y)
print(max(0, H - D) * max(0, W - L))


from typing import List

def answer(w: int, h: int, n: int, xyas: List[List[int]]) -> int:
	bottom_left_corner_of_white = {'x': 0, 'y': 0}
	top_right_corner_of_white = {'x': w, 'y': h}
	for xya in xyas:
		(x, y, a) = xya
		if a == 1:
			if bottom_left_corner_of_white['x'] < x:
				bottom_left_corner_of_white['x'] = x
		if a == 2:
			if x < top_right_corner_of_white['x']:
				top_right_corner_of_white['x'] = x
		if a == 3:
			if bottom_left_corner_of_white['y'] < y:
				bottom_left_corner_of_white['y'] = y
		if a == 4:
			if y < top_right_corner_of_white['y']:
				top_right_corner_of_white['y'] = y
	width_of_white = max(0, top_right_corner_of_white['x'] - bottom_left_corner_of_white['x'])
	height_of_white = max(0, top_right_corner_of_white['y'] - bottom_left_corner_of_white['y'])
	return width_of_white * height_of_white

def main():
	(w, h, n) = map(int, input().split())
	xyas = [list(map(int, input().split())) for _ in range(n)]
	print(answer(w, h, n, xyas))

def __starting_point():
	main()
__starting_point()


def main():
	(w, h, n) = list(map(int, input().split()))
	x_min = 0
	x_max = w
	y_min = 0
	y_max = h
	for _ in range(n):
		(x, y, a) = list(map(int, input().split()))
		if a == 1:
			x_min = max(x_min, x)
		elif a == 2:
			x_max = min(x_max, x)
		elif a == 3:
			y_min = max(y_min, y)
		else:
			y_max = min(y_max, y)
	print((x_max - x_min) * (y_max - y_min) if x_min < x_max and y_min < y_max else 0)

def __starting_point():
	main()
__starting_point()


import os
import sys
import numpy as np

def main():
	(W, H, N) = list(map(int, input().split()))
	square = [[0, W], [0, H]]
	for _ in range(N):
		(x, y, a) = list(map(int, input().split()))
		if a == 1 and square[0][0] < x:
			square[0][0] = x
		elif a == 2 and square[0][1] > x:
			square[0][1] = x
		elif a == 3 and square[1][0] < y:
			square[1][0] = y
		elif a == 4 and square[1][1] > y:
			square[1][1] = y
	if square[0][0] >= square[0][1] or square[1][0] >= square[1][1]:
		print(0)
		return
	print((square[0][1] - square[0][0]) * (square[1][1] - square[1][0]))

def __starting_point():
	main()
__starting_point()


(w, h, n) = map(int, input().split())
W = set(range(w))
H = set(range(h))
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		W &= set(range(x, w))
	if a == 2:
		W &= set(range(0, x))
	if a == 3:
		H &= set(range(y, h))
	if a == 4:
		H &= set(range(0, y))
print(len(W) * len(H))


(w, h, n) = map(int, input().split())
w0 = h0 = 0
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		w0 = max(x, w0)
	elif a == 2:
		w = min(x, w)
	elif a == 3:
		h0 = max(y, h0)
	elif a == 4:
		h = min(y, h)
w = max(0, w - w0)
h = max(0, h - h0)
print(w * h)


(w, h, n) = map(int, input().split())
X = set(range(1, w + 1))
Y = set(range(1, h + 1))
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		X = X & set(range(x + 1, w + 1))
	if a == 2:
		X = X & set(range(1, x + 1))
	if a == 3:
		Y = Y & set(range(y + 1, h + 1))
	if a == 4:
		Y = Y & set(range(1, y + 1))
print(len(X) * len(Y))


(W, H, N) = map(int, input().split())
xl = 0
xr = W
yu = H
yd = 0
for _ in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1 and xl < x:
		xl = x
	elif a == 2 and xr > x:
		xr = x
	elif a == 3 and yd < y:
		yd = y
	elif a == 4 and yu > y:
		yu = y
print(max(0, yu - yd) * max(0, xr - xl))


(w, h, n) = map(int, input().split())
width = w * [1]
height = h * [1]
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		width[:x] = x * [0]
	elif a == 2:
		width[x:] = (w - x) * [0]
	elif a == 3:
		height[:y] = y * [0]
	else:
		height[y:] = (h - y) * [0]
print(width.count(1) * height.count(1))


(w, h, n) = map(int, input().split())
x1 = [0]
x2 = [w]
y1 = [0]
y2 = [h]
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		x1.append(x)
	elif a == 2:
		x2.append(x)
	elif a == 3:
		y1.append(y)
	elif a == 4:
		y2.append(y)
left = max(x1)
right = min(x2)
bottom = max(y1)
top = min(y2)
ans = max(0, right - left) * max(0, top - bottom)
print(ans)


(W, H, N) = map(int, input().split())
(xl, xr, yh, yl) = (0, W, H, 0)
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		xl = max(xl, x)
	elif a == 2:
		xr = min(xr, x)
	elif a == 3:
		yl = max(yl, y)
	elif a == 4:
		yh = min(yh, y)
print(max(xr - xl, 0) * max(yh - yl, 0))


(w, h, n) = map(int, input().split())
x1 = 0
y1 = 0
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		x1 = max(x1, x)
	elif a == 2:
		w = min(w, x)
	elif a == 3:
		y1 = max(y, y1)
	elif a == 4:
		h = min(h, y)
print((w - x1) * (h - y1) if w > x1 and h > y1 else 0)


(w, h, n) = map(int, input().split())
g = [[1] * h for _ in range(w)]
for _ in range(n):
	(x, y, a) = map(int, input().split())
	for i in range(w):
		for j in range(h):
			if a == 1 and i < x or (a == 2 and i >= x) or (a == 3 and j < y) or (a == 4 and j >= y):
				g[i][j] = 0
print(sum(map(sum, g)))


(w, h, n) = map(int, input().split())
ux = w
lx = 0
uy = h
ly = 0
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		lx = max(lx, x)
	if a == 2:
		ux = min(ux, x)
	if a == 3:
		ly = max(ly, y)
	if a == 4:
		uy = min(uy, y)
print(max(ux - lx, 0) * max(uy - ly, 0))


(W, H, N) = map(int, input().split())
l1 = 0
l2 = W
l3 = 0
l4 = H
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		l1 = max(l1, x)
	if a == 2:
		l2 = min(l2, x)
	if a == 3:
		l3 = max(l3, y)
	if a == 4:
		l4 = min(l4, y)
r = max(0, l2 - l1) * max(0, l4 - l3)
print(r)


(W, H, N) = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(N)]
X = Y = 0
for i in range(N):
	if xya[i][2] == 1:
		X = max(X, xya[i][0])
	if xya[i][2] == 2:
		W = min(W, xya[i][0])
	if xya[i][2] == 3:
		Y = max(Y, xya[i][1])
	if xya[i][2] == 4:
		H = min(H, xya[i][1])
print(max(W - X, 0) * max(H - Y, 0))


(w, h, n) = map(int, input().split())
(x, y) = (0, 0)
(X, Y) = (w, h)
for i in range(n):
	(a, b, c) = map(int, input().split())
	if c == 1 and x < a:
		x = a
	elif c == 2 and a < X:
		X = a
	elif c == 3 and y < b:
		y = b
	elif c == 4 and b < Y:
		Y = b
print(max(X - x, 0) * max(Y - y, 0))


(W, H, N) = map(int, input().split())
(l, t, r, b) = (0, 0, W, H)
for _ in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		l = min(max(l, x), r)
	if a == 2:
		r = max(min(r, x), l)
	if a == 3:
		t = min(max(t, y), b)
	if a == 4:
		b = max(min(b, y), t)
print((r - l) * (b - t))


(w, h, n) = map(int, input().split())
lw = 0
rw = w
lh = 0
rh = h
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		lw = max(lw, x)
	elif a == 2:
		rw = min(rw, x)
	elif a == 3:
		lh = max(lh, y)
	else:
		rh = min(rh, y)
print(max(0, rh - lh) * max(rw - lw, 0))


(w, h, n) = map(int, input().split())
xx = 0
xr = w
yy = 0
yt = h
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		xx = max(xx, x)
	elif a == 2:
		xr = min(xr, x)
	elif a == 3:
		yy = max(yy, y)
	else:
		yt = min(yt, y)
s = max(min(w, xr) - xx, 0) * max(min(h, yt) - yy, 0)
print(s)


(w, h, n) = map(int, input().split())
x_pos = [0, w]
y_pos = [0, h]
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		x_pos[0] = max(x_pos[0], x)
	elif a == 2:
		x_pos[1] = min(x_pos[1], x)
	elif a == 3:
		y_pos[0] = max(y_pos[0], y)
	else:
		y_pos[1] = min(y_pos[1], y)
if x_pos[1] - x_pos[0] < 0 or y_pos[1] - y_pos[0] < 0:
	ans = 0
else:
	ans = (x_pos[1] - x_pos[0]) * (y_pos[1] - y_pos[0])
print(ans)


(W, H, N) = map(int, input().split())
(a1, a2, a3, a4) = (-1, 101, -1, 101)
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		a1 = max(a1, x)
	elif a == 2:
		a2 = min(a2, x - 1)
	elif a == 3:
		a3 = max(a3, y)
	else:
		a4 = min(a4, y - 1)
mass = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
	for j in range(W):
		if i < a3 or a4 < i:
			mass[i][j] += 1
		if j < a1 or a2 < j:
			mass[i][j] += 1
cnt = 0
for k in mass:
	cnt += k.count(0)
print(cnt)


import numpy as np
(w, h, n) = map(int, input().split())
loc = [input() for _ in range(n)]

def black(x, y, i):
	if i == 1:
		mtx[:x,] = 0
	elif i == 2:
		mtx[x:,] = 0
	elif i == 3:
		mtx[:, :y] = 0
	elif i == 4:
		mtx[:, y:] = 0
mtx = np.ones((w, h), dtype=int)
for l in loc:
	(x, y, i) = map(int, l.split())
	black(x, y, i)
print(mtx.sum())


(W, H, N) = map(int, input().split())
(x0, y0) = (0, 0)
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1 and x > x0:
		x0 = x
	elif a == 2 and x < W:
		W = x
	elif a == 3 and y > y0:
		y0 = y
	elif a == 4 and y < H:
		H = y
if W < x0 or H < y0:
	print(0)
else:
	print((W - x0) * (H - y0))


(w, h, n) = map(int, input().split())
b = 0
l = 0
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		l = max(l, x)
	elif a == 2:
		w = min(w, x)
	elif a == 3:
		b = max(b, y)
	else:
		h = min(h, y)
print(max(h - b, 0) * max(w - l, 0))


(w, h, n) = list(map(int, input().split()))
sw = 0
sh = 0
for _ in range(n):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		sw = max(sw, x)
	elif a == 2:
		w = min(w, x)
	elif a == 3:
		sh = max(sh, y)
	elif a == 4:
		h = min(h, y)
if sw < w and sh < h:
	print((w - sw) * (h - sh))
else:
	print(0)


(w, h, n) = list(map(int, input().split()))
lx = 0
ly = 0
rx = w
ry = h
for i in range(n):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		if lx < x:
			lx = x
	elif a == 2:
		if rx > x:
			rx = x
	elif a == 3:
		if ly < y:
			ly = y
	elif ry > y:
		ry = y
print(max(rx - lx, 0) * max(ry - ly, 0))


(W, H, N) = map(int, input().split())
x1 = y1 = 0
(x2, y2) = (W, H)
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		x1 = min(x2, max(x1, x))
	elif a == 2:
		x2 = max(x1, min(x2, x))
	elif a == 3:
		y1 = min(y2, max(y1, y))
	else:
		y2 = max(y1, min(y2, y))
print((x2 - x1) * (y2 - y1))


(W, H, N) = map(int, input().split())
XYA = [tuple(map(int, input().split())) for i in range(N)]
(l, r, d, u) = (0, W, 0, H)
for (x, y, a) in XYA:
	if a == 1:
		l = max(l, x)
	elif a == 2:
		r = min(r, x)
	elif a == 3:
		d = max(d, y)
	else:
		u = min(u, y)
w = max(0, r - l)
h = max(0, u - d)
print(w * h)


(w, h, n) = map(int, input().split())
list = [0, w, 0, h]
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1 and list[0] <= x:
		list[0] = x
	elif a == 2 and list[1] >= x:
		list[1] = x
	elif a == 3 and list[2] <= y:
		list[2] = y
	elif a == 4 and list[3] >= y:
		list[3] = y
	else:
		pass
if list[0] > list[1] or list[2] > list[3]:
	print(0)
else:
	print((list[0] - list[1]) * (list[2] - list[3]))


(w, h, n) = list(map(int, input().split()))
r_w = w
l_w = 0
u_h = h
d_h = 0
for i in range(n):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		l_w = max(l_w, x)
	elif a == 2:
		r_w = min(r_w, x)
	elif a == 3:
		d_h = max(d_h, y)
	elif a == 4:
		u_h = min(u_h, y)
res = max(0, r_w - l_w) * max(0, u_h - d_h)
print(res)


(W, H, N) = [int(x) for x in input().split()]
(x_min, x_max, y_min, y_max) = (0, W, 0, H)
num_lists = [[int(x) for x in input().split()] for _ in range(N)]
for num_list in num_lists:
	if num_list[2] == 1 and num_list[0] > x_min:
		x_min = num_list[0]
	if num_list[2] == 2 and num_list[0] < x_max:
		x_max = num_list[0]
	if num_list[2] == 3 and num_list[1] > y_min:
		y_min = num_list[1]
	if num_list[2] == 4 and num_list[1] < y_max:
		y_max = num_list[1]
if x_min > x_max or y_min > y_max:
	print(0)
else:
	print((x_max - x_min) * (y_max - y_min))


url = 'https://atcoder.jp//contests/abc047/tasks/abc047_b'

def main():
	(w, h, n) = list(map(int, input().split()))
	xya = [list(map(int, input().split())) for _ in range(n)]
	(x, y) = ([0, w], [0, h])
	for low in xya:
		if low[2] == 1 and x[0] < low[0]:
			x[0] = low[0]
		elif low[2] == 2 and x[1] > low[0]:
			x[1] = low[0]
		elif low[2] == 3 and y[0] < low[1]:
			y[0] = low[1]
		elif low[2] == 4 and y[1] > low[1]:
			y[1] = low[1]
	xs = x[1] - x[0]
	ys = y[1] - y[0]
	if xs < 0 or ys < 0:
		print(0)
	else:
		ans = xs * ys
		print(ans)

def __starting_point():
	main()
__starting_point()


(w, h, n) = list(map(int, input().split()))
plots = [list(map(int, input().split())) for _ in range(n)]
(w_min, w_max, h_min, h_max) = (0, w, 0, h)
for i in range(n):
	if plots[i][2] == 1:
		w_min = max(w_min, plots[i][0])
	elif plots[i][2] == 2:
		w_max = min(w_max, plots[i][0])
	elif plots[i][2] == 3:
		h_min = max(h_min, plots[i][1])
	else:
		h_max = min(h_max, plots[i][1])
print(max(0, w_max - w_min) * max(0, h_max - h_min))


(W, H, N) = map(int, input().split())
(w, h) = (0, 0)
for _ in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		if w < x:
			w = x
	elif a == 2:
		if W > x:
			W = x
	elif a == 3:
		if h < y:
			h = y
	elif a == 4:
		if H > y:
			H = y
if W - w < 0 or H - h < 0:
	print(0)
else:
	print((W - w) * (H - h))


(w, h, N) = map(int, input().split())
n = h
e = 0
w = w
s = 0
for _ in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		e = max(e, x)
	elif a == 2:
		w = min(w, x)
	elif a == 3:
		s = max(s, y)
	else:
		n = min(n, y)
print(0 if e >= w or s >= n else (n - s) * (w - e))


(W, H, N) = [int(x) for x in input().split()]
x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(N):
	(x, y, a) = [int(x) for x in input().split()]
	if a == 1:
		x_min = max(x_min, x)
	elif a == 2:
		x_max = min(x_max, x)
	elif a == 3:
		y_min = max(y_min, y)
	else:
		y_max = min(y_max, y)
area = max(0, x_max - x_min) * max(0, y_max - y_min)
print(area)


class Combination:

	def __init__(self, n, mod):
		self.n = n
		self.mod = mod
		self.fac = [1 for i in range(self.n + 1)]
		self.finv = [1 for i in range(self.n + 1)]
		for i in range(2, self.n + 1):
			self.fac[i] = self.fac[i - 1] * i % self.mod
			self.finv[i] = self.finv[i - 1] * pow(i, -1, self.mod) % self.mod

	def comb(self, n, m):
		return self.fac[n] * (self.finv[n - m] * self.finv[m] % self.mod) % self.mod

def iparse():
	return list(map(int, input().split()))

def __starting_point():
	(w, h, n) = iparse()
	xmax = w
	xmin = 0
	ymin = 0
	ymax = h
	for i in range(n):
		(x, y, a) = iparse()
		if a == 1:
			xmin = max(xmin, x)
		if a == 2:
			xmax = min(xmax, x)
		if a == 3:
			ymin = max(ymin, y)
		if a == 4:
			ymax = min(ymax, y)
	print(max(xmax - xmin, 0) * max(0, ymax - ymin))
__starting_point()


(w, h, n) = map(int, input().split())
xl = 0
xr = w
yd = 0
yu = h
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		xl = max(xl, x)
	if a == 2:
		xr = min(xr, x)
	if a == 3:
		yd = max(yd, y)
	if a == 4:
		yu = min(yu, y)
print(max(0, xr - xl) * max(0, yu - yd))


(W, H, N) = map(int, input().split())
(A, B, C, D) = ([0], [W], [0], [H])
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		A.append(x)
	elif a == 2:
		B.append(x)
	elif a == 3:
		C.append(y)
	elif a == 4:
		D.append(y)
W = min(B) - max(A)
H = min(D) - max(C)
if W < 0 or H < 0:
	ans = 0
else:
	ans = H * W
print(ans)


(w, h, n) = map(int, input().split())
hl = 0
hu = w
wl = 0
wu = h
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		hl = max(x, hl)
	if a == 2:
		hu = min(x, hu)
	if a == 3:
		wl = max(y, wl)
	if a == 4:
		wu = min(y, wu)
print(max(0, hu - hl) * max(0, wu - wl))


(w, h, n) = map(int, input().split())
x = y = 0
for i in range(n):
	(xi, yi, a) = map(int, input().split())
	if a == 1:
		x = max(x, xi)
	elif a == 2:
		w = min(w, xi)
	elif a == 3:
		y = max(y, yi)
	elif a == 4:
		h = min(h, yi)
print(0 if x >= w or y >= h else (w - x) * (h - y))


(w, h, n) = map(int, input().split())
(max_x, min_x, max_y, min_y) = (w, 0, h, 0)
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		min_x = max(min_x, x)
	elif a == 2:
		max_x = min(max_x, x)
	elif a == 3:
		min_y = max(min_y, y)
	elif a == 4:
		max_y = min(max_y, y)
print(max(0, max_x - min_x) * max(0, max_y - min_y))


(nim, mike, kite) = map(int, input().split())
x1 = 0
y1 = 0
x2 = nim
y2 = mike
for i in range(kite):
	(x, y, a) = map(int, input().split())
	if a == 1:
		x1 = max(x1, x)
	elif a == 2:
		x2 = min(x2, x)
	elif a == 3:
		y1 = max(y1, y)
	elif a == 4:
		y2 = min(y2, y)
print(max(0, x2 - x1) * max(0, y2 - y1))


(W, H, N) = map(int, input().split())
L = 0
R = W
D = 0
U = H
for _ in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		L = max(L, x)
	if a == 2:
		R = min(R, x)
	if a == 3:
		D = max(D, y)
	if a == 4:
		U = min(U, y)
x = max(0, R - L)
y = max(0, U - D)
answer = x * y
print(answer)


def main():
	(W, H, N) = list(map(int, input().split()))
	X = Y = 0
	for i in range(N):
		(x, y, a) = list(map(int, input().split()))
		if a == 1:
			X = max(X, x)
		elif a == 2:
			W = min(W, x)
		elif a == 3:
			Y = max(Y, y)
		else:
			H = min(H, y)
	print(max(W - X, 0) * max(H - Y, 0))
main()


def main():
	(W, H, N) = list(map(int, input().split()))
	X = 0
	Y = 0
	for _ in range(N):
		(x, y, a) = list(map(int, input().split()))
		if a == 1:
			X = max(X, x)
		elif a == 2:
			W = min(W, x)
		elif a == 3:
			Y = max(Y, y)
		elif a == 4:
			H = min(H, y)
	S = max(W - X, 0) * max(H - Y, 0)
	print(S)

def __starting_point():
	main()
__starting_point()


(w, h, n) = map(int, input().split())
x = [0] * n
y = [0] * n
a = [0] * n
for i in range(n):
	(x[i], y[i], a[i]) = map(int, input().split())
w_l = 0
h_l = 0
for i in range(n):
	if a[i] == 1:
		if w_l < x[i]:
			w_l = x[i]
	elif a[i] == 2:
		if w > x[i]:
			w = x[i]
	elif a[i] == 3:
		if h_l < y[i]:
			h_l = y[i]
	elif a[i] == 4:
		if h > y[i]:
			h = y[i]
W = w - w_l
H = h - h_l
if W < 0 or H < 0:
	ans = 0
else:
	ans = W * H
print(ans)


(w, h, n) = map(int, input().split())
(p, q, r, s) = (0, w, 0, h)
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		p = max(p, x)
	elif a == 2:
		q = min(q, x)
	elif a == 3:
		r = max(r, y)
	elif a == 4:
		s = min(s, y)
print(max(0, q - p) * max(0, s - r))


import sys
import math
inint = lambda : int(sys.stdin.readline())
inintm = lambda : map(int, sys.stdin.readline().split())
inintl = lambda : list(inintm())
instrm = lambda : map(str, sys.stdin.readline().split())
instrl = lambda : list(instrm())
(w, h, n) = inintm()
ll = [0, 0]
rh = [w, h]
for i in range(n):
	(x, y, a) = inintm()
	if a == 1:
		ll[0] = max(ll[0], x)
	elif a == 2:
		rh[0] = min(rh[0], x)
	elif a == 3:
		ll[1] = max(ll[1], y)
	else:
		rh[1] = min(rh[1], y)
if rh[0] - ll[0] < 0 or rh[1] - ll[1] < 0:
	print(0)
else:
	print((rh[0] - ll[0]) * (rh[1] - ll[1]))


(w, h, n) = map(int, input().split())
(lx, hx, ly, hy) = (0, w, 0, h)
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		lx = max(lx, x)
	elif a == 2:
		hx = min(hx, x)
	elif a == 3:
		ly = max(ly, y)
	elif a == 4:
		hy = min(hy, y)
print(max(0, hx - lx) * max(0, hy - ly))


(w, h, n) = map(int, input().split())
a = [[int(i) for i in input().split()] for j in range(n)]
S = [[0, w], [0, h]]
for i in a:
	if i[2] == 1:
		S[0][0] = max(i[0], S[0][0])
	if i[2] == 2:
		S[0][1] = min(i[0], S[0][1])
	if i[2] == 3:
		S[1][0] = max(i[1], S[1][0])
	if i[2] == 4:
		S[1][1] = min(i[1], S[1][1])
ans = max(0, S[0][1] - S[0][0]) * max(0, S[1][1] - S[1][0])
print(ans)


(w, h, n) = map(int, input().split())
l = [[int(j) for j in input().split()] for i in range(n)]
b = c = 0
d = w
e = h
for i in range(n):
	a = l[i][2]
	if a == 1:
		b = max(b, l[i][0])
	if a == 2:
		d = min(d, l[i][0])
	if a == 3:
		c = max(c, l[i][1])
	if a == 4:
		e = min(e, l[i][1])
print([(d - b) * (e - c), 0][(d < b) | (e < c)])


(W, H, N) = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
(L, R, U, D) = (0, W, H, 0)
for p in P:
	(x, y, a) = p
	if a == 1:
		L = max(L, x)
	elif a == 2:
		R = min(R, x)
	elif a == 3:
		D = max(D, y)
	else:
		U = min(U, y)
print(max(U - D, 0) * max(R - L, 0))


(w, h, n) = map(int, input().split())
chk = [0] * 101
wx = [1] * w
wy = [1] * h
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		wx[:x] = chk[:x]
	elif a == 2:
		wx[x:] = chk[x + 1:w - 1]
	elif a == 3:
		wy[:y] = chk[:y]
	else:
		wy[y:] = chk[y + 1:h - 1]
ws = wx.count(1) * wy.count(1)
print(ws)


(W, H, N) = map(int, input().split())
xl = yd = 0
xr = W
yu = H
for _ in range(N):
	(X, Y, A) = map(int, input().split())
	if A == 1:
		xl = max(X, xl)
	elif A == 2:
		xr = min(X, xr)
	elif A == 3:
		yd = max(Y, yd)
	elif A == 4:
		yu = min(Y, yu)
s = max(0, xr - xl) * max(0, yu - yd)
print(s)


import math
from math import gcd, pi, sqrt
INF = float('inf')
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return list(map(int, input().split()))

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	(w, h, n) = i_map()
	up = h
	right = w
	down = 0
	left = 0
	for i in range(n):
		(x, y, a) = i_map()
		if a == 1:
			left = max(left, x)
		elif a == 2:
			right = min(right, x)
		elif a == 3:
			down = max(down, y)
		else:
			up = min(up, y)
	print(max(up - down, 0) * max(right - left, 0))

def __starting_point():
	main()
__starting_point()


(w, h, n) = map(int, input().split())
lx = 0
rx = w
by = 0
ty = h
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		lx = max(lx, x)
	elif a == 2:
		rx = min(rx, x)
	elif a == 3:
		by = max(by, y)
	else:
		ty = min(ty, y)
if rx - lx > 0 and ty - by > 0:
	print((rx - lx) * (ty - by))
else:
	print(0)


(w, h, n) = list(map(int, input().split()))
(ox, oy) = (0, 0)
for i in range(n):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		if ox < x:
			ox = x
	elif a == 2:
		if w > x:
			w = x
	elif a == 3:
		if oy < y:
			oy = y
	elif h > y:
		h = y
print(max(w - ox, 0) * max(h - oy, 0))


o1 = 0
o2 = 0
oo1 = 0
oo2 = 0
(w, h, n) = map(int, input().split())
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		oo1 = max(o1 + x, oo1)
	elif a == 2:
		w = min(x, w)
	elif a == 3:
		oo2 = max(o2 + y, oo2)
	else:
		h = min(y, h)
if oo1 >= w or oo2 >= h:
	print(0)
else:
	print((w - oo1) * (h - oo2))


(W, H, N) = map(int, input().split())
(x, y, a) = ([0] * N, [0] * N, [0] * N)
for i in range(N):
	(x[i], y[i], a[i]) = map(int, input().split())
xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):
	if a[i] == 1:
		xmin = max(x[i], xmin)
	elif a[i] == 2:
		xmax = min(x[i], xmax)
	elif a[i] == 3:
		ymin = max(y[i], ymin)
	else:
		ymax = min(y[i], ymax)
height = ymax - ymin
width = xmax - xmin
if height <= 0 or width <= 0:
	print(0)
else:
	print(height * width)


(W, H, N) = map(int, input().split())
maxX = W
maxY = H
minX = 0
minY = 0
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		minX = max(minX, x)
	elif a == 2:
		maxX = min(maxX, x)
	elif a == 3:
		minY = max(minY, y)
	else:
		maxY = min(maxY, y)
print(max(maxX - minX, 0) * max(maxY - minY, 0))


(w, h, n) = map(int, input().split())
(o, p, q, r) = (0, 0, 0, 0)
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		o = max(o, x)
	elif a == 2:
		p = max(p, w - x)
	elif a == 3:
		q = max(q, y)
	elif a == 4:
		r = max(r, h - y)
w -= o + p
h -= q + r
if w > 0 and h > 0:
	print(w * h)
else:
	print(0)


(w, h, n) = map(int, input().split())
(right, left, lower, upper) = (0, w, 0, h)
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		right = max(right, x)
	if a == 2:
		left = min(left, x)
	if a == 3:
		lower = max(lower, y)
	if a == 4:
		upper = min(upper, y)
a = left - right
b = upper - lower
if a <= 0 or b <= 0:
	print(0)
else:
	print(a * b)


(w, h, n) = map(int, input().split())
xl = 0
xr = w
yd = 0
yu = h
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		xl = max(xl, x)
	elif a == 2:
		xr = min(xr, x)
	elif a == 3:
		yd = max(yd, y)
	else:
		yu = min(yu, y)
ans = max(xr - xl, 0) * max(yu - yd, 0)
print(ans)


(w, h, n) = map(int, input().split())
(l, r, u, d) = (0, w, h, 0)
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		l = max(l, x)
	elif a == 2:
		r = min(r, x)
	elif a == 3:
		d = max(d, y)
	else:
		u = min(u, y)
if u - d < 0 or r - l < 0:
	u = d
print((u - d) * (r - l))


(W, H, N) = list(map(int, input().split()))
xs = ys = 0
xe = W
ye = H
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	if a == 1 and x > xs:
		xs = x
	elif a == 2 and x < xe:
		xe = x
	elif a == 3 and y > ys:
		ys = y
	elif a == 4 and y < ye:
		ye = y
w = xe - xs
h = ye - ys
if w > 0 and h > 0:
	ans = w * h
else:
	ans = 0
print(ans)


(w, h, N) = list(map(int, input().split()))
rect = [0, w, 0, h]
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])([x, y][a > 2], rect[a - 1], [1, -1][a % 2])
length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))


(W, H, N) = map(int, input().split())
(X1, X2, Y1, Y2) = (0, W, 0, H)
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		X1 = max(x, X1)
	elif a == 2:
		X2 = min(x, X2)
	elif a == 3:
		Y1 = max(y, Y1)
	elif a == 4:
		Y2 = min(y, Y2)
print(max(0, X2 - X1) * max(0, Y2 - Y1))


(W, H, N) = map(int, input().split())
values = [[0], [W], [0], [H]]
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a <= 2:
		values[a - 1].append(x)
	elif a >= 3:
		values[a - 1].append(y)
print(max(0, min(values[1]) - max(values[0])) * max(0, min(values[3]) - max(values[2])))


import numpy as np
(w, h, n) = list(map(int, input().split()))
area = np.zeros((w, h))
for i in range(n):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		area[:x, :] = 1
	elif a == 2:
		area[x:, :] = 1
	elif a == 3:
		area[:, :y] = 1
	else:
		area[:, y:] = 1
print(w * h - int(area.sum()))


import sys, math
from itertools import combinations as c, product as p
from collections import deque
sys.setrecursionlimit(10 ** 9)

def si():
	return input()

def ii():
	return int(input())

def fi():
	return float(input())

def lint():
	return list(map(int, input().split()))

def lint_dec():
	return list(map(lambda x: int(x) - 1, input().split()))

def lnstr(n):
	return [input() for _ in range(n)]

def lnint(n):
	return [int(input()) for _ in range(n)]

def lint_list(n):
	return [lint() for _ in range(n)]
(W, H, N) = lint()
queue = lint_list(N)
xmin = max([x for (x, y, a) in queue if a == 1] + [0])
xmax = min([x for (x, y, a) in queue if a == 2] + [W])
ymin = max([y for (x, y, a) in queue if a == 3] + [0])
ymax = min([y for (x, y, a) in queue if a == 4] + [H])
print(max(0, xmax - xmin) * max(0, ymax - ymin))


(w, h, n) = map(int, input().split())
ww = hh = 0
for _ in [0] * n:
	(x, y, a) = map(int, input().split())
	if a == 1:
		ww = max(ww, x)
	elif a == 2:
		w = min(w, x)
	elif a == 3:
		hh = max(hh, y)
	else:
		h = min(h, y)
print((w - ww) * (h - hh) * (w > ww) * (h > hh))


(w, h, n) = map(int, input().split())
(w1, h1, w2, h2) = (0, 0, w, h)
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		w1 = max(w1, x)
	elif a == 2:
		w2 = min(w2, x)
	elif a == 3:
		h1 = max(h1, y)
	elif a == 4:
		h2 = min(h2, y)
if w2 - w1 < 0 or h2 - h1 < 0:
	print(0)
else:
	print((w2 - w1) * (h2 - h1))


(w, h, n) = map(int, input().split())
points = []
area = [0, w, 0, h]
for i in range(n):
	(x, y, a) = map(int, input().split())
	points.append([x, y, a])
for i in range(n):
	if points[i][2] == 1:
		area[0] = max(area[0], points[i][0])
	if points[i][2] == 2:
		area[1] = min(area[1], points[i][0])
	if points[i][2] == 3:
		area[2] = max(area[2], points[i][1])
	if points[i][2] == 4:
		area[3] = min(area[3], points[i][1])
ans = max(0, area[1] - area[0]) * max(0, area[3] - area[2])
print(ans)


(w, h, n) = list(map(int, input().split()))
s_w = [0, w]
s_h = [0, h]
for _ in range(n):
	(x, y, a) = list(map(int, input().split()))
	if a == 1 and x > s_w[0]:
		s_w[0] = x
	elif a == 2 and x < s_w[1]:
		s_w[1] = x
	elif a == 3 and y > s_h[0]:
		s_h[0] = y
	elif a == 4 and y < s_h[1]:
		s_h[1] = y
ans_w = s_w[1] - s_w[0]
ans_h = s_h[1] - s_h[0]
print(ans_w * (ans_w > 0) * (ans_h * (ans_h > 0)))


(w, h, n) = list(map(int, input().split()))
xmin = 0
xmax = w
ymin = 0
ymax = h
for i in range(n):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		xmin = max(x, xmin)
	elif a == 2:
		xmax = min(x, xmax)
	elif a == 3:
		ymin = max(y, ymin)
	else:
		ymax = min(y, ymax)
print(max(0, xmax - xmin) * max(0, ymax - ymin))


import sys
input = sys.stdin.readline

def main():
	(W, H, N) = list(map(int, input().split()))
	X = [0, W]
	Y = [0, H]
	for i in range(N):
		(x, y, a) = list(map(int, input().split()))
		if a == 1:
			X[0] = max(x, X[0])
		elif a == 2:
			X[1] = min(x, X[1])
		elif a == 3:
			Y[0] = max(y, Y[0])
		else:
			Y[1] = min(y, Y[1])
	if X[1] <= X[0] or Y[1] <= Y[0]:
		ans = 0
	else:
		ans = (X[1] - X[0]) * (Y[1] - Y[0])
	print(ans)

def __starting_point():
	main()
__starting_point()


(W, H, N) = map(int, input().split())
n = H
e = 0
w = W
s = 0
for i in range(N):
	(X, Y, A) = map(int, input().split())
	if A == 1:
		e = max(e, X)
	elif A == 2:
		w = min(w, X)
	elif A == 3:
		s = max(s, Y)
	else:
		n = min(n, Y)
if e >= w or s >= n:
	print(0)
else:
	print((w - e) * (n - s))


(w, h, n) = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(n)]
My = h
Mx = w
my = 0
mx = 0
for (x, y, a) in xya:
	if a == 1 and mx < x:
		mx = x
	if a == 2 and Mx > x:
		Mx = x
	if a == 3 and my < y:
		my = y
	if a == 4 and My > y:
		My = y
if Mx - mx <= 0 or My - my <= 0:
	print(0)
else:
	print((Mx - mx) * (My - my))


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '5 4 2\n2 1 1\n3 3 4'
		output = '9'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '5 4 3\n2 1 1\n3 3 4\n1 4 2'
		output = '0'
		self.assertIO(input, output)

	def test_入力例_3(self):
		input = '10 10 5\n1 6 1\n4 1 3\n6 9 4\n9 4 2\n3 1 3'
		output = '64'
		self.assertIO(input, output)

def resolve():
	(W, H, N) = list(map(int, input().split()))
	a = []
	ox = 0
	oy = 0
	for _ in range(N):
		a.append(list(map(int, input().split())))
	for i in range(N):
		if a[i][2] == 1:
			ox = max(a[i][0], ox)
		elif a[i][2] == 2:
			W = min(a[i][0], W)
		elif a[i][2] == 3:
			oy = max(a[i][1], oy)
		elif a[i][2] == 4:
			H = min(a[i][1], H)
	print(max(W - ox, 0) * max(H - oy, 0))

def __starting_point():
	resolve()
__starting_point()


(W, H, N) = list(map(int, input().split()))
ans = [0, W, 0, H]
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		if ans[0] < x:
			ans[0] = x
	elif a == 2:
		if ans[1] > x:
			ans[1] = x
	elif a == 3:
		if ans[2] < y:
			ans[2] = y
	elif ans[3] > y:
		ans[3] = y
S = (ans[1] - ans[0]) * (ans[3] - ans[2])
if ans[1] - ans[0] < 0:
	print(0)
elif ans[3] - ans[2] < 0:
	print(0)
else:
	print(S)


(w, h, n) = map(int, input().split())
xa = 0
xb = w
ya = 0
yb = h
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		xa = max(x, xa)
	if a == 2:
		xb = min(x, xb)
	if a == 3:
		ya = max(y, ya)
	if a == 4:
		yb = min(y, yb)
print(max((xb - xa) * max(yb - ya, 0), 0))


(w, h, n) = map(int, input().split())
b = [0, w, 0, h]
for _ in range(n):
	(*a,) = map(int, input().split())
	s = int((a[2] % 2 - 0.5) * 2)
	b[a[2] - 1] = s * max(s * a[a[2] // 3], s * b[a[2] - 1])
print(max(b[1] - b[0], 0) * max(b[3] - b[2], 0))


(w, h, n) = map(int, input().split())
sq = [0, -w, 0, -h]
for i in range(n):
	(x, y, b) = map(int, input().split())
	dumy = [x, -x, y, -y]
	a = b - 1
	if sq[a] < dumy[a]:
		sq[a] = dumy[a]
if -sq[1] - sq[0] < 0:
	s = 0
elif -sq[3] - sq[2] < 0:
	s = 0
else:
	s = (-sq[1] - sq[0]) * (-sq[3] - sq[2])
print(s)


import sys
imput = sys.stdin.read
(w, h, n) = map(int, input().split())
t = [list(map(int, input().split())) for i in range(n)]
su = []
st = []
sv = []
sw = []
sux = svy = 0
stx = w
swy = h
for j in range(n):
	if t[j][2] == 1:
		su.append(t[j][0])
		sux = max(su)
	elif t[j][2] == 2:
		st.append(t[j][0])
		stx = min(st)
	elif t[j][2] == 3:
		sv.append(t[j][1])
		svy = max(sv)
	else:
		sw.append(t[j][1])
		swy = min(sw)
if sux - stx >= 0 or svy - swy >= 0:
	print(0)
else:
	print((stx - sux) * (swy - svy))


(w, h, n) = map(int, input().split())
(x1, x2, y1, y2) = (0, w, 0, h)
for _ in range(n):
	(xi, yi, ai) = map(int, input().split())
	if ai == 1:
		x1 = max(xi, x1)
	elif ai == 2:
		x2 = min(xi, x2)
	elif ai == 3:
		y1 = max(yi, y1)
	else:
		y2 = min(yi, y2)
dx = max(0, x2 - x1)
dy = max(0, y2 - y1)
print(dx * dy)


(w, h, n) = map(int, input().split())
s = 0
b = w
t = 0
c = h
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		s = max(s, x)
	elif a == 2:
		b = min(b, x)
	elif a == 3:
		t = max(t, y)
	else:
		c = min(c, y)
if b > s and c > t:
	print((b - s) * (c - t))
else:
	print(0)


(w, h, n) = map(int, input().split())
L = [list(map(int, input().split())) for i in range(n)]
x1 = 0
x2 = w
y1 = 0
y2 = h
for i in range(n):
	if L[i][2] == 1:
		x1 = max(L[i][0], x1)
	if L[i][2] == 2:
		x2 = min(L[i][0], x2)
	if L[i][2] == 3:
		y1 = max(L[i][1], y1)
	if L[i][2] == 4:
		y2 = min(L[i][1], y2)
ans = 0
if x2 >= x1 and y2 >= y1:
	ans = (x2 - x1) * (y2 - y1)
print(ans)


(W, H, N) = map(int, input().split())
(Xu, Xd, Yu, Yd) = (W, 0, H, 0)
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		Xd = max(Xd, x)
	elif a == 2:
		Xu = min(Xu, x)
	elif a == 3:
		Yd = max(Yd, y)
	elif a == 4:
		Yu = min(Yu, y)
X = max(0, Xu - Xd)
Y = max(0, Yu - Yd)
print(X * Y)


(w, h, n) = map(int, input().split())
l = [0, w, 0, h]
for i in range(n):
	(a, c, d) = map(int, input().split())
	x = c if d // 3 else a
	f = min if (d - 1) % 2 else max
	l[d - 1] = f(l[d - 1], x)
if l[0] < l[1] and l[2] < l[3]:
	print((l[1] - l[0]) * (l[3] - l[2]))
else:
	print(0)


(width, height, num) = map(int, input().rstrip('\n').split())
area = [0, width, 0, height]
for _ in range(num):
	(x, y, a) = map(int, input().rstrip('\n').split())
	area[a - 1] = [max, min][(a - 1) % 2](area[a - 1], [x, y][a > 2])
print(max(0, area[1] - area[0]) * max(0, area[3] - area[2]))


(w, h, n) = map(int, input().split())
(a1, a2, a3, a4) = (0, w, 0, h)
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		a1 = max(a1, x)
	elif a == 2:
		a2 = min(a2, x)
	elif a == 3:
		a3 = max(a3, y)
	else:
		a4 = min(a4, y)
print(max(a2 - a1, 0) * max(a4 - a3, 0))


(w, h, n) = map(int, input().split())
w_d = 0
h_d = 0
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		w_d = max(w_d, x)
	if a == 2:
		w = min(w, x)
	if a == 3:
		h_d = max(h_d, y)
	if a == 4:
		h = min(h, y)
if w <= w_d or h <= h_d:
	print(0)
else:
	print((w - w_d) * (h - h_d))


(W, H, N) = map(int, input().split())
array = [list(map(int, input().split())) for i in range(N)]
xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):
	if array[i][2] == 1:
		xmin = max(xmin, array[i][0])
	elif array[i][2] == 2:
		xmax = min(xmax, array[i][0])
	elif array[i][2] == 3:
		ymin = max(ymin, array[i][1])
	elif array[i][2] == 4:
		ymax = min(ymax, array[i][1])
area = (xmax - xmin) * (ymax - ymin)
if area <= 0 or xmax < xmin or ymax < ymin:
	print(0)
else:
	print(area)


(w, h, n) = map(int, input().split())
xya = [list(map(int, input().split())) for _ in [0] * n]
minx = max([x for (x, y, a) in xya if a == 1] + [0])
maxx = min([x for (x, y, a) in xya if a == 2] + [w])
miny = max([y for (x, y, a) in xya if a == 3] + [0])
maxy = min([y for (x, y, a) in xya if a == 4] + [h])
print(max(0, maxx - minx) * max(0, maxy - miny))