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):
inp = list(map(int,input().split()))
left_max=0
right_min=inp[0]
upper_min=inp[1]
lower_max=0

for i in range(inp[2]):
    inin = list(map(int,input().split()))
    if inin[2] == 1 and inin[0]>left_max:
        left_max=inin[0]
    if inin[2] == 2 and inin[0]<right_min:
        right_min=inin[0]
    if inin[2] == 4 and inin[1]<upper_min:
        upper_min=inin[1]
    if inin[2] == 3 and inin[1]>lower_max:
        lower_max=inin[1]
left_max=min(left_max,right_min)
upper_min=max(upper_min,lower_max)
print((right_min-left_max)*(upper_min-lower_max))

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

x = [int(i) for i in range(w+1)]
y = [int(i) for i in range(h+1)]

for i in range(n):
    x_i, y_i, a = map(int,input().split())
    if a == 1:
        x = [int(j) for j in x if j >= int(x_i)]
    elif a == 2:
        x = [int(j) for j in x if j <= int(x_i)]
    elif a == 3:
        y = [int(j) for j in y if j >= int(y_i)]
    elif a == 4:
        y = [int(j) for j in y if j <= int(y_i)]
if len(x) == 0 or len(y) == 0:
    print('0')
else:
    print((max(x)-min(x)) * (max(y)-min(y)))

Solution (Python):
W,H,N = map(int, input().split())
l = []
for i in range (N):
    x,y,a = map(int,input().split())
    l.append([x,y,a])
y1 = 0
y2 = H
x1 = 0
x2 = W
for j in range (N):
    if (l[j][2] == 1) & (x1 < l[j][0]):
        x1 = l[j][0]
    elif (l[j][2] == 2) & (x2 > l[j][0]):
        x2 = l[j][0]
    elif (l[j][2] == 3) & (y1 < l[j][1]):
        y1 = l[j][1]
    elif (l[j][2] == 4) & (y2 > l[j][1]):
        y2 = l[j][1]
S = (x2 - x1)*(y2 - y1)
if (x2 > x1) & (y2 > y1):
    print(S)
else:
    print(0)

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

minx=0
maxx=w
miny=0
maxy=h

for i in range(n):
    if p[i][2]==1:
        minx=max(minx,p[i][0])
    if p[i][2]==2:
        maxx=min(maxx,p[i][0])
    if p[i][2]==3:
        miny=max(miny,p[i][1])
    if p[i][2]==4:
        maxy=min(maxy,p[i][1])
w=maxx-minx
h=maxy-miny
print(w*h if w>0 and h>0 else 0)

