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())
W = []
H = []

for _ in range(n):
  x,y,a = map(int,input().split())
  
  if a==1:
    W+=list(range(x))
  elif a==2:
    W+=list(range(x+1, w+1))
  elif a==3:
    H+=list(range(y))
  elif a==4:
    H+=list(range(y+1, h+1))

print(max(0, h-len(set(H)))*max(0, w-len(set(W))))

Solution (Python):
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD = 10 ** 9 + 7


W, H, N = MI()
m = [0, 0, W, 0, H]
for _ in range(N):
    x, y, a = MI()
    if a == 1:
        m[a] = max(m[a], x)
    elif a == 2:
        m[a] = min(m[a], x)
    elif a == 3:
        m[a] = max(m[a], y)
    else:
        m[a] = min(m[a], y)
print(max(0, m[2] - m[1]) * max(0, m[4] - m[3]))

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

x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(len(a)):
    if a[i] == 1:
        if x_min < x[i]:
            x_min = x[i]
    elif a[i] == 2:
        if x_max > x[i]:
            x_max = x[i]
    elif a[i] == 3:
        if y_min < y[i]:
            y_min = y[i]
    else:
        if y_max > y[i]:
            y_max = y[i]
        
x_len = x_max-x_min
y_len = y_max-y_min
result = x_len*y_len
if (x_len<0)|(y_len<0):
    result = 0

print(result)

Solution (Python):
import numpy as np

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

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

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

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

print(np.sum(ze))

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

x = [0,w]
y = [0,h]
for i in range(len(xya)):
    if xya[i][2]==1:
        x[0] = max([x[0], xya[i][0]])
    elif xya[i][2]==2:
        x[1] = min([x[1],xya[i][0]])
    elif xya[i][2]==3:
        y[0] = max([y[0], xya[i][1]])
    else:
        y[1] = min([y[1], xya[i][1]])
if x[1]<x[0]:
    x[0]=x[1]
if y[1]<y[0]:
    y[0]=y[1]
print((x[1]-x[0])*(y[1]-y[0]))

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

a = 0
b = w
c = 0
d = h

for i,j,k in l:
    if k == 1:
        a = max(a,i)
    elif k == 2:
        b = min(b,i)
    elif k==3:
        c = max(c,j)
    else:
        d = min(d,j)

    if a >= b or c >= d:
        print(0)
        exit()
print((b-a)*(d-c))

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

points = []
for i in range(n):
    points.append(list(map(int, input().split(' '))))

mx = 0
my = 0
xx = w
xy = h
    
for point in points:
    if point[2] == 1 and mx < point[0]:
        mx = point[0]
    elif point[2] == 2 and xx > point[0]:
        xx = point[0]
    elif point[2] == 3 and my < point[1]:
        my = point[1]
    elif point[2] == 4 and xy > point[1]:
        xy = point[1]
        
a = xx - mx if xx - mx > 0 else 0
b = xy - my if xy - my > 0 else 0
print(a * b)

Solution (Python):
W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

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

    if a == 1:
        min_W = max(x, min_W)
    elif a == 2:
        max_W = min(x, max_W)
    elif a == 3:
        min_H = max(y, min_H)
    else:
        max_H = min(y, max_H)

if min_W > max_W or min_H > max_H:
    print(0)
else:
    print((max_H - min_H) * (max_W - min_W))

Solution (Python):


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

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

up = H
down = 0
left = 0
right = W

for l in xya:
  if l[2] == 1 and l[0] > left:
    left = l[0]
  elif l[2] == 2 and l[0] < right:
    right = l[0]
  elif l[2] == 3 and l[1] > down:
    down = l[1]
  elif l[2] == 4 and l[1] < up:
    up = l[1]
    
if left >= right or down >= up:
  area = 0
else:
  area = (up-down)*(right-left)
  
print(area)

Solution (Python):
w,h,n=map(int,input().split())
x1_max = 0
x2_min = w
y3_max = 0
y4_min = h

