AtCoder Beginner Contest 047 - Snuke's Coloring 2 (ABC Edit)

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.

Source: atcoder | 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())
A = 0
B = W
C = 0
D = H
for _ in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		A = max(A, x)
	elif a == 2:
		B = min(B, x)
	elif a == 3:
		C = max(C, y)
	else:
		D = min(D, y)
print(max(B - A, 0) * max(0, D - C))


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


(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) = list(map(int, input().split()))
white = [[1 for _ in range(H)] for _ in range(W)]
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		for i in range(x):
			for j in range(H):
				white[i][j] = 0
	elif a == 2:
		for i in range(x, W):
			for j in range(H):
				white[i][j] = 0
	elif a == 3:
		for i in range(W):
			for j in range(y):
				white[i][j] = 0
	else:
		for i in range(W):
			for j in range(y, H):
				white[i][j] = 0
print(sum((sum(x) for x in white)))


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


(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())
(p, q) = ([0, w], [0, h])
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		p[0] = max(p[0], x)
	elif a == 2:
		p[1] = min(p[1], x)
	elif a == 3:
		q[0] = max(q[0], y)
	else:
		q[1] = min(q[1], y)
s = (p[1] - p[0]) * (q[1] - q[0])
print(s if p[0] <= p[1] and q[0] <= q[1] else 0)


(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())
R = [0, 0, W, 0, H]
for _ in [0] * N:
	(*wh, a) = map(int, input().split())
	R[a] = eval(['min', 'max'][a % 2] + '(R[a],wh[a//3])')
(_, w, W, h, H) = R
print((W - w) * (H - h) * (W > w) * (H > h))


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


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


(W, H, N) = list(map(int, input().split()))
X = []
Y = []
A = []
field = [[0] * W for _ in range(H)]
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	X.append(x)
	Y.append(y)
	A.append(a)
for i in range(N):
	if A[i] == 1:
		for j in range(X[i]):
			for k in range(H):
				field[k][j] = 1
	elif A[i] == 2:
		for j in range(X[i], W):
			for k in range(H):
				field[k][j] = 1
	elif A[i] == 3:
		for j in range(W):
			for k in range(Y[i]):
				field[k][j] = 1
	else:
		for j in range(W):
			for k in range(Y[i], H):
				field[k][j] = 1
Sum = 0
for i in range(W):
	for j in range(H):
		if field[j][i] == 0:
			Sum += 1
print(Sum)


(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)


whn = list(map(int, input().split()))
(w, h, n) = (whn[0], whn[1], whn[2])
xyas = [list(map(int, input().split())) for _ in range(n)]
c = [[1 for _ in range(h)] for _ in range(w)]
for xya in xyas:
	(x, y, a) = (xya[0], xya[1], xya[2])
	if a == 1:
		for i in range(x):
			c[i] = [0 for _ in range(h)]
	elif a == 2:
		for i in range(x, w):
			c[i] = [0 for _ in range(h)]
	elif a == 3:
		for i in range(w):
			for j in range(y):
				c[i][j] = 0
	elif a == 4:
		for i in range(w):
			for j in range(y, h):
				c[i][j] = 0
print(sum([sum(c2) for c2 in c]))


(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))


(W, H, N) = map(int, input().split())
(L, R, D, U) = (0, W, 0, H)
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)
print(max(0, R - L) * max(0, U - D))


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())
l = [[0] * w for _ in range(h)]
count = 0
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		for i in range(h):
			for j in range(x):
				if l[i][j] == 0:
					l[i][j] = 1
					count += 1
	if a == 2:
		for i in range(h):
			for j in range(x, w):
				if l[i][j] == 0:
					l[i][j] = 1
					count += 1
	if a == 3:
		for i in range(y):
			for j in range(w):
				if l[i][j] == 0:
					l[i][j] = 1
					count += 1
	if a == 4:
		for i in range(y, h):
			for j in range(w):
				if l[i][j] == 0:
					l[i][j] = 1
					count += 1
print(w * h - count)


(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())
W = [1] * w
H = [1] * h
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		for j in range(x):
			W[j] = 0
	elif a == 2:
		for j in range(x, w):
			W[j] = 0
	elif a == 3:
		for j in range(y):
			H[j] = 0
	elif a == 4:
		for j in range(y, h):
			H[j] = 0
