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 resolve():
    
    
    
    w, h, n = list(map(int, input().split()))
    
    
    
    
    


    Area = [[True] * w] * h
    for _ in range(n):
        x, y, a = list(map(int, input().split()))
        if a == 1:
            for i in range(h):
                for j in range(x):
                    Area[i][j] = False
        if a == 2:
            for i in range(h):
                for j in range(w - x):
                    Area[i][j + x] = False
        if a == 3:
            for i in range(y):
                Area[i] = [False] * w
        if a == 4:
            for i in range(h - y):
                Area[i + y] = [False] * w

    cnt = 0
    for i in Area:
        cnt += i.count(True)
    print(cnt)
resolve()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


w,h,n=MI()
rect=[0,w,0,h]
for i in range(n):
    a,b,c=MI()
    if c==1:
        rect[0]=max(a,rect[0])
    elif c==2:
        rect[1]=min(a,rect[1])
    elif c==3:
        rect[2]=max(b,rect[2])
    else:
        rect[3]=min(b,rect[3])
print(max(0,rect[3]-rect[2])*max(0,rect[1]-rect[0]))

Solution (Python):
if __name__ == '__main__':

    w, h, n = map(int, input().split())
    x = y = 0
    xx = w
    yy = h
    for i in range(n):
        xi, yi, a = map(int, input().split())
        if a == 1:
            x = max(x, xi)
        elif a == 2:
            xx = min(xx, xi)
        elif a == 3:
            y = max(y, yi)
        elif a == 4:
            yy = min(yy, yi)
    print(0 if x >= xx or y >= yy else (xx - x) * (yy - y))

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)

print((b-a)*(d-c) if b-a>=0 and d-c>=0 else 0)

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

Solution (Python):
W,H,N=map(int,input().split())
x_right=W
x_left=0
y_ceil=H
y_floor=0
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        x_left=max(x,x_left)
    elif a==2:
        x_right=min(x,x_right)
    elif a==3:
        y_floor=max(y,y_floor)
    else:
        y_ceil=min(y,y_ceil)
ans=(x_right-x_left)*(y_ceil-y_floor)
if x_left>=x_right or y_ceil<=y_floor:
    ans=0
print(ans)

Solution (Python):
w,h,n=map(int,input().split())
lis=[]
for i in range(n):
  lis.append(list(map(int,input().split())))
count=0
for i in range(0,w):
  for j in range(0,h):
    keep=0
    for k in range(0,n):
      x=lis[k][0]
      y=lis[k][1]
      a=lis[k][2]
      if a==1:
        if i<x:
          keep=1
      elif a==2:
        if i>=x:
          keep=1
      elif a==3:
        if j<y:
          keep=1
      elif a==4:
        if j>=y:
          keep=1
    if keep==0:
      count+=1
print(count)

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

x=[0]*W
y=[0]*H


for _ in range(N):
    xi,yi,ai=map(int,input().split())

    if ai==1:
        for i in range(xi):
            x[i]=1
    elif ai==2:
        for i in range(xi,W):
            x[i]=1
    elif ai==3:
        for i in range(yi):
            y[i]=1
    elif ai==4:
        for i in range(yi,H):
            y[i]=1

print(y.count(0)*x.count(0))

Solution (Python):
w, h, n = map(int, input().split())
xyas = [list(map(int, input().split())) for _ in range(n)]
min_x = 0
max_x = w
min_y = 0
max_y = h
for xya in xyas:
    if xya[2] == 1:
        min_x = max(min_x, xya[0])
    elif xya[2] == 2:
        max_x = min(max_x, xya[0])
    elif xya[2] == 3:
        min_y = max(min_y, xya[1])
    else:
        max_y = min(max_y, xya[1])
if ((max_x - min_x) < 0) or ((max_y - min_y) < 0):
    print(0)
else:
    print((max_x - min_x) * (max_y - min_y))

