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):
W, H, N = map(int, input().split())
xl, xh = 0, W
yl, yh = 0, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        xl = max(xl, x)
    elif a == 2:
        xh = min(xh, x)
    elif a == 3:
        yl = max(yl, y)
    else:
        yh = min(yh, y)

if xl >= xh or yl >= yh:
    print(0)
else:
    print((xh-xl) * (yh-yl))

Solution (Python):
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())
b=[0]
c=[W]
d=[0]
e=[H]
for i in range(N):
    if a[i]==1:
        b.append(x[i])
    if a[i]==2:
        c.append(x[i])
    if a[i]==3:
        d.append(y[i])
    if a[i]==4:
        e.append(y[i])
w=min(c)-max(b)
h=min(e)-max(d)
if w<=0 or h<=0:
    print(int(0))
else:
    print(w*h)

Solution (Python):
W,H,N = map(int,input().split())
grid = []
for i in range(N):
	array = list(map(int,input().split()))
	grid.append(array)
x1 = 0
xW = W
y1 = 0
yH = H
for i in grid:
	if i[2] == 1 and x1 < i[0]:
		x1 = i[0]
	elif i[2] == 2 and xW > i[0]:
		xW = i[0]
	elif i[2] == 3 and y1 < i[1]:
		y1 = i[1]
	elif i[2] == 4 and yH > i[1]:
		yH = i[1]
print(max(0,xW-x1)*max(0,yH-y1))

Solution (Python):
w, h, n = map(int, input().split())
l = 0
r = w
u = h
d = 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)
print((r - l) * (u - d) if r - l > 0 and u - d > 0 else 0)

Solution (Python):
W, H, N = map(int, input().split())
Q = [0,W,0,H]
for i in range(N):
    q = list(map(int, input().split()))
    if q[2]==1 and Q[0]<q[0]:
        Q[0]=q[0]
    elif q[2]==2 and Q[1]>q[0]:
        Q[1]=q[0]
    elif q[2]==3 and Q[2]<q[1]:
        Q[2]=q[1]
    elif q[2]==4 and Q[3]>q[1]:
        Q[3]=q[1]

print(max((Q[1]-Q[0]), 0)*max((Q[3]-Q[2]),0))

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

x_l=0
x_h=W
y_l=0
y_h=H

for i in xya:
    if i[2]==1 and x_l<i[0]:
        x_l=i[0]
    elif i[2]==2 and x_h>i[0]:
        x_h=i[0]
    elif i[2]==3 and y_l<i[1]:
        y_l=i[1]
    elif i[2]==4 and y_h>i[1]:
        y_h=i[1]

print(max(0,x_h-x_l)*max(0,y_h-y_l))

Solution (Python):
W, H, N = map(int,input().split())
w = [1] * (W + 1)
h = [1] * (H + 1)
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        w[:x] = [0 for _ in range(x)]
    if a == 2:
        w[(x + 1):] = [0 for _ in range(W - x)]
    if a == 3:
        h[:y] = [0 for _ in range(y)]
    if a == 4:
        h[(y + 1):] = [0 for _ in range(H - y)]
if sum(w):
    A = sum(w) - 1
else:
    A = 0
if sum(h):
    B = sum(h) - 1
else:
    B = 0
print(A * B)

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

Solution (Python):
import numpy as np
w, h, n = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]

arr = np.array([[1 for _ in range(w)] for _ in range(h)])

for x, y, a in mat:
    if a == 1:
        arr[:,:x] = 0
    elif a == 2:
        arr[:, x:] = 0
    elif a == 3:
        arr[-y:,:] = 0
    
    elif a == 4:
        arr[:-y,:] = 0

print(arr.sum())

Solution (Python):
import numpy as np

if __name__ == "__main__":
    w, h, n = map(int, input().split())
    mp = np.zeros((h, w))

    for i in range(n):
        tmp = list(map(int, input().split()))
        if tmp[2] == 1:
            mp[0:h, 0:tmp[0]] = 1
        elif tmp[2] == 2:
            mp[0:h, tmp[0]:w] = 1
        elif tmp[2] == 3:
            mp[0:tmp[1], 0:w] = 1
        else:
            mp[tmp[1]:h, 0:w] = 1

    print(w*h - np.count_nonzero(mp))

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:
        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)
if max_x-min_x<=0 or max_y-min_y<=0:
    print(0) 
else:
    ans=(max_x-min_x)*(max_y-min_y)
    print(max(ans,0))