print(sum(W) * sum(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())
x_b = w
x_s = 0
y_b = h
y_s = 0
for i in range(1, n + 1):
	(x, y, a) = map(int, input().split())
	if a == 2:
		x_b = min(x, x_b)
	elif a == 1:
		x_s = max(x, x_s)
	elif a == 4:
		y_b = min(y, y_b)
	else:
		y_s = max(y, y_s)
if x_b <= x_s or y_b <= y_s:
	print(0)
else:
	print((x_b - x_s) * (y_b - y_s))


(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())
p = 0
q = w
r = 0
s = h
for k in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1 and x > p:
		p = x
	if a == 2 and x < q:
		q = x
	if a == 3 and y > r:
		r = y
	if a == 4 and y < s:
		s = y
if q - p > 0 and s - r > 0:
	print((q - p) * (s - r))
else:
	print(0)


(w, h, n) = map(int, input().split())
(xl, xr) = (0, w)
(yl, yu) = (0, h)
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)
	else:
		yu = min(yu, y)
print((xr - xl) * (yu - yl)) if xl < xr and yl < yu else print(0)


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


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


(W, H, N) = (int(T) for T in input().split())
XYA = [[0], [W], [0], [H]]
for TN in range(0, N):
	(X, Y, A) = (int(T) for T in input().split())
	if A in [1, 2]:
		XYA[A - 1].append(X)
	else:
		XYA[A - 1].append(Y)
CW = min(XYA[1]) - max(XYA[0])
CH = min(XYA[3]) - max(XYA[2])
if CW >= 0 and CH >= 0:
	print(CW * CH)
else:
	print(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, a) = ([], [], [])
for i in range(n):
	(X, Y, A) = map(int, input().split())
	x.append(X)
	y.append(Y)
	a.append(A)
zahyou = [[1 for _ in range(h)] for __ in range(w)]

def m1(d):
	for i in range(d):
		for j in range(h):
			zahyou[i][j] = 0

def m2(d):
	for i in range(w - d):
		for j in range(h):
			zahyou[i + d][j] = 0

def m3(d):
	for i in range(w):
		for j in range(d):
			zahyou[i][j] = 0

def m4(d):
	for i in range(w):
		for j in range(h - d):
			zahyou[i][j + d] = 0
for i in range(n):
	if a[i] == 1:
		m1(x[i])
	elif a[i] == 2:
		m2(x[i])
	elif a[i] == 3:
		m3(y[i])
	else:
		m4(y[i])
print(sum(map(sum, zahyou)))


(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))


import numpy as np
(w, h, n) = map(int, input().split())
b = np.zeros((h, w), dtype=np.int)
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		b[:, :x] = 1
	elif a == 2:
		b[:, x:] = 1
	elif a == 3:
		b[:y, :] = 1
	else:
		b[y:, :] = 1
print(np.count_nonzero(b < 1))


(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())
query = [tuple(map(int, input().split())) for _ in range(n)]
(sx, sy) = (0, 0)
for (x, y, a) in query:
	if a == 1:
		sx = max(sx, x)
	elif a == 2:
		w = min(w, x)
	elif a == 3:
		sy = max(sy, y)
	else:
		h = min(h, y)
print(max(0, w - sx) * max(0, h - sy))


(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))


p1 = [0, 0]
(*p2, N) = map(int, input().split())
for _ in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1 and p1[0] < x:
		p1[0] = x
	elif a == 2 and p2[0] > x:
		p2[0] = x
	elif a == 3 and p1[1] < y:
		p1[1] = y
	elif a == 4 and p2[1] > y:
		p2[1] = y
else:
	print(max(0, p2[0] - p1[0]) * max(0, p2[1] - p1[1]))


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


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


(W, H, N) = [int(n) for n in input().split()]
sx = 0
ex = W
sy = 0
ey = H
for n in range(N):
	(x, y, a) = [int(w) for w in input().split()]
	if a == 1:
		sx = max(sx, x)
	elif a == 2:
		ex = min(ex, x)
	elif a == 3:
		sy = max(sy, y)
	else:
		ey = min(ey, y)
print(max(0, ex - sx) * max(0, ey - sy))


(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)
	elif a == 2:
		r = min(r, x)
	elif a == 3:
		d = max(d, y)
	elif a == 4:
		u = min(u, y)
print(max(r - l, 0) * max(u - d, 0))


(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))


(xr, yt, n, *l) = map(int, open(0).read().split())
xl = yb = 0
for (x, y, a) in zip(*[iter(l)] * 3):
	if a == 1:
		xl = max(xl, x)
	elif a == 2:
		xr = min(xr, x)
	elif a == 3:
		yb = max(yb, y)
	else:
		yt = min(yt, y)