for i in range(n):
  x,y,a=map(int, input().split())
  if a==1: x1_max = max(x1_max, x)
  elif a==2: x2_min = min(x2_min, x)
  elif a==3: y3_max = max(y3_max, y)
  elif a==4: y4_min = min(y4_min, y)
    
print((x2_min - x1_max if x1_max < x2_min else 0)*(y4_min - y3_max if y3_max < y4_min else 0))

Solution (Python):
w,h,n = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
list_w = [1]*w
list_h = [1]*h

for i in range(n):
  if a[i][2] == 1:
    for j in range(a[i][0]):
      list_w[j] = 0
  elif a[i][2] == 2:
    for j in range(w-1,a[i][0]-1,-1):
      list_w[j] = 0
  elif a[i][2] == 3:
    for j in range(a[i][1]):
      list_h[j] = 0
  elif a[i][2] == 4:
    for j in range(h-1,a[i][1]-1,-1):
      list_h[j] = 0

h = list_h.count(1)
w = list_w.count(1)
print(h*w)

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

Solution (Python):
W,H,N=map(int,input().split())
A=[]
right=W
left=0
top=H
under=0

for i in range(N):
  A.append(list(map(int,input().split())))
  if A[i][2]==1:
    if left<A[i][0]:
      left=A[i][0]
  if A[i][2]==2:
    if right>A[i][0]:
      right=A[i][0]
  if A[i][2]==3:
    if under<A[i][1]:
      under=A[i][1]
  if A[i][2]==4:
    if top>A[i][1]:
      top=A[i][1]

print(max(0,top-under)*max(0,right-left))

Solution (Python):
w,h,n=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
ue=h
sita=0
migi=w
hidari=0
for i in range(n):
    if li[i][2]==1:
        if li[i][0]>hidari:
            hidari=li[i][0]

    if li[i][2]==2:
        if li[i][0]<migi:
            migi=li[i][0]

    if li[i][2]==3:
        if li[i][1]>sita:
            sita=li[i][1]

    if li[i][2]==4:
        if li[i][1]<ue:
            ue=li[i][1]
print(max(0,(ue-sita))*max(0,(migi-hidari)))

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

_W = b[2] - b[1]
_H = b[4] - b[3]

if _W < 0 or _H < 0:
    print(0)
else:
    print(_W * _H)

Solution (Python):
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for _ in range(n)]
xya_1=0
xya_2=w
xya_3=0
xya_4=h
for _ in range(n):
  if xya[_][2]==1:
    xya_1=max(xya_1,xya[_][0])
  elif xya[_][2]==2:
    xya_2=min(xya_2,xya[_][0])
  elif xya[_][2]==3:
    xya_3=max(xya_3,xya[_][1])
  else:
    xya_4=min(xya_4,xya[_][1])
print(max(0,xya_2-xya_1)*max(0,xya_4-xya_3))

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

new_w = [0] * w
new_h = [0] * h



for i in range(n):
  x , y , a = list(map(int,input().split()))
  if a == 1:
    for t in range(x):
      new_w[t] = 1
  
  elif a == 2:
    for t in range(len(new_w) - x):
      new_w[-1 - t] = 1
  
  elif a == 3:
    for t in range(y):
      new_h[-1-t] = 1
  
  else:
    for t in range(len(new_h) - y):
      new_h[t] = 1

w_long = len(new_w) - sum(new_w)
h_long = len(new_h) - sum(new_h)


print(w_long * h_long)

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

left_x = [0]
right_x = [W]
down_y = [0]
up_y = [H]

for i in range(N):
    if a[i] == 1:
        left_x.append(x[i])
    elif a[i] == 2:
        right_x.append(x[i])
    elif a[i] == 3:
        down_y.append(y[i])
    elif a[i] == 4:
        up_y.append(y[i])

w = min(right_x) - max(left_x)
h = min(up_y) - max(down_y)