Solution (Python):
w,h,n=map(int,input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
wl,wr,hu,ht=0,w,0,h
for i in range(n):
    if xya[i][2]==1:
        wl=max(wl,int(xya[i][0]))
    elif xya[i][2]==2:
        wr=min(wr,int(xya[i][0]))
    elif xya[i][2]==3:
        hu=max(hu,int(xya[i][1]))
    elif xya[i][2]==4:
        ht=min(ht,int(xya[i][1]))
    else:pass
if wl>wr or hu>ht:print(0)
else:print((wr-wl)*(ht-hu))

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

Solution (Python):

w,h,n=list(map(int,input().split()))
x=[]
y=[]
a=[]

for i in range(n):
    x1,y1,a1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    a.append(a1)

lp=0
x_max=[0]
x_min=[w]
y_max=[0]
y_min=[h]

for aa in a:
    
    if aa== 1:
        x_max.append(x[lp])

    elif aa==2:
        x_min.append(x[lp])

    elif aa==3:
        y_max.append(y[lp])

    elif aa==4:
        y_min.append(y[lp])
    
    lp+=1

x=min(x_min)-max(x_max)
y=min(y_min)-max(y_max)

if x<=0:
    x=0
if y<=0:
    y=0

ans=x*y

print(ans)

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

left = 0
right = w
high = h
low = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        left = max(left, x)
    if a == 2:
        right = min(right, x)
    if a == 3:
        low = max(low, y)
    if a == 4:
        high = min(high, y)

print(max(0, right - left) * max(0, high - low))

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

Solution (Python):
W,H,N=map(int,input().split())
leftW,leftH=0,0
rightW,rightH=W,H

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1 and leftW<x:
        leftW=x
    elif a==2 and x<rightW:
        rightW=x
    elif a==3 and leftH<y:
        leftH=y
    elif a==4 and y<rightH:
        rightH=y
ansH=rightH-leftH
ansW=rightW-leftW
if ansH<0: ansH=0
if ansW<0: ansW=0
print(ansH*ansW)

Solution (Python):
W, H , N = list(map(int, input().split()))
W0 = 0
H0 = 0
X = []
Y = []
A = []
for i in range(N):
    x,y,a=[int(i) for i in input().split()]
    X.append(x)
    Y.append(y)
    A.append(a)
for j in range (N):
    if A[j] == 1:
        if X[j] >=  W0:
            W0 = X[j]
    elif A[j] == 2:
        if X[j] <= W:
            W = X[j]
    elif A[j] == 3:
        if Y[j] >= H0:
            H0 = Y[j]
    elif A[j] == 4:
        if Y[j] <= H:
            H = Y[j]
h = H - H0
w = W - W0
if h >=0 and w >= 0:
    print(h*w)
else:
    print(0)

Solution (Python):
w,h,n = [int(x) for x in input().split()]
l = 0
r = w
b = 0
t = h
for _ in range(n):
    x,y,a = [int(x) for x in input().split()]
    if a == 1:
        l = max(x,l)
    elif a == 2:
        r = min(r,x)
    elif a == 3:
        b = max(b,y)
    elif a == 4:
        t = min(t,y)

if r<l or t<b:
    print(0)
else:
    print((r-l) * (t-b))

Solution (Python):
W,H,N=map(int,input().split())
x=[0]*N
y=[0]*N
a=[0]*N
H_min=0
H_max=H
W_min=0
W_max=W

for i in range(N):
  x[i],y[i],a[i] = map(int,input().split())
  if a[i]==1:
    W_min=max(x[i],W_min)
  elif a[i]==2:
    W_max=min(x[i],W_max)
  elif a[i]==3:
    H_min=max(y[i],H_min)
  else:
    H_max=min(y[i],H_max)

height = max(0,H_max-H_min)
width = max(0,W_max-W_min)
print(height*width)

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

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

xl, xr, yb, yt = 0, w, 0, h

for i in range(n):
    if xya[i][2] == 1:
        xl = max(xl, xya[i][0])
    elif xya[i][2] == 2:
        xr = min(xr, xya[i][0])
    elif xya[i][2] == 3:
        yb = max(yb, xya[i][1])
    else:
        yt = min(yt, xya[i][1])

if xr - xl <= 0 or yt - yb <= 0:
    print(0)
else:
    print((xr - xl)*(yt - yb))

Solution (Python):
W,H,N=list(map(int,input().split()))
L=[]
for h in range(H):
    L.append([])
    for w in range(W):
        L[h].append(0)

X=[]
Y=[]
A=[]
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 h in range(H):
            for w in range(W):
                if 0<=w<X[i]:
                    L[h][w]=1
    elif A[i]==2:
        for h in range(H):
            for w in range(W):
                if X[i]<=w<=W-1:
                    L[h][w]=1
    elif A[i]==3:
        for h in range(H):
            for w in range(W):
                if 0<=h<Y[i]:
                    L[h][w]=1
    elif A[i]==4:
        for h in range(H):
            for w in range(W):
                if Y[i]<=h<=H-1:
                    
                    L[h][w]=1
                    pass

count=0
for h in range(H-1,-1,-1):
    for w in range(W):
        if L[h][w]==0:
            count+=1
    
print(count)

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

Solution (Python):
W, H, N = map(int, input().split())
left, right, bottom, top = 0, W, 0, H
for _ 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:
    bottom = max(bottom, y)
  elif a == 4:
    top = min(top, y)
if right > left and top > bottom:
  ans = (right - left) * (top - bottom)
else:
  ans = 0
print(ans)

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

l=[-1]*5
l[2]=float('inf')
l[4]=float('inf')
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        l[1]=max(l[1],x)
    elif a==2:
        l[2]=min(l[2],x)
    elif a==3:
        l[3]=max(l[3],y)
    else:
        l[4]=min(l[4],y)

for i in range(h):
    for j in range(w):
        
        if j<l[1]:
            mat[i][j]=0
        if l[2]<=j:
            mat[i][j]=0
        if i<l[3]:
            mat[i][j]=0
        if l[4]<=i:
            mat[i][j]=0

ans=0
for i in range(h):
    for j in range(w):
        ans+=mat[i][j]
print(ans)

Solution (Python):
w,h,n=map(int,input().split())
xl=0
xh=w
yl=0
yh=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 yh<=yl or xh<=xl:
    print(0)
else:
    print((yh-yl)*(xh-xl))

Solution (Python):
w,h,n = map(int,input().split())
area = h*w
a1=0
a2=w
a3=0
a4=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)
  elif a==4:
    a4 = min(a4,y)