print(max(0, xr - xl) * max(0, yt - yb))


(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)


(W, H, N) = map(int, input().split())
b = 0
t = H
l = 0
r = W
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:
		b = max(b, y)
	else:
		assert a == 4
		t = min(t, y)
print(max(t - b, 0) * max(r - l, 0))


(W, H, N) = map(int, input().split())
x = []
y = []
a = []
X = [1] * W
Y = [1] * H
ans = 0
for _ in range(N):
	(i, j, k) = map(int, input().split())
	x.append(i)
	y.append(j)
	a.append(k)
for i in range(N):
	if a[i] == 1:
		for j in range(x[i]):
			X[j] = 0
	elif a[i] == 2:
		for j in range(x[i], W):
			X[j] = 0
	elif a[i] == 3:
		for j in range(y[i]):
			Y[j] = 0
	else:
		for j in range(y[i], H):
			Y[j] = 0
for i in range(H):
	for j in range(W):
		if X[j] and Y[i]:
			ans += 1
print(ans)


(w, h, n) = list(map(int, input().split()))
ans = [[0 for _ in range(w)] for _ in range(h)]
for i in range(n):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		for j in range(h):
			ans[j][:x] = [1 for _ in range(x)]
	if a == 2:
		for j in range(h):
			ans[j][x:] = [1 for _ in range(w - x)]
	if a == 3:
		for j in range(h - y, h):
			ans[j] = [1 for _ in range(w)]
	if a == 4:
		for j in range(h - y):
			ans[j] = [1 for _ in range(w)]
cnt = 0
for k in ans:
	cnt += k.count(0)
print(cnt)


