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())
xya=[list(map(int,input().split())) for i in range(n)]
xya1=[i[0] for i in xya if i[2]==1]+[0]
xya2=[i[0] for i in xya if i[2]==2]+[w]
xya3=[i[1] for i in xya if i[2]==3]+[0]
xya4=[i[1] for i in xya if i[2]==4]+[h]
left=max(xya1)
right=min(xya2)
lower=max(xya3)
upper=min(xya4)
if left>=right or lower>=upper:
  print(0)
else:
  print((right-left)*(upper-lower))

Solution (Python):
W, H, N = map(int, input().split())
XYA = [tuple(map(int, input().split())) for _ in range(N)]
XYA += [(0,0,1),(W,0,2),(0,0,3),(0,H,4)]
h1 = max(x for x,y,a in XYA if a == 1)
h2 = min(x for x,y,a in XYA if a == 2)
w1 = max(y for x,y,a in XYA if a == 3)
w2 = min(y for x,y,a in XYA if a == 4)
print((max(0,h2-h1))*(max(0,w2-w1)))

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

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

coordinate = [[0, 0], [W, H]]

for i in l:
    if i[2] == 1:
        if coordinate[0][0] < i[0]:
            coordinate[0][0] = i[0]
    elif i[2] == 2:
        if coordinate[1][0] > i[0]:
            coordinate[1][0] = i[0]
    elif i[2] == 3:
        if coordinate[0][1] < i[1]:
            coordinate[0][1] = i[1]
    elif i[2] == 4:
        if coordinate[1][1] > i[1]:
            coordinate[1][1] = i[1]

x = coordinate[1][0] - coordinate[0][0]
y = coordinate[1][1] - coordinate[0][1]

if x <= 0 or y <= 0:
    print(0)
else:
    print(x * y)

Solution (Python):
"""
author : halo2halo
date : 2, Feb, 2020
"""

import sys
import itertools

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W, H, N = map(int, readline().split())
Xt = W
Xd = 0
Yt = H
Yd = 0
for _ in range(N):
    x, y, a = map(int, readline().split())
    if a == 1:
        Xd = max(x, Xd)
    elif a == 2:
        Xt = min(x, Xt)
    elif a == 3:
        Yd = max(y, Yd)
    else:
        Yt = min(y, Yt)

print(0 if Xd > Xt or Yd > Yt else (Xt - Xd) * (Yt - Yd))

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][0] = max(x, d[0][0])
  elif a == 2:
    d[0][1] = min(x, d[0][1])
  elif a == 3:
    d[1][0] = max(y, d[1][0])
  elif a == 4:
    d[1][1] = min(y, d[1][1])
print(max((d[0][1] - d[0][0]), 0) * max((d[1][1] - d[1][0]), 0))

Solution (Python):
import math
import sys
import numpy as np


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())
area = np.ones([w,h])

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

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

Solution (Python):
w,h,n = map(int,input().split())
up = h
down = 0
left = 0
right = w
for i 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:
        down = max(down,y)
    else:
        up = min(up,y)
print(max(0, right - left) * max(0, up - down))

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


low_x=0
low_y=0
for i in range(n):
    if l[i][-1]==1 and low_x<l[i][0]:
        low_x=l[i][0]
    elif l[i][-1]==2 and w>l[i][0]:
        w=l[i][0]
    elif l[i][-1]==3 and low_y<l[i][1]:
        low_y=l[i][1]
    elif l[i][-1]==4 and h>l[i][1]:
        h=l[i][1]


print((w-low_x)*(h-low_y) if w>=low_x and h>=low_y else 0)

Solution (Python):

W, H, N = map(int, input().split())
x, y, a = [0]*N, [0]*N, [0]*N
for i in range(N):
    tmp_x, tmp_y, tmp_a = map(int, input().split())
    x[i], y[i], a[i] = tmp_x, tmp_y, tmp_a
xya = zip(x,y,a)

W_L, W_R, W_H0, W_H1 = 0, W, 0, H
for x_i, y_i, a_i in xya:
    if a_i == 1:
        W_L = max(W_L,x_i)
    if a_i == 2:
        W_R = min(W_R,x_i)
    if a_i == 3:
        W_H0 = max(W_H0,y_i)
    if a_i == 4:
        W_H1 = min(W_H1,y_i)

if W_R-W_L <= 0 or W_H1-W_H0 <= 0:
    print(0)