if w <= 0 or h <= 0:
    print(0)
else:
    print(w*h)

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

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

border = [0,W,0,H]

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

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

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

border = [0,W,0,H]

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    border[a-1] = max(border[a-1], x)
  elif a == 2:
    border[a-1] = min(border[a-1], x)
  elif a == 3:
    border[a-1] = max(border[a-1], y)
  elif a== 4:
    border[a-1] = min(border[a-1], y)
if border[1] - border[0] < 0 and border[3] - border[2] < 0:
  print(0)
  exit()
    
print(max((border[1] - border[0]) * (border[3] - border[2]), 0))

Solution (Python):
w,h,n = map(int,input().split())
a1 = [0]
a2 = [w]
a3 = [0]
a4 = [h]

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    else:
        a4.append(y)
        
xl = max(a1)
xh = min(a2)
yl = max(a3)
yh = min(a4)

if xh - xl < 0:
    ansx = 0
else:
    ansx = xh - xl
if yh - yl < 0:
    ansy = 0
else:
    ansy = yh - yl
print(ansx * ansy)

Solution (Python):




W,H,N = list(map(int, input().rstrip().split()))
x_y_a = [list(map(int, input().rstrip().split())) for _ in range(N)]

x_max,y_max = W,H
x_min,y_min = 0,0

for x,y,a in x_y_a:
    if a == 1 and x_min < x:
        x_min = x
    elif a == 2 and x_max > x:
        x_max = x
    elif a == 3 and y_min < y:
        y_min = y
    elif a == 4 and y_max > y:
        y_max = y
    
if (x_max >= x_min) and (y_max >= y_min):
    area = (x_max - x_min) * (y_max - y_min)
else:
    area = 0

print(area)

Solution (Python):
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
list_w=[1]*w
list_h=[1]*h

for i in range(n):
	if a[i][2]==1:
		for j in range(a[i][0]):
			list_w[j]=0
	elif a[i][2]==2:
		for j in range(w-1,a[i][0]-1,-1):
			list_w[j]=0
	elif a[i][2]==3:
		for j in range(a[i][1]):
			list_h[j]=0		
	elif a[i][2]==4:
		for j in range(h-1,a[i][1]-1,-1):
			list_h[j]=0

h=list_h.count(1)
w=list_w.count(1)
print(h*w)

Solution (Python):


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

x = [0,w,0,h]

for i in range(n):
    if l[i][2] == 1:
        x[0] = max(x[0],l[i][0])
    elif l[i][2] == 2:
        x[1] = min(x[1],l[i][0])
    elif l[i][2] == 3:
        x[2] = max(x[2],l[i][1])
    else:
        x[3] = min(x[3],l[i][1])
    
    
    if x[0] >= x[1] or x[2] >= x[3]:
        print(0)
        break
        
        
if x[0] < x[1] and x[2] < x[3]:
    print((x[1]-x[0])*(x[3]-x[2]))

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

Solution (Python):
W, H, N = map(int, input().split())
input_li = [list(map(int, input().split())) for i in range(N)]
dic = {"1" : 0, "2": W, "3" : 0, "4" : H}
for l in input_li :
    if l[2] == 1 and dic[str(l[2])] < l[0] :
        dic[str(l[2])] = l[0]
    if l[2] == 2 and dic[str(l[2])] > l[0] :
        dic[str(l[2])] = l[0]
    if l[2] == 3 and dic[str(l[2])] < l[1] :
        dic[str(l[2])] = l[1]
    if l[2] == 4 and dic[str(l[2])] > l[1] :
        dic[str(l[2])] = l[1]
if dic["2"] - dic["1"] < 0 and dic["4"] - dic["3"] < 0 :
    print(0)
else :
    print(max(0, (dic["2"] - dic["1"]) * (dic["4"] - dic["3"])))

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

xmin, xmax, ymin, ymax = 0,w,0,h