(w, h, n) = map(int, input().split())
X = [list(map(int, input().split())) for i in range(n)]
A = [0, -w, 0, -h]
for i in range(n):
	j = X[i][2] - 1
	A[j] = max(A[j], X[i][j // 2] * (-1) ** j)
print(max(0, -A[1] - A[0]) * max(0, -A[3] - A[2]))


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())
s = [[1 for i in range(w)] for j in range(h)]
b = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
alist = []
for i in range(n):
	(x, y, a) = map(int, input().split())
	alist.append(a)
	if a == 1:
		for j in range(h):
			for k in range(0, x):
				s[j][k] = 0
	if a == 2:
		for j in range(h):
			for k in range(x, w):
				s[j][k] = 0
	if a == 3:
		for k in range(w):
			for j in range(0, y):
				s[j][k] = 0
	if a == 4:
		for k in range(w):
			for j in range(y, h):
				s[j][k] = 0
ans = 0
for i in range(h):
	ans = ans + s[i].count(1)
print(ans)


(w, h, n) = map(int, input().split())
s = [0, w, 0, h]
for i in range(n):
	p = list(map(int, input().split()))
	if p[2] == 1 or p[2] == 3:
		s[p[2] - 1] = max(p[p[2] // 2], s[p[2] - 1])
	else:
		s[p[2] - 1] = min(p[p[2] // 2 - 1], s[p[2] - 1])
print(max(s[1] - s[0], 0) * max(s[3] - s[2], 0))


(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))


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


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


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


(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) = [int(x) for x in input().split()]
a = []
for i in range(n):
	a.append([int(x) for x in input().split()])
mp = [[0] * h for x in range(w)]
for i in range(n):
	if a[i][2] == 1:
		for j in range(a[i][0]):
			for k in range(h):
				mp[j][k] = 1
	elif a[i][2] == 2:
		for j in range(a[i][0], w):
			for k in range(h):
				mp[j][k] = 1
	elif a[i][2] == 3:
		for j in range(w):
			for k in range(a[i][1]):
				mp[j][k] = 1
	elif a[i][2] == 4:
		for j in range(w):
			for k in range(a[i][1], h):
				mp[j][k] = 1
res = 0
for i in range(w):
	for j in range(h):
		if mp[i][j] == 0:
			res += 1
print(res)


(W, H, N) = map(int, input().split())
L = 0
R = W
B = 0
T = H
for i in range(N):
	(x, y, a) = map(int, input().split())
	if a == 1:
		L = max(x, L)
	if a == 2:
		R = min(R, x)
	if a == 3:
		B = max(B, y)
	if a == 4:
		T = min(T, y)
if R < L or T < B:
	print(0)
else:
	print((R - L) * (T - B))


import sys
input = sys.stdin.readline

def read():
	(W, H, N) = list(map(int, input().strip().split()))
	XYA = []
	for i in range(N):
		(x, y, a) = list(map(int, input().strip().split()))
		XYA.append((x, y, a))
	return (W, H, N, XYA)

def solve(W, H, N, XYA):
	S = [[0 for j in range(W + 1)] for i in range(H + 1)]
	for (x, y, a) in XYA:
		if a == 1:
			(lt, rt, lb, rb) = ((0, 0), (x, 0), (0, H), (x, H))
		elif a == 2:
			(lt, rt, lb, rb) = ((x, 0), (W, 0), (x, H), (W, H))
		elif a == 3:
			(lt, rt, lb, rb) = ((0, 0), (W, 0), (0, y), (W, y))
		elif a == 4:
			(lt, rt, lb, rb) = ((0, y), (W, y), (0, H), (W, H))
		S[lt[1]][lt[0]] += 1
		S[rt[1]][rt[0]] -= 1
		S[lb[1]][lb[0]] -= 1
		S[rb[1]][rb[0]] += 1
	for i in range(H):
		for j in range(W + 1):
			S[i + 1][j] += S[i][j]
	for i in range(H + 1):
		for j in range(W):
			S[i][j + 1] += S[i][j]
	ans = 0
	for i in range(H):
		for j in range(W):
			if S[i][j] == 0:
				ans += 1
	return ans

def __starting_point():
	inputs = read()
	print(solve(*inputs))
__starting_point()


lst = input().split()
W = int(lst[0])
H = int(lst[1])
N = int(lst[2])
field = [[0] * W] * H
L = []
for i in range(N):
	L = input().split()
	if L[2] == '1':
		for j in range(H):
			for k in range(int(L[0])):
				field[j][k] = 1
	elif L[2] == '2':
		for j in range(H):
			for k in range(int(L[0]), W):
				field[j][k] = 1
	elif L[2] == '3':
		for j in range(int(L[1])):
			field[j] = [1] * W
	elif L[2] == '4':
		for j in range(int(L[1]), H):
			field[j] = [1] * W
ans = 0
for s in field:
	ans += s.count(0)
print(ans)


(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) = list(map(int, input().split()))
X_Y_A = [list(map(int, input().split())) for _ in range(N)]
oX = 0
oY = 0
for (x, y, a) in X_Y_A:
	if a == 1:
		oX = max(x, oX)
	elif a == 2:
		W = min(x, W)
	elif a == 3:
		oY = max(y, oY)
	else:
		H = min(y, H)
print(max(0, W - oX) * max(0, H - oY))


(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))


(w, h, n) = map(int, input().split())
answ = set(range(w + 1))
ansh = set(range(w + 1))
for i in range(n):
	(x, y, a) = map(int, input().split())
	if a == 1:
		answ = answ & set(range(x, w + 1))
	elif a == 2:
		answ = answ & set(range(x + 1))
	elif a == 3:
		ansh = ansh & set(range(y, h + 1))
	elif a == 4:
		ansh = ansh & set(range(y + 1))
if len(answ) == 0 or len(ansh) == 0:
	print(0)
else:
	print((max(answ) - min(answ)) * (max(ansh) - min(ansh)))


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))


(h, w, n) = map(int, input().split())
d = {1: 0, 2: h, 3: 0, 4: w}
for _ in range(n):
	(x, y, a) = map(int, input().split())
	if a % 2:
		d[a] = max(d[a], [x, y][a // 2])
	else:
		d[a] = min(d[a], [x, y][a // 2 - 1])
if d[1] > d[2] or d[3] > d[4]:
	print(0)
else:
	ans = (d[2] - d[1]) * (d[4] - d[3])
	print(ans)


(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) = list(map(int, input().split()))
xl = []
yl = []
al = []
for _ in range(n):
	(x, y, a) = list(map(int, input().split()))
	xl.append(x)
	yl.append(y)
	al.append(a)
sx = 0
gx = w
sy = 0
gy = h
for i in range(len(al)):
	if al[i] == 1 and sx < xl[i]:
		sx = xl[i]
		if sx > gx:
			print(0)
			return
	elif al[i] == 2 and gx > xl[i]:
		gx = xl[i]
		if sx > gx:
			print(0)
			return
	elif al[i] == 3 and sy < yl[i]:
		sy = yl[i]
		if sy > gy:
			print(0)
			return
	elif al[i] == 4 and gy > yl[i]:
		gy = yl[i]
		if sy > gy:
			print(0)
			return
	if i == len(al) - 1:
		print((gx - sx) * (gy - sy))


(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())
data = list((input().split() for i in range(n)))
x_1 = 0
x_2 = w
y_1 = 0
y_2 = h
for i in range(n):
	if int(data[i][2]) == 1:
		if int(data[i][0]) > x_1:
			x_1 = int(data[i][0])
	elif int(data[i][2]) == 2:
		if int(data[i][0]) < x_2:
			x_2 = int(data[i][0])
	elif int(data[i][2]) == 3:
		if int(data[i][1]) > y_1:
			y_1 = int(data[i][1])
	elif int(data[i][1]) < y_2:
		y_2 = int(data[i][1])
if x_2 - x_1 <= 0 or y_2 - y_1 <= 0:
	print(0)
else:
	print((x_2 - x_1) * (y_2 - y_1))


(W, H, N) = list(map(int, input().split()))
max_x = 0
max_y = 0
min_x = W
min_y = H
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		max_x = max(max_x, x)
	elif a == 2:
		min_x = min(min_x, x)
	elif a == 3:
		max_y = max(max_y, y)
	else:
		min_y = min(min_y, y)
if min_x > max_x and min_y > max_y:
	print((min_x - max_x) * (min_y - max_y))
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)


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


(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) = list(map(int, input().split()))
m = [[0] * W] * H
import numpy as np
arr = np.array(m)
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		arr[:, :x] = 1
	if a == 2:
		arr[:, x:] = 1
	if a == 3:
		arr[H - y:, :] = 1
	if a == 4:
		arr[:H - y, :] = 1
print(np.count_nonzero(arr == 0))


(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])))


(w, h, n) = list(map(int, input().split()))
ans = [[0] * w for i in range(h)]
for i in range(n):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		for i in range(x):
			for j in range(h):
				ans[j][i] = 1
	elif a == 2:
		for i in range(x, w):
			for j in range(h):
				ans[j][i] = 1
	elif a == 3:
		for i in range(w):
			for j in range(y):
				ans[j][i] = 1
	elif a == 4:
		for i in range(w):
			for j in range(y, h):
				ans[j][i] = 1
cnt = 0
for i in ans:
	cnt += sum(i)
print(h * w - cnt)


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))