Solution (Python):
W,H,N=map(int,input().split())
ll=[list(map(int,input().split()))for i in range(N)]
wmax=W
hmax=H
wmin=0
hmin=0
for i in range(N):
    if ll[i][2]==1 and ll[i][0]>=wmin:
        wmin=ll[i][0]
    elif ll[i][2]==2 and ll[i][0]<=wmax:
        wmax=ll[i][0]
    elif ll[i][2]==3 and ll[i][1]>=hmin:
        hmin=ll[i][1]
    elif ll[i][2]==4 and ll[i][1]<=hmax:
        hmax=ll[i][1]
ans = (wmax-wmin)*(hmax-hmin)
if wmax-wmin>0 and hmax-hmin>0:
    print((wmax-wmin)*(hmax-hmin))
else:
    print(0)

Solution (Python):
def resolve():
    W, H, N = list(map(int, input().split()))
    XYA = [list(map(int, input().split())) for i in range(N)]
    xmin, xmax, ymin, ymax = 0, W, 0, H
    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])
    print(max(max(0,(xmax-xmin))*max((ymax-ymin), 0), 0))

if '__main__' == __name__:
    resolve()

Solution (Python):
w,h,n=map(int,input().split())
xya = [map(int, input().split()) for _ in range(n)]
x, y ,a= [list(i) for i in zip(*xya)]
p=[]
q=[]
t=[]
s=[]
for i in range(n):
    if a[i]==1:
        p.append(x[i])
    elif a[i]==2:
        q.append(x[i])
    elif a[i]==3:
        t.append(y[i])
    else:
        s.append(y[i])

l=max(p) if p else 0
r=min(q) if q else w
d=max(t) if t else 0
u=min(s) if s else h

if l>r or d>u:
    print(0)
else:
    print((r-l)*(u-d))

Solution (Python):
w,h,n = map(int, input().split())
t=h
u=0
r=w
l=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:
        u=max(u,y)
    elif a==4:
        t=min(t,y)

if l>=r or u>=t:
    print(0)
else:
    print((r-l)*(t-u))

Solution (Python):
import numpy as np

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

c = np.zeros((W, H), int)

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

ans = W * H - np.sum(c)
print(ans)

Solution (Python):
W,H,N = map(int,input().split())
p = 0
q = W
l = 0
m = H

for i in range(N):
  x,y,a = map(int, input().split())
  if a == 1:
    p = max(p,x)
  if a == 2:
    q = min(q,x)
  if a == 3:
    l = max(l,y)
  if a == 4:
    m = min(m,y)
if (q-p)<0 or (m-l)<0:
  print(0)
  exit()
else:
  S = (q-p)*(m-l)
  print(S)

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

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

    s = max(0, xh - xl) * max(0, yh - yl)

    print(s)


if __name__ == '__main__':
    main()

Solution (Python):
W, H, N = map(int,input().split())
p = 0
q = W
r = 0
s = H
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        if x > p:
            p = x
    if a == 2:
        if x < q:
            q = x
    if a == 3:
        if y > r:
            r = y
    if a == 4:
        if y < s:
            s = y
ans = (q-p)*(s-r)
if q < p or s < r:
    ans = 0
print(ans)

Solution (Python):
w,h,n=map(int,input().split())
xmin, xmax, ymin, ymax = 0, w, 0, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > xmin:
            xmin = x
    elif a == 2:
        if x < xmax:
            xmax = x
    elif a == 3:
        if y > ymin:
            ymin = y
    else:
        if y < ymax:
            ymax = y

if xmax-xmin < 0 or ymax-ymin < 0:
    print(0)
    exit()
ans = (xmax-xmin) * (ymax-ymin)
print(ans)

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

left = 0
right = w
down = 0
up = h

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        down = max(down, y)
    elif a == 4:
        up = min(up, y)

if left >= right or down >= up:
    ans = 0
else:
    ans = (right - left) * (up - down)
print(ans)

Solution (Python):
w,h,n = map(int,input().split())
left = 0
right = w
under = 0
hight= h

for i in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        left = max(left,x)
    elif a==2:
        right = min(right,x)
    elif a==3:
        under = max(under,y)
    else:
        hight = min(hight,y)

if left>=right or under>=hight:
    print(0)
else:
    print((right-left)*(hight-under))

