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):
def square() : 
  
  W , H, N = tuple(map(int, input().split()))
  
  leftrange = 0
  lowrange = 0
  rightrange = W
  upperrange = H
  
  for i in range(N) : 
    x, y, a = tuple(map(int, input().split()))
    if a == 1 :
      if x > leftrange : 
        leftrange = x
    if a == 2 : 
      if x < rightrange : 
        rightrange = x
    if a == 3 :
      if y > lowrange : 
        lowrange = y
    if a == 4 : 
      if y < upperrange : 
        upperrange = y
        
  return leftrange, rightrange, lowrange, upperrange

def answer(x1, x2, y1, y2) : 
  if (x1 >= x2 or y1 >= y2) : 
    return 0
  return (x2 - x1) * (y2 - y1)

def main() : 
  leftrange, rightrange, lowrange, upperrange = square()
  print(answer(leftrange, rightrange, lowrange, upperrange))
  
  
main()

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

rx, uy = W, H
lx, dy = 0, 0
for v in P:
    x, y, a = v
    if a == 1:
        lx = max(lx, x)
    elif a == 2:
        rx = min(rx, x)
    elif a == 3:
        dy = max(dy, y)
    elif a == 4:
        uy = min(uy, y)
print(max(rx - lx, 0) * max(uy - dy, 0))

Solution (Python):
X, Y, N = map(int, input().split())
canvas = [[1 for _ in range(X)]for _ in range(Y)]

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        for j in range(Y):
            for k in range(x):
                canvas[j][k] = 0
    if a == 2:
        for j in range(Y):
            for k in range(x,X):
                canvas[j][k] = 0
    if a == 3:
        for j in range(X):
            for k in range(y):
                canvas[k][j] = 0
    if a == 4:
        for j in range(X):
            for k in range(y,Y):
                canvas[k][j] = 0
print(sum([sum(i) for i in canvas]))

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

if end[0] - start[0] > 0 and end[1] - start[1] > 0:
    print((end[0] - start[0])*(end[1] - start[1]))
else:
    print(0)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


w, h, n = LI()
ws = list(range(w + 1))
hs = list(range(h + 1))
for _ in range(n):
    x, y, a = LI()
    if a == 1:
        ws = [i for i in ws if x <= i]
    elif a == 2:
        ws = [i for i in ws if i <= x]
    elif a == 3:
        hs = [i for i in hs if y <= i]
    else:
        hs = [i for i in hs if i <= y]
if len(ws) == 0 or len(hs) == 0:
    ans = 0
else:
    ans = (ws[-1] - ws[0]) * (hs[-1] - hs[0])
print(ans)

Solution (Python):
W, H, N = map(int, input().split())
a1, a2, a3, a4 = [], [], [], []
dispatch = {1: a1, 2: a2, 3: a3, 4: a4}
for _ in range(N):
    x, y, a = map(int, input().split())
    dispatch[a].append((x, y))

a1x = max(a1, key=lambda x: x[0])[0] if a1 else 0
a2x = min(a2, key=lambda x: x[0])[0] if a2 else W
a3y = max(a3, key=lambda x: x[1])[1] if a3 else 0
a4y = min(a4, key=lambda x: x[1])[1] if a4 else H

if a2x - a1x > 0 and a4y - a3y > 0:
    print((a2x - a1x) * (a4y - a3y))
else:
    print(0)

Solution (Python):
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(x,x1)
    elif a == 2:
        x2 = min(x,x2)
    elif a == 3:
        y1 = max(y,y1)
    else:
        y2 = min(y,y2)
if x2-x1 <= 0 or y2-y1 <= 0:
    print(0)
else:
    print((x2-x1)*(y2-y1))

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)
    if a==2:
        right=min(right,x)
    if a==3:
        down=max(down,y)
    if a==4:
        up=min(up,y)

   
if right>left and up>down:
    print((right-left)*(up-down))
else:
    print(0)

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)
  elif a == 4:
    u = min(u,y)
  
S = max(0, u-d) * max(0,r-l)
print(int(S))

Solution (Python):
W, H, N = map(int, input().split())
a1, a2, a3, a4 = 0, W, 0, H
for i 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)
    else:
        a4 = min(a4, y)
if a1>=a2 or a3>=a4:
    print(0)
else:
    print((a2-a1)*(a4-a3))

Solution (Python):
import numpy as np

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


BW = np.zeros([H,W])

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        BW[:, :x] = 1
    elif a == 2:
        BW[:, x:] = 1
    elif a == 3:
        BW[H-y:, :] = 1
    elif a == 4:
        BW[:H-y, :] = 1
print(np.count_nonzero(BW-1))

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

Solution (Python):
import numpy as np

