Problem:
 Score : 200 points    Problem Statement 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 1 5 4 2
2 1 1
3 3 4      Sample Output 1 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 .       Sample Input 2 5 4 3
2 1 1
3 3 4
1 4 2      Sample Output 2 0  It is possible that the whole region within the rectangle is painted black.       Sample Input 3 10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3      Sample Output 3 64

Solution (Python):
def main():
    w, h, n = map(int, input().split())
    coord = [[1] * w for _ in range(h)]

    for _ in range(n):
        xi, yi, a = map(int, input().split())
        if a == 1:
            for y in range(h):
                for x in range(0, xi):
                    coord[y][x] = 0
        elif a == 2:
            for y in range(h):
                for x in range(xi, w):
                    coord[y][x] = 0
        elif a == 3:
            for y in range(0, yi):
                coord[y] = [0] * w
        else:
            for y in range(yi, h):
                coord[y] = [0] * w

    print(sum(map(sum, coord)))


if __name__ == '__main__':
    main()

Solution (Python):
w, h, n = map(int, input().split())
c = []
for i in range(n):
    c.append([int(m) for m in input().split()])

sx = [0, w]
sy = [0, h]
for i in range(n):
    if c[i][2] == 1:
        if sx[0] < c[i][0]:
            sx[0] = c[i][0]
    elif c[i][2] == 2:
        if sx[1] > c[i][0]:
            sx[1] = c[i][0]
    elif c[i][2] == 3:
        if sy[0] < c[i][1]:
            sy[0] = c[i][1]
    elif c[i][2] == 4:
        if sy[1] > c[i][1]:
            sy[1] = c[i][1]
if sx[1] <= sx[0] or sy[1] <= sy[0]:
    print(0)
else:
    print((sx[1] - sx[0]) * (sy[1] - sy[0]))

Solution (Python):
W,H,N=map(int,input().split())
XYA=[list(map(int,input().split())) for i in range(N)]

MINX=0
MAXX=W
MINY=0
MAXY=H

for x,y,a in XYA:
    if a==1:
        MINX=max(MINX,x)
    if a==2:
        MAXX=min(MAXX,x)
    if a==3:
        MINY=max(MINY,y)
    if a==4:
        MAXY=min(MAXY,y)

print(max(MAXY-MINY,0)*max(MAXX-MINX,0))

Solution (Python):
w, h, n = [int(i) for i in input().split()]
table = [[0 for _ in range(w)] for _ in range(h)]

for _ in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        table[0][0] += 1
        if x < w:
            table[0][x] -= 1
    elif a == 2:
        if x < w:
            table[0][x] += 1
    elif a == 3:
        table[0][0] += 1
        if y < h:
            table[y][0] -= 1
    elif a == 4:
        if y < h:
            table[y][0] += 1

for i in range(len(table)):
    for j in range(1, len(table[i])):
        table[i][j] += table[i][j-1]
for i in range(1, len(table)):
    for j in range(len(table[i])):
        table[i][j] += table[i-1][j]
count = 0
for i in range(len(table)):
    for j in range(len(table[i])):
        if table[i][j] == 0:
            count += 1
print(count)

Solution (Python):
import numpy as np
W, H, N = map(int, input().split())
P = [tuple(map(int, input().split())) for _ in range(N)]
rect = np.ones([W, H])
for p in P:
    if p[2] == 1:
        rect[:p[0]] = 0
    elif p[2] == 2:
        rect[p[0]:] = 0
    elif p[2] == 3:
        rect[:, :p[1]] = 0
    elif p[2] == 4:
        rect[:, p[1]:] = 0
print(int(np.sum(rect)))

Solution (Python):
line = input().split(" ")
w = int(line[0])
h = int(line[1])
n = int(line[2])
area = [[0 for wx in range(w)] for hy in range(h)]
c = 0

