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())
flag=0
lst=[]
most_up=H
most_down=0
most_right=W
most_left=0
now_location=[most_up, most_down, most_right, most_left]
for i in range(N):
    lst.append(list(map(int,input().split())))
for i in lst:
    if i[2]==1:
        if now_location[3] <= i[0]:
            now_location[3]=i[0]
    elif i[2]==2:
        if now_location[2] >= i[0]:
            now_location[2]=i[0]
    elif i[2]==3:
        if now_location[1] <= i[1]:
            now_location[1]=i[1]
    else:
        if now_location[0] >= i[1]:
            now_location[0]=i[1]
height=now_location[0]-now_location[1]
width=now_location[2]-now_location[3]
print(0) if (height<0 or width<0) else print(height*width)

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

l,r,t,b = 0,W,0,H
for _ in range(N):
  x,y,a = map(int, raw_input().split())
  if a==1:
    l = max(l, x)
  if a==2:
    r = min(r, x)
  if a==3:
    t = max(t, y)
  if a==4:
    b = min(b, y)
print max(r-l, 0)*max(b-t, 0)

Solution (Python):
whn = list (map(int, input().split()))
x = 0
y = 0
flag = 0

for i in range(whn[2]):
    xya = list(map(int,input().split()))
    if xya[2] == 1:
        x = max(x, xya[0])
    elif xya[2] == 2:
        whn[0] = min(whn[0], xya[0])
    elif xya[2] == 3:
        y = max(y, xya[1])
    else:
        whn[1] = min(whn[1], xya[1])
    if x >= whn[0] or y >= whn[1]:
        print(0)
        flag += 1
        break
        
if flag == 0:
    print((whn[0]-x)*(whn[1]-y))

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

print(sum(W)*sum(H))

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

space=[[0 for _ in range(H)] for __ in range(W)]
for point in points:
    if point[2]==1:
        for i in range(W):
            for j in range(H):
                if i<point[0]:
                    space[i][j]=1
    elif point[2]==2:
        for i in range(W):
            for j in range(H):
                if i>=point[0]:
                    space[i][j]=1
    elif point[2]==3:
        for i in range(W):
            for j in range(H):
                if j<point[1]:
                    space[i][j]=1
    elif point[2]==4:
        for i in range(W):
            for j in range(H):
                if j>=point[1]:
                    space[i][j]=1

count=0

for i in range(W):
    for j in range(H):
        if space[i][j]==0:
            count+=1
print(count)

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

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

dp = [[0] * W for i in range(H)]

for i in range(N):
    if L[i][2] == 1:
        for y in range(H):
            for x in range(L[i][0]):
                dp[y][x] = 1
                
    elif L[i][2] == 2:
        for y in range(H):
            for x in range(L[i][0], W):
                dp[y][x] = 1
                
    elif L[i][2] == 3:
        for y in range(L[i][1]):
            for x in range(W):
                dp[y][x] = 1
                
    else:
        for y in range(L[i][1], H):
            for x in range(W):
                dp[y][x] = 1
                

res = 0

for x in range(W):
    for y in range(H):
        if dp[y][x] == 0:
            res += 1
        
print(res)

Solution (Python):
w,h,n=map(int,input().split())
cx = [0,w]
cy = [0,h]
for _ in range(n):
    x,y,a=map(int,input().split())
    if a == 1:
        if cx[0] < x:
            cx[0] = x
    if a == 2:
        if cx[1] > x:
            cx[1] = x
    if a == 3:
        if cy[0] < y:
            cy[0] = y
    if a == 4:
        if cy[1] > y:
            cy[1] = y

if cx[0] >= cx[1] or cy[0] >= cy[1]:
    print(0)
else:
    print((cx[1]-cx[0])*(cy[1]-cy[0]))

Solution (Python):
w,h,n = map(int,input().split())
xmin, ymin = 0,0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        if xmin < x:
            xmin = x
    elif a == 2:
        if w > x:
            w = x
    elif a == 3:
        if ymin < y:
            ymin = y
    else:
        if h > y:
            h = y
        
s = (w-xmin)*(h-ymin)
if (w-xmin) <= 0 or (h-ymin) <= 0:
    print(0)
else:
    print(s)

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

