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

C = [[1 for i in range(W)] for j in range(H)]

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


ans = 0

for i in range(H):
    ans += sum(C[i])


print(ans)

Solution (Python):
W, H, N =map(int,input().split())
xya = [list(map(int,input().split())) for i in range(N)]
lxy=[0,0]
rxy=[W,H]
for i in range(N):
    if xya[i][2]==1:
        lxy[0] = max(lxy[0],xya[i][0])
    elif xya[i][2]==2:
        rxy[0] = min(rxy[0],xya[i][0])
    elif xya[i][2]==3:
        lxy[1] = max(lxy[1],xya[i][1])
    else: rxy[1] = min(rxy[1],xya[i][1])

print(max(0,(rxy[1]-lxy[1]))*(max(0,rxy[0]-lxy[0])))

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

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

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

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

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

field=[]
for i in range(N):
    array = list(map(int,input().split()))
    field.append(array)

for i in range(N):
    state = field[i][2]

    if state == 1:
        for j in range(0,H):
            for k in range (0,field[i][0]):
                ans[j][k]=1
    if state == 2:
        for j in range(0,H):
            for k in range (field[i][0],W):
                ans[j][k]=1
    if state == 3:
        for j in range(H-field[i][1],H):
            for k in range (0,W):
                ans[j][k]=1
    if state == 4:
        for j in range(0,H-field[i][1]):
            for k in range (0,W):
                ans[j][k]=1
    
result=0
for i in range(H):
    result += str(ans[i]).count("0")

print(result)

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

X = [0, W]
Y = [0, H]

for l in lst:
    if l[2] == 1 and X[0] < l[0]:
        X[0] = l[0]
    elif l[2] == 2 and l[0] < X[1]:
        X[1] = l[0]
    elif l[2] == 3 and Y[0] < l[1]:
        Y[0] = l[1]
    elif l[2] == 4 and l[1] < Y[1]:
        Y[1] = l[1]

width = X[1] - X[0] if X[1] - X[0] > 0 else 0
height = Y[1] - Y[0] if Y[1] - Y[0] > 0 else 0

print(width * height)

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

Solution (Python):
w,h,n = map(int,input().split())
x_start = 0
x_end = w
y_start = 0
y_end = h 
array = []
for i in range(n):
    x,y,a=map(int,input().split())
    if a == 1:
        x_start = max(x,x_start)
    elif a == 2:
        x_end = min(x,x_end)
    elif a == 3:
        y_start = max(y,y_start)
    elif a == 4:
        y_end = min(y,y_end)
x_len = x_end-x_start
y_len = y_end-y_start
if x_len <= 0 or y_len <= 0:
    print(0)
else:
    print(x_len * y_len)

Solution (Python):
w, h, n = map(int, input().split())
xl, xr, yl, yh= 0, w, 0, h

for _ in range(n):
  a, b, c = map(int, input().split())
  if c == 1:
    xl = max(xl, a)
  elif c == 2:
    xr = min(xr, a)
  elif c == 3:
    yl = max(yl, b)
  else:
    yh = min(yh, b)
if yh - yl >= 0 and xr - xl >= 0:
  print((yh - yl) * (xr - xl))
else :
  print(0)

Solution (Python):



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





width = []
height = []

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



print(width.count(0) * height.count(0))

Solution (Python):
w,h,n = map(int,input().split())
a = [list(map(int,input().split()))for _ in range(n)]
z1 = [0,0]
z2 = [w,h]
for i in range (n):
    if a[i][2] == 1 and z1[0] <= a[i][0]:
        z1[0] = a[i][0]
    elif a[i][2] == 2 and z2[0] >= a[i][0]:
        z2[0] = a[i][0]
    elif a[i][2] == 3 and z1[1] <= a[i][1] :
        z1[1] = a[i][1]
    elif a[i][2] == 4 and z2[1] >= a[i][1] :
        z2[1] = a[i][1]
if z2[0] > z1[0] and z2[1] > z1[1]:
    print((z2[0]-z1[0])*(z2[1]-z1[1]))
else:
    print(0)

Solution (Python):
import numpy as np

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

x_s,y_s,a_s = [],[],[]
for i in range(N):
  x,y,a = map(int, input().split())
  x_s.append(x)
  y_s.append(y)
  a_s.append(a)
    
x_s = np.array(x_s)
y_s = np.array(y_s)
a_s = np.array(a_s)