Solution (Python):

W, H,N = map(int, input().split())
a = [input().split() for l in range(N)]
tmpx = W
tmpx1 = 0
tmpy = H
tmpy1 = 0
for i in range(N):
    if a[i][2] == "1":
        if tmpx1 < int(a[i][0]):
            tmpx1 = int(a[i][0])
        else:
            pass
    elif a[i][2] == "2" :
        if tmpx > int(a[i][0]):
            tmpx = int(a[i][0])
        else:
            pass
    elif a[i][2] == "3" :
        if tmpy1 < int(a[i][1]):
            tmpy1 = int(a[i][1])
    elif a[i][2] == "4" :
        if tmpy > int(a[i][1]):
            tmpy = int(a[i][1])
    else:
        print(0)
        exit()

if tmpx-tmpx1 <= 0 or tmpy - tmpy1 <=0:
    print(0)
else:
    print(abs(tmpx-tmpx1)*abs(tmpy-tmpy1))

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

fie = [[1]*h for i in range(w)]

for i in range(n):
        x, y, a = map(int, input().split())
        if a==1:
                for j in range(x):
                        for k in range(h): fie[j][k] = 0
        if a==2:
                for j in range(x, w):
                        for k in range(h): fie[j][k] = 0
        if a==3:
                for j in range(w):
                        for k in range(y): fie[j][k] = 0
        if a==4:
                for j in range(w):
                        for k in range(y, h): fie[j][k] = 0
sm = 0
for i in range(w): sm += sum(fie[i])
print(sm)

Solution (Python):

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

Solution (Python):

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

x_left = 0
x_right = w
y_lower = 0
y_upper = h
for i in range(n):
    if a[i][2] == 1:
        x_left = max(a[i][0], x_left)
    if a[i][2] == 2:
        x_right = min(a[i][0], x_right)
    if a[i][2] == 3:
        y_lower = max(a[i][1], y_lower)
    if a[i][2] == 4:
        y_upper = min(a[i][1], y_upper)
if y_lower >= y_upper or x_left >= x_right:
    print(0)
else:
    
    
    print((y_upper - y_lower) * (x_right - x_left))

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

Solution (Python):
W, H, N = map(int,input().split())
G = [[0]*W for k in range(H)]

for q in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        for k in range(H):
            for l in range(x):
                G[k][l] = 1
    elif a == 2:
        for k in range(H):
            for l in range(x,W):
                G[k][l] = 1
    elif a == 3:
        for k in range(y):
            for l in range(W):
                G[k][l] = 1
    else:
        for k in range(y,H):
            for l in range(W):
                G[k][l] = 1

ans = H*W
for k in range(H):
    for l in range(W):
        ans -= G[k][l]
print(ans)

Solution (Python):
def main():
    W, H, N = (int(i) for i in input().split())
    seen = [[True]*W for _ in range(H)]
    for i in range(N):
        X, Y, a = (int(i) for i in input().split())
        if a == 1:
            for h in range(H):
                for x in range(X):
                    seen[h][x] = False
        elif a == 2:
            for h in range(H):
                for x in range(X, W):
                    seen[h][x] = False
        elif a == 3:
            for w in range(W):
                for y in range(Y):
                    seen[y][w] = False
        else:
            for w in range(W):
                for y in range(Y, H):
                    seen[y][w] = False
    
    ans = 0
    for h in range(H):
        for w in range(W):
            if seen[h][w]:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