for i in range(n):
    line = input().split(" ")
    x = int(line[0])
    y = int(line[1])
    a = int(line[2])
    if a == 1:
        for xi in range(h):
            for yi in range(x):
                area[xi][yi] = 1
    elif a == 2:
        for xi in range(h):
            for yi in range(w-x):
                area[xi][yi+x] = 1
    elif a == 3:
        for yi in range(w):
            for xi in range(y):
                area[xi][yi] = 1
    elif a == 4:
        for yi in range(w):
            for xi in range(h-y):
                area[xi+y][yi] = 1

for i in range(h):
    c = area[i].count(0) + c
print(c)

Solution (Python):
import collections as cl

W,H,N = [int(i) for i in input().split()]
action_list = []
ACTION_INDEX = {
	"X" : 0,
	"Y" : 1,
	"TYPE" : 2
}
ACTION_TYPE = {
	"LESS_THAN_X" : 1,
	"MORE_THAN_X" : 2,
	"LESS_THAN_Y" : 3,
	"MORE_THAN_Y" : 4,
}

for i in range(N) :
	action_list.append([int(i) for i in input().split()])

arr = [[0 for i in range(H)] for j in range(W)]

for actions in action_list :
	if(actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["LESS_THAN_X"]) :
		for i in range(actions[ACTION_INDEX["X"]]) :
			for j in range(H) :
				arr[i][j] = 1

	elif (actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["MORE_THAN_X"]) :
		for i in range(actions[ACTION_INDEX["X"]], W) :
			for j in range(H) :
				arr[i][j] = 1
	elif (actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["LESS_THAN_Y"]) :
		for i in range(W) :
			for j in range(actions[ACTION_INDEX["Y"]]) :
				arr[i][j] = 1
	elif (actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["MORE_THAN_Y"]) :
		for i in range(W) :
			for j in range(actions[ACTION_INDEX["Y"]], H) :
				arr[i][j] = 1

arr2 = []
for i in range(W) :
	for j in range(H) :
		arr2.append(arr[i][j])
c = cl.Counter(arr2)
print(c[0])

Solution (Python):
W,H,N = map(int, input().split())
x_min, y_min = 0,0
x_max, y_max = W,H
for _ in range(N):
    x,y,a = 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)
width = max(0, x_max-x_min)
height = max(0, y_max-y_min)
print(width*height)

Solution (Python):
W,H,N = map(int, input().split())
rec = [["W"]*(W) for _ in range(H)]

for _ in range(N):
    x,y,a = map(int, input().split())
    if a==1:
        for h in range(H):
            for w in range(W):
                if w<x:
                    rec[h][w]="B"
    elif a==2:
        for h in range(H):
            for w in range(W):
                if w>=x:
                    rec[h][w]="B"
    elif a==3:
        for h in range(H):
            for w in range(W):
                if h<y:
                    rec[h][w]="B"
    else:
        for h in range(H):
            for w in range(W):
                if h>=y:
                    rec[h][w]="B"
                    
ans = 0
for h in range(H):
    for w in range(W):
        if rec[h][w]=="W":
            ans += 1
print(ans)

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

Solution (Python):
wt,ht,n=map(int,input().split())


w=[1]*wt
h=[1]*ht
for i in range(n):
  W,Y,A=map(int,input().split())
  if A==1:
    w=[0]*(W)+w[W:]
  elif A==2:
    w=w[:W]+[0]*(wt-W)
  elif A==3:
    h=h[:ht-(Y+1)+1]+[0]*(Y)
  elif A==4:
    h=[0]*(ht-Y)+h[ht-Y:]

print(sum(w)*sum(h))

Solution (Python):
W, H, N = map(int, input().split())
rec = []
for h in range(H):
    rec.append([])
    for w in range(W):
        rec[h].append(1)
        
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for h in range(H):
            for _x in range(x):
                rec[h][_x] = 0
    elif a == 2:   
        for h in range(H):
            for _x in range(x, W):
                rec[h][_x] = 0
    elif a == 3:
        for w in range(W):
            for _y in range(y):
                rec[_y][w] = 0
    else:   
        for w in range(W):
            for _y in range(y, H):
                rec[_y][w] = 0
    
for h in range(H):
    rec[h] = sum(rec[h])
print(sum(rec))