Solution (Python):
W,H,N=map(int,input().split())
l=[]
x=W
y=H
max1=0
max2=0
max3=W
max4=H
for i in range(N):
     x1,y1,z=map(int,input().split())
     ls=[]
     ls.append(x1)
     ls.append(y1)
     ls.append(z)
     l.append(ls)
for i in l:
     if i[2]==1:
          c=i[0]
          if c>max1:
               x-=c-max1
               max1=c
     elif i[2]==2:
          a=i[0]
          if a<max3:
               x-=max3-a
               max3=a
     elif i[2]==3:
          b=i[1]
          if b>max2:
               y-=b-max2
               max2=b
     elif i[2]==4:
          d=i[1]
          if d<max4:
               y-=max4-d
               max4=d
if y<=0 or x<=0:
     print('0')
else:
     print(x*y)

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




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

Solution (Python):
import numpy
I=lambda:map(int,input().split())
W,H,N=I()
m=numpy.zeros((H,W),int)
while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1
print(W*H-m.sum())

Solution (Python):
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W),int)
while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1
print(W*H-m.sum())

Solution (Python):
import numpy;I=lambda:map(int,input().split());W,H,N=I();m=numpy.zeros((H,W),int)
while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1
print(W*H-m.sum())

Solution (Python):
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W),int)
for _ in[0]*N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1
print(W*H-m.sum())

Solution (Python):
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for _ in[0]*N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1
print(W*H-int(sum(m)))

Solution (Python):
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for i in range(N):x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1
print(W*H-int(sum(m)))

Solution (Python):
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for i in range(N):x,y,a=I();m[y*(a>3):H*(a!=3)or y,x*(a==2):W*~-a or x]=1
print(W*H-int(sum(m)))

Solution (Python):
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for i in range(N):x,y,a=I();m[y*(a>3):y*(a==3or H),x*(a==2):x*(a<2or W)]=1
print(W*H-int(sum(m)))

Solution (Python):


def paint_gt_x(area, threhsold):
    for y in range(len(area)):
        for x in range(len(area[y])):
            if x < threhsold:
                area[y][x] = 1

def paint_lt_x(area, threhsold):
    for y in range(len(area)):
        for x in range(len(area[y])):
            if x > threhsold:
                area[y][x] = 1

def paint_gt_y(area, threhsold):
    for y in range(len(area)):
        for x in range(len(area[y])):
            if y < threhsold:
                area[y][x] = 1

def paint_lt_y(area, threhsold):
    for y in range(len(area)):
        for x in range(len(area[y])):
            if y > threhsold:
                area[y][x] = 1


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

area = []
for _ in range(h):
    area.append([0 for _ in range(w)])

for _ in range(n):
    (x, y, a) = map(int, input().split())
    if 1 == a:
        paint_gt_x(area, x)
    elif 2 == a:
        paint_lt_x(area, x - 1)
    elif 3 == a:
        paint_gt_y(area, y)
    else:
        paint_lt_y(area, y - 1)

count = 0
for row in area:
    for cell in row:
        count += 1 if 0 == cell else 0
print(count)

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

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

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

print(ans)

Solution (Python):


import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


w, h, n = LI()
A = [0] * 4
A[1] = w
A[3] = h
for _ in range(n):
    x, y, a = LI()
    a -= 1
    if a == 0:
        A[a] = max(A[a], x)
    elif a == 1:
        A[a] = min(A[a], x)
    elif a == 2:
        A[a] = max(A[a], y)
    else:
        A[a] = min(A[a], y)

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

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

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

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