if a1>=a2 or a3>=a4:
  print(0)
else:
  area -= a1*h + (w-a2)*h + a3*w + (h-a4)*w 
 
  print(area+(a1*(a3+(h-a4))+(w-a2)*(a3+(h-a4))))

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

def main():
    W, H, N = [int(x) for x in input().split()]
    XYA = [[int(x) for x in input().split()] for _ in range(N)]

    sx, sy, lx, ly = 0, 0, W, H
    for x, y, a in XYA:
        if a == 1:
            sx = max(sx, x)
        elif a == 2:
            lx = min(lx, x)
        elif a == 3:
            sy = max(sy, y)
        else:
            ly = min(ly, y)

    print(max(0, lx - sx) * max(0, ly - sy))
    

if __name__ == '__main__':
    main()

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

if e[0] >= s[0] and e[1] >= s[1]:
    print((e[0] - s[0]) * (e[1] - s[1]))
else:
    print(0)

Solution (Python):
import numpy as np

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

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

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

Solution (Python):
W, H, N = map(int, input().split())
zahyo = [list(map(int, input().split())) for i in range(N)]
x_min = y_min = 0
x_max = W
y_max = H
for i in range(N):
    if zahyo[i][2] == 1:
        if x_min < zahyo[i][0]:
            x_min = zahyo[i][0]
    
    elif zahyo[i][2] == 2:
        if zahyo[i][0] < x_max:
            x_max = zahyo[i][0]
            
    elif zahyo[i][2] == 3:
        if y_min < zahyo[i][1]:
            y_min = zahyo[i][1]
            
    elif zahyo[i][2] == 4:
        if zahyo[i][1] < y_max:
            y_max = zahyo[i][1]
    
if (x_max - x_min) > 0 and  (y_max - y_min) > 0:
    print((x_max - x_min) * (y_max - y_min))
else:
    print(0)

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

left = 0
under =0
right = W
upper = H

for _ in range(N):
    x,y,a = map(int,input().split())
    if a ==1:
        left = max(x,left)
    elif a ==2:
        right =min(x,right)
    elif a == 3:
        under = max(y,under)
    elif a == 4:
        upper = min(y,upper)

if (right-left)>0 and (upper-under)>0:
    S = (right-left)*(upper-under)
    print(S)
else:
    print(0)

Solution (Python):
W, H, N = map(int, input().split())
zahyo = [list(map(int, input().split())) for i in range(N)]
area = [[0 for i in range(H)] for j in range(W)]
for i in range(N):
    if zahyo[i][2] == 1:
        for j in range(zahyo[i][0]):
            for k in range(H):
                area[j][k] = 1
                
    elif zahyo[i][2] == 2:
        for j in range(zahyo[i][0], W):
            for k in range(H):
                area[j][k] = 1
                
    elif zahyo[i][2] == 3:
        for j in range(W):
            for k in range(zahyo[i][1]):
                area[j][k] = 1
                
    elif zahyo[i][2] == 4:
        for j in range(W):
            for k in range(zahyo[i][1], H):
                area[j][k] = 1

cnt = 0
for l in area:
    for m in range(H):
        if l[m] == 0:
            cnt += 1
print(cnt)

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

point_list = [input().split() for i in range(n)]

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