w,h,n = map(int,input().split())
arr = [[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 k in range(x):
                arr[j][k] = 0
    elif a == 2:
        for j in range(h):
            for k in range(x, w):
                arr[j][k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(w):
                arr[j][k] = 0
    elif a == 4:
        for j in range(y, h):
            for k in range(w):
                arr[j][k] = 0
ans = 0
for i in range(h):
    ans += sum(arr[i])
print(ans)

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

w = [0, W]
h = [0, H]
for x, y, a in xya:
  if a == 1 and w[0] < x:
    w[0] = x
  elif a == 2 and w[1] > x:
    w[1] = x
  elif a == 3 and h[0] < y:
    h[0] = y
  elif a == 4 and h[1] > y:
    h[1] = y

if w[0] < w[1] and h[0] < h[1]:
  print(abs(w[0] - w[1]) * abs(h[0] - h[1]))
else: print(0)

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

Solution (Python):
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

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

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

    if a == 1:
        grid[:, :x] = 1
    elif a == 2:
        grid[:, x:] = 1
    elif a == 3:
        grid[:y, :] = 1
    else:
        grid[y:, :] = 1

ans = H * W - np.count_nonzero(grid)
print(ans)

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

l = 0
b = 0
r = W
t = H
for x,y,a in xya:
    if a == 1: l = max(l, x)
    elif a == 2: r = min(r, x)
    elif a == 3: b = max(b, y)
    elif a == 4: t = min(t, y)
print(max(0, r-l) * max(0, t-b))

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

Solution (Python):
W,H,N = map(int,input().split())
minx,maxx = 0,W
miny,maxy = 0,H

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)
    elif a == 4:
        maxy = min(maxy,y)

if minx >= maxx or miny >= maxy:
    print(0)
else:
    print((maxy-miny)*(maxx-minx))

Solution (Python):
w, h, n = [int(i) for i in input().split()]
W = set(range(w))
H = set(range(h))
for i in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        W &= set(range(x, w))
    elif a == 2:
        W &= set(range(0, x))
    elif a == 3:
        H &= set(range(y, h))
    elif a == 4:
        H &= set(range(0, y))
print(len(W) * len(H))

Solution (Python):
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:
        x0=max(x0,x)
    elif a==2:
        w=min(w,x)
    elif a==3:
        y0=max(y0,y)
    else:
        h=min(h,y)
print(0 if w-x0<=0 or h-y0<=0 else (w-x0)*(h-y0))

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

t = [[1] * 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(x):
              t[h][w] = 0
    elif a == 2:
        for h in range(H):
            for w in range(x, W):
              t[h][w] = 0
    elif a == 3:
        for h in range(y):
            for w in range(W):
              t[h][w] = 0
    elif a == 4:
        for h in range(y, H):
            for w in range(W):
              t[h][w] = 0
print(sum(sum(l) for l in t))

Solution (Python):
w, h, n = map(int, input().split())
a1, a2, a3, a4 = [0], [w], [0], [h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        a1.append(x)
    if a == 2:
        a2.append(x)
    if a == 3:
        a3.append(y)
    if a == 4:
        a4.append(y)
print(max(min(a2) - max(a1), 0) * max(min(a4) - max(a3), 0))

Solution (Python):
import numpy as np

W,H,N = [int(i) for i in input().split()]

x = np.ones(N)
y = np.ones(N)
a = np.ones(N)

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


init_s = np.zeros([H+1,W+1])

ind_a_1 = [ind for ind,v in enumerate(a) if v == 1]
ind_a_2 = [ind for ind,v in enumerate(a) if v == 2]
ind_a_3 = [ind for ind,v in enumerate(a) if v == 3]
ind_a_4 = [ind for ind,v in enumerate(a) if v == 4]

if len(ind_a_1)==0:
    x_1 = 0
else:
    x_1=x[int(ind_a_1[0])]
    for i in ind_a_1:
        int_ind = int(i)
        if x_1<x[int_ind]:
            x_1=x[int_ind]
    
if len(ind_a_3)==0:
    y_3 = 0
else:
    y_3=y[int(ind_a_3[0])]
    for i in ind_a_3:
        int_ind = int(i)
        if y_3<y[int_ind]:
            y_3=y[int_ind]  
            
if len(ind_a_2)==0:
    x_2 = W
else:
    x_2=x[int(ind_a_2[0])]
    for i in ind_a_2:
        int_ind = int(i)
        if x_2>x[int_ind]:
            x_2=x[int_ind]
            
if len(ind_a_4)==0:
    y_4 = H
else:
    y_4=y[int(ind_a_4[0])]
    for i in ind_a_4:
        int_ind = int(i)
        if y_4>y[int_ind]:
            y_4=y[int_ind]
            
            
if (x_2-x_1>0) & (y_4-y_3>0):
    ans =int((x_2-x_1)*(y_4-y_3))
else:
    ans = int(0)
print(ans)

Solution (Python):

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

Solution (Python):
w,h,n = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]

a1,a2,a3,a4 = 0,w,0,h
for i in range(n):
    if l[i][2] == 1:
        a1 = max(l[i][0], a1)
    elif l[i][2] == 2:
        a2 = min(l[i][0], a2)
    elif l[i][2] == 3:
        a3 = max(l[i][1], a3)
    else:
        a4 = min(l[i][1], a4)

print(0) if a2-a1 <= 0 or a4-a3 <= 0 else print((a2-a1)*(a4-a3))

Solution (Python):
w,h,n = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]

a1,a2,a3,a4 = 0,w,0,h
for i in range(n):
    if l[i][2] == 1:
        a1 = max(l[i][0], a1)
    elif l[i][2] == 2:
        a2 = min(l[i][0], a2)
    elif l[i][2] == 3:
        a3 = max(l[i][1], a3)
    else:
        a4 = min(l[i][1], a4)

if a2-a1 <= 0 or a4-a3 <= 0:
    print(0)
else:
    print((a2-a1)*(a4-a3))

Solution (Python):
w,h,n = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]

a1,a2,a3,a4 = 0,w,0,h
for i in range(n):
    if l[i][2] == 1:
        a1 = max(l[i][0], a1)
    elif l[i][2] == 2:
        a2 = min(l[i][0], a2)
    elif l[i][2] == 3:
        a3 = max(l[i][1], a3)
    elif l[i][2] == 4:
        a4 = min(l[i][1], a4)

if a2-a1 <= 0 or a4-a3 <= 0:
    print(0)
else:
    print((a2-a1)*(a4-a3))

Solution (Python):
list=[]
W,H,N=map(int,input().split())
for a in range(N):
    x,y,a=map(int,input().split())
    list.append([x,y,a])
yoko=[d for d in range(W+1)]
tate=[e for e in range(H+1)]
for f in range(N):
    if list[f][2]==1:
        yoko=[g for g in yoko if g>=list[f][0]]
    elif list[f][2]==2:
        yoko=[h for h in yoko if h<=list[f][0]]
    elif list[f][2]==3:
        tate=[i for i in tate if i>=list[f][1]]
    else:
        tate=[j for j in tate if j<=list[f][1]]
if len(yoko)==0 or len(tate)==0:
    print(0)
else:
    nyoko = max(yoko) - min(yoko)
    ntate = max(tate) - min(tate)
    print(ntate * nyoko)

Solution (Python):
W,H,N = map(int,input().split())
c = [0]*N
max_x,min_x = 0,W
max_y,min_y = 0,H
for _ in range(N):
  x,y,a = 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 or min_y <= max_y:
      print(0)
      exit()
print((min_x-max_x)*(min_y-max_y))

Solution (Python):
w, h, n = map(int, input().split())
z = [input().split() for i in range(n)]
w = list(range(w+1))
h = list(range(h+1))
for i in range(n):
    if z[i][2] == '1':
        w = [j for j in w if j >= int(z[i][0])]
    elif z[i][2] == '2':
        w = [j for j in w if j <= int(z[i][0])]
    elif z[i][2] == '3':
        h = [j for j in h if j >= int(z[i][1])]
    elif z[i][2] == '4':
        h = [j for j in h if j <= int(z[i][1])]
if w == [] or h == []:
    print(0)
else:
    dh = max(h)-min(h)
    dw = max(w)-min(w)
    print(dh * dw)

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

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

for x,y,a in xya:
  
  if a == 1:
    for i in range(x):
      for j in range(H):
        Result[i][j] = 0
  elif a == 2:
    for i in range(x, W):
      for j in range(H):
        Result[i][j] = 0
  elif a == 3:
    for i in range(W):
      for j in range(y):
        Result[i][j] = 0
  elif a == 4:
    for i in range(W):
      for j in range(y, H):
        Result[i][j] = 0


Result = [flatten for inner in Result for flatten in inner]
print(sum(Result))

Solution (Python):
w, h, n = map(int, input().split())
xya = [[0] * 3 for i in range(n)]
for i in range(n):
    x, y, a = map(int, input().split())
    xya[i][0], xya[i][1], xya[i][2] = x, y, a

area = [[False] * w for i in range(h)]
for i in xya:
    if i[2] == 1:
        for row in range(h):
            for col in range(0, i[0]):
                area[row][col] = True
    elif i[2] == 2:
        for row in range(h):
            for col in range(i[0], w):
                area[row][col] = True
    elif i[2] == 3:
        for row in range(0, i[1]):
            for col in range(w):
                area[row][col] = True
    else:
        for row in range(i[1], h):
            for col in range(w):
                area[row][col] = True

ans = 0
for row in range(h):
    for col in range(w):
        if not area[row][col]:
            ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

W, H, N = map(int, input().split(' '))
field = [[0 for _ in range(W)] for _ in range(H)]
for _ in range(N):
    x, y, a = map(int, input().split(' '))
    if a == 1:
        for i in range(H):
            for j in range(x):
                field[i][j] = 1
    elif a == 2:
        for i in range(H):
            for j in range(x, W):
                field[i][j] = 1
    elif a == 3:
        for i in range(y):
            field[i] = [1] * (W)
    elif a == 4:
        for i in range(y, H):
            field[i] = [1] * (W)
ans = 0
for i in range(H):
    for j in range(W):
        if field[i][j] == 0:
            ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

W, H, N = map(int, input().split(' '))
bound = {'l': 0, 'r': W, 'd': 0, 'u': H}
for _ in range(N):
    x, y, a = map(int, input().split(' '))
    if a == 1 and bound['l'] < x:
        bound['l'] = x
    elif a == 2 and bound['r'] > x:
        bound['r'] = x
    elif a == 3 and bound['d'] < y:
        bound['d'] = y
    elif a == 4 and bound['u'] > y:
        bound['u'] = y

w = max(0, bound['r']-bound['l'])
h = max(0, bound['u']-bound['d'])
print(w * h)

Solution (Python):

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

Solution (Python):
w, h, n = map(int, input().split())
c = [[True] * w for i in range(h)]
l = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
    if l[i][2] == 1:
        for j in range(w):
            for k in range(h):
                if j < l[i][0]:
                    c[k][j] = False
    elif l[i][2] == 2:
        for j in range(w):
            for k in range(h):
                if j > l[i][0]-1:
                    c[k][j] = False
    elif l[i][2] == 3:
        for j in range(w):
            for k in range(h):
                if k < l[i][1]:
                    c[k][j] = False
    else:
        for j in range(w):
            for k in range(h):
                if k > l[i][1]-1:
                    c[k][j] = False
for i in range(h):
    ans += c[i].count(True)
print(ans)

Solution (Python):


import numpy as np

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

x_list = []
y_list = []
a_list = []

field = np.ones((H, W), dtype=np.int)

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(x):
            for j in range(H):
                field[j, i] = 0
    elif a == 2:
        for i in range(x, W):
            for j in range(H):
                field[j, i] = 0
    elif a == 3:
        for i in range(y):
            for j in range(W):
                field[i, j] = 0
    elif a == 4:
        for i in range(y, H):
            for j in range(W):
                field[i, j] = 0

print(np.count_nonzero(field == 1))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    w,h,N=mis()
    s,t=0,0
    for i in range(N):
        x,y,a=mis()
        if a==1 and s<x: s=x
        elif a==2 and w>x: w=x
        elif a==3 and t<y: t=y
        elif a==4 and h>y: h=y
    print(0 if h-t<=0 or w-s<=0 else (h-t)*(w-s))



if __name__ == "__main__":
    main()

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

w_min, w_max = 0, W
h_min, h_max = 0, H

for _ in range(N) :
    x, y, a = map(int, input().split())
    
    if (a == 1):
        w_min = max(w_min, x)
    elif (a == 2):
        w_max = min(w_max, x)
    elif (a == 3):
        h_min = max(h_min, y)
    else:
        h_max = min(h_max, y)


if (w_max < w_min or h_max < h_min):
    print(0)
else:
    area = (w_max - w_min) * (h_max - h_min)
    print(area)

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

Solution (Python):
W,H,N=map(int,input().split())
x=[0]*N
y=[0]*N
a=[0]*N
minX=0
maxX=W
minY=0
maxY=H
for i in range(N):
  x[i],y[i],a[i]=map(int,input().split())
  if a[i]==1:
    minX=max(minX,x[i])
  if a[i]==2:
    maxX=min(maxX,x[i]) 
  if a[i]==3:
    minY=max(minY,y[i])
  if a[i]==4:
    maxY=min(maxY,y[i]) 

ans=(maxX-minX)*(maxY-minY)
if maxX<minX or maxY<minY:
  ans=0
print(ans)

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

Solution (Python):
import sys









mod = int(1e9+7)
INF = 1<<29

def main():
    w,h,n = map(int,input().split())
    face = [[0 for j in range(w)] for i in range(h)]
    for i in range(n):
        x,y,a = map(int,input().split())
        if a == 1:
            for j in range(x):
                for k in range(h):
                    face[k][j] = 1
        elif a == 2:
            for j in range(x,w):
                for k in range(h):
                    face[k][j] = 1
        elif a == 3:
            for j in range(y):
                for k in range(w):
                    face[j][k] = 1
        else:
            for j in range(y,h):
                for k in range(w):
                    face[j][k] = 1
    ans = 0
    for i in range(h):
        for j in range(w):
            if face[i][j] == 0:
                ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()

Solution (Python):
W, H, N = [int(i) for i in input().split()]
top, bottom, left, right = H, 0, 0, W
for _ in range(N):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        bottom = max(bottom, y)
    elif a == 4:
        top = min(top, y)
print(max(right - left, 0) * max(top - bottom, 0))

Solution (Python):
def main():
  w, h, n = input_list()
  
  points = []
  for x in range(w):
    row = [True]*h
    points.append(row)
      
  for _ in range(n):
    x, y, a = input_list()
    if a == 1:
      for px, row in enumerate(points):
        for py, v in enumerate(row):
          if px+1 <= x:
            points[px][py] = False
    if a == 2:
      for px, row in enumerate(points):
        for py, v in enumerate(row):
          if px+1 > x:
            points[px][py] = False
    if a == 3:
      for px, row in enumerate(points):
        for py, v in enumerate(row):
          if py+1 <= y:
            points[px][py] = False
    if a == 4:
      for px, row in enumerate(points):
        for py, v in enumerate(row):
          if py+1 > y:
            points[px][py] = False
  ans = 0
  for p in points:
    ans += p.count(True)
  print(ans)

def input_list():
  return map(int, input().split())

import math
main()

Solution (Python):
w, h, n = (int(x) for x in input().split())
x = []
s = [[1 for _ in range(w)] for _ in range(h)]
for _ in range(n): x.append([int(i) for i in input().split()])
for x_i in x:
    a = x_i[2]
    if a == 1:
        for h_ in range(h):
            for w_ in range(x_i[0]):
                s[h_][w_] = 0
    elif a == 2:
        for h_ in range(h):
            for w_ in range(x_i[0], w):
                s[h_][w_] = 0
    elif a == 3:
        for h_ in range(x_i[1]):
            for w_ in range(w):
                s[h_][w_] = 0
    else:
        for h_ in range(x_i[1], h):
            for w_ in range(w):
                s[h_][w_] = 0
print(sum([s[i][j] for j in range(w) for i in range(h)]))

Solution (Python):
W, H, N = map(int,input().split())
lx, rx = 0, W
dy, uy = 0, 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:
    dy = max(dy, y)
  elif a == 4:
    uy = min(uy, y)

w, h = rx - lx, uy - dy
if w <= 0 or h <= 0:
  print(0)
else:
  print(w*h)

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
W,H,N=map(int, input().split())
s=[[1]*W for i in range(H)]
for i in range(N):
    x,y,n=map(int,input().split())
    if n==1:
        for j in range(x):
            for k in range(H):
                s[k][j]=0
    elif n==2:
        for j in range(x,W):
            for k in range(H):
                s[k][j]=0
    elif n==3:
        for j in range(W):
            for k in range(y):
                s[k][j]=0
    elif n==4:
        for j in range(W):
            for k in range(y,H):
                s[k][j]=0
a=0
for i in s:
    a+=sum(i)
print(a)

Solution (Python):
w, h, n = [int(e) for e in input().split()]
x_under, x_lim, y_under, y_lim = 0, w, 0, h
for _ in range(n):
    x, y, a = [int(e) for e in input().split()]
    if a == 1 and x_under < x:
        x_under = x
    elif a == 2 and x < x_lim:
        x_lim = x
    elif a == 3 and y_under < y:
        y_under = y
    elif a == 4 and y < y_lim:
        y_lim = y
x_len = x_lim - x_under
y_len = y_lim - y_under
if x_len < 0 or y_len < 0:
    print('0')
else:
    print(x_len * y_len)

Solution (Python):
def main():
    width, height, point_num = map(int, input().split())
    points = [tuple(map(int, input().split())) for _ in range(point_num)]
    white_range = [[0, 0], [width, height]]
    for point in points:
        if point[2] == 1:
            white_range[0][0] = max(point[0], white_range[0][0])
        elif point[2] == 2:
            white_range[1][0] = min(point[0], white_range[1][0])
        elif point[2] == 3:
            white_range[0][1] = max(point[1], white_range[0][1])
        else:
            white_range[1][1] = min(point[1], white_range[1][1])
    if white_range[1][0] < white_range[0][0] or white_range[1][0] < white_range[0][0]:
        print(0)
    else:
        print((white_range[1][0] - white_range[0][0]) * (white_range[1][1] - white_range[0][1]))


if __name__ == '__main__':
    main()