import bisect, collections, copy, itertools, math, string
import sys

def I():
	return int(sys.stdin.readline().rstrip())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def S():
	return sys.stdin.readline().rstrip()

def LS():
	return list(sys.stdin.readline().rstrip().split())

def main():
	(w, h, n) = LI()
	board = [[1] * h for _ in range(w)]
	for _ in range(n):
		(x, y, a) = LI()
		if a == 1:
			for i in range(x):
				board[i] = [0 for _ in range(h)]
		elif a == 2:
			for i in range(x, w):
				board[i] = [0 for _ in range(h)]
		elif a == 3:
			for i in range(w):
				for j in range(y):
					board[i][j] = 0
		elif a == 4:
			for i in range(w):
				for j in range(y, h):
					board[i][j] = 0
	ans = 0
	for line in board:
		ans += sum(line)
	print(ans)
main()


(X, Y, N) = list(map(int, input().split()))
lst = [[0 for i in range(X)] for j in range(Y)]
for i in list(range(N)):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		for j in range(Y):
			for k in range(x):
				lst[j][k] = 1
	elif a == 2:
		for j in range(Y):
			for k in range(X - 1, x - 1, -1):
				lst[j][k] = 1
	elif a == 3:
		for j in range(y):
			for k in range(X):
				lst[j][k] = 1
	elif a == 4:
		for j in range(Y - 1, y - 1, -1):
			for k in range(X):
				lst[j][k] = 1
count = 0
for i in lst:
	count += i.count(0)
print(count)


import numpy as np

def main():
	(w, h, n) = list(map(int, input().split()))
	xyas = [list(map(int, input().split())) for _ in range(n)]
	board = np.array([[0 for i in range(w)] for j in range(h)])
	for (x, y, a) in xyas:
		if a == 1:
			board[:, :x] = 1
		elif a == 2:
			board[:, x:] = 1
		elif a == 3:
			board[-y:, :] = 1
		elif a == 4:
			board[:-y, :] = 1
	ans = w * h - np.sum(board)
	print(ans)