for _ in range(n):
    *a, = map(int, input().split())
    s = int((a[2] % 2 - 0.5)*2)
    b[a[2]-1] = s*max(s*a[a[2]//3], s*b[a[2]-1])
print(max((b[1]-b[0]), 0)*max((b[3]-b[2]), 0))

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

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

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

    if a==1:
        s,t=range(h),range(x)
    elif a==2:
        s,t=range(h),range(x,w)
    elif a==3:
        s,t=range(y),range(w)
    elif a==4:
        s,t=range(y,h),range(w)

    for i in s:
        for j in t:
            l[i][j]=True

print(h*w-sum(map(sum,l)))

Solution (Python):
w, h, n = list(map(int, input().split()))
x0, y0 = 0, 0
for _ in range(n):
    x, y, a =list(map(int, input().split()))
    if a == 1:
        x0 = max(x0, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        y0 = max(y0, y)
    else:
        h = min(h, y)

print(max(0, w - x0) * max(0, h - y0))

Solution (Python):
import numpy as np

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

for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        wh[:,:x]=0
    if a==2:
        wh[:,x:]=0
    if a==3:
        wh[:y,:]=0
    if a==4:
        wh[y:,:]=0
print(int(np.sum(wh)))

Solution (Python):
w,h,n= map(int,input().split())
kuro = [[0,w],[0,h]]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if kuro[0][0]<x:
            kuro[0][0]=x
    if a==2:
        if kuro[0][1]>x:
            kuro[0][1]=x
    if a==3:
        if kuro[1][0]<y:
            kuro[1][0]=y
    if a==4:
        if kuro[1][1]>y:
            kuro[1][1]=y
            
yoko = max(kuro[0][1]-kuro[0][0] , 0)
tate = max(kuro[1][1]-kuro[1][0] , 0)
print(yoko*tate)

Solution (Python):
W,H,N = map(int,input().split())
x = [0]*N
y = [0]*N
a = [0]*N
Xmin = -1
Xmax = W+1
Ymin = -1
Ymax = H+1
for i in range(0,N):
	x[i],y[i],a[i] = map(int,input().split())
	if a[i] == 1 and Xmin < x[i]:
		Xmin = x[i]
	if a[i] == 2 and Xmax > x[i]:
		Xmax = x[i]
	if a[i] == 3 and Ymin < y[i]:
		Ymin = y[i]
	if a[i] == 4 and Ymax > y[i]:
		Ymax = y[i]

ans = 0

if Xmin == -1:
	Xmin = 0
if Xmax == W+1:
	Xmax = W
if Ymin == -1:
	Ymin = 0
if Ymax == H+1:
	Ymax = H
ans = (Xmax-Xmin)*(Ymax-Ymin)
if Xmin > Xmax or Ymin > Ymax:
	ans = 0
print(ans)

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

for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
    if a[i] == 1:
        if lx < x[i]:
            lx = x[i]
    elif a[i] == 2:
        if x[i] < rx:
            rx = x[i]
    elif a[i] == 3:
        if ly < y[i]:
            ly = y[i]
    else:
        if y[i] < ry:
            ry = y[i]

if lx >= rx or ly >= ry:
    print(0)
else:
    print((rx - lx) * (ry - ly))

Solution (Python):
def execute(w, h, n, xya):
    s = [[1 for _ in range(w)] for _ in range(h)]
    for x, y, a in xya:
        for xi in range(w):
            for yi in range(h):
                if a == 1:
                    if xi < x:
                        s[yi][xi] = 0
                if a == 2:
                    if xi >= x:
                        s[yi][xi] = 0
                if a == 3:
                    if yi < y:
                        s[yi][xi] = 0
                if a == 4:
                    if yi >= y:
                        s[yi][xi] = 0
    return sum(map(sum, s))


if __name__ == '__main__':
    w, h, n = map(int, input().split())
    xya = []
    for _ in range(n):
        xya.append(list(map(int, input().split())))
    print(execute(w, h, n, xya))

Solution (Python):
w,h,n=map(int,input().split())
s=[0,w,0,h]
for i in range(n):
    p=list(map(int,input().split()))
    if p[2]==1 or p[2]==3:
        s[p[2]-1]=max(p[p[2]//2],s[p[2]-1])
    else:
        s[p[2]-1]=min(p[p[2]//2-1],s[p[2]-1])
print(max(s[1]-s[0],0)*max(s[3]-s[2],0))

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

x1 = []
x2 = []
y3 = []
y4 = []

for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y3.append(y)
  else:
    y4.append(y)

if not x1:
  if not x2:
    W = W
  else:
    W = min(x2)
elif not x2:
  W -= max(x1)
elif max(x1) >= min(x2):
  W = 0
else:
  W = min(x2) - max(x1)

if not y3:
  if not y4:
    H = H
  else:
    H = min(y4)
elif not y4:
  H -= max(y3)
elif max(y3) >= min(y4):
  H = 0
else:
  H = min(y4) - max(y3)
  
print(W*H)

Solution (Python):

def zeros(n): return [0 for i in range(n)]
W, H, N = [int(x) for x in input().split()]
white = [[0,0],[W,H]]

for i in range(N):
    
    x, y, a = [int(x) for x in input().split()]
    
    if a==1: white[0][0] = max(white[0][0], x)
    elif a==2: white[1][0] = min(white[1][0], x)
    elif a==3: white[0][1] = max(white[0][1], y)
    elif a==4: white[1][1] = min(white[1][1], y)
    else: print('error')
    
    
print(max(white[1][0]-white[0][0], 0)*max(white[1][1]-white[0][1], 0))

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

li_point = list()
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        ws = x if x >= ws else ws
    elif a == 2:
        w = x if x <= w else w
    elif a == 3:
        hs = y if y >= hs else hs
    else: 
        h = y if y <= h else h

yoko = w - ws if w - ws > 0 else 0
tate = h - hs if h - hs > 0 else 0

print(yoko * tate)

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())
b=c=0
for _ in [0]*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([(w-b)*(h-c),0][(w<b)|(h<c)])

Solution (Python):
w,h,n=map(int,input().split())
l=[[int(j) for j in input().split()] for i in range(n)]
b=c=0
for i in range(n):
    x,y,a=l[i][0],l[i][1],l[i][2]
    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([(w-b)*(h-c),0][(w<b)|(h<c)])

Solution (Python):
w,h,n=map(int,input().split())
l=[[int(j) for j in input().split()] for i in range(n)]
b=c=0
d=w
e=h
for i in range(n):
    a=l[i][2]
    if a==1:b=max(b,l[i][0])
    if a==2:d=min(d,l[i][0])
    if a==3:c=max(c,l[i][1])
    if a==4:e=min(e,l[i][1])
print([(d-b)*(e-c),0][(d<b)|(e<c)])

Solution (Python):




def solveProblem(XLine,YLine,PointCounter):
	graphPaper = [[1 for _ in range(0,YLine,+1)] for _ in range(0,XLine,+1)]
	xplot = list()
	yplot = list()
	processSelect = list()
	for _ in range(0,PointCounter,+1):
		xplotEach,yplotEach,processSelectEach = map(int,input().strip().split(' '))
		xplot.append(xplotEach)
		yplot.append(yplotEach)
		processSelect.append(processSelectEach)

	for i in range(0,PointCounter,+1):
		if processSelect[i]==1:
			xrange = range(0,xplot[i],+1)
			yrange = range(0,YLine,+1)
		elif processSelect[i]==2:
			xrange = range(xplot[i],XLine,+1)
			yrange = range(0,YLine,+1)
		elif processSelect[i]==3:
			xrange = range(0,XLine,+1)
			yrange = range(0,yplot[i],+1)
		elif processSelect[i]==4:
			xrange = range(0,XLine,+1)
			yrange = range(yplot[i],YLine,+1)
		for x in xrange:
			for y in yrange:
				graphPaper[x][y]=0
	menseki=0
	for x in range(0,XLine,+1):
		for y in range(0,YLine,+1):
			if graphPaper[x][y]==1:
				menseki = menseki + 1
	answer = menseki
	return answer


if __name__ == '__main__':
	W,H,N = map(int,input().strip().split(' '))
	solution = solveProblem(W,H,N)
	print("{}".format(solution))

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

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)
x0,x1,y0,y1 = 0,W,0,H
for i in range(N):
    if A[i]==1:
        x0 = max(x0,X[i])
    elif A[i]==2:
        x1 = min(x1,X[i])
    elif A[i]==3:
        y0 = max(y0,Y[i])
    else:
        y1 = min(y1,Y[i])

print(max(0,(x1-x0))*max(0,(y1-y0)))

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:
        if x >= W:
            W0 = W
        elif x >= W0:
            W0 = x
    elif a == 2:
        if x <= W0:
            W = W0
        elif x <= W:
            W = x
    elif a == 3:
        if y >= H:
            H0 = H
        elif y >= H0:
            H0 = y
    else:
        if y <= H0:
            H = H0
        elif y <= H:
            H = y
print((W-W0)*(H-H0))

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

LL = []

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

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        
        for j in range(H):
            LL[j][:x] = [1 for k in range(x)]
    elif a == 2:
        
        for j in range(H):
            LL[j][x:] = [1 for k in range(x)]
    elif a == 3:
        
        cnt = 0
        for j in range(H):
            if cnt >= H - y:
                LL[j] = [1 for k in range(x)]
            cnt += 1
    else:
        
        for j in range(H - y):
            LL[j] = [1 for k in range(x)]

ans = 0
for i in LL:
    for j in i:
        if j == 0:
            ans += 1

print(ans)

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 and x > min_x:
        min_x = x
    if a == 2 and x < max_x:
        max_x = x
    if a == 3 and y > min_y:
        min_y = y
    if a == 4 and y < max_y:
        max_y = y
if max_x - min_x < 0 or max_y - min_y < 0:
    ans = 0
else:
    ans = (max_x - min_x) * (max_y - min_y)

print(ans)

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


x_max, y_max, N = il()
x_min, y_min = 0, 0
s = 0
for i in range(N):
    x, y, a = il()
    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)
    else:
        y_max = min(y_max, y)
if x_min > x_max or y_min > y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))

Solution (Python):
x2, y2, n = [int(i) for i in input().split()]
x1, y1 = (0, 0)

for i in range(n):
    x, y, a = [int(x) for x in 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, 0) * max(y2 - y1, 0))

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

if x_max > x_min or y_max > y_min:
    print(0)
else:
    if y_min == 100:
        y_min = H
    if x_min == 100:
        x_min = W
    print((y_min-y_max)*(x_min-x_max))

Solution (Python):
def inpl(): return list(map(int, input().split()))

W, H, N = inpl()
l, r, d, u = 0, W, 0, H

for _ in range(N):
    x, y, a = inpl()
    if a == 1:
        l = max(l, x)
    elif a == 2:
        r = min(r, x)
    elif a == 3:
        d = max(d, y)
    else:
        assert a == 4
        u = min(u, y)
print(max((r-l), 0)*max((u-d), 0))

Solution (Python):
w, h, n = map(int, input().split())
lx, mx = 0, w
ly, my = 0, h

for _ in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    lx = max(lx, x)
  elif a == 2:
    mx = min(mx, x)
  elif a == 3:
    ly = max(ly, y)
  elif a == 4:
    my = min(my, y)
print((mx-lx)*(my-ly) if mx > lx and my > ly else 0)

Solution (Python):
x,y,n = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(n)]
a,b,c,d = [0,0],[x,0],[x,y],[0,y]