else:
    print(abs(W_R-W_L)*abs(W_H1-W_H0))

Solution (Python):
W, H, N = map(int, input().split())
lx, rx, uy, dy = 0, W, H, 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        lx = max(lx, x)
    if a == 2:
        rx = min(rx, x)
    if a == 3:
        dy = max(dy, y)
    if a == 4:
        uy = min(uy, y)

print(max(0, uy - dy) * max(0, rx - lx))

Solution (Python):

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

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

print(max(0,min_x - max_x) * max(0,min_y - max_y))

Solution (Python):
import numpy as np
w,h,n=map(int,input().split())
ans=np.ones((h,w),dtype=np.int)
for _ in range(n):
    x,y,a=map(int,input().split())
    if a == 1:
        ans[:,:x]=0
    elif a == 2:
        ans[:,x:]=0
    elif a ==3:
        ans[:y,:]=0
    else:
        ans[y:,:]=0
print(np.count_nonzero(ans))

Solution (Python):
w,h,n = map(int, input().split())
x_min, x_max = 0, w
y_min, y_max = 0, h
for _ in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x_min, x)
    elif a == 2:
        x_max = min(x_max, x)
    elif a == 3:
        y_min = max(y_min, y)
    elif a == 4:
        y_max = min(y_max, y)
dx = x_max - x_min
dy = y_max - y_min
white_space = max(dx,0) * max(dy,0)
print(white_space)

Solution (Python):




import sys
[a,b,c]=list(map(int,input().split()))
lst=[]
for i in range(c):
    lst.append(list(map(int,input().split())))


lstxmax=[0]
lstxmin=[a]
lstymax=[0]
lstymin=[b]
for i in lst:
    if i[2]==1:
        lstxmax.append(i[0])
    if i[2]==2:
        lstxmin.append(i[0])
    if i[2]==3:
        lstymax.append(i[1])
    if i[2]==4:
        lstymin.append(i[1])

xmin=min(lstxmin)
xmax=max(lstxmax)
ymin=min(lstymin)
ymax=max(lstymax)


if xmin-xmax>=0 and ymin-ymax>=0:
    print((xmin-xmax)*(ymin-ymax))
else:
    print(0)

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

xmin = 0
ymin = 0
xmax = W
ymax = H
for x,y,a in XYA:
  if a == 1:
    xmin = max(x,xmin)
  elif a == 2:
    xmax = min(x,xmax)
  elif a == 3:
    ymin = max(y,ymin)
  else:
    ymax = min(y,ymax)

print(max(xmax-xmin,0)*max(ymax-ymin,0))

Solution (Python):
W, H, N = map(int, input().split())
p = [map(int, input().split()) for _ in range(N)]
w_left = 0
w_right = W
h_bottom = 0
h_top = H

for x, y, a in p:
    if a == 1:
        w_left = max(w_left, x)
    elif a == 2:
        w_right = min(w_right, x)
    elif a == 3:
        h_bottom = max(h_bottom, y)
    else:
        h_top = min(h_top, y)

ans = max(0, w_right - w_left) * max(0, h_top - h_bottom)

print(ans)

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