Solution (Python):
W, H, N = [int(_) for _ in input().split()]
maxX = W
minX = 0
maxY = H
minY = 0
for _ in range(N):
    X, Y, A = [int(_) for _ in 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)
if maxX > minX and maxY > minY:
    print((maxX - minX) * (maxY - minY))
else:
    print(0)

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

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

Solution (Python):
W,H,N=map(int,input().strip().split(" "))
Sum=0
r=0
xx=0
yy=0
for i in range(N):
    x,y,a=map(int,input().strip().split(" "))
    
    if(a==1):
        if(xx<x):
            xx=x
    elif(a==2):
        if(W>x):
            W=x
    elif(a==3):
        if(yy<y):
            yy=y
    elif(a==4):
        if(H>y):
            H=y
Sum=(W-xx)*(H-yy)

if((W-xx)<=0 or (H-yy)<=0):
    print("0")
else:
    print(Sum)

Solution (Python):
w, h, n = list(map(int, input().split()))
x_max = 0
x_min = w
y_max = 0
y_min = h

for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        x_max = max(x_max, x)
    elif a == 2:
        x_min = min(x_min, x)
    elif a == 3:
        y_max = max(y_max, y)
    else:
        y_min = min(y_min, y)
        
if x_max >= x_min or y_max >= y_min:
    print(0)
else:
    print((x_min - x_max) * (y_min - y_max))

Solution (Python):

W, H, N = map(int, input().split())
a1 = 0
a2 = W
a3 = 0
a4 = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x >= a1:
            a1 = x
    if a == 2:
        if x <= a2:
            a2 = x
    if a == 3:
        if y >= a3:
            a3 = y
    if a == 4:
        if y <= a4:
            a4 = y

ans = max(0, (a2 - a1)) * max(0, (a4 - a3))
print(ans)

Solution (Python):
W, H, N = [int(x) for x in input().split()]
A = [[0] * (W) for i in range(H)]

for i in range(N):
    x_i, y_i, a_i = [int(x) for x in input().split()]
    for y in range(H):
        for x in range(W):
            if a_i == 1:
                if x <  x_i: A[y][x] = 1
            elif a_i == 2:
                if x >= x_i: A[y][x] = 1
            elif a_i == 3:
                if y <  y_i: A[y][x] = 1
            else:
                if y >= y_i: A[y][x] = 1
cnt = 0
for y in range(H):
    for x in range(W):
        if A[y][x] == 0: cnt += 1

print(cnt)

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

Solution (Python):
W,H,N = map(int, input().split())
s = set([])
for h in range(H):
    for w in range(W):
        s.add((w+0.5, h+0.5))


for _  in range(N):
    x,y,a = map(int, input().split())
    rm = set([])
    if a==1:
        for si in s:
            if si[0]<x: rm.add(si)
    if a==2:
        for si in s:
            if si[0]>x: rm.add(si)
    if a==3:
        for si in s:
            if si[1]<y: rm.add(si)
    if a==4:
        for si in s:
            if si[1]>y: rm.add(si)
    s = s - rm
                
print(len(s))

Solution (Python):

W, H, N = map(int, input().split())
min_x, max_x = 0, W
min_y, max_y = 0, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if max_x <= x:
            min_x, max_x = 0, 0
        elif min_x <= x:
            min_x = x
    elif a == 2:
        if min_x >= x:
            min_x, max_x = 0, 0
        elif x <= max_x:
            max_x = x
    elif a == 3:
        if max_y <= y:
            min_y, max_y = 0, 0
        elif min_y <= y:
            min_y = y
    else:
        if y <= min_y:
            min_y, max_y = 0, 0
        elif y <= max_y:
            max_y = y
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)

Solution (Python):


xl, yl, n = map(int, input().split())
xr = 0
yr = 0

for n in range(n):
    x, y, a = map(int, input().split())

    if a == 1:
        if xl < x:
            xl = x

        if xr < x:
            xr = x

    elif a == 2:
        if xl > x:
            xl = x

        if xr > x:
            xr = x

    elif a == 3:
        if yl < y:
            yl = y

        if yr < y:
            yr = y

    elif a == 4:
        if yl > y:
            yl = y

        if yr > y:
            yr = y