for point in point_list:

    if point[2] == "1":
        for i in range(h):
            for j in range(int(point[0])):
                area[i][j] = 0
    elif point[2] == "2":
        for i in range(h):
            for j in range(int(point[0]), w):
                area[i][j] = 0
    elif point[2] == "3":
        for i in range(int(point[1])):
            for j in range(w):
                area[i][j] = 0
    elif point[2] == "4":
        for i in range(int(point[1]), h):
            for j in range(w):
                area[i][j] = 0

print(sum([sum(i) for i in area]))

Solution (Python):


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

right = w
left = 0
upper = h
under = 0

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

    if a ==1:
        left = max(x,left)
    elif a ==2:
        right = min(x,right)
    elif a ==3:
        under = max(y,under)
    else:
        upper = min(y,upper)

if(upper-under)>0 and (right-left)>0:
    c = (upper-under)*(right-left)
    print(c)
else:
    print(0)

Solution (Python):
W,H,N = map(int, input().split())
a = [0] * N
x = [0] * N
y = [0] * N

xl = 0
xr = W
yt = H
yb = 0

for i 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:
        yb = max(y,yb)    

    else :
        yt = min(y, yt)






ans = (xr - xl) * (yt - yb)
if ans <= 0 or ((xr - xl < 0 )or (yt - yb < 0)):
    ans = 0

print(ans)

Solution (Python):
W,H,N=map(int,input().split())
rec=[[0,0],[W,H]]

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        rec[0][0]=max(rec[0][0],x)
    elif a==2:
        rec[1][0]=min(rec[1][0],x)
    elif a==3:
        rec[0][1]=max(rec[0][1],y)
    elif a==4:
        rec[1][1]=min(rec[1][1],y)

if (rec[1][0]-rec[0][0]) >=0 and (rec[1][1]-rec[0][1])>=0:
    ans=(rec[1][0]-rec[0][0])*(rec[1][1]-rec[0][1])
else:
    ans=-1
print(ans if ans>=0 else 0)

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

a1 = []
a2 = []
a3 = []
a4 = []

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

    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    elif a == 4:
        a4.append(y)

if len(a1) == 0:
    aa1 = 0
else:
    aa1 = max(a1)

if len(a2) == 0:
    aa2 = 0
else:
    aa2 = min(a2)

if len(a3) == 0:
    aa3 = 0
else:
    aa3 = max(a3)

if len(a4) == 0:
    aa4 = 0
else:
    aa4 = min(a4)

rx = 0
if aa2 != 0:
    rx = w - aa2

ty = 0
if aa4 != 0:
    ty = h - aa4
s = (w - aa1 - rx) * (h - aa3 - ty)

if s >= 0:
    print(s)
else:
    print(0)

Solution (Python):
w, h, n = map(int, input().split())
nums_list=[list(map(int, input().split())) for i in range(n)]
minX = 0
maxX = w
minY = 0
maxY = h
for nums in nums_list:
	x, y, a = map(int, nums)
	if a == 1:
		minX = minX if (minX > x) else x
	elif a == 2:
		maxX = maxX if (maxX < x) else x
	elif a == 3:
		minY = minY if (minY > y) else y
	else:
		maxY = maxY if (maxY < y) else y
width = maxX-minX
width = width if (width > 0) else 0
height = maxY-minY
height = height if (height > 0) else 0
v = width*height
print(v)

Solution (Python):
import sys

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

zahyo = [list(map(int, input().split())) for i in range(n)]

area = [[0 for i in range(h)] for j in range(w)]

for i in range(n):
    if zahyo[i][2] == 1:
        for j in range(zahyo[i][0]):
            for k in range(len(area[j])):
                area[j][k] = 1
    elif zahyo[i][2] == 2:
        for j in range(w - 1, zahyo[i][0] - 1, -1):
            for k in range(len(area[j])):
                area[j][k] = 1
    elif zahyo[i][2] == 3:
        for j in range(len(area)):
            for k in range(zahyo[i][1]):
                area[j][k] = 1
    elif zahyo[i][2] == 4:
        for j in range(len(area)):
            for k in range(h - 1, zahyo[i][1] - 1, -1):
                area[j][k] = 1

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

print("{}".format(cnt_zero))