n,m,l = map(int,input().split())
X = [1]*n
Y = [1]*m

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

c_x = 0
c_y = 0
for x in X:
    if x == 1:
        c_x += 1

for y in Y:
    if y == 1:
        c_y += 1

print(c_x*c_y)

Solution (Python):
import sys
def v():
    W,H,N=tuple(map(int,sys.stdin.readline().split()))
    lx,ux,ly,uy=0,W,0,H
    for _ in [0]*N:
        x,y,a=tuple(map(int,sys.stdin.readline().split()))
        if a==1 and lx<x:lx=x
        elif a==2 and ux>x:ux=x
        elif a==3 and ly<y:ly=y
        elif a==4 and uy>y:uy=y
    if lx<ux and ly<uy:print((ux-lx)*(uy-ly))
    else:print(0)
if __name__=='__main__':v()

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

l = [0, W, 0, H]

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

if l[0] < l[1] and l[2] < l[3]:
  print((l[1]-l[0])*(l[3]-l[2]))
else:
  print(0)

Solution (Python):
import sys

W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
ans = 0
x_s, y_s, x_e, y_e = 0, 0, W, H

for x, y, a in xya:
    if a == 1:
        if (x_s < x) and (x_e > x):
            x_s = x
        elif x_e <= x:
            print(0)
            sys.exit()
        elif x_s >= x:
            pass
    elif a == 2:
        if (x_s < x) and (x_e > x):
            x_e = x
        elif x_e <= x:
            pass
        elif x_s >= x:
            print(0)
            sys.exit()
    elif a == 3:
        if (y_s < y) and (y_e > y):
            y_s = y
        elif y_e <= y:
            print(0)
            sys.exit()
        elif y_s >= y:
            pass
    elif a == 4:
        if (y_s < y) and (y_e > y):
            y_e = y
        elif y_e <= y:
            pass
        elif y_s >= y:
            print(0)
            sys.exit()
print((x_e - x_s) * (y_e - y_s))

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

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

for i in range(n):
  x,y,b=map(int,input().split())
  dumy = [x,-x,y,-y]
  a=b-1
  if sq[a]<dumy[a]:
    sq[a]=dumy[a]


if -sq[1]-sq[0]<0:
  s=0
elif -sq[3]-sq[2]<0:
  s=0
else:
  s=(-sq[1]-sq[0])*(-sq[3]-sq[2])

print(s)

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *

from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]








w,h,n=l()
r=[i for i in range(w+1)]
c=[i for i in range(h+1)]
for i in range(n):
    
    a,b,x=l()
    if(x==1):
        r=r[br(r,a-1):]
    elif(x==2):
        r=r[:bl(r,a+1)]
    elif(x==3):
        c=c[br(c,b-1):]
    else:
        c=c[:bl(c,b+1)]

if(len(r)==0 or len(c)==0):
    print(0)
    exit()
print((max(r)-min(r))*(max(c)-min(c)))

Solution (Python):
w,h,n = map(int, input().split())
x_left = 0
x_right = w
y_up = h
y_down = 0
for _ in range(n):
  x,y,a = map(int, input().split())
  if a==1 and x_left <= x:
    x_left = x
  elif a==2 and x_right >= x:
    x_right = x
  elif a==3 and y_down <= y:
    y_down = y
  elif a==4 and y_up >= y:
    y_up = y

if x_right <= x_left or y_up <= y_down:
  print(0)
else:
  print((x_right - x_left)*(y_up - y_down))

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

if W[1]-W[0] < 0 or (H[1]-H[0]) < 0:
    print(0)
else:
    print((W[1]-W[0]) * (H[1]-H[0]))

Solution (Python):
import itertools

w, h, n = map(int,input().split())
now = [[1]*w]*h
li = [list(map(int,input().split())) for i in range(n)]

for x in li:
    if x[2]==1: 
        for i in range(h):
            for j in range(x[0]):
                now[i][j] = 0
    if x[2]==2: 
        for i in range(h):
            for j in range(w-x[0]):
                now[i][x[0]+j] = 0
    if x[2]==3: 
        for i in range(x[1]):
            now[i] = [0]*w
    if x[2]==4: 
        for i in range(x[1],h):
            now[i] = [0]*w

print(sum(list(itertools.chain.from_iterable(now))))

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

l, r, b, u = 0, w, 0, h
for x, y, a in xya:
    if a == 1:
        l = max(x, l)
    elif a == 2:
        r = min(x, r)
    elif a == 3:
        b = max(y, b)
    elif a == 4:
        u = min(y, u)
print(max(0,r - l) * max(0,u - b))

