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())
z = [list(map(int, input().split())) for _ in range(N)]
one, two, three, four = [0], [W], [0], [H]
for i in range(N):
	if z[i][2] == 1:
		one.append(z[i][0])
	elif z[i][2] == 2:
		two.append(z[i][0])
	elif z[i][2] == 3:
		three.append(z[i][1])
	else:
		four.append(z[i][1])
w = W - max(one) - (W - min(two))
h = H - max(three) - (H - min(four))
if w > 0 and h > 0:
	print(w * h)
else:
	print(0)

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

Solution (Python):
W, H, N = map(int, input().split())
z = [list(map(int, input().split())) for _ in range(N)]
one, two, three, four = [0], [W], [0], [H]
for i in range(N):
	if z[i][2] == 1:
		one.append(z[i][0])
	elif z[i][2] == 2:
		two.append(z[i][0])
	elif z[i][2] == 3:
		three.append(z[i][1])
	else:
		four.append(z[i][1])
w = W - max(one) - (W - min(two))
h = H - max(three) - (H - min(four))
if w > 0 and h > 0:
	print(w * h)
else:
	print(0)

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

Ws = [x for x in range(W + 1)]
Hs = [x for x in range(H + 1)]

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

    if a == 1:
        Ws = list(filter(lambda x: x >= x_i,Ws))
    if a == 2:
        Ws = list(filter(lambda x: x <= x_i,Ws))
    if a == 3:
        Hs = list(filter(lambda y: y >= y_i,Hs))
    if a == 4:
        Hs = list(filter(lambda y: y <= y_i,Hs))

if len(Ws) == 0 or len(Hs) == 0:
    print(0)
else:
    print((Ws[-1] - Ws[0]) * (Hs[-1] - Hs[0]))

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

for i in range(N):
  if xya[i][2] == 1:
    for a in range(H):
      for b in range(xya[i][0]):
        M[a][b] = 1
  elif xya[i][2] == 2:
    for a in range(H):
      for b in range(W-xya[i][0]):
        M[a][W-b-1] = 1
  elif xya[i][2] == 3:
    for a in range(xya[i][1]):
      for b in range(W):
        M[a][b] = 1
  else:
    for a in range(H-xya[i][1]):
      for b in range(W):
        M[H-a-1][b] = 1

c = 0
for i in range(H):
  c += M[i].count(0)
print(c)

Solution (Python):


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

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

    return w, h, n, points


def submit():
    w, h, n, points = read_input()

    area_x = [0, w]
    area_y = [0, h]

    for point in points:
        if point[2] == 1:
            if area_x[0] < point[0]:
                area_x[0] = point[0]
            continue

        if point[2] == 2:
            if point[0] < area_x[1]:
                area_x[1] = point[0]
            continue

        if point[2] == 3:
            if area_y[0] < point[1]:
                area_y[0] = point[1]
            continue

        if point[2] == 4:
            if point[1] < area_y[1]:
                area_y[1] = point[1]
            continue

    if area_x[1] - area_x[0] < 0 or area_y[1] - area_y[0] < 0:
        print(0)
    else:
        print((area_x[1] - area_x[0]) * (area_y[1] - area_y[0]))

if __name__ == '__main__':
    submit()

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

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

for i in range(N):
    if a[i] == 1:
        left = max(left, x[i])
    elif a[i] == 2:
        right = min(right, x[i])
    elif a[i] == 3:
        down = max(down, y[i])
    else:
        up = min(up, y[i])

print(max(right-left, 0) * max(up-down, 0))

Solution (Python):

def re(x,y,a,rect):
    if a==1:
        for i in range(1,len(rect)):
            rect[i][1:x+1]=[0]*x
    elif a==2:
        for i in range(1,len(rect)):
            rect[i]=rect[i][:x+1]+[0]*(len(rect[i])-x-1)
    elif a==3:
        for i in range(1,y+1):
            rect[i]=[0]*(len(rect[y]))
    else:
        for i in range(y+1,len(rect)):
            rect[i]=[0]*(len(rect[y]))
        
    return rect



w,h,n=map(int,input().split())
rect=[[0]*(w+1)]
for i in range(h):
    rect+=[[0]+[1]*w]

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


cnt=0
for k in range(h+1):
    cnt+=sum(rect[k])
print(cnt)

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

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

Sum = 0
for i in box:
    Sum += sum(i)

print(W*H - Sum)

Solution (Python):

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