for i in range(n):
    if A[i][2] == 1:
        if A[i][0] >= b[0]:
            print(0)
            break
        else:
            a[0] = max(A[i][0],a[0])
            d[0] = a[0]
    if A[i][2] == 2:
        if A[i][0] <= a[0]:
            print(0)
            break
        else:
            b[0] = min(A[i][0],b[0])
            c[0] = b[0]
    if A[i][2] == 3:
        if A[i][1] >= d[1]:
            print(0)
            break
        else:
            a[1] = max(A[i][1],a[1])
            b[1] = a[1]
    if A[i][2] == 4:
        if A[i][1] <= a[1]:
            print(0)
            break
        else:
            c[1] = min(A[i][1],c[1])
            d[1] = c[1]
else:
    print((b[0]-a[0])*(d[1]-a[1]))

Solution (Python):
W, H, N = map(int, input().split())
wl = 0
wr = W
hu = 0
hl = W

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

    if a == 1:
        if x > wl:
            wl = x
    elif a == 2:
        if x < wr:
            wr = x
    elif a == 3:
        if y > hu:
            hu = y
    else:
        if y < hl:
            hl = y

if wl >= wr or hu >= hl:
    print(0)
else:
    ans = (wr - wl) * (hl - hu)
    print(ans)

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

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