g = [[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:
                g[i][j] = 0
            elif a == 2 and x <= j:
                g[i][j] = 0
            elif a == 3 and i < y:
                g[i][j] = 0
            elif a == 4 and y <= i:
                g[i][j] = 0

print(sum(map(sum, g)))

Solution (Python):
w,h,n = map(int,input().split())
w0 = 0
h0 = 0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        w0 = max(w0,x)
    if a == 2:
        w = min(w,x)
    if a == 3:
        h0 = max(h0,y)
    if a == 4:
        h = min(h,y)
if (w-w0 > 0) and (h-h0 >0):
    print((w-w0)*(h-h0))
else:
    print(0)

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

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

    if a == 1:
        w0 = max(w0,x)
    
    if a == 2:
        w  = min(w,x)

    if a == 3:
        h0 = max(h0,y)
    
    if a == 4:
        h  = min(h,y)

print(max(0,w-w0)*max(0,h-h0))

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

W_right = W
W_left = 0
H_up = H
H_down = 0
for i 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_down < y:
            H_down = y
    else:
        if H_up > y:
            H_up = y

if W_right >= W_left and H_up >= H_down:
    print((W_right - W_left) * (H_up - H_down))
else:
    print(0)

Solution (Python):
w,h,n=map(int,input().split())
x=int(0)
y=int(0)
sx=int(w)
sy=int(h)
for i in range(n):
    X,Y,a=map(int,input().split())
    if a==1:
        if x<X:
            x=X
    elif a==2:
        if X<sx:
            sx=X
    elif a==3:
        if y<Y:
            y=Y
    else:
        if Y<sy:
            sy=Y

if sx<x or sy<y:
    print(0)

else:
    print((sx-x)*(sy-y))

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

w,h,n=LI()
x,X=0,w
y,Y=0,h
for i in ' '*n:
    s,t,a=LI()
    if a==1:
        x=max(x,s)
    elif a==2:
        X=min(X,s)
    elif a==3:
        y=max(y,t)
    elif a==4:
        Y=min(Y,t)

print(max(0,X-x)*max(0,Y-y))

Solution (Python):
w,h,n=map(int,input().split())
white_mostleft=0
white_mostright=w
white_mostup=h
white_mostdown=0

for _ in range(n):
    x,y,a=map(int,input().split())
    if(a==1 and white_mostleft < x):
        white_mostleft=x
    elif(a==2 and white_mostright > x):
        white_mostright=x
    elif(a==3 and white_mostup > h-y):
        white_mostup = h-y
    elif(a==4 and white_mostdown < h-y):
        white_mostdown = h-y

ans=max(0,white_mostright-white_mostleft) * max(0,white_mostup-white_mostdown)
print(ans)

Solution (Python):
arr = input().split()
arr = list(map(int, arr))
w = arr[0]
h = arr[1]
n = arr[2]

x = []
y = []
a = []
for i in range(n):
    arr = input().split()
    arr = list(map(int, arr))
    x.append(arr[0])
    y.append(arr[1])
    a.append(arr[2])

x1,x2 = 0,w
y1,y2 = h,0

for i in range(n):
    if a[i] == 1:
        if x1 <= x[i]:
            x1 = x[i]
    elif a[i] == 2:
        if x2 >= x[i]:
            x2 = x[i]
    elif a[i] == 3:
        if y2 <= y[i]:
            y2 = y[i]
    elif a[i] == 4:
        if y1 >= y[i]:
            y1 = y[i]           

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

Solution (Python):
import numpy as np
w, h, n = map(int, input().split())

mat = np.ones(w * h).reshape(h, w)
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        mat[:, :x] = 0
    elif a == 2:
        mat[:, x:] = 0
    elif a == 3:
        mat[-y+h:, :] = 0
    else:
        mat[:-y+h, :] = 0
print(len(mat[mat == 1]))

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

Solution (Python):
import sys


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


list = []
for i in range(n):
    xi, yi, ai = map(int, input().split())
    list.append([xi, yi, ai])


x_min, y_min = 0, 0
x_max, y_max = w, h

for list_1 in list:
    
    if list_1[2] == 1:
        if x_min < list_1[0]:
            x_min = list_1[0]
    
    if list_1[2] == 2:
        if x_max > list_1[0]:
            x_max = list_1[0]
    
    if list_1[2] == 3:
        if y_min < list_1[1]:
            y_min = list_1[1]
    
    if list_1[2] == 4:
        if y_max > list_1[1]:
            y_max = list_1[1]


area = (x_max - x_min) * (y_max - y_min)
if (x_max - x_min) > 0 and (y_max - y_min) > 0:
    print(area)
else:
    print(0)

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

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

w1 = 0
w2 = w
h1 = 0
h2 = h

for i in range(n):
    if(mat[i][2] == 1 and w1 < mat[i][0]):
        w1 = mat[i][0]
    elif(mat[i][2] == 2 and w2 > mat[i][0]):
        w2 = mat[i][0]
    elif(mat[i][2] == 3 and h1 < mat[i][1]):
        h1 = mat[i][1]
    elif(mat[i][2] == 4 and h2 > mat[i][1]):
        h2 = mat[i][1]
        
print((w2-w1)*(h2-h1) if w2 >= w1 and h2 >= h1 else 0)

Solution (Python):
def solve(w, h, n, XYA):
    m = [0, w, 0, h]
    for x, y, a in XYA:
        if a == 1 and m[0] < x:
            m[0] = x
        if a == 2 and m[1] > x:
            m[1] = x
        if a == 3 and m[2] < y:
            m[2] = y
        if a == 4 and m[3] > y:
            m[3] = y
        if m[0] >= m[1] or m[2] >= m[3]:
            return 0
    return (m[1] - m[0]) * (m[3] - m[2])

_w, _h, _n = list(map(int, input().split()))
_XYA = [map(int, input().split()) for _ in range(_n)]
print(solve(_w, _h, _n, _XYA))

Solution (Python):
if __name__ == '__main__':
	w, h, n = map(int, input().split())
	
	dots = []

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

	x_min = 0
	x_max = w
	y_min = 0
	y_max = h

	for i in range(0,n):
		if dots[i][2] == 1 and x_min < dots[i][0]:
			x_min = dots[i][0]
		elif dots[i][2] == 2 and x_max > dots[i][0]:
			x_max = dots[i][0]
		elif dots[i][2] == 3 and y_min < dots[i][1]:
			y_min = dots[i][1]
		elif dots[i][2] == 4 and y_max > dots[i][1]:
			y_max = dots[i][1]

	if x_min >= x_max or y_min >= y_max:
		ans = 0
	else:
		ans = (x_max - x_min) * (y_max - y_min)

	print(ans)

Solution (Python):
def main():
    w,h,n=map(int,input().split())
    L=[tuple(map(int,input().split())) for _ in range(n)]
    xl,xr,yl,yu=0,w,0,h
    for l in L:
        if l[2]<2:
            xl = max(xl,l[0])
        elif l[2]<3:
            xr = min(xr,l[0])
        elif l[2]<4:
            yl = max(yl,l[1])
        else:
            yu = min(yu,l[1])
    
    print(max(xr-xl,0)*max(yu-yl,0))
main()

Solution (Python):
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)] 
w1=0
h1=0
w2=w
h2=h