X=Y=0

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

  if a==1:
    X=max(X,x)
  elif a==2:
    W=min(W,x)
  elif a==3:
    Y=max(Y,y)
  else:
    H=min(H,y)


print(max(W-X,0)*max(H-Y,0))

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

Solution (Python):
[W,H,N] = list(map(int,input().split()))
minx = 0
maxx = W
miny = 0
maxy = H
for i in range(N):
    [x,y,a] = list(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)
    else:
        maxy = min(maxy,y)
print(max(0,maxx-minx)*max(0,maxy-miny))

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

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

ans = [[0, 0], [W, H]]
for x, y, a in XYA:
    if a == 1 and x > ans[0][0]:
        ans[0][0] = x
    elif a == 2 and x < ans[1][0]:
        ans[1][0] = x
    elif a == 3 and y > ans[0][1]:
        ans[0][1] = y
    elif a == 4 and y < ans[1][1]:
        ans[1][1] = y

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

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    W, H, N = map(int, input().split())
    xl = 0
    xr = W
    yu = H
    yd = 0
    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:
            yd = max(yd, y)
        else:
            yu = min(yu, y)

    if xr <= xl or yu <= yd:
        return 0

    return (xr - xl) * (yu - yd)


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

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

boundary = [[0], [w], [0], [h]]
for i in range(n):
    x, y, a = [int(item) for item in input().split()]
    if a == 1 or a == 2:
        val = x
    elif a == 3 or a == 4:
        val = y
    else:
        exit()
    boundary[a-1].append(val)
    
w = min(boundary[1]) - max(boundary[0])
h = min(boundary[3]) - max(boundary[2])
if w >= 0 and h >= 0:
    print(w*h)
else:
    print(0)

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

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

Solution (Python):
import numpy as np
a,b,c=map(int, input().split())
d=[list(map(int,input().split())) for s in range(c)]
e=np.zeros((a,b),dtype=int)
for i in d:
    if i[2]==1:
        for j in range(i[0]):
            for k in range(b):
                e[j][k]=1
    if i[2]==2:
        for j in range(i[0],a):
            for k in range(b):
                e[j][k]=1
    if i[2]==3:
        for j in range(i[1]):
            for k in range(a):
                e[k][j]=1
    if i[2]==4:
        for j in range(i[1],b):
            for k in range(a):
                e[k][j]=1
f=[a]*b-sum(e)
print(sum(f))

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)
    elif a==2:
        w = min(w,x)
    elif a==3:
        h0 = max(h0,y)
    elif a==4:
        h = min(h,y)
if w-w0<0 or h-h0<0:
    print(0)
else:
    print((w-w0)*(h-h0))

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

for i in range(N):
    l = input().split()
    x = int(l[0])
    y = int(l[1])
    a = int(l[2])
    if a == 1:
        if x_list[0] < x:
            x_list[0] = x
    if a == 2:
        if x_list[1] > x:
            x_list[1] = x
    if a == 3:
        if y_list[0] < y:
            y_list[0] = y
    if a == 4:
        if y_list[1] > y:
            y_list[1] = y
            
S = (x_list[1] - x_list[0]) * (y_list[1] - y_list[0])

if x_list[1] - x_list[0] <= 0 or y_list[1] - y_list[0] <= 0:
    print(0)
else:
    print(S)

Solution (Python):
w,h,n=map(int,input().split())
X=[]
for i in range(n):
    x,y,a=map(int,input().split())
    X.append([x,y,a])

X_max=[0]
X_min=[w]
Y_max=[0]
Y_min=[h]


for i in range(n):
    if X[i][2]==1:
        X_max.append(X[i][0])
    elif X[i][2]==2:
        X_min.append(X[i][0])
    elif X[i][2]==3:
        Y_max.append(X[i][1])
    elif X[i][2]==4:
        Y_min.append(X[i][1])

a=min(X_min)-max(X_max)
b=min(Y_min)-max(Y_max)

if a<=0 or b<=0:
    ans=0
else:
    ans=a*b


print(ans)

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

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

Solution (Python):


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

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

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

counter = 0

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

print(counter)

Solution (Python):
import numpy as np

i = list(map(int, input().split()))
array=np.ones((i[1],i[0]))

n=[]
for l in range(i[2]):
    x,y,z=[int(l) for l in input().split()]
    n.append([x,y,z])

for num in range(i[2]):
  if n[num][2]==1:
    array[:, :n[num][0]]=0
  elif n[num][2]==2:
    array[:, n[num][0]:]=0
  elif n[num][2]==3:
    array[:n[num][1],:]=0
  elif n[num][2]==4:
    array[n[num][1]:,:]=0  