Solution (Python):
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
for i in range(N):
    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]
    elif a[i] == 4:
        if y_max > y[i]:
            y_max = y[i]
if x_max <= x_min or y_max <= y_min:
    print(0)
else:
    print((x_max - x_min)*(y_max - y_min))

Solution (Python):
w,h,n=map(int,input().split())
xmax=w
ymax=h
xmin=0
ymin=0

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1 and xmin<x:
    xmin=x
  if a==2 and xmax>x:
    xmax=x
  if a==3 and ymin<y:
    ymin=y
  if a==4 and ymax>y:
    ymax=y

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

Solution (Python):
w,h,n=map(int,input().split())
x0=y0=0
xx=w
yy=h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    if x0<x:
      x0=x
  elif a==2:
    if x<xx:
      xx=x
  elif a==3:
    if y0<y:
      y0=y
  elif a==4:
    if y<yy:
      yy=y
if (xx-x0)<=0 or (yy-y0)<=0:
  print(0)
else: 
  print((xx-x0)*(yy-y0))

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

for i in range(n):
    x,y,a=map(int,input().split())
    if(a==1):
        ax=max(ax,x)
    elif(a==2):
        w=min(w,x)
    elif(a==3):
        ay=max(ay,y)
    else:
        h=min(h,y)

print('0'if ax>=w or ay>=h else(w-ax)*(h-ay))