Solution (Python):
w,h,n=map(int,input().split())
ans=[0]*(w*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):
                ans[j*w+k]=1
    if a==2:
        for j in range(h):
            for k in range(x,w):
                ans[j*w+k]=1
    if a==3:
        for j in range(y):
            for k in range(w):
                ans[j*w+k]=1
    if a==4:
        for j in range(y,h):
            for k in range(w):
                ans[j*w+k]=1
print(ans.count(0))

Solution (Python):
W,H,N = list(map(int,input().split()))
XYA = [list(map(int,input().split())) for _ in range(N)]
XMAX = W
XMIN = 0
YMAX = H
YMIN = 0
for xya in XYA:
    if xya[2] == 1:
        XMIN = max(XMIN,xya[0])
    elif xya[2] == 2:
        XMAX = min(XMAX,xya[0])
    elif xya[2] == 3:
        YMIN = max(YMIN,xya[1])
    elif xya[2] == 4:
        YMAX = min(YMAX,xya[1])
if XMIN >= XMAX or YMIN >= YMAX:
    print(0)
else:
    print((XMAX-XMIN)*(YMAX-YMIN))

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

Solution (Python):
w1, h1, 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:
        w1 = min(w1, x)
    elif a == 3:
        h0 = max(h0, y)
    else:
        h1 = min(h1, y)
print(max(0, (w1 - w0)) * max(0, (h1 - h0)))

Solution (Python):
W, H, N = map(int, input().split())
sx, sy, gx, gy = 0, 0, W, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = max(sx, x)
    elif a == 2:
        gx = min(gx, x)
    elif a == 3:
        sy = max(sy, y)
    else:
        gy = min(gy, y)

dx, dy = gx-sx, gy-sy
if dx <= 0 or dy <= 0:
    print(0)
else:
    print(dx*dy)

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

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

sikaku_x = [0, W]
sikaku_y = [0, H]

for v in lst:
    x, y, a = v[0], v[1], v[2]
    if a == 1:
        if x > sikaku_x[0]:
            sikaku_x[0] = x
    elif a == 2:
        if x < sikaku_x[1]:
            sikaku_x[1] = x
    elif a == 3:
        if y > sikaku_y[0]:
            sikaku_y[0] = y
    else:
        if y < sikaku_y[1]:
            sikaku_y[1] = y
    if sikaku_x[0] >= sikaku_x[1] or sikaku_y[0] >= sikaku_y[1]:
        print(0)
        exit()

print((sikaku_x[1] - sikaku_x[0]) * (sikaku_y[1] - sikaku_y[0]))

Solution (Python):
w, h, n = map(int, input().split())
 
x0, y0 = (0, 0)
x1, y1 = (w, h)
 
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x0 < x:
            x0 = x
        if x1 < x:
            x1 = x
    if a == 2:
        if x0 > x:
            x0 = x
        if x1 > x:
            x1 = x
    if a == 3:
        if y0 < y:
            y0 = y
        if y1 < y:
            y1 = y
    if a == 4:
        if y0 > y:
            y0 = y
        if y1 > y:
            y1 = y
 
ans = (x1 - x0) * (y1 - y0)
print(ans)

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

x0, y0 = (0, 0)
x1, y1 = (w, h)

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x0 < x:
            x0 = x
        if x1 < x:
            x1 = x
    if a == 2:
        if x0 > x:
            x0 = x
        if x1 > x:
            x1 = x
    if a == 3:
        if y0 < y:
            y0 = y
        if y1 < y:
            y1 = y
    if a == 4:
        if y0 > y:
            y0 = y
        if y1 > y:
            y1 = y

ans = (x1 - x0) * (y1 - y0)
print(ans)

Solution (Python):
import numpy as np
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

w, h, n = imap()
x = [0]*n; y = [0]*n; a = [0]*n
for i in range(n):
    x[i], y[i], a[i] = imap()

xr = yu = 0
xl = w; yd = h
for i in range(n):
    if a[i]==1: xr = max(xr, x[i])
    if a[i]==2: xl = min(xl, x[i])
    if a[i]==3: yu = max(yu, y[i])
    if a[i]==4: yd = min(yd, y[i])
sx = min(w, xr+w-xl)
sy = min(h, yu+h-yd)
print(h*w-(sx*h+sy*w-sx*sy))

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)
  if a == 2:
    maxx = min(maxx,x)
  if a == 3:
    miny = max(miny,y)
  if 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())
u, d, r, l = H, 0, W, 0
for _ 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)
print(max(r-l, 0)*max(u-d, 0))

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

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

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

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

Solution (Python):
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)
    else:
        yr = min(yr, y)
print(max(0, xr-xl)*max(0, yr-yl))

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