print(array.sum())

Solution (Python):
W,H,N=map(int,input().split())
xM=W
xm=0
yM=H
ym=0
for i in range(N):
    a=list(map(int,input().split()))
    if a[2]==1:
        if a[0]>xm:
            xm=a[0]
        else:
            continue
    elif a[2]==2:
        if a[0]<xM:
            xM=a[0]
        else:
            continue
    elif a[2]==3:
        if a[1]>ym:
            ym=a[1]
        else:
            continue
    else:
        if a[1]<yM:
            yM=a[1]
        else: 
            continue
xl=xM-xm
yl=yM-ym
print(max(0,xl)*max(0,yl))

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

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        
        w = max(w, x)
    elif a == 2:
        
        W = min(W, x)
    elif a == 3:
        
        h = max(h, y)
    else:
        
        H = min(H, y)

if W < w or H < h:
    print(0)
else:
    print((W-w)*(H-h))

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

for ls in lists:
    x, y, a = ls[0], ls[1], ls[2]
    if a == 1:
        
        for h in range(H):
            for w in range(x):
                cells[h][w] = 1
    elif a == 2:
        
        for h in range(H):
            for w in range(x, W):
                cells[h][w] = 1
    elif a == 3:
        
        for h in range(H-y, H):
            for w in range(W):
                cells[h][w] = 1
    else:
        
        for h in range(H-y):
            for w in range(W):
                cells[h][w] = 1

count = 0
for rows in cells:
    count += rows.count(0)

print(count)

Solution (Python):
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(list(map(int,input().split())))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

if h-d>0 and w-l>0:
    print((h-d)*(w-l))
else:
    print(0)

Solution (Python):


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

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


print(max(0,w-x)*max(0,h-y))

Solution (Python):
w,h,n=map(int,input().split())
wlist=[0]*w
hlist=[0]*h
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    for i in range(x):
      wlist[i]=1
  elif a==2:
    for i in range(x,w):
      wlist[i]=1
  elif a==3:
    for i in range(y):
      hlist[i]=1
  elif a==4:
    for i in range(y,h):
      hlist[i]=1
print(wlist.count(0)*hlist.count(0))

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

h, w = H, W
x0, y0 = 0, 0
ans = 1

for i in range(N):
    if xya[i][2] == 1:
        if xya[i][0] <= w:
            x0 = max(xya[i][0], x0)
        else:
            ans = 0
    elif xya[i][2] == 2:
        if x0 <= xya[i][0] and xya[i][0] <= w:
            w = xya[i][0]
        elif xya[i][0] < x0:
            ans = 0
    elif xya[i][2] == 3:
        if xya[i][1] <= h:
            y0 = max(xya[i][1], y0)
        else:
            ans = 0
    else:
        if y0 <= xya[i][1] and xya[i][1] <= h:
            h = xya[i][1]
        elif xya[i][1] < y0:
            ans = 0
if ans != 0:
    ans = (w - x0) * (h - y0)
print(ans)

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

Solution (Python):
import numpy as np
W, H, N = map(int,input().split())
Map = np.ones((H, W),dtype = int)
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        Map[:,:x] = 0
    elif a == 2:
        Map[:,x:] = 0
    elif a == 3:
        Map[:y,:] = 0
    else:
        Map[y:,:] = 0
print(Map.sum())

Solution (Python):
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for i in range(n)]
m=[[0 for i in range(w)]for i in range(h)]
for x,y,a in xya:
    if a==1:
        for i in range(h):
            for j in range(x):
                m[i][j]=1
    elif a==2:
        for i in range(h):
            for j in range(x,w):
                m[i][j]=1
    elif a==3:
        for i in range(y):
            for j in range(w):
                m[i][j]=1
    else:
        for i in range(y,h):
            for j in range(w):
                m[i][j]=1
ans=0
for i in m:
    ans+=i.count(0)
print(ans)

Solution (Python):
w,h,n=[int(i) for i in input().split(' ')]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=[int(i) for i in 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)
    
if y2<=y1 or x2 <= x1:
  print(0)
else:
  print(max(0,(y2-y1)*(x2-x1)))