if (xl - xr) <= 0 or (yl - yr) <= 0:
    print('0')
else:
    print((xl - xr) * (yl - yr))

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

Solution (Python):
W, H, N = map(int, input().split())
l = 0
r = W
b = 0
t = H
for i in range(N):
    L = [int(i) for i in input().split()]
    if L[2] == 1:
        l = max(l, L[0])
    elif L[2] == 2:
        r = min(r, L[0])
    elif L[2] == 3:
        b = max(b, L[1])
    else:
        t = min(t, L[1])
if l < r and b < t:
    print((r-l)*(t-b))
else:
    print(0)

Solution (Python):
w, h, n = map(int, input().split())
x0, y0, x1, y1 = 0, 0, w, h

for _ in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x0 = max(x0, x)
  if a == 2:
    x1 = min(x1, x)
  if a == 3:
    y0 = max(y0, y)
  if a == 4:
    y1 = min(y1, y)

print(max(x1 - x0, 0) * max(y1 - y0, 0))

Solution (Python):
w, h, n = map(int, input().split())

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

if x1 - x0 <= 0 or y1 - y0 <= 0:
    print(0)
else:
    print((x1 - x0) * (y1 - y0))

Solution (Python):
W, H, N = list(map(int, input().split()))
x0 = 0
x1 = W
y0 = 0
y1 = H

for i in range(N):
	x, y, a = list(map(int, input().split()))
	if a == 1:
		if x0 <= x:
			x0 = x
	elif a == 2:
		if x <= x1:
			x1 = x
	elif a == 3:
		if y0 <= y:
			y0 = y
	else:
		if y <= y1:
			y1 = y

if x1 - x0 <= 0 or y1 - y0 <= 0:
	print(0)
else:
	print((x1 - x0) * (y1 - y0))

Solution (Python):
w,h,n = map(int, input().split())
xya = []
xl, xr, yu, yt = 0, w, 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
       if xl < x:
           xl = x 
    elif a == 2:
        if xr > x:
            xr = x
    elif a == 3:
        if yu < y:
            yu = y
    else:
        if yt > y:
            yt = y
print([(xr - xl) * (yt - yu), 0][(xr - xl) <= 0 or (xr - xl) <= 0])

Solution (Python):
w,h,n = map(int,input().split())
wmax = w
wmin = 0
hmax = h
hmin = 0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        if wmin < x:
            wmin = x
    elif a == 2:
        if wmax > x:
            wmax = x
    elif a == 3:
        if hmin < y:
            hmin = y
    elif a == 4:
        if hmax > y:
            hmax = y

ver = hmax - hmin if hmax > hmin else 0
hor = wmax - wmin if wmax > wmin else 0

print(ver*hor)

Solution (Python):
W, H, N = map(int, input().split())

ans = [[1 for _ in range(W)] for _ in range(H)]

for i in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        for j in range(H):
            for i in range(x):
                ans[j][i] = 0
                
    elif a == 2:
        for j in range(H):
            for i in range(x, W):
                ans[j][i] = 0

    elif a == 3:
        for j in range(y):
            for i in range(W):
                ans[j][i] = 0        
        
    elif a == 4:
        for j in range(y, H):
            for i in range(W):
                ans[j][i] = 0

print(sum(map(sum, ans)))

Solution (Python):
w,h,n = map(int,input().split())
g = [[0]*w for i in range(h)]
for i in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        for p in range(x):
            for q in range(h):
                g[q][p] = 1
    elif a==2:
        for p in range(x,w):
            for q in range(h):
                g[q][p] = 1
    elif a==3:
        for p in range(w):
            for q in range(y):
                g[q][p] = 1
    else:
        for p in range(w):
            for q in range(y,h):
                g[q][p] = 1
cnt = 0
for i in range(h):
    cnt += g[i].count(0)
print(cnt)

Solution (Python):
import numpy as np