Solution (Python):
import numpy as np
def solve():
    def do(x,y,a):
        if a == 1:
            square[0:x:, :] *= 0
        if a == 2:
            square[x::, :] *= 0
        if a == 3:
            square[:, 0:y:] *= 0
        if a == 4:
            square[:, y::] *= 0

    W, H, N = map(int, input().split())
    
    square = np.array([[1 for _ in range(H)] for _2 in range(W)], dtype=np.int32)

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

    print(np.sum(square))




if __name__ == '__main__':
    solve()

Solution (Python):
w,h,n = map(int, input().split())
xya = [list(map(int,input().split())) for _ in range(n)]
X = [0,w]
Y = [0,h]
for x,y,a in xya:
    if a == 1 and X[0] < x: X[0] = x
    elif a == 2 and X[1] > x: X[1] = x
    elif a == 3 and Y[0] < y: Y[0] = y
    elif a == 4 and Y[1] > y: Y[1] = y
h, w = Y[1]-Y[0], X[1]-X[0]
print(0 if h<0 or w<0 else h*w)

Solution (Python):
W,H,N = map(int,input().split())
X1 = W
X2 = 0
Y1 = H
Y2 = 0
for _ in range(N):
    x,y,a = map(int,input().split())
    if a==1:
        X2 = max(X2,x)
    elif a==2:
        X1 = min(X1,x)
    elif a==3:
        Y2 = max(Y2,y)
    elif a==4:
        Y1 = min(Y1,y)
if X2>=X1 and Y2>=Y1:
    ans = 0
elif X2>=X1 and Y2<Y1:
    ans = 0
elif X2<X1 and Y2>=Y1:
    ans = 0
elif X2<X1 and Y2<Y1:
    ans = (X1-X2)*(Y1-Y2)
print(ans)

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

width=max(x_max-x_min,0)
height=max(y_max-y_min,0)
print(int(width*height))