Solution (Python):
w, h, n = map(int, input().split())
minx = miny = 0
maxx = w
maxy = h
for _ in range(n):
    x1, y1, a = map(int, input().split())
    if a == 1:
        minx = max(minx, x1)
    if a == 2:
        maxx = min(maxx, x1)
    if a == 3:
        miny = max(miny, y1)
    if a == 4:
        maxy = min(maxy, y1)

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

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

white_x = sikaku_x[1] - sikaku_x[0]
if white_x < 0:
    white_x = 0
white_y = sikaku_y[1] - sikaku_y[0]
if white_y < 0:
    white_y = 0
print(white_x*white_y)

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

width = [0, w]
height = [0, h]

for x, y, a in xya:
    if a == 1:
        width = [max(width[0], x), width[1]]
    elif a == 2:
        width = [width[0], min(width[1], x)]
    elif a == 3:
        height = [max(height[0], y), height[1]]
    elif a == 4:
        height = [height[0], min(height[1], y)]

ans = max(0, width[1] - width[0]) * max(0, height[1] - height[0])
print(ans)

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

for x, y, a in values:
    x_range = (0, W)
    y_range = (0, H)
    if a == 1:
        x_range = (0, x)
    elif a == 2:
        x_range = (x, W)
    elif a == 3:
        y_range = (0, y)
    elif a == 4:
        y_range = (y, H)

    for i in range(*y_range):
        for j in range(*x_range):
            canvas[i][j] = 1

sum_filled = sum([sum(row) for row in canvas])
print(W * H - sum_filled)

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 accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7



W, H, N = MAP()

left = 0
right = W
bottom = 0
top = H
 
for _ in range(N):
	x, y, a = MAP()
	if a == 1:
		left = max(x, left)
	elif a == 2:
		right = min(x, right)
	elif a == 3:
		bottom = max(y, bottom)
	elif a == 4:
		top = min(y, top
			)
if right - left < 0 or top - bottom < 0:
	print(0)
else:
	print((right-left)*(top-bottom))

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 accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7



W, H, N = MAP()
 
dict = defaultdict(int)
dict[1] = 0
dict[2] = W
dict[3] = 0
dict[4] = H
 
for _ in range(N):
	x, y, a = MAP()
	if a == 1:
		dict[1] = max(x, dict[1])
	elif a == 2:
		dict[2] = min(x, dict[2])
	elif a == 3:
		dict[3] = max(y, dict[3])
	elif a == 4:
		dict[4] = min(y, dict[4])
 
if dict[2]-dict[1] < 0 or dict[4]-dict[3] < 0:
	print(0)
else:
	print(max(0, (dict[2]-dict[1])*(dict[4]-dict[3])))

Solution (Python):
import math
import fractions



def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''














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

data = Zeros(h,w)

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

print(w*h-sum([sum(data[j]) for j in range(h)]))

Solution (Python):
w,h,N=map(int,input().split())
X,Y,W,H=0,0,w,h
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(y,H)
    if X>=w or Y>=h or W<=0 or H<=0 or X>=W or Y>=H:
        print(0)
        exit()
print((W-X)*(H-Y))

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

Solution (Python):
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") 

w,h,n = map(int,input().split())
field = [[True for i in range(w)] for j in range(h)]

def paint(start,end,rotate=False):
    if rotate:
        for i in range(start,end):
            field[i] = [False for i in range(w)]

    else:
        for line in field[:]:
            for i in range(start,end):
                line[i] = False
for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:  
        paint(0,x)
    elif a == 2:
        paint(x,w)
    elif a == 3:
        paint(0,y,rotate=True)
    else:       
        paint(y,h,rotate=True)

count = 0
for li in field[:]:
    count += li.count(True)
print(count)

Solution (Python):
W, H, N = map(int, input().split())
zahyo = [list(map(int, input().split())) for _ in range(N)]
grid = [["w" for __ in range(W)] for ___ in range(H)]


def paint(h=range(H), w=range(W)):
    for i in h:
        for j in w:
            grid[i][j] = "b"


for xya in zahyo:
    if xya[2] == 1:
        paint(w=range(xya[0]))
    elif xya[2] == 2:
        paint(w=range(xya[0], W))
    elif xya[2] == 3:
        paint(h=range(xya[1]))
    elif xya[2] == 4:
        paint(h=range(xya[1], H))
print(sum(grid, []).count("w"))

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

left = 0
right = w
upper = h
lower = 0

for i in range(n):
	x, y, a = [int(k) for k in input().split()]
	if a == 1 and left < x:
		left = x
	elif a == 2 and right > x:
		right = x
	elif a == 3 and lower < y:
		lower = y
	elif a == 4 and upper > y:
		upper = y

S = (right-left)*(upper-lower)
if right-left < 0 or upper-lower < 0:
	print(0)
else:
	print(S)