Solution (Python):
w,h,n = map(int,input().split())
Mx = w ; My = h
mx = 0 ; my = 0

for i in range(n):
    x,y,a = map(int,input().split())
    
    if a == 1:
        mx = max(mx,x)
    elif a == 2:
        Mx = min(Mx,x)
    elif a == 3:
        my = max(my,y)
    else:
        My = min(My,y)
        
s = (Mx - mx)*(My - my)
print(s if mx < Mx and my < My else 0)

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

xr = w
xl = 0
yu = h
yl = 0

for i in range(n):
    if T[i][2] == 2:
        xr = min(xr, T[i][0])
    elif T[i][2] == 1:
        xl = max(xl, T[i][0])
    elif T[i][2] == 4:
        yu = min(yu, T[i][1])
    else:
        yl = max(yl, T[i][1])

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

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

left = 0
right = w
under = 0
upper = h

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

    if a==1:
        left = max(x, left)
    elif a==2:
        right = min(x, right)
    elif a==3:
        under = max(y, under)
    else:
        upper = min(y, upper)

if (upper-under)>0 and (right-left)>0:
    ans = (upper-under)*(right-left)
    print(ans)
else:
    print(0)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    W,H,N=MI()
    L=[0,W,0,H]
    for _ in range(N):
        x,y,a=MI()
        a-=1
        if a==0:
            L[a]=max(L[a],x)
        elif a==1:
            L[a]=min(L[a],x)
        elif a==2:
            L[a]=max(L[a],y)
        else:
            L[a]=min(L[a],y)
            
            
    dx=L[1]-L[0]
    dy=L[3]-L[2]
    
    if dx>0 and dy>0:
        print(dx*dy)
    else:
        print(0)
            

main()

Solution (Python):

w,h,n=map(int,input().split())
zahyo=[]
a=[]
for i in range(n):
    x,y,z=map(int,input().split())
    zahyo.append([x,y])
    a.append(z)
l=[0,0]
r=[w,h]

def white(i):
    if a[i]==1:
        if l[0]<zahyo[i][0]:
            l[0]=zahyo[i][0]
    elif a[i]==2:
        if r[0]>zahyo[i][0]:
            r[0]=zahyo[i][0]
    elif a[i]==3:
        if l[1]<zahyo[i][1]:
            l[1]=zahyo[i][1]
    else:
        if r[1]>zahyo[i][1]:
            r[1]=zahyo[i][1]


for i in range(n):
    white(i)

yoko=r[0]-l[0]
tate=r[1]-l[1]
ans=0
if yoko>=0 and tate>=0:
    ans=yoko*tate
print(ans)

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

c1 = [0, 0] 
c2 = [W, H] 

while(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if c1[0] < x:
            c1[0] = x
    elif a == 2:
        if c2[0] > x:
            c2[0] = x
    elif a == 3:
        if c1[1] < y:
            c1[1] = y
    else:
        if c2[1] > y:
            c2[1] = y
            
    N = N - 1

if (c2[0] - c1[0]) >= 0 and (c2[1] - c1[1]) >= 0:
    S = (c2[0] - c1[0]) * (c2[1] - c1[1])
    print(S)
else:
    print(0)

Solution (Python):
W, H, N = map(int, input().split())
P = [None for _ in range(N)]
a = [None for _ in range(N)]
for i in range(N):
  *P[i], a[i] = map(int, input().split())

ans = [[1] * W for _ in range(H)]
for i in range(N):
  if a[i] == 1:
    for j in range(H):
      for k in range(P[i][0]):
        ans[j][k] = 0
  elif a[i] == 2:
    for j in range(H):
      for k in range(P[i][0],W):
        ans[j][k] = 0
  elif a[i] == 3:
    for j in range(P[i][1]):
      for k in range(W):
        ans[j][k] = 0
  else:
    for j in range(P[i][1],H):
      for k in range(W):
        ans[j][k] = 0
  
print(sum(map(sum,ans)))

Solution (Python):
w, h, n = map(int, input().split())
u, d = 0, h
l, r = 0, w

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

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

Solution (Python):








def resolve():
    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())


    w,h=0,0
    for i in range(N):
        if a[i]==1:
            w=max(w,x[i])
        elif a[i]==2:
            W=min(W,x[i])
        elif a[i]==3:
            h = max(h, y[i])
        elif a[i] == 4:
            H = min(H, y[i])

    print((W-w)*(H-h) if (W-w)>=0 and (H-h)>=0 else 0)