Solution (Python):
W,H,N = map(int,input().split())
l = [0,0,W,0,H]
for i in range(N):
  x,y,a = map(int,input().split())
  if a%2 == 1:
    l[a] = max(l[a],[x,y][(a-1)//2])
  else:
    l[a] = min(l[a],[x,y][(a-2)//2])
ans = (l[2]-l[1])*(l[4]-l[3])    
if (l[2]-l[1]) <= 0 or (l[4]-l[3]) <= 0:
  print(0)
else:  
  print(ans)

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

print(int(W*H- R.sum()))

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

xy=[['.' for i in range(w)] for i in range(h)]

for x,y,a in l:
  x-=1
  y-=1

  if a==1:
    for i in range(h):
      for j in range(w):
        if j<=x:
          xy[i][j]='
  if a==2:
    for i in range(h):
      for j in range(w):
        if x<j:
          xy[i][j]='
  if a==3:
    for i in range(h):
      for j in range(w):
        if i<=y:
          xy[i][j]='
  if a==4:
    for i in range(h):
      for j in range(w):
        if y<i:
          xy[i][j]='

cnt=0
for i in xy:
  cnt+=i.count('.')
print(cnt)

Solution (Python):
W,H,N=map(int,input().split())
x_l=0
x_r=W
y_h=H
y_l=0

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        x_l=max(x_l,x)
    elif a==2:
        x_r=min(x_r,x)
    elif a==3:
        y_l=max(y_l,y)
    else:
        y_h=min(y_h,y)



print(max(x_r-x_l,0)*max(y_h-y_l,0))

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

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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))

def resolve():
    W,H,N=pin()
    ans=[0,W,0,H]
    for n in range(N):
        x,y,a=pin()
        if a==1:
            ans[0]=max(ans[0],x)
        elif a==2:
            ans[1]=min(ans[1],x)
        elif a==3:
            ans[2]=max(ans[2],y)
        else:
            ans[3]=min(ans[3],y)
    t=((ans[1]-ans[0])*(ans[3]-ans[2]))
    if ans[1]-ans[0]<0 or ans[3]-ans[2]<0:t=0
    print(t)    

resolve()

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


if __name__ == '__main__':
    main()

Solution (Python):
w, h, n = map(int, input().split())
xya = []
for _ in range(n):
    x, y, a = map(int, input().split())
    xya.append((x, y, a))
l = 0
r = w
t = h
b = 0
for x, y, a in xya:
    if a==1:
        l = max(l, x)
    elif a==2:
        r = min(r, x)
    elif a==3:
        b = max(b, y)
    else:
        t = min(t, y)

print((r-l)*(t-b) if l<=r and b<=t else 0)

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    W, H, N = (int(i) for i in input().split())
    XYA = [[int(i) for i in input().split()] for j in range(N)]
    seen = [[True]*W for _ in range(H)]
    for x, y, a in XYA:
        if a == 1:
            for h in range(H):
                for w in range(x):
                    seen[h][w] = False
        elif a == 2:
            for h in range(H):
                for w in range(x, W):
                    seen[h][w] = False
        elif a == 3:
            for h in range(y):
                for w in range(W):
                    seen[h][w] = False
        elif a == 4:
            for h in range(y, H):
                for w in range(W):
                    seen[h][w] = False
    ans = 0
    for h in range(H):
        for w in range(W):
            if seen[h][w]:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

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

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

G = [[1] * H for _ in range(W)]

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

    if a == 1:
        for x_ in range(x):
            for y_ in range(H):
                G[x_][y_] = 0

    if a == 2:
        for x_ in range(x, W):
            for y_ in range(H):
                G[x_][y_] = 0
    
    if a == 3:
        for x_ in range(W):
            for y_ in range(y):
                G[x_][y_] = 0
    
    if a == 4:
        for x_ in range(W):
            for y_ in range(y, H):
                G[x_][y_] = 0

ans = 0
for g in G:
    
    ans += sum(g)

print (ans)

Solution (Python):
def examA():
    C = [SI()for _ in range(3)]
    ans = C[0][0]+C[1][1]+C[2][2]
    print(ans)
    return

def examB():
    N, M = LI()
    P = [0]*N
    S = [LSI()for _ in range(M)]
    pena = 0
    ac = set()
    for p,s in S:
        p = int(p)-1
        if s=="WA":
            P[p] += 1
        else:
            if p in ac:
                continue
            ac.add(p)
            pena += P[p]

    print(len(ac),pena)
    return

def examC():
    W, H, N = LI()
    lx, rx, ly, ry = 0, W, 0, H
    A = [LI()for _ in range(N)]
    for x,y,a in A:
        if a==1:
            lx = max(lx,x)
        elif a==2:
            rx = min(rx,x)
        elif a==3:
            ly = max(ly,y)
        elif a==4:
            ry = min(ry,y)
    ans = max(0,rx-lx)*max(0,ry-ly)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  






W, H, N = read_ints()
A = [0, W, 0, H]
for _ in range(N):
    x, y, a = read_ints()
    a -= 1
    if a == 0:
        A[a] = max(x, A[a])
    if a == 1:
        A[a] = min(x, A[a])
    if a == 2:
        A[a] = max(y, A[a])
    if a == 3:
        A[a] = min(y, A[a])

if A[1] - A[0] > 0 and A[3] - A[2] > 0:
    print((A[1] - A[0]) * (A[3] - A[2]))
else:
    print(0)

Solution (Python):
w,h,n = map(int,input().split())
xya = [list(map(int,input().split())) for i in range(n)]
x = [0,w]
y = [0,h]
for i in xya:
  if i[2] == 1:
    if x[0] < i[0]:
      x[0] = i[0]
  if i[2] == 2:
    if x[1] > i[0]:
      x[1] = i[0]
  if i[2] == 3:
    if y[0] < i[1]:
      y[0] = i[1]
  if i[2] == 4:
    if y[1] > i[1]:
      y[1] = i[1]
if x[0] < x[1] and y[0] < y[1]:
  print((x[1]-x[0])*(y[1]-y[0]))
else:
  print(0)

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

print((r-l)*(b-t))

Solution (Python):
import numpy as np

W, H, N = map(int, input().split())
Map = np.zeros([W, H], dtype=int)

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

print(H*W - Map.sum())

Solution (Python):
W,H,N=map(int,input().split())
minx=0
maxx=W
miny=0
maxy=H
for i in range(1,N+1):
    x,y,a=map(int,input().split())
    if a==1:
        minx=max(minx,x)
    elif a==2:
        maxx=min(maxx,x)
    elif a==3:
        miny=max(miny,y)
    elif a==4:
        maxy=min(maxy,y)
ans=(maxx-minx)*(maxy-miny)
if maxx>=minx and maxy>=miny:
    print(ans)
elif maxx<=minx and maxy>=miny:
    print("0")
elif maxx>=minx and maxy<=miny:
    print("0")
elif maxx<=minx and maxy<=miny:
    print("0")

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

Solution (Python):
import sys

readline = sys.stdin.readline
W, H, N = map(int, readline().split())
XYA = [tuple(map(int, readline().split())) for _ in range(N)]


def f(i, j, xya):
    x, y, a = xya
    if ((a == 1 and i > x) or
        (a == 2 and i <= x) or 
        (a == 3 and j > y) or
        (a == 4 and j <= y)):
        return True
    else:
        return False

ans = 0
for i in range(1, W+1):
    for j in range(1, H+1):
        if all(f(i, j, xya) for xya in XYA):
            ans += 1
print(ans)

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

w1=0
w2=0
h1=0
h2=0
for i in range(n):
    if a[i]==1:
        w1=max(w1,x[i])
    if a[i]==2:
        w2=max(w2,w-x[i])
    if a[i]==3:
        h1=max(h1,y[i])
    if a[i]==4:
        h2=max(h2,h-y[i])


if (w-w1-w2)<0 and (h-h1-h2)<0:
    print(0)
else:
    print(max(0,(w-w1-w2)*(h-h1-h2)))

Solution (Python):
W,H,N = map(int,input().split())
X = [0]*N
Y = [0]*N
A = [0]*N
X_max= W
X_min= 0
Y_max= H
Y_min= 0
for i in range(N):
	X[i],Y[i],A[i] = map(int,input().split())
for i in range(N):
	if A[i]==1:
		X_min=max(X_min,X[i])
	elif A[i]==2:X_max=min(X_max,X[i])
	elif A[i]==3:Y_min=max(Y_min,Y[i])
	else:Y_max=min(Y_max,Y[i])

if X_max-X_min>0 and Y_max-Y_min>0:
	print((X_max-X_min)*(Y_max-Y_min))
else: print(0)

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

if X0 >= X or Y0 >= Y:
    print (0)
else:
    print ((X-X0)*(Y-Y0))

Solution (Python):
w,h,N=map(int,input().split())
n=h
e=0
w=w
s=0
for _ in range(N):
    x,y,a=map(int,input().split())
    if a==1: e=max(e,x)
    elif a==2: w=min(w,x)
    elif a==3: s=max(s,y)
    else: n=min(n,y)
print(0 if (e>=w or s>=n) else (n-s)*(w-e))

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

x_list = []
for i in range(w+1):
    x_list += [i]
    
y_list = []
for i in range(h+1):
    y_list += [i]  

for i in range(q):
    a, b, c = map(int, input().split())
    if (c == 1):
        x_list = [x for x in x_list if x >= a]
    elif (c == 2):
        x_list = [x for x in x_list if x <= a]
    elif (c == 3):
        y_list = [y for y in y_list if y >= b]
    elif (c == 4):
        y_list = [y for y in y_list if y <= b]

output = 0
if (x_list != [] and y_list != []):
    output = (max(x_list)-min(x_list)) * (max(y_list)-min(y_list))
    
print(output)

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

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

x = (0, W)
y = (0, H)
for xya in XYA:
    a = xya[2]
    if a == 1:
        if x[0] < xya[0]:
            x = (xya[0], x[1])
    elif a == 2:
        if xya[0] < x[1]:
            x = (x[0], xya[0])
    elif a == 3:
        if y[0] < xya[1]:
            y = (xya[1], y[1])
    else:
        if xya[1] < y[1]:
            y = (y[0], xya[1])

res = (x[1] - x[0]) * (y[1] - y[0])
if x[1] - x[0] < 0 or y[1] - y[0] < 0:
    res = 0

print(res)

Solution (Python):
left = 0 
down = 0
right , up , n =map(int,input().split())
for _ in range(n):
	x,y,a = map(int,input().split())
	if a==1:
		if x>left:
			left = x
	elif a==2:
		if right>x:
			right = x
	elif a==3:
		if y>down:
			down = y
	elif a==4:
		if up>y:
			up = y
if abs(right)>=abs(left) and abs(up)>=abs(down):
	h = abs(up)-abs(down)
	w = abs(right)-abs(left)
	print(h*w)
else:
	print(0)

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:
        x0 = max(x0, x) 
    elif a == 2:
        x1 = min(x1, x)
    elif a == 3:
        y0 = max(y0, y)
    elif a == 4:
        y1 = min(y1, y)

print((x1 - x0) * (y1 - y0) if x1-x0 > 0 and y1 - y0 > 0 else 0)

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

x1,x2,y1,y2 = 0,w,0,h
for _ in range(n):
    x,y,a = map(int, input().split())
    if a==1:
        x1 = max(x1,x)
    elif a==2:
        x2 = min(x2,x)
    elif a==3:
        y1 = max(y1,y)
    else:
        y2 = min(y2,y)

if x1>=x2:
    print(0)
    exit()
if y1>=y2:
    print(0)
    exit()

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

Solution (Python):
w, h, n = map(int,input().split())
a_1 = 0
a_2 = w
a_3 = 0
a_4 = h
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        a_1 = max(a_1,x)
    elif a == 2:
        a_2 = min(a_2,x)
    elif a == 3:
        a_3 = max(a_3,y)
    else:
        a_4 = min(a_4,y)

if a_1 > a_2:
    print(0)
elif a_3 > a_4:
    print(0)
else:
    print((a_2-a_1)*(a_4-a_3))

Solution (Python):
W, H, N = map(int, input().split())
max1=0
min2=W
max3=0
min4=H
for i in range(N):
    x, y, a = map(int, input().split())
    if (a==1 and max1<x):
        max1=x
    elif(a==2 and min2>x):
        min2=x
    elif(a==3 and max3<y):
        max3=y
    elif(a==4 and min4>y):
        min4=y

if (max1>=min2 or max3>=min4):
    print(0)
else:
    print((min2-max1)*(min4-max3))

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

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

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

x, y, a = [0] * n, [0] * n, [0] * n

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

start, end  = [0, 0], [w, h]

for i in range(n):
    if a[i] == 1 and x[i] > start[0]:
        start[0] = x[i]
    elif a[i] == 2 and x[i] < end[0]:
        end[0] = x[i]
    elif a[i] == 3 and start[1] < y[i]:
        start[1] = y[i]
    elif a[i] == 4 and end[1] > y[i]:
        end[1] = y[i]
    
if (end[0] - start[0]) <= 0 or (end[1] - start[1]) <= 0:
    print(0)
else:
    print( (end[0] - start[0]) * (end[1] - start[1]))

Solution (Python):

w, h, n = map(int, input().split())
x, y, a = [0] * n, [0] * n, [0] * n

for i in range(n):
    x[i], y[i], a[i] = map(int, input().split())
fill_area = [[0] * w for _ in range(h)]

def fill(l, r, d, u, area):
    for i in range(d, u):
        for j in range(l, r):
            if area[i][j] == 0:
                area[i][j] = 1
        
    

for i in range(n):
    if a[i] == 1:
        fill(0, x[i], 0,  h, fill_area)
    elif a[i] == 2:
        fill(x[i], w, 0, h, fill_area)
    elif a[i] == 3:
        fill(0, w, h - y[i], h, fill_area)
    else:
        fill(0, w, 0, h - y[i], fill_area)
    """
    for j in range(h):
        print(fill_area[j])
    print()
    """

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

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

def draw(x0, x1, y0, y1):
    for y in range(y0, y1 + 1):
        for x in range(x0, x1 + 1):
            field[y][x] = "

for i in range(n):
    X, Y, a = map(int, input().split())
    if a == 1:
        draw(0, X - 1, 0, h - 1)
    elif a == 2:
        draw(X, w - 1, 0, h - 1)
    elif a == 3:
        draw(0, w - 1, 0, Y - 1)
    elif a == 4:
        draw(0, w - 1, Y, h - 1)

c = 0
for y in range(h):
    for x in range(w):
        if field[y][x] == "":
            c += 1

print(c)