def main():
    W, H, N = map(int, input().split())
    s = np.zeros((W, H))
    for _ in range(N):
        x, y, a = map(int, input().split())

        if a == 1:
            s[:x, :] = 1
        elif a == 2:
            s[x:, :] = 1
        elif a == 3:
            s[:, :y] = 1
        elif a == 4:
            s[:, y:] = 1

    print(W * H - np.sum(s))


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin


def main():
    w = next_int()
    h = next_int()
    n = next_int()

    x = 0
    y = 0

    for i in range(n):
        xi, yi, a = map(int, input().split())
        if a == 1:
            x = max(x, xi)
        if a == 2:
            w = min(w, xi)
        if a == 3:
            y = max(y, yi)
        if a == 4:
            h = min(h, yi)

    print(max(0, (w - x)) * max(0, (h - y)))


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin


def main():
    w = next_int()
    h = next_int()
    n = next_int()
    arr = [[1] * w for _ in range(h)]

    for i in range(n):
        xi, yi, a = map(int, input().split())

        for y in range(h):
            for x in range(w):
                if a == 1:
                    if x < xi:
                        arr[y][x] = 0
                if a == 2:
                    if x >= xi:
                        arr[y][x] = 0
                if a == 3:
                    if y < yi:
                        arr[y][x] = 0
                if a == 4:
                    if y >= yi:
                        arr[y][x] = 0

    ans = 0
    for y in range(h):
        ans += sum(arr[y])
    print(ans)


def next_int():
    return int(next_str())


def next_str():
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
from sys import stdin


def main():
    w = next_int()
    h = next_int()
    n = next_int()
    arr = np.ones((h, w), dtype=np.int)

    for i in range(n):
        xi, yi, a = map(int, input().split())

        for y in range(h):
            for x in range(w):
                if a == 1:
                    if x < xi:
                        arr[y][x] = 0
                if a == 2:
                    if x >= xi:
                        arr[y][x] = 0
                if a == 3:
                    if y < yi:
                        arr[y][x] = 0
                if a == 4:
                    if y >= yi:
                        arr[y][x] = 0

    ans = arr.sum()
    print(ans)


def next_int():
    return int(next_str())


def next_str():
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):
W,H,N = map(int, input().split())
li = [list(map(int,input().split())) for i in range(N)]

a_x = 0
a_y = 0
b_x = W
b_y = 0
c_x = W
c_y = H
d_x = 0
d_y = H
area = 1

for l in li:
    if l[2] == 1:
        if l[0] >= b_x:
            area = 0
            break
        elif l[0] > a_x:
            a_x = l[0]
            d_x = l[0]
        
    elif l[2] == 2:
        if l[0] <= a_x:
            area = 0
            break
        elif l[0] < b_x:
            b_x = l[0]
            c_x = l[0]

    elif l[2] == 3:
        if l[1] >= d_y:
            area = 0
            break
        elif l[1] > a_y:
            a_y = l[1]
            b_y = l[1]
        
    elif l[2] == 4:
        if l[1] <= a_y:
            area = 0
            break
        elif l[1] < d_y:
            c_y = l[1]
            d_y = l[1]

if area != 0:
    area = (b_x - a_x)*(d_y - a_y)

print(area)

Solution (Python):

from sys import stdin

w,h,n = [int(x) for x in stdin.readline().rstrip().split()]
board = [[1] * w for i in range(h)]
ans = 0