if (a_s==1).sum()>=1:
  x_min = x_s[a_s==1].max()
else:
  x_min = 0
  
if (a_s==2).sum()>=1:
  x_max = x_s[a_s==2].min()
else:
  x_max = W
  
if (a_s==3).sum()>=1:
  y_min = y_s[a_s==3].max()
else:
  y_min = 0
  
if (a_s==4).sum()>=1:
  y_max = y_s[a_s==4].min()
else:
  y_max = H
  
if (x_min>=x_max)|(y_min>=y_max):
  ans = 0
else:
  ans = (x_max-x_min)*(y_max-y_min)
  
print(int(ans))

Solution (Python):


w_right, h_top, n = map(int, input().split())
w_left, h_bottom = 0, 0

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if w_left < x:
            w_left = x
    elif a == 2:
        if w_right > x:
            w_right = x
    elif a == 3:
        if h_bottom < y:
            h_bottom = y
    elif a == 4:
        if h_top > y:
            h_top = y

if w_right >= w_left and h_top >= h_bottom:
    print((w_right - w_left) * (h_top - h_bottom))
else:
    print(0)

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

minx=W
maxx=0
miny=H
maxy=0

for x,y,a in List:
  if a==1:
    if x > maxx:
      maxx=x
  elif a==2:
    if x < minx:
      minx=x  
  elif a==3:
    if y > maxy:
      maxy=y    
  elif a==4:
    if y < miny:
      miny=y

lenx=(minx-maxx)
leny=(miny-maxy)
if lenx >0 and leny >0:
  print(lenx*leny)
else:
  print(0)

Solution (Python):
H, W, N = map(int, input().split(" "))
arr = [[0 for i in range(H)] for j 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(W):
        arr[k][j] = 1
  elif a == 2:
    for j in range(x, H):
      for k in range(W):
        arr[k][j] = 1
        
  elif a == 3:
    for j in range(H):
      for k in range(y):
        arr[k][j] = 1
  else:
    for j in range(H):
      for k in range(y, W):
        arr[k][j] = 1

count = 0
for i in arr:
  count += i.count(0)
print(count)

Solution (Python):
w, h, n = map(int, input().split())
rect = [[1 for _ in range(w)] for _ in range(h)]
for _ in range(n):
    x, y, a = map(int, input().split())
    for i in range(h):
        for j in range(w):
            if (a == 1 and j < x) or (a == 2 and x <= j) \
                or (a == 3 and i < y) or (a == 4 and y <= i):
                rect[i][j] = 0
else:
    print(sum(sum(r) for r in rect))

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    w, h, n = list(map(int, input().rstrip('\n').split()))
    max_w = w
    max_h = h
    min_w = 0
    min_h = 0

    for i in range(n):
        x, y, a = list(map(int, input().rstrip('\n').split()))
        if a == 1:
            min_w = max(min_w, x)
        elif a == 2:
            max_w = min(max_w, x)
        elif a == 3:
            min_h = max(min_h, y)
        elif a == 4:
            max_h = min(max_h, y)
    if min_h >= max_h or min_w >= max_w:
        print(0)
    else:
        print((max_h - min_h) * (max_w - min_w))


if __name__ == '__main__':
    slove()

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

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

ll=[0,0]
ur=[w,h]
for i in range(n):
    if xya[i][2]==1:
        ll[0]=max(ll[0],xya[i][0])
    elif xya[i][2]==2:
        ur[0]=min(ur[0],xya[i][0])
    elif xya[i][2]==3:
        ll[1]=max(ll[1],xya[i][1])
    elif xya[i][2]==4:
        ur[1]=min(ur[1],xya[i][1])
if ur[0]-ll[0]<=0 or ur[1]-ll[1]<=0:
    print(0)
else:
    print((ur[0]-ll[0])*(ur[1]-ll[1]))

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 j in range(H):
      ans[j][:x] = [1]*x
  elif a == 2:
    for j in range(H):
      ans[j][x:] = [1]*(W-x)
  elif a == 3:
    for j in range(y):
      ans[j] = [1]*W
  else:
    for j in range(y,H):
      ans[j] = [1]*W
ans_ = 0
for i in range(H):
  ans_ += ans[i].count(0)
print(ans_)

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

W_ = [0, W] 
H_ = [0, H]

for l in lst:
    if l[2] == 1 and W_[0] < l[0]:
        W_[0] = l[0]
    elif l[2] == 2 and l[0] < W_[1]:
        W_[1] = l[0]
    elif l[2] == 3 and H_[0] < l[1]:
        H_[0] = l[1]
    elif l[2] == 4 and l[1] < H_[1]:
        H_[1] = l[1]
        
width = W_[1] - W_[0] if W_[1] - W_[0] > 0 else 0
height = H_[1] - H_[0] if H_[1] - H_[0] > 0 else 0

print(width * height)

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

minx=w
maxx=0
miny=h
maxy=0
for x,y,a in xya:
    if a==1:
        maxx=max(maxx,x)
    elif a==2:
        minx=min(minx,x)
    elif a==3:
        maxy=max(maxy,y)
    elif a==4:
        miny=min(miny,y)

x=max(0,minx-maxx)
y=max(0,miny-maxy)
print(x*y)

Solution (Python):
w, h, n = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(n)]
_w = [0, w]
_h = [0, h]
for x, y, a in points:
    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