for i in range(n):
    xi,yi,ai = map(int, input().split())
    if ai == 1:
        if xmin < xi:
            xmin = xi
    if ai == 2:
        if xmax > xi:
            xmax = xi
    if ai == 3:
        if ymin < yi:
            ymin = yi
    if ai == 4:
        if ymax > yi:
            ymax = yi

if xmax < xmin or ymax < ymin:
    menseki = 0
else:
    menseki = (xmax-xmin) * (ymax-ymin)
print(menseki)

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

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

def main():
    W, H, N = map(int, input().split())
    dots = [list(map(int, input().split())) for _ in range(N)]
    max_x_left = 0
    min_x_right = W
    max_y_down = 0
    min_y_up = H
    for dot in dots:
        if dot[2] == 1 and dot[0] > max_x_left:
            max_x_left = dot[0]
        elif dot[2] == 2 and dot[0] < min_x_right:
            min_x_right = dot[0]
        elif dot[2] == 3 and dot[1] > max_y_down:
            max_y_down = dot[1]
        elif dot[2] == 4 and dot[1] < min_y_up:
            min_y_up = dot[1]
    if min_x_right <= max_x_left or min_y_up <= max_y_down:
        print(0)
    else:
        print((min_x_right - max_x_left) * (min_y_up - max_y_down))

if __name__ == '__main__':
    main()

Solution (Python):

import sys
from bisect import bisect_left
INF = float("inf")


def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    X = [[0], [W], [0], [H]]
    for i in range(N):
        b = a[i]-1
        if b == 0 or b == 1:
            X[b].append(x[i])
        else:
            X[b].append(y[i])
    lower_x = max(X[0])
    upper_x = min(X[1])
    lower_y = max(X[2])
    upper_y = min(X[3])

    area = max(upper_x-lower_x, 0)*max(upper_y-lower_y, 0)
    print(area)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  
    H = int(next(tokens))  
    N = int(next(tokens))  
    x = [int()] * (N)  
    y = [int()] * (N)  
    a = [int()] * (N)  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)


if __name__ == '__main__':
    main()

Solution (Python):
[W, H, N] = list(map(int, input().split()))
[x, y, a] = [ [], [], [] ]
for _ in range(N):
  input_line = list(map(int, input().split()))
  x.append(input_line[0])
  y.append(input_line[1])
  a.append(input_line[2])
area = []
for i in range(W):
  area.append([])
  for j in range(H):
    area[i].append("")
    
for i in range(N):
  if a[i] == 1:
    for X in range(x[i]):
      for Y in range(H):
        area[X][Y] = "f"
  if a[i] == 2:
    for X in range(x[i], W):
      for Y in range(H):
        area[X][Y] = "f"
  if a[i] == 3:
    for X in range(W):
      for Y in range(y[i]):
        area[X][Y] = "f"
  if a[i] == 4:
    for X in range(W):
      for Y in range(y[i], H):
        area[X][Y] = "f"
        
count = 0
for i in range(W):
  for j in range(H):
    if area[i][j] == "":
      count += 1
      
print(count)

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

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        minx=max(x,minx)
    if a==2:
        maxx=min(maxx,x)
    if a==3:
        miny=max(y,miny)
    if a==4:
        maxy=min(y,maxy)

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

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

a1 = [0,0]
a2 = [W,0]
a3 = [0,0]
a4 = [0,H]

for i in range(0,N):
  lst = [int(i) for i in input().split(" ")]
  if lst[2] == 1:
    a1[0] = max(a1[0],lst[0])
  elif lst[2] == 2:
    a2[0] = min(a2[0],lst[0])
  elif lst[2] == 3:
    a3[1] = max(a3[1],lst[1])
  elif lst[2] == 4:
    a4[1] = min(a4[1],lst[1])

print(max(0,a2[0]-a1[0])*max(0,a4[1]-a3[1]))

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

a1 = [0,0]
a2 = [W,0]
a3 = [0,0]
a4 = [0,H]