for i in a:
    if i[2]==1:
        w1=max(w1,i[0])
    elif i[2]==2:
        w2=min(w2,i[0])
    elif i[2]==3:
        h1=max(h1,i[1])
    elif i[2]==4:
        h2=min(h2,i[1])
if min((w2-w1),(h2-h1))<=0:
    print(0)
else:
    print((w2-w1)*(h2-h1))

Solution (Python):

INF = 10**9

def main():
    w, h, n = map(int, input().split())
    x_max = -1
    x_min = INF
    y_max = -1
    y_min = INF
    for i in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            x_max = max(x_max, x)
        if a == 2:
            x_min = min(x_min, x)     
        if a == 3:
            y_max = max(y_max, y)
        if a == 4:
            y_min = min(y_min, y)

    if x_max == -1:
        x_max = 0 
    if x_min == INF:
        x_min = w
    if y_max == -1:
        y_max = 0
    if y_min == INF:
        y_min = h

    dx_max = x_max
    dx_min = w - x_min
    dy_max = y_max
    dy_min = h - y_min 

    x = w - (dx_max+dx_min)
    y = h - (dy_max+dy_min)

    if (x<=0) | (y<=0):
        print(0)
    else:
        print(x*y)
    
main()

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

Solution (Python):
xyas = []

w, h, n = list(map(int, input().split()))
for _ in range(n):
  xyas.append(list(map(int, input().split())))

x = [0, w]
y = [0, h]
  
for xya in xyas:
  if xya[2] == 1:
    if x[0] < xya[0]:
      x[0] = xya[0]
  elif xya[2] == 2:
    if x[1] > xya[0]:
      x[1] = xya[0]
  elif xya[2] == 3:
    if y[0] < xya[1]:
      y[0] = xya[1]
  else:
    if y[1] > xya[1]:
      y[1] = xya[1]

width = (x[1] - x[0]) 
height = (y[1] - y[0])
if width <= 0 or height <= 0:
  print(0)
else:
  print(width * height)

Solution (Python):
a = input().split()
w = int(a[0])
h = int(a[1])
n = int(a[2])

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    a = input().split()
    wp = int(a[0])
    hp = int(a[1])
    ap = int(a[2])
    if ap == 1:
        if x_min < wp:
            x_min = wp
    elif ap == 2:
        if x_max > wp:
            x_max = wp
    elif ap == 3:
        if y_min < hp:
            y_min = hp
    elif ap == 4:
        if y_max > hp:
            y_max = hp
    

if x_max < x_min:
    ws = 0
else:
    ws = x_max - x_min

if y_max < y_min:
    hs = 0
else:
    hs = y_max - y_min

squea = ws * hs

print(squea)