for i in range(n):
    x,y,a = [int(x) for x in stdin.readline().rstrip().split()]
    if a == 1:
        for j in range(h):
            for k in range(x):
                board[j][k] = 0
    elif a == 2:
        for j in range(h):
            for k in range(x,w):
                board[j][k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(w):
                board[j][k] = 0            
    elif a == 4:
        for j in range(y,h):
            for k in range(w):
                board[j][k] = 0

for i in range(h):
    ans += sum(board[i])

print(ans)

Solution (Python):
W, H, N = map(int, input().split())
a_list =[] 
for i in range(N):
  a_list.append(list(map(int, input().split())))
a1_list = [i[0] for i in a_list if i[2] == 1 ]
a2_list = [i[0] for i in a_list if i[2] == 2 ]
a3_list = [i[1] for i in a_list if i[2] == 3 ]
a4_list = [i[1] for i in a_list if i[2] == 4 ]
if a1_list == []:
  a1_max = 0
else:
  a1_max = max(a1_list)
if a2_list == []:
  a2_min = W
else:
  a2_min = min(a2_list)
if a3_list ==[]:
  a3_max = 0
else:
  a3_max = max(a3_list)
if a4_list == []:
  a4_min = H
else:
  a4_min = min(a4_list)
S = (a2_min - a1_max)*(a4_min - a3_max)
if (a2_min - a1_max) >= 0 and (a4_min - a3_max) >= 0:
  print(S)
else:
  print(0)

Solution (Python):
import sys
def 解():
    iW,iH,iN =[int(_) for _ in input().split()]
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    iU = iH
    iD = 0
    iL = 0
    iR = iW

    for x,y,a in aD:
        if a == 1:
            iL = max(iL,x)
        elif a == 2 :
            iR = min(iR,x)
        elif a == 3:
            iD = max(iD,y)
        elif a == 4:
            iU = min(iU,y)
    if iD > iU or iL > iR:
        print (0)
    else:
        print((iU-iD)*(iR-iL) )
解()

Solution (Python):



"""
    白い部分を1, 黒い部分を0
"""
import numpy as np

test_mode = False

x = []
y = []
a = []

x_add = 0
y_add = 0
a_add = 0

W, H, N = map(int, input().split())

arr_2d = np.ones((W, H))    

for _ in range(N):
    x_add, y_add, a_add = map(int, input().split())
    x.append(x_add)
    y.append(y_add)
    a.append(a_add)


for i in range(N):
    if a[i] == 1:
        arr_2d[:x[i], :] = 0
    if a[i] == 2:
        arr_2d[x[i]:, :] = 0
    if a[i] == 3:
        arr_2d[:, :y[i]] = 0
    if a[i] == 4:
        arr_2d[:, y[i]:] = 0

if test_mode:
    print(arr_2d)

print(np.sum(arr_2d == 1))


"""
    numpy使い方_2_スライスとブールインデックス
    http://ism1000ch.hatenablog.com/entry/2014/01/15/025328
    NumPyで全要素を同じ値で初期化した配列ndarrayを生成
    https://note.nkmk.me/python-numpy-zeros-ones-full/
"""

Solution (Python):
w, h, n = map(int, input().split())

matrix = []
for j in range(h):
	line = []
	for i in range(w):
		line.append(0)
	matrix.append(line)

for k in range(n):
	x, y, a = map(int, input().split())
	if a == 1:
		for i in range(len(matrix)):
			for j in range(x):
				matrix[i][j] = 1
	elif a == 2:
		for i in range(len(matrix)):
			for j in range(x, len(matrix[0])):
				matrix[i][j] = 1
	elif a == 3:
		for i in range(y):
			for j in range(len(matrix[0])):
				matrix[i][j] = 1
	else:
		for i in range(y, len(matrix)):
			for j in range(len(matrix[0])):
				
				
				matrix[i][j] = 1

cnt = 0
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] == 0:
			cnt += 1

print(cnt)

Solution (Python):
w, h, n = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(n)]
s, t = [0, w], [0, h]
for i in range(n):
    x = p[i][0]
    y = p[i][1]
    a = p[i][2]
    if a == 1:
        if x <= s[0]:
            continue
        elif s[0] < x < s[1]:
            s[0] = x
        else:
            print(0)
            exit()
    elif a == 2:
        if x <= s[0]:
            print(0)
            exit()
        elif s[0] < x < s[1]:
            s[1] = x
        else:
            continue
    elif a == 3:
        if y <= t[0]:
            continue
        elif t[0] < y < t[1]:
            t[0] = y
        else:
            print(0)
            exit()
    else:
        if y <= t[0]:
            print(0)
            exit()
        elif t[0] < y < t[1]:
            t[1] = y
        else:
            continue