Solution (Python):
xmax, ymax, N = map(int, input().split())
xmin = 0
ymin = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > xmin: xmin = x
    if a == 2:
        if x < xmax: xmax = x
    if a == 3:
        if y > ymin: ymin = y
    if a == 4:
        if y < ymax: ymax = y
print(max(xmax - xmin, 0) * max(ymax - ymin, 0))

Solution (Python):
W,H,N=map(int, input().split())
gss=[[1] * (H) for _ in range(W)]
for _ in range(N):
    x,y,a=map(int, input().split())
    xFr,xTo,yFr,yTo=0,W-1,0,H-1
    if a==1: xTo=x-1
    elif a==2: xFr=x
    elif a==3: yTo=y-1
    elif a==4: yFr=y
    for x in range(xFr,xTo+1):
        for y in range(yFr,yTo+1):
            gss[x][y]=0
print(sum(map(sum, gss)))

Solution (Python):
w,h,n = map(int,input().split())
x1,y1,x2,y2 = 0,0,w,h
for i in range(n):
    b,c,d = map(int,input().split())
    if d == 1:
        x1 = max(x1,b)
    elif d == 2:
        x2 = min(x2,b)
    elif d == 3:
        y1 = max(y1,c)
    else:
        y2 = min(y2,c)
if x2-x1 <= 0 or y2 <= 0:
    print(0)
else:
    print((x2-x1)*(y2-y1))

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

for i in range(N):
  x, y, a = map(int,input().split())
  if(a == 1):
    dx = max(dx, x)
  elif(a == 2):
    W = min(W, x)
  elif(a == 3):
    dy = max(dy, y)
  else:
    H = min(H, y)
if(W <= dx or H <= dy):
  print(0)
else:
  print((dx-W) * (dy-H))

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

for i in range(n):
    x,y,a=map(int,input().split())
    if(a==1):
        ax=max(ax,x)
    elif(a==2):
        w=min(w,x)
    elif(a==3):
        ay=max(ay,y)
    else:
        h=min(h,y)

print('0'if ax>=w or ay>=h else(w-ax)*(h-ay))

Solution (Python):
w,h,n=map(int,input().split())
ax=0
ix=w
ay=0
iy=h

for i in range(n):
    x,y,a=map(int,input().split())
    if(a==1):
        ax=max(ax,x)
    elif(a==2):
        ix=min(ix,x)
    elif(a==3):
        ay=max(ay,y)
    else:
        iy=min(iy,y)

if(ax>=ix or ay>=iy):
    print('0')
    exit()

else:
    print((ix-ax)*(iy-ay))

Solution (Python):
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
ax=0
ix=w
ay=0
iy=h

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

for j in range(n):
    if(a[j]==1):
        ax=max(ax,x[j])
    elif(a[j]==2):
        ix=min(ix,x[j])
    elif(a[j]==3):
        ay=max(ay,y[j])
    else:
        iy=min(iy,y[j])

if(ax>=ix or ay>=iy):
    print('0')
    exit()

else:
    print((ix-ax)*(iy-ay))

Solution (Python):
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
maxx=0
minx=w
maxy=0
miny=h

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

for j in range(n):
    if(a[j]==1):
        maxx=max(maxx,x[j])
    elif(a[j]==2):
        minx=min(minx,x[j])
    elif(a[j]==3):
        maxy=max(maxy,y[j])
    else:
        miny=min(miny,y[j])

if(maxx>=minx):
    print('0')
    exit()

elif(maxy>=miny):
    print('0')
    exit()

if(maxx<minx or maxy<miny):
    print((minx-maxx) * (miny-maxy))