Solution (Python):

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

x_min=0
y_min=0

for i in l:
    if i[-1]==1:
        x_min=max(i[0],x_min)

    elif i[-1]==2:
        w=min(i[0],w)

    elif i[-1]==3:
        y_min=max(i[1],y_min)

    else:
        h=min(i[1],h)

print((w-x_min)*(h-y_min) if (w-x_min)>0 and (h-y_min)>0 else 0)

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

L = 0
R = w
D = 0
U = h

for _ in range(n):
    x,y,a = map(int, input().split())
    if a==1:
        L = max(L,x)
    if a==2:
        R = min(R,x)
    if a==3:
        D = max(D,y)
    if a==4:
        U = min(U,y)
    

x = max(0, R-L)
y = max(0, U-D)

ans = x*y

print(ans)

Solution (Python):
W, H, N = map(int, input().split())
paint_dot = {}
for _ in range(N):
  t1, t2, t3 = map(int,input().split())
  paint_dot[(t1, t2)] = t3

pattern_H = [1]*H
pattern_W = [1]*W

for key in paint_dot:
  if paint_dot[key] == 1:
    for i in range(key[0]):
      pattern_W[i] = 0
  elif paint_dot[key] == 2:
    for i in range(key[0],W):
      pattern_W[i] = 0
  elif paint_dot[key] == 3:
    for i in range(key[1]):
      pattern_H[i] = 0
  else:
    for i in range(key[1],H):
      pattern_H[i] = 0

print(sum(pattern_W) * sum(pattern_H))

Solution (Python):
W, H, N = map(int, input().split())
paint_dot = {}
for _ in range(N):
  t1, t2, t3 = map(int,input().split())
  paint_dot[(t1, t2)] = t3

mat = [[1]*W for i in range(H)]

for key in paint_dot:
  x = paint_dot[key]
  if x == 1:
    for row in mat:
      for i in range(key[0]):
        row[i] = 0    
  elif x == 2:    
    for row in mat:
      for i in range(key[0], W):
        row[i] = 0
  elif x == 3:
    for i in range(key[1]):
      for j in range(W):
      	mat[i][j] = 0
  else:
    for i in range(key[1], H):
      for j in range(W):
      	mat[i][j] = 0


print(sum(map(sum,mat)))

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

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

for i in range(N):
    if A[i][2] == 1:
        if x1 < A[i][0]:
            x1 = A[i][0]
    elif A[i][2] == 2:
        if x2 > A[i][0]:
            x2 = A[i][0]
    elif A[i][2] == 3:
        if y1 < A[i][1]:
            y1 = A[i][1]
    elif A[i][2] == 4:
        if y2 > A[i][1]:
            y2 = A[i][1]

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

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    w,h,n=INTM()
    X,Y,A=[],[],[]
    for i in range(n):
        x,y,a=INTM()
        X.append(x)
        Y.append(y)
        A.append(a)
    wh=[[0]*w]*h
    for i in range(n):
        if A[i]==1:
            for j in range(h):
                wh[j][0:X[i]]=[1]*X[i]
        elif A[i]==2:
            for j in range(h):
                wh[j][X[i]:w]=[1]*(w-X[i])
        elif A[i]==3:
            wh[0:Y[i]]=[[1]*w]*Y[i]
        else:
            wh[Y[i]:h]=[[1]*w]*(h-Y[i])
        
    ct=0
    
    for i in range(h):
        ct+=sum(wh[i])
    print(h*w-ct)
if __name__ == '__main__':
    do()

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

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

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

for j in range(n):
    x.append(data[j][0])
    y.append(data[j][1])
    a.append(data[j][2])

x1=0
x2=w
y1=0
y2=h

for j in range(n):
    if a[j]==1 and x[j]>x1:
        x1=x[j]
    elif a[j]==2 and x[j]<x2:
        x2=x[j]
    elif a[j]==3 and y[j]>y1:
        y1=y[j]
    elif a[j]==4 and y[j]<y2:
        y2=y[j]

if x1>x2 or y1>y2:
    print(0)

else:
    print((x2-x1)*(y2-y1))

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

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x0=max(x0,x)
  elif a==2:
    w=min(w,x)
  elif a==3:
    y0=max(y0,y)
  elif a==4:
    h=min(h,y)
    
print(max(w-x0,0)*max(h-y0,0))