print((s[1]-s[0])*(t[1]-t[0]))

Solution (Python):
W,H,N = map(int,input().split())

xl = 0
xr = W
yu = H
yd = 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:
        yd = max(yd,y)
    else:
        yu = min(yu,y)

ans = max(0,xr - xl) * max(0,yu - yd)

print(ans)

Solution (Python):
import numpy as np

W,H,N = map(int,input().split())

xl = 0
xr = W
yu = H
yd = 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:
        yd = max(yd,y)
    else:
        yu = min(yu,y)

ans = max(0,xr - xl) * max(0,yu - yd)

print(ans)

Solution (Python):
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)))

Solution (Python):
W, H, N = map(int, input().split())
tyoten = [0, 0]
ans = W*H
for i in range(N):
    x, y, a = map(int, input().split())
    
    if a == 1:
        
        if tyoten[0] < x < W:
            tyoten[0] = x
        elif W <= x:
            ans = 0
    
    elif a == 2:
        
        if tyoten[0] < x < W:
            W = x
        elif x <= tyoten[0]:
            ans = 0
    
    elif a == 4:
        
        if tyoten[1] < y < H:
            H = y
        elif y <= tyoten[1]:
            ans = 0
        
    elif a == 3:
        
        if tyoten[1] < y < H:
            tyoten[1] = y
        elif H <= y:
            ans = 0

print(0 if ans == 0 else (W-tyoten[0])*(H-tyoten[1]))

Solution (Python):
W, H, N = map(int, input().split())
x = []
y = []
a = []
for i in range(N):
    x_i, y_i, a_i = map(int, input().split())
    x.append(x_i)
    y.append(y_i)
    a.append(a_i)

x_low = 0
x_high = W
y_low = 0
y_high = H

for i in range(N):
    if a[i] == 1:
        if x_low < x[i]:
            x_low = x[i]
    if a[i] == 2:
        if x_high > x[i]:
            x_high = x[i]
    if a[i] == 3:
        if y_low < y[i]:
            y_low = y[i]
    if a[i] == 4:
        if y_high > y[i]:
            y_high = y[i]

if x_high < x_low or y_high < y_low:
    print(0)
else:
    print((x_high - x_low) * (y_high - y_low))

Solution (Python):
w,h,n = map(int,input().split())
x_min = 0
x_max = w
y_min = 0
y_max = h
for _ in [0]*n:
  x,y,a = 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(max(x_max-x_min,0)*max(y_max-y_min,0))

Solution (Python):
import numpy as np
h,w,n=map(int, input().split())
c=np.ones(h*w).reshape(w,h)
for i in range(n):
    x,y,a=map(int, input().split())
    if a==1:c[:,:x]=0
    if a==2:c[:,x:]=0
    if a==3:c[:y,:]=0
    if a==4:c[y:,:]=0
print(int(c.sum()))

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    W, H, N = map(int, input().split())
    field = [[0] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        min_y, max_y, min_x, max_x = 0, H, 0, W
        if a == 1:
            max_x = x
        elif a == 2:
            min_x = x
        elif a == 3:
            max_y = y
        elif a == 4:
            min_y = y

        for y in range(min_y, max_y):
            for x in range(min_x, max_x):
                field[y][x] = 1

    ans = 0
    for y in range(H):
        for x in range(W):
            ans += (field[y][x] == 0)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
w,h,n = map(int, input().split())
count = 0
list_prob = []
while count < n:
    list_prob.append(list((map(int, input().split()))))
    count += 1
w_max = w
h_max = h
w_min = 0
h_min = 0

for row in list_prob:
    if row[2] == 1:
        if w_min < row[0]:
            w_min = row[0]
    elif row[2] == 2:
        if w_max > row[0]:
            w_max = row[0]
    elif row[2] == 3:
        if h_min < row[1]:
            h_min = row[1]
    else:
        if h_max > row[1]:
            h_max = row[1]
if w_max < w_min or h_max < h_min:
    print(0)
else:
    print((w_max - w_min)*(h_max - h_min))