Solution (Python):
W, H, N = map(int, input().rstrip().split())
xya = [list(map(int, input().rstrip().split())) for _ in range(N)]
xy = [[0]*H for _ in range(W)]
for i in xya:
    x_y = i[:2]
    a = i[2]
    if a == 1:
        for j in range(x_y[0]):
            xy[j] = list(map(lambda x: x+1, xy[j]))
    elif a == 2:
        for j in range(x_y[0],W):
            xy[j] = list(map(lambda x: x+1, xy[j]))
    elif a == 3:
        y = x_y[1]
        for j in range(W):
            for k in range(H):
                xy[j][k] += 1 if k < y else 0  
    else:
        y = x_y[1]
        for j in range(W):
            for k in range(H):
                xy[j][k] += 1 if k >= y else 0
area = 0
for i in xy:
    area += i.count(0)
print(area)

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

x=[0]*n
y=[0]*n
a=[0]*n
white=[0,h,w,0]
for i in range(n):
    line = list(map(int, input().split()))
    x[i] = line[0]
    y[i] = line[1]
    a[i] = line[2]

    if a[i] == 1:
        white[0] = max(white[0],x[i])
    elif a[i] == 2:
        white[2] = min(white[2], x[i])
    elif a[i] == 3:
        white[3] = max(white[3], y[i])
    elif a[i] == 4:
        white[1] = min(white[1], y[i])

newh = (white[1] - white[3])
neww = (white[2] - white[0])
print(newh * neww if newh >=0 and neww >=0 else 0)

Solution (Python):
w,h,n = map(int,input().split())
lo = [0,0]
hi = [w,h]
for i in range(n):
    a,b,x = map(int,input().split())
    if x == 1:
        if a >= lo[0]:
            lo[0] = a
    if x == 2:
        if a <= hi[0]:
            hi[0] = a

    if x == 3:
        if b >= lo[1]:
            lo[1] = b

    if x == 4:
        if b <= hi[1]:
            hi[1] = b
if hi[0] >= lo[0] and hi[1] >= lo[1]:
    print( (hi[0] - lo[0])*(hi[1] - lo[1]) )
else:
    print(0)

Solution (Python):
W, H, N = map(int, input().split())
lx, dy, rx, uy = 0, 0, W, H 
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if lx <= x:
            lx = x
    elif a == 2:
        if x <= rx:
            rx = x
    elif a == 3:
        if dy <= y:
            dy = y
    elif a == 4:
        if y <= uy:
            uy = y
if rx - lx <= 0 or uy - dy <= 0:
    print(0)
else:
    print((rx - lx) * (uy - dy))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

W, H, N = MAP()
xya = [LIST() for _ in range(N)]

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

for x, y, a in xya:
	if a == 1 and left < x < right:
		left = x
	elif a == 1 and right <= x:
		S = 0
		break
	elif a == 2 and left < x < right:
		right = x
	elif a == 2 and x <= left:
		S = 0
		break
	elif a == 3 and bottom < y < top:
		bottom = y
	elif a == 3 and top <= y:
		S = 0
		break
	elif a == 4 and bottom < y < top:
		top = y
	elif a == 4 and y <= bottom:
		S = 0
		break
	else:
		pass
	
	S = (right-left)*(top-bottom)
if S <= 0:
	S = 0
print(S)

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

x = 0
y = 0
a = 0
p1 = 0
p2 = W
p3 = 0
p4 = H
for i in range(N):
	x, y, a = map(int, input().split())

	if a==1:
		p1 = max(p1, x)
	elif a==2:
		p2 = min(p2, x)
	elif a==3:
		p3 = max(p3, y)
	elif a==4:
		p4 = min(p4, y)

if p1>=p2 or p3>=p4:
	print(0)
else:
	print((p2-p1)*(p4-p3))

Solution (Python):
def snuke_coloring2(W: int, H: int, N: int, queries: list) -> int:
    
    u, d, r, l = H, 0, W, 0

    for x, y, a in queries:
        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)

    return max(r - l, 0) * max(u - d, 0)


if __name__ == "__main__":
    N = 0
    W, H, N = map(int, input().split())
    queries = [tuple(int(s) for s in input().split()) for _ in range(N)]
    ans = snuke_coloring2(W, H, N, queries)
    print(ans)

Solution (Python):
w, h, n = map(int,input().split())
x1 = []
x2 = []
y3 = []
y4 = []
for i 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)

for t in [x1,y3]:
    if not t:
        t.append(0)
if not x2:
    x2.append(w)
if not y4:
    y4.append(h)

if max(x1) >= min(x2) or max(y3) >= min(y4):
    print(0)
    exit()
print((min(x2) - max(x1)) * (min(y4) - max(y3)))

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

x0, y0, x1, y1 = 0, 0, W, 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 < x1:
            x1 = x
    elif a == 3:
        if y0 < y:
            y0 = y
    else:
        if y < y1:
            y1 = y