for i in range(0,N):
  lst = [int(i) for i in input().split(" ")]
  if lst[2] == 1 and lst[0] > a1[0]:
    a1[0] = lst[0]
  elif lst[2] == 2 and lst[0] < a2[0]:
    a2[0] = lst[0]
  elif lst[2] == 3 and lst[1] > a3[1]:
    a3[1] = lst[1]
  elif lst[2] == 4 and lst[1] < a4[1]:
    a4[1] = lst[1]

if (a2[0]-a1[0])<0 or (a4[1]-a3[1])<0:
    print(0)
else:
    print((a2[0]-a1[0])*(a4[1]-a3[1]))

Solution (Python):
w,h,n=map(int,input().split())
x1,x2=0,w
y1,y2=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)
    elif a==4:
        y2 = min(y2,y)
print(max((x2-x1)*(y2-y1),0) if x2-x1>0 else 0)

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

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

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and left <= x:
        left = x
    elif a == 2 and right >= x:
        right = x
    elif a == 3 and bottom <= y:
        bottom = y
    elif a == 4 and top >= y:
        top = y

if (top-bottom)*(right-left) > 0 and (top-bottom)>0 and (right-left)>0:
    print((top-bottom)*(right-left))
else:
    print(0)

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

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

Solution (Python):
w,h,n=map(int,input().split())
A=[[int(i) for i in input().split()] for l in range(n)]
o=[]
for y in range(h):
    p=[]
    for x in range(w):
        p.append(1)
    o.append(p)
for a in A:
    if a[2]==1:
        for y in range(h):
            for x in range(a[0]):
                o[y][x]=0
    if a[2]==2:
        for y in range(h):
            for x in range(a[0],w):
                o[y][x]=0
    if a[2]==3:
        for y in range(a[1]):
            for x in range(w):
                o[y][x]=0
    if a[2]==4:
        for y in range(a[1],h):
            for x in range(w):
                o[y][x]=0
print(sum(map(sum,o)))

Solution (Python):
W, H, N = map(int, input().split())
x_l, x_r, y_l, y_r = 0, W, 0, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x_l = max(x_l, x)
    elif a == 2:
        x_r = min(x_r, x)
    elif a ==3:
        y_l = max(y_l, y)
    else:
        y_r = min(y_r, y)
if x_l >= x_r or y_l >= y_r:
    print(0)
    exit()
print((x_r-x_l)*(y_r-y_l))

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

x_min, y_min = (0, 0)
x_max, y_max = (W, H)

for _ in range(N):
    if lst_xya[-1][2] == 4:
        if y_max > lst_xya[-1][1]:
            y_max = lst_xya[-1][1]
        lst_xya.pop()
    elif lst_xya[-1][2] == 3:
        if y_min < lst_xya[-1][1]:
            y_min = lst_xya[-1][1]
        lst_xya.pop()
    elif lst_xya[-1][2] == 2:
        if x_max > lst_xya[-1][0]:
            x_max = lst_xya[-1][0]
        lst_xya.pop()
    else:
        if x_min < lst_xya[-1][0]:
            x_min = lst_xya[-1][0]
        lst_xya.pop()
        
S = (x_max - x_min) * (y_max - y_min)
if x_max - x_min < 0 and y_max - y_min < 0:
    print(0)
else:
    print(S if S > 0 else 0)

Solution (Python):
w, h, n = map(int, input().split())
xyaList = [list(map(int, input().split())) for _ in range(n)]
blackRec = [[0, w], [0, h]]
for i in range(n):
    x = xyaList[i][0]
    y = xyaList[i][1]
    a = xyaList[i][2]
    if a == 1 and blackRec[0][0] < x:
        blackRec[0][0] = x
    elif a == 2 and blackRec[0][1] > x:
        blackRec[0][1] = x
    elif a == 3 and blackRec[1][0] < y:
        blackRec[1][0] = y
    elif a == 4 and blackRec[1][1] > y:
        blackRec[1][1] = y