width = _w[1] - _w[0] if _w[1] - _w[0] > 0 else 0
height = _h[1] - _h[0] if _h[1] - _h[0] > 0 else 0
print(width * height)

Solution (Python):
W, H, N = list(map(int, input().split(' ')))
xya_list = [list(map(int, input().split(' '))) for i in range(N)]
field = [[1 for j in range(W)] for i in range(H)]



for jia in xya_list:
    if jia[2] == 1:
        for i in range(H):
            for j in range(jia[0]):
                field[i][j] = 0

    if jia[2] == 2:
        for i in range(H):
            for j in range(jia[0], W):
                field[i][j] = 0

    if jia[2] == 3:
        for i in range(jia[1]):
            for j in range(W):
                field[i][j] = 0

    if jia[2] == 4:
        for i in range(jia[1], H):
            for j in range(W):
                field[i][j] = 0
    
    

sum_ = 0
for field_list in field:
    sum_ += sum(field_list)
print(sum_)

Solution (Python):
from enum import IntEnum


class Sides(IntEnum):
    Left = 1
    Right = 2
    Bottom = 3
    Top = 4


original_width, original_height, n = (int(x) for x in input().split())

left, right, bottom, top = 0, original_width, 0, original_height

for i in range(n):
    x, y, a = (int(x) for x in input().split())
    if a == Sides.Left:
        left = max(left, x)
    elif a == Sides.Right:
        right = min(right, x)
    elif a == Sides.Bottom:
        bottom = max(bottom, y)
    elif a == Sides.Top:
        top = min(top, y)

width = right - left
height = top - bottom
area = width * height
print(area if width > 0 and height > 0 else 0)

Solution (Python):
def resolve():
    w, h, n = map(int, input().split())
    min_x, min_y = 0, 0
    max_x, max_y = w, h
    for _ 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 min_x >= max_x or min_y >= max_y:
        print(0)
    else:
        print((max_x - min_x) * (max_y - min_y))


if __name__ == "__main__":
    resolve()

Solution (Python):
def resolve():
    w, h, n = map(int, input().split())
    xya = list(list(map(int, input().split())) for _ in range(n))
    min_x, min_y = 0, 0
    max_x, max_y = w, h
    for x, y, a in xya:
        if a == 1 and x > min_x:
            min_x = x
        elif a == 2 and x < max_x:
            max_x = x
        elif a == 3 and y > min_y:
            min_y = y
        elif a == 4 and y < max_y:
            max_y = y
    if min_x >= max_x or min_y >= max_y:
        print(0)
    else:
        print((max_x - min_x) * (max_y - min_y))


if __name__ == "__main__":
    resolve()

Solution (Python):
if __name__ == '__main__':
    W, H, N = map(int, input().split())
    x = [0 for i in range(N)]
    y = [0 for i in range(N)]
    a = [0 for i in range(N)]
    for i in range(N):
        x[i], y[i], a[i] = map(int, input().split())
        
    left = 0
    right = W
    top = H
    bottom = 0
    
    for i in range(N):
        if a[i] == 1 and left < x[i]:
            left = x[i]
        elif a[i] == 2 and x[i] < right:
            right = x[i]
        elif a[i] == 3 and bottom < y[i]:
            bottom = y[i]
        elif a[i] == 4 and y[i] < top:
            top = y[i]
    
    if left < right and bottom < top:
        print((top - bottom) * (right - left))
    else:
        print(0)