resolve()

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

Op1 = [0]
Op2 = [w]
Op3 = [0]
Op4 = [h]
for j in range(n):
    if Op[j][2] == 1:
        Op1.append(Op[j][0])
    elif Op[j][2] == 2:
        Op2.append(Op[j][0])
    elif Op[j][2] == 3:
        Op3.append(Op[j][1])
    elif Op[j][2] == 4:
        Op4.append(Op[j][1])
'''
print(Op1)
print(Op2)
print(Op3)
print(Op4)
'''
if min(Op2)-max(Op1) < 0:
    print(0)
elif min(Op4)-max(Op3) < 0:
    print(0)
else:
    print((min(Op2)-max(Op1))*(min(Op4)-max(Op3)))

Solution (Python):
W, H, N = map(int,input().split())
B = [[0]*W for k in range(H)]
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        for k in range(x):
            for l in range(H):
                B[l][k] = 1
    elif a == 2:
        for k in range(x,W):
            for l in range(H):
                B[l][k] = 1
    elif a == 3:
        for k in range(W):
            for l in range(y):
                B[l][k] = 1
    else:
        for k in range(W):
            for l in range(y,H):
                B[l][k] = 1
ans = 0
for e in B:
    ans += e.count(0)
print(ans)

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

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

A = [0]*4
for i in range(4):
  A[i] = []
for i in range(N):
  x,y,a = map(int, input().split())
  if a==1 or a==2:
  	A[a-1].append(x)
  else:
    A[a-1].append(y)

A[0] = max(A[0]) if len(A[0])!=0 else 0
A[1] = min(A[1]) if len(A[1])!=0 else W
A[2] = max(A[2]) if len(A[2])!=0 else 0
A[3] = min(A[3]) if len(A[3])!=0 else W
print(max(0,A[1]-A[0])*max(0,A[3]-A[2]))

Solution (Python):
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)
    elif a==2:
        x2=min(x,x2)
    elif a==3:
        y1=max(y1,y)
    elif a==4:
        y2=min(y,y2)
if x2<x1 or y2<y1:
    print(0)
    exit()
xx=x2-x1
yy=y2-y1
print(xx*yy)

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

w,h,n = map(int,readline().split())

lst1 = [0,w,0,h] 
for i in range(n):
    x,y,a = map(int,readline().split())
    if a==1 or a==3: 
        if a==1: 
            lst1[a-1] = max(lst1[a-1],x)
        else: 
            lst1[a-1] = max(lst1[a-1],y)
    
    else:
        if a==2: 
            lst1[a-1] = min(lst1[a-1],x)
        else: 
            lst1[a-1] = min(lst1[a-1],y)

class Square_area():
    """
    about:
    四角形の左縁からx1,右縁からx2迄,下縁からy1迄,上縁からy2迄,塗りつぶした時の、塗りつぶした面積を出力する。
    require:
    w,h,x1,x2,y1,y2
    w:幅
    h:高さ
    四角形の左下の座標を(0,0)とした時、
    x1:その左側を塗りつぶす
    x2:その右〃
    y1:その下〃
    y2:その上〃
    x1とx2の領域が重なる(x2<x1)の場合は、全て塗りつぶすという扱いになる。yについても同様。
    """
    def __init__(self,w,h,x1,x2,y1,y2): 
        self.w = w
        self.h = h
        self.area = w*h
        self.x1 = x1
        if x2 < x1:
            self.x2 = w-x1
        else:
            self.x2 = w-x2
        self.y1 = y1
        if y2 < y1:
            self.y2 = h-y1
        else:
            self.y2 = h-y2
        
        for i in [self.x1,self.x2]:
            if not 0 <= i <= w:
                raise Exception
        for i in [self.y1,self.y2]:
            if not 0 <= i <= h:
                raise Exception

    def get_outer(self): 
        return (self.x1+self.x2)*self.h +(self.y1+self.y2)*self.w - self.dublication()

    def get_inner(self): 
        return self.area - self.get_outer()

    def dublication(self): 
        return self.x1*(self.y1+self.y2)+self.x2*(self.y1+self.y2)