def __starting_point():
	main()
__starting_point()


(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))


(W, H, N) = list(map(int, input().split()))
input_list = []
for i in range(N):
	input_list.append(list(map(int, input().split())))
point_list = []
for h in range(H):
	list_ = []
	for w in range(W):
		list_.append(1)
	point_list.append(list_)
for input_ in input_list:
	(x, y, a) = input_
	if a == 1:
		for h in range(H):
			for i in range(x):
				point_list[h][i] = 0
	if a == 2:
		for h in range(H):
			for i in range(x, W):
				point_list[h][i] = 0
	if a == 3:
		for i in range(y):
			for w in range(W):
				point_list[i][w] = 0
	if a == 4:
		for i in range(y, H):
			for w in range(W):
				point_list[i][w] = 0
ans = sum([sum(point) for point in point_list])
print(ans)


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())
b = d = 0
for _ in [0] * n:
	(x, y, a) = map(int, input().split())
	if a < 2:
		b = max(x, b)
	elif a < 3:
		w = min(x, w)
	elif a < 4:
		d = max(y, d)
	else:
		h = min(h, y)
print([(w - b) * (h - d), 0][(w < b) | (h < d)])


(w, h, n) = [int(i) for i in input().split()]
list_2d = [[0] * w for i in range(h)]

def nurie(x, y, a):
	if a == 1:
		for i in range(h):
			for j in range(x):
				list_2d[i][j] = 1
	elif a == 2:
		for i in range(h):
			for j in range(x, w):
				list_2d[i][j] = 1
	elif a == 3:
		for i in range(y):
			for j in range(w):
				list_2d[i][j] = 1
	else:
		for i in range(y, h):
			for j in range(w):
				list_2d[i][j] = 1
	return list_2d
for i in range(n):
	(x, y, a) = [int(i) for i in input().split()]
	nurie(x, y, a)
sum = 0
for i in range(h):
	sum += list_2d[i].count(0)
print(sum)


(r, t, n, *k) = map(int, open(0).read().split())
l = b = 0
M = max
for (x, y, a) in zip(*[iter(k)] * 3):
	exec(('l=M(l,x)', 'r=min(r,x)', 'b=M(b,y)', 't=min(t,y)')[a - 1])
print(M(0, r - l) * M(0, t - b))


(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())
xya = [list(map(int, input().split())) for _ in range(n)]
(x, y, a) = zip(*xya)
(xl, xr, yb, yt) = (0, w, 0, h)
for i in range(n):
	if a[i] == 1:
		xl = max(xl, x[i])
	elif a[i] == 2:
		xr = min(xr, x[i])
	elif a[i] == 3:
		yb = max(yb, y[i])
	else:
		yt = min(yt, y[i])
print((xr - xl) * (yt - yb) * (xr > xl and yt > yb))


import numpy as np
(W, H, N) = list(map(int, input().split()))
X = [[0 for _ in range(W)] for _ in range(H)]
for i in range(N):
	(x, y, a) = list(map(int, input().split()))
	if a == 1:
		for j in range(H):
			X[j][:x] = [1 for _ in range(x)]
	elif a == 2:
		for j in range(H):
			X[j][x:] = [1 for _ in range(W - x)]
	elif a == 3:
		for j in range(H - y, H):
			X[j] = [1 for _ in range(W)]
	else:
		for j in range(H - y):
			X[j] = [1 for _ in range(W)]
ans = 0
for k in X:
	ans += k.count(0)
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))


num_line = input().split(' ')
x_num = int(num_line[0])
y_num = int(num_line[1])
num = int(num_line[2])
tangle = [[1] * x_num for i in range(y_num)]
for i in range(num):
	line = input().split(' ')
	x_tem = int(line[0])
	y_tem = int(line[1])
	index = int(line[2])
	if index == 1:
		for j in range(y_num):
			for k in range(x_tem):
				tangle[j][k] = 0
	elif index == 2:
		for j in range(y_num):
			for k in range(x_num - x_tem):
				tangle[j][k + x_tem] = 0
	elif index == 3:
		for j in range(y_tem):
			for k in range(x_num):
				tangle[j][k] = 0
	else:
		for j in range(y_num - y_tem):
			for k in range(x_num):
				tangle[j + y_tem][k] = 0
result = 0
for i in range(y_num):
	for j in range(x_num):
		result += tangle[i][j]
print(result)


(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))