Solution (Python):
w,h,n = map(int,input().split())
minx = 0
miny = 0
maxx = w
maxy = 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((maxx-minx)*(maxy-miny))

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

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

Solution (Python):
import sys
from collections import Counter

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7

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

Solution (Python):
W,H,N=map(int,input().split())
A=[[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 j in range(H):
            for k in range(0,x):
                A[j][k] = 1
    if a==2:
        for j in range(H):
            for k in range(x,W):
                A[j][k] = 1  
    if a==3:
        for j in range(0,y):
            for k in range(W):
                A[j][k] = 1
    if a==4:
        for j in range(y,H):
            for k in range(W):
                A[j][k] = 1 
print(W*H-sum(map(sum, A)))

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

s = [[0 for i in range(w)] for j in range(h)]
for k in range(n):
    a,b,c = map(int,input().split(" "))
    if c == 1:
        for i in range(h):
            for j in range(a):
                if s[i][j] == 0:
                    s[i][j] = 1                 
    elif c == 2:
        for i in range(h):
            for j in range(a,w):
                if s[i][j] == 0:
                    s[i][j] = 1   
    elif c == 3:
        for j in range(b):
            for i in range(w):
                if s[j][i] == 0:
                    s[j][i] = 1   
    else:
        for j in range(b,h):
            for i in range(w):
                if s[j][i] == 0:
                    s[j][i] = 1   

counter = 0
for i in range(w):
    for j in range(h):
        if s[j][i] == 0:
            counter += 1
print(counter)

Solution (Python):
W, H, N = map(int, input().split())
xl, xr = 0, W
yd, yu = 0, 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)
if xl >= xr or yd >= yu:
    print(0)
else:
    print((xr - xl) * (yu - yd))

Solution (Python):
w,h,n =[int(i) for i in input().split()]
x=[]
y=[]
a=[]
x_r=[0,w]
y_r=[0,h]
for q in range(n):
	X,Y,A=[int(i) for i in input().split()]
	x.append(X)
	y.append(Y)
	a.append(A)
for d in range(n):
	if a[d] == 1 and x_r[0] <= x[d]:
		x_r[0] = x[d]
	elif a[d] == 2 and x_r[1] >= x[d]:
		x_r[1] = x[d]
	elif a[d] == 3 and y_r[0] <= y[d]:
		y_r[0] = y[d]
	elif a[d] == 4 and y_r[1] >= y[d]:
		y_r[1] = y[d]
if x_r[1]-x_r[0] <=0 or y_r[1]-y_r[0] <=0:
	s = 0
else:
	s = (x_r[1]-x_r[0])*(y_r[1]-y_r[0])
print(s)

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

xya = [list(map(int, input().split())) for _ in range(N)]

x_s,y_s,x_e,y_e = 0,0,W,H
for b in xya:
  if b[2] == 1:
    x_s = max(x_s, b[0])
  elif b[2] == 2:
    x_e = min(x_e, b[0])
  elif b[2] == 3:
    y_s = max(y_s, b[1])
  elif b[2] == 4:
    y_e = min(y_e, b[1])

if x_e < x_s or y_e < y_s:
  print(0)
else:
  print((x_e - x_s) * (y_e - y_s))

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

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

Solution (Python):
w,h,n = map(int,input().split())
x1 = 0
x2 = w
y3 = 0
y4 = 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(x2,x)
    elif a == 3:
        y3 = max(y3,y)
    else:
        y4 = min(y4,y)
X = x2 - x1
Y = y4 - y3
s = X * Y
if X < 0 or Y < 0:
    print(0)
else:
    print(s)

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

XYA = []

x1 = 0
x2 = W
y1 = 0
y2 = H

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

for i in range(N):
  if XYA[i][2]==1:
    x1 = max(x1, XYA[i][0])
  if XYA[i][2]==2:
    x2 = min(x2, XYA[i][0])
  if XYA[i][2]==3:
    y1 = max(y1, XYA[i][1])
  if XYA[i][2]==4:
    y2 = min(y2, XYA[i][1])

print(max(x2-x1,0)*max(y2-y1,0))

Solution (Python):
w,h,n = map(int,input().split())
x1 = 0
x2 = w
y3 = 0
y4 = 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(x2,x)
    elif a == 3:
        y3 = max(y3,y)
    else:
        y4 = min(y4,y)
X = x2 - x1
Y = y4 - y3
s = X * Y
if X < 0 or Y < 0:
    print(0)
else:
    print(s)

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

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

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

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

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)
if xl >= xr or yd >= yu:
    print(0)