req = Square_area(w,h,lst1[0],lst1[1],lst1[2],lst1[3])

print(req.get_inner())

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

w,h,n = map(int,readline().split())

lst1 = [0,w,0,h] 
for i in range(n):
    x,y,a = map(int,readline().split())
    if a==1 or a==3: 
        if a==1: 
            lst1[a-1] = max(lst1[a-1],x)
        else: 
            lst1[a-1] = max(lst1[a-1],y)
    
    else:
        if a==2: 
            lst1[a-1] = min(lst1[a-1],x)
        else: 
            lst1[a-1] = min(lst1[a-1],y)

class Square_area():
    """
    about:
    四角形の縁からx,yだけ塗りつぶした時の、塗りつぶした面積を出力する。
    require:
    w,h,x1,x2,y1,y2
    w:幅
    h:高さ
    四角形の左下の座標を(0,0)とした時、
    x1:その左側を塗りつぶす
    x2:その右〃
    y1:その下〃
    y2:その上〃
    x1とx2の領域が重なる(x2<x1)の場合は、全て塗りつぶすという扱いになる。yについても同様。
    """
    def __init__(self,w,h,x1=0,x2=w,y1=0,y2=h):
        self.w = w
        self.h = h
        self.area = w*h
        self.x1 = x1
        if x2 < x1:
            self.x2 = w-x1
        else:
            self.x2 = w-x2
        self.y1 = y1
        if y2 < y1:
            self.y2 = h-y1
        else:
            self.y2 = h-y2
    
    def get_outer(self): 
        return (self.x1+self.x2)*h +(self.y1+self.y2)*w - self.dublication()

    def get_inner(self): 
        return self.area - self.get_outer()

    def dublication(self): 
        return self.x1*(self.y1+self.y2)+self.x2*(self.y1+self.y2)

req = Square_area(w,h,lst1[0],lst1[1],lst1[2],lst1[3])

print(req.get_inner())

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

w,h,n = map(int,readline().split())

lst1 = [0,w,0,h] 
for i in range(n):
    x,y,a = map(int,readline().split())
    if a==1 or a==3: 
        if a==1: 
            lst1[a-1] = min(lst1[1],max(lst1[a-1],x))
        else: 
            lst1[a-1] = min(lst1[3],max(lst1[a-1],y))
    
    else:
        if a==2: 
            lst1[a-1] = max(lst1[0],min(lst1[a-1],x))
        else: 
            lst1[a-1] = max(lst1[2],min(lst1[a-1],y))

print(w*h
    - lst1[0]*h
    - (w-lst1[1])*h
    - lst1[2]*w
    - (h-lst1[3])*w
    + lst1[0]*lst1[2]
    + lst1[0]*(h-lst1[3])
    + (w-lst1[1])*lst1[2]
    + (w-lst1[1])*(h-lst1[3])
     )

Solution (Python):
w, h, n = map(int, input().split())
y0 = 0
y1 = h
x0 = 0
x1 = w
for i 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 (x1-x0>0) and (y1-y0>0):
    print((x1-x0)*(y1-y0))
else:
    print(0)

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

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

def calcArea(M, H, N, plot_infos):
  pointA = [M, H]
  pointB = [0, 0]
  for i in range(N):
    plot_info = plot_infos[i]
    if plot_info[2] == 1:
      pointB[0] = max(plot_info[0], pointB[0])
    elif plot_info[2] == 2:
      pointA[0] = min(plot_info[0], pointA[0])
    elif plot_info[2] == 3:
      pointB[1] = max(plot_info[1], pointB[1])
    elif plot_info[2] == 4:
      pointA[1] = min(plot_info[1], pointA[1])
      
  if pointA[0] < pointB[0] or pointA[1] < pointB[1]:
      return 0
      
  return (pointA[0] - pointB[0]) * (pointA[1] - pointB[1])

print(calcArea(W, H, N, plot_infos))