if x1-x0<0 or y1-y0<0:
    print(0)
else:
    print((x1-x0)*(y1-y0))

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

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

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

Solution (Python):
from functools import reduce

def main():
    
    

    
    

    
    
    
    
    

    
    
    
    
    
    s = input().rstrip().split(' ')
    W = int(s[0])
    W_S = 0
    H = int(s[1])
    H_S = 0
    N = int(s[2])
    x = []
    y = []
    a = []
    for i in range(N):
        s = input().rstrip().split(' ')
        x.append(int(s[0]))
        y.append(int(s[1]))
        a.append(int(s[2]))

    for i in range(N):
        if(a[i]==1 and x[i]>W_S ):
            W_S = x[i]
        elif(a[i]==2 and x[i]<W ):
            W = x[i]
        elif(a[i]==3 and y[i]>H_S ):
            H_S = y[i]
        elif(a[i]==4 and y[i]<H ):
            H = y[i]        
    if W-W_S <0 or H-H_S < 0:
        ans = 0
    else:
        ans = (W-W_S) * (H-H_S)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
w,h,n=map(int,input().split())
x_a=0
x_b=w
y_a=0
y_b=h

for i in range(n):
  x,y,z=map(int,input().split())
  if(z==1):
    x_a=max(x_a,x)
  elif(z==2):
    x_b=min(x_b,x)
  elif(z==3):
    y_a=max(y_a,y)
  elif(z==4):
    y_b=min(y_b,y)

if(x_b-x_a>0 and y_b-y_a>0):
  print((x_b-x_a)*(y_b-y_a))
else:
  print(0)

Solution (Python):
p1=[0,0]
*p2,N=map(int,input().split())
for _ in range(N):
	x,y,a=map(int,input().split())
	if a==1 and p1[0] < x:
		p1[0]=x
	elif a==2 and p2[0] > x:
		p2[0]=x
	elif a==3 and p1[1] < y:
		p1[1]=y
	elif a==4 and p2[1] > y:
		p2[1]=y
else:
	print(max(0,p2[0]-p1[0])*max(0,p2[1]-p1[1]))

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

Solution (Python):
W, H, N = map(int, input().split())
L = 0
R = W
D = 0
U = H

for i 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)
print(max((R-L),0) * max((U-D),0))

Solution (Python):
W, H, N = map(int, input().split())
x1 = y1 = a1 = 0
xmin = 0
xmax = W
ymin = 0
ymax = H
for _ in range(N):
  x2, y2, a2 = map(int, input().split())
  if (a2 == 1):
    xmin = max(x2, xmin)
  if (a2 == 2):
    xmax = min(x2, xmax)
  if (a2 == 3):
    ymin = max(y2, ymin)
  if (a2 == 4):
    ymax = min(y2, ymax)
  if (xmax<= xmin or ymax <= ymin):
    print(0)
    exit()
print((xmax - xmin) * (ymax - ymin))

Solution (Python):
import numpy as np

w,h,n = map(int, input().split())
mp = np.zeros((w,h))
for i in range(n):
    xi, yi, ai = map(int, input().split())
    if ai == 1:
        mp[:xi, :] = 1
    elif ai == 2:
        mp[xi:, :] = 1
    elif ai == 3:
        mp[:, :yi] = 1
    elif ai == 4:
        mp[:, yi:] = 1
print(w*h - np.sum(mp))

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

ld = [0,0]
ru = [W,H]

flag = True
for x,y,a in xya:
    if a == 1:
        if ld[0] < x: ld[0] = x
    if a == 2:
        if ru[0] > x: ru[0] = x
    if a == 3:
        if ld[1] < y: ld[1] = y
    if a == 4:
        if ru[1] > y: ru[1] = y
    tate = ru[1] - ld[1]
    yoko = ru[0] - ld[0]
    if tate <= 0 or yoko <= 0:
        flag = False
        break

if flag:
    print(tate*yoko)
else:
    print(0)

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = LI()
    if sum(s) ==  2*max(s):
        print("Yes")
    else:
        print("No")
    return


def B():
    w,h,n = LI()
    l,r = 0,w
    d,u = 0,h
    for i in range(n):
        x,y,a = LI()
        if a == 1:
            l = max(x,l)
        elif a == 2:
            r = min(x,r)
        elif a == 3:
            d = max(y,d)
        else:
            u = min(y,u)
    print(max(r-l,0)*max(u-d,0))
    return


def C():
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    B()