else:
    print((xr-xl)*(yu-yd))

Solution (Python):
w, h, n = map(int, input().split())
max_x = w
min_x = 0
max_y = h
min_y = 0

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

Solution (Python):
def main():
    W, H, N = map(int, input().split())
    best = [0, W, 0, H]
    for _ in range(N):
        x, y, a = map(int, input().split())
        if a == 1:
            best[a-1] = max(best[a-1], x)
        elif a == 2:
            best[a-1] = min(best[a-1], x)
        elif a == 3:
            best[a-1] = max(best[a-1], y)
        elif a == 4:
            best[a-1] = min(best[a-1], y)
    
    
    if best[0] >= best[1] or best[2] >= best[3]:
        return 0
    else:
        v =(W-best[1] + best[0])*H + (H-best[3]+best[2])*W
        
        v -= (W-best[1])*(H-best[3]) + (W-best[1])*best[2]
        
        v -= best[0]*(H-best[3]) + best[0]*best[2]
        return H*W - v

if __name__ == '__main__':
    print(main())

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

x1 = 0
y1 = 0
x2 = w
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(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    elif a == 4:
        y2 = min(y2, y)

if x1 < x2 and y1 < y2:
    print((x2 - x1) * (y2 - y1))
else:
    print(0)

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

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

Solution (Python):
W,H,N = (int(i) for i in input().split())

X1 = []
X2 = []
Y3 = []
Y4 = []

for i in range(N):
    x,y,a = (int(j) for j in input().split())
    
    if a == 1:
        X1.append(x)
    elif a == 2:
        X2.append(x)
    elif a == 3:
        Y3.append(y)
    elif a == 4:
        Y4.append(y)
        
if X1 == []:
    A1 = 0
else:
    A1 = max(X1)
        
if X2 == []:
    A2 = W
else:
    A2 = min(X2)

        
if Y3 == []:
    A3 = 0
else:
    A3 = max(Y3)
    
if Y4 == []:
    A4 = H
else:
    A4 = min(Y4)
    
    
if A2 - A1 < 0:
    X_ans = 0
else:
    X_ans = A2 - A1
    
    
if A4 - A3 < 0:
    Y_ans = 0
else:
    Y_ans = A4 - A3
    
ans = X_ans * Y_ans
print(ans)

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

ans=[0,0,w,h]
for i in range(n):
    if xya[i][2] == 1:
        if xya[i][0] >= ans[0]:
            ans[0] = xya[i][0]
    elif xya[i][2] == 2:
        if xya[i][0] <= ans[2]:
            ans[2] = xya[i][0]
    elif xya[i][2] == 3:
        if xya[i][1] >= ans[1]:
            ans[1] = xya[i][1]
    elif xya[i][2] == 4:
        if xya[i][1] <= ans[3]:
            ans[3] = xya[i][1]

print(0 if (ans[2]-ans[0])<=0 or (ans[3]-ans[1])<=0 else (ans[2]-ans[0])*(ans[3]-ans[1]))

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

ans=[0,0,w,h]
for i in range(n):
    if xya[i][2] == 1:
        if xya[i][0] >= ans[0]:
            ans[0] = xya[i][0]
    elif xya[i][2] == 2:
        if xya[i][0] <= ans[2]:
            ans[2] = xya[i][0]
    elif xya[i][2] == 3:
        if xya[i][1] >= ans[1]:
            ans[1] = xya[i][1]
    elif xya[i][2] == 4:
        if xya[i][1] <= ans[3]:
            ans[3] = xya[i][1]

print(0 if ans[2]-ans[0] <= 0 or ans[3]-ans[1] <= 0 else (ans[2]-ans[0])*(ans[3]-ans[1]))

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

ans=[0,0,w,h]
for i in range(n):
    if xya[i][2] == 1:
        if xya[i][0] >= ans[0]:
            ans[0] = xya[i][0]
    elif xya[i][2] == 2:
        if xya[i][0] <= ans[2]:
            ans[2] = xya[i][0]
    elif xya[i][2] == 3:
        if xya[i][1] >= ans[1]:
            ans[1] = xya[i][1]
    elif xya[i][2] == 4:
        if xya[i][1] <= ans[3]:
            ans[3] = xya[i][1]

print(0 if (ans[2]-ans[0] <= 0) or (ans[3]-ans[1] <= 0) else (ans[2]-ans[0])*(ans[3]-ans[1]))

Solution (Python):
Wg, Hg, n = map(int, input().split())
Ws, Hs = 0, 0

for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1 and Ws < x:
    Ws = x
  elif a == 2 and Wg > x:
    Wg = x
  elif a == 3 and Hs < y:
    Hs = y
  elif a == 4 and Hg > y:
    Hg = y
    
  if Ws > Wg or Hs > Hg:
    break
    
ans = (Wg - Ws) * (Hg - Hs)
if ans <= 0:
  print("0")
else:
  print(ans)

Solution (Python):
w,h,n = map(int,input().split())
nums = [list(map(int,input().split())) for i in range(n)]
s = w*h
x1 = 0
x2 = w
y1 = 0
y2 = h
for num in nums:
    if num[2]==1 and x1<num[0]:
        x1 = num[0]
    elif num[2]==2 and x2>num[0]:
        x2 = num[0]
    elif num[2]==3 and y1<num[1]:
        y1 = num[1]
    elif num[2]==4 and y2>num[1]:
        y2 = num[1]
if x2<=x1 or y2<=y1:
    print(0)
else:
    print((x2-x1)*(y2-y1))

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

W, H, N = map(int, input().split())
L = [[int(v) for v in input().split()] for _ in range(N)]
m = [[0 for _ in range(W)] for _ in range(H)]

for x, y, a in L:
    for i in range(H):
        for j in range(W):
            if a == 1 and j < x:
                m[i][j] += 1
            elif a == 2 and j >= x:
                m[i][j] += 1
            elif a == 3 and i < y:
                m[i][j] += 1
            elif a == 4 and i >= y:
                m[i][j] += 1

ans = 0
for v in m:
    ans += len([p for p in v if p == 0])

print(ans)

Solution (Python):
w,h,n=map(int,input().split())
l = [[int(i) for i in input().split()] for i in range(n)]
right=w
left=0
up=h
down=0

for i in range(n):
    if l[i][2]==1:
        left=max(left,l[i][0])
    elif l[i][2]==2:
        right=min(right,l[i][0])
    elif l[i][2]==3:
        down=max(down,l[i][1])
    elif l[i][2]==4:
        up=min(up,l[i][1])
square_size=(right-left)*(up-down)
if right-left>0 and up-down>0:
    print(square_size)
else:
    print('0')

Solution (Python):
w,h,n=map(int,input().split())
L=[list(map(int,input().split())) for i in range(n)]
r=w
l=0
u=h
d=0
for i in range(n):
    if L[i][2]==1:
        l=max(l,L[i][0])
    elif L[i][2]==2:
        r=min(r,L[i][0])
    elif L[i][2]==3:
        d=max(d,L[i][1])
    else:
        u=min(u,L[i][1])
if l<r and d<u:
    print((r-l)*(u-d))
else:
    print(0)

Solution (Python):
import sys
W, H, N= map(int, sys.stdin.readline().rstrip().split())
bucket = [[1 for j in range(W)] for i in range(H)]
for i in range(N):
    x, y, a = map(int, sys.stdin.readline().rstrip().split())
    if a == 1:
        for i in range(H):
            for j in range(0,x):
                bucket[i][j] = 0
    elif a == 2:
        for i in range(H):
            for j in range(x,W):
                bucket[i][j] = 0
    elif a == 3:
        for i in range(0,y):
            for j in range(W):
                bucket[i][j] = 0
    else:
        for i in range(y,H):
            for j in range(W):
                bucket[i][j] = 0
sum = sum(map(sum, bucket))
print(sum)

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

right = W
left = 0
top = H
bottom = 0

for i in range(N):
  if xya[i][2] == 1 and  xya[i][0] > left:
    left = xya[i][0]
  elif xya[i][2] == 2 and xya[i][0] < right:
    right = xya[i][0]
  elif xya[i][2] == 3 and xya[i][1] > bottom:
    bottom = xya[i][1]
  elif xya[i][2] == 4 and xya[i][1] < top:
    top = xya[i][1]

if top <= bottom or right <= left:
  print(0)
else:
  print((top - bottom ) * (right - left))