width = blackRec[0][1] - blackRec[0][0]
height = blackRec[1][1] - blackRec[1][0]
ans = width * height
if width < 0 or height < 0:
    ans = 0
print(ans)

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

w=[0,W]
h=[0,H]

for i in range(N):
    if dots[i][2]==1:
        if w[0]<dots[i][0]:
            w[0]=dots[i][0]
    elif dots[i][2]==2:
        if w[1]>dots[i][0]:
            w[1]=dots[i][0]
    elif dots[i][2]==3:
        if h[0]<dots[i][1]:
            h[0]=dots[i][1]
    else:
        if h[1]>dots[i][1]:
            h[1]=dots[i][1]

if ((w[1]-w[0])>0)and((h[1]-h[0])>0):
    print((w[1]-w[0])*(h[1]-h[0]))
else:
    print("0")

Solution (Python):
w,h,n = map(int, input().split())
s = w * h
l = [0,0]
r = [w,h]

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        if l[0] < x:
            l[0] = x
    elif a == 2:
        if r[0] > x:
            r[0] = x
    elif a == 3:
        if l[1] < y:
            l[1] = y
    else:
        if r[1] > y:
            r[1] = y

tate = r[1] - l[1]
yoko = r[0] - l[0]

if l[0] < r[0] and l[1] < r[1]:
    print(tate * yoko)
else:
    print(0)

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

xyal = []
for _ in range(n):
    xyal.append(list(map(int, input().split())))

for xya in xyal:
    if xya[2] == 1:
        for y in range(h):
            for x in range(xya[0]):
                whl[y][x] = 1

    if xya[2] == 2:
        for y in range(h):
            if xya[0]+1 > w:
                break
            for x in range(xya[0], w):
                whl[y][x] = 1

    if xya[2] == 3:
        for y in range(xya[1]):
            for x in range(w):
                whl[y][x] = 1

    if xya[2] == 4:
        for y in range(xya[1], h):
            for x in range(w):
                whl[y][x] = 1

ans = 0
for wh in whl:
    ans += wh.count(0)
print(ans)

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



w = [1] * (W)
h = [1] * (H)

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        w[:x] = [0] * x
    elif a == 2:
        w[x:] = [0] * (H - x)
    elif a == 3:
        h[:y] = [0] * y
    elif a == 4:
        h[y:] = [0] * (H - y)

ans = sum(w) * sum(h)
print(ans)

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

Solution (Python):
W, H, N = map(int, input().split())
X = [0, W]
Y = [0, H]
for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1 and X[0] < x:
    X[0] = x
  elif a == 2 and X[1] > x:
    X[1] = x
  elif a == 3 and Y[0] < y:
    Y[0] = y
  elif a == 4 and Y[1] > y:
    Y[1] = y

h = Y[1] - Y[0]
w = X[1] - X[0]
print(0 if h < 0 or w < 0 else h * w)

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

print(max(0,c-a) * max(0,d-b))

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

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

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

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

w = max(0, x2-x1)
h = max(0, y2-y1)

print(w*h)

Solution (Python):

W, H, N = map(int, input().split())
list = [0 for i in range(0,N)]
for i in range(0,N) :
    x, y, a = map(int, input().split())
    list[i] = (x,y,a)

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

for i in range(0,N) :
    if list[i][2] == 1 :
        x_low = max(x_low, list[i][0])
    elif list[i][2] == 2 :
        x_high = min(x_high, list[i][0])
    elif list[i][2] == 3 :
        y_low = max(y_low, list[i][1])
    else :
        y_high = min(y_high, list[i][1])

area = (x_high - x_low) * (y_high - y_low)

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

Solution (Python):
x, y, n = map(int, input().split())
wlist = []
for i in range(n):
    wlist.append(list(map(int, input().split())))