Solution (Python):
import sys
input = sys.stdin.readline
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)
    if a==2:
        x2=min(x2,x)
    if a==3:
        y1=max(y1,y)
    if a==4:
        y2=min(y2,y)
print(max((x2-x1)*(y2-y1),0) if x2-x1>0 else 0)

Solution (Python):
import numpy as np

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


def calc_paint(x, y, a):
 
 
    if a == 1:
        area[:, :x] = 0
    elif a == 2:
        area[:, x:] = 0
    elif a == 3:
        area[:y, :] = 0
    elif a == 4:
        area[y:, :] = 0


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

print(int(np.sum(area)))

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

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

area  = [[True for _ in range(W)] for _ in range(H)]

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

w1 = 0
h1 = 0
w2 = W
h2 = H

for i in range(N):
    if a[i] == 1:
        w1 = max(w1, x[i])
    if a[i] == 2:
        w2 = min(w2, x[i])
    if a[i] == 3:
        h1 = max(h1, y[i])
    if a[i] == 4:
        h2 = min(h2, y[i])


if w2 - w1  < 0 or h2 - h1 < 0:
    S = 0
else:
    S = (w2-w1)*(h2-h1)

print(S)

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

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



square = []
for i in range(H):
    horizonatlArea = []
    for j in range(W):
        horizonatlArea.append(0)
    square.append(horizonatlArea)


for n in range(N):
    if A[n] == 1:
        for i in range(X[n]):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 2:
        for i in range(X[n], W):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 3:
        for i in range(W):
            for j in range(Y[n]):
                square[j][i] = 1
    elif A[n] == 4:
        for i in range(W):
            for j in range(Y[n], H):
                square[j][i] = 1


cnt = 0
for j in range(H):
    cnt += square[j].count(0)

print(cnt)

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

Solution (Python):


w,h,n = map(int, input().split())
x = ["" for _ in range(n)]
y = ["" for _ in range(n)]
a = ["" for _ in range(n)]

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

hl = 0
hh = 0
wl = 0
wh = 0
for i in range(n):
    if a[i] == 1:
        wl = max(wl, x[i])
    if a[i] == 2:
        wh = max(wh, w - x[i])
    if a[i] == 3:
        hl = max(hl, y[i])
    if a[i] == 4:
        hh = max(hh, h - y[i])

"""
print("wl :", wl)
print("wh :", wh)
print("hl :", hl)
print("hh :", hh)
"""

ans_w = w - (wl+wh)
ans_h = h - (hl+hh)

if ans_w < 0 or ans_h < 0:
    print(0)
else:
    print(ans_w*ans_h)

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

if wmax-wmin < 0 or hmax-hmin < 0:
  print(0)
else:
  print((wmax-wmin) * (hmax-hmin))

Solution (Python):
W,H,N = map(int, input().split())
minX = 0
maxX = W
minY = 0
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())
minx=0
maxx=w
miny=0
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)
print(max((maxx-minx),0)*max(0,(maxy-miny)))

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

x_min = max((xya[0] for xya in XYA if xya[2] == 1), default=0)
x_max = min((xya[0] for xya in XYA if xya[2] == 2), default=W)
y_min = max((xya[1] for xya in XYA if xya[2] == 3), default=0)
y_max = min((xya[1] for xya in XYA if xya[2] == 4), default=H)
print(max(x_max - x_min, 0) * max(y_max - y_min, 0))

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

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

print(max(0, end[0]-start[0])*max(0, end[1]-start[1]))

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

x_min = max([0] + [xya[0] for xya in XYA if xya[2] == 1])
x_max = min([W] + [xya[0] for xya in XYA if xya[2] == 2])
y_min = max([0] + [xya[1] for xya in XYA if xya[2] == 3])
y_max = min([H] + [xya[1] for xya in XYA if xya[2] == 4])
print(max(x_max - x_min, 0) * max(y_max - y_min, 0))

Solution (Python):
def solve():
    W,H,N = map(int, input().split())
    xl,xr = 0,W
    yl,yr = 0,H
    for _ in range(N):
        x,y,a = map(int, input().split())
        if a == 1:
            xl = max(xl, x)
        elif a == 2:
            xr = min(xr, x)
        elif a == 3:
            yl = max(yl, y)
        elif a == 4:
            yr = min(yr, y)
    
    print((xr-xl)*(yr-yl) if xr-xl > 0 and yr-yl > 0 else 0)
    
solve()