dst = []
x = [0, x]
y = [0, y]
for i in wlist:
    if i[2] == 1:
        x[0] = i[0] if i[0] > x[0] else x[0]
    elif i[2] == 2:
        x[1] = i[0] if i[0] < x[1] else x[1]
    elif i[2] == 3:
        y[0] = i[1] if i[1] > y[0] else y[0]
    else:
        y[1] = i[1] if i[1] < y[1] else y[1]
x = x[1]-x[0] if x[1]-x[0] > 0 else 0
y = y[1]-y[0] if y[1]-y[0] > 0 else 0
dst = x*y
print(dst)

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

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

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

Xend = W
Yend = H
Xstart = 0
Ystart = 0
for xya in XYA:
    if xya[2] == 1:
        Xstart = max(Xstart,xya[0])
    elif xya[2] == 2:
        Xend = min(Xend,xya[0])
    elif xya[2] == 3:
        Ystart = max(Ystart,xya[1])
    elif xya[2] == 4:
        Yend = min(Yend,xya[1])
if (Xend - Xstart)>0 and (Yend - Ystart)>0:
    print((Xend - Xstart)*(Yend - Ystart))
else:
    print(0)

Solution (Python):
x,y,n=list(map(int,input().split()))
xx=x
yy=y
S=[]
a1=0
b1=0
for _ in range(n):
    S.append(list(map(int,input().split())))
for a in S :
    if a[2]==1:
        a1 = max(a1,a[0])
    elif a[2]==2:
        xx = min(xx,a[0])
    elif a[2]==3:
        b1 = max(b1,a[1])
    elif a[2]==4:
        yy = min(yy,a[1])
print( (xx-a1)*(yy-b1) if a1<xx and b1<yy else 0)

Solution (Python):


import numpy as np


def main():
    W, H, N = map(int, input().split())
    result = np.zeros((W, H))

    for _ in range(N):
        X, Y, A = map(int, input().split())
        if A == 1:
            result[:X, :] = 1
        elif A == 2:
            result[X:, :] = 1
        elif A == 3:
            result[:, :Y] = 1
        elif A == 4:
            result[:, Y:] = 1
    print(np.count_nonzero(1 - result))


if __name__ == "__main__":
    main()

Solution (Python):
w, h, n = map(int, input().split())
xlist = [0, w]
ylist = [0, h]
for count in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and xlist[0] < x: xlist[0] = x
    elif a == 2 and xlist[1] > x: xlist[1] = x
    elif a == 3 and ylist[0] < y: ylist[0] = y
    elif a == 4 and ylist[1] > y: ylist[1] = y
print(max(0, xlist[1] - xlist[0]) * max(0, ylist[1] - ylist[0]))

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

for i in range(len(xya)):
    if 1<=xya[i][2]<=2:
        for j in range(1,3):
            if xya[i][2]==j:
                lst[j-1].append(xya[i][0])
    else:
        for j in range(3,5):
            if xya[i][2]==j:
                lst[j-1].append(xya[i][1])

if min(lst[1])>=max(lst[0]):
    bla_width = w-min(lst[1])+max(lst[0])
else:
    bla_width = w

if min(lst[3])>=max(lst[2]):
    bla_height = h-min(lst[3])+max(lst[2])
else:
    bla_height = h

whi_area = (w-bla_width)*(h-bla_height)
print(whi_area)

Solution (Python):
W, H, N = list(map(int, input().split()))
W = [0, W]
H = [0, H]
pt = []
for i in range(N):
  x, y, n = list(map(int, input().split()))
  
  if n == 1:
    if W[0] < x:
      W[0] = x
  elif n == 2:
    if x < W[1]:
      W[1] = x
  elif n == 3:
    if H[0] < y:
      H[0] = y
  else:
    if y < H[1]:
      H[1] = y
  
if W[0] < W[1] and H[0] < H[1]:
  print((W[1]-W[0])*(H[1]-H[0]))
else:
  print("0")