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):
import sys

W, H, N = map(int, sys.stdin.readline().strip().split())
opes = []
for _ in range(N):
    x, y, a = map(int, sys.stdin.readline().strip().split())
    opes.append((x, y, a))

x_min = 0
x_max = W
y_min = 0
y_max = H
for (x, y, a) in opes:
    if a == 1:
        x_min = max(x_min, x)
    elif a == 2:
        x_max = min(x_max, x)
    if a == 3:
        y_min = max(y_min, y)
    if a == 4:
        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())
xya = [[int(i) for i in input().split()] for i in range(N)]
Lower_left = [0, 0]
Top_right = [W, H]
ans = 0
for x, y, a in xya:
    if a == 1:
        if x > Lower_left[0]:
            Lower_left[0] = x
    elif a == 2:
        if x < Top_right[0]:
            Top_right[0] = x
    elif a == 3:
        if y > Lower_left[1]:
            Lower_left[1] = y
    elif a == 4:
        if y < Top_right[1]:
            Top_right[1] = y

    if Top_right[0] > Lower_left [0] and Top_right[1] > Lower_left[1]:
        ans = (Top_right[0] - Lower_left[0]) * (Top_right[1] - Lower_left[1])
    else:
        ans = 0

print(ans)

Solution (Python):
W, H, N = map(int, input().split())
XY = [1 for i in range(W * H)]
for n in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    for i in range(W * H):
      if i % W < x :
      	XY[i] = 0 
  if a == 2:
    for i in range(W * H):
      if i % W >= x:
      	XY[i] = 0
  if a == 3:
    for i in range(y * W):
      XY[i] = 0 
  if a == 4:
    for i in range(y * W, W * H):
      XY[i] = 0 
print(sum(XY))

Solution (Python):
W, H, N = map(int,input().split())
xya = [list(map(int,input().split())) for _ in range(N)]
ls = list(range(1,W*H+1))
for n in range(N):
  if xya[n][2] == 1:
    ls = [K for K in ls if (K-1)%W >= xya[n][0]]
  if xya[n][2] == 2:
    ls = [K for K in ls if (K-1)%W < xya[n][0]]
  if xya[n][2] == 3:
    ls = [K for K in ls if (K-1)/W >= xya[n][1]]
  if xya[n][2] == 4:
    ls = [K for K in ls if (K-1)/W <= xya[n][1]]
print(len(ls))

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

    corners = [0, 0, w, h]

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

        if a == 1:
            if x > corners[0]:
                corners[0] = x
        elif a == 2:
            if x < corners[2]:
                corners[2] = x
        elif a == 3:
            if y > corners[1]:
                corners[1] = y
        else:
            if y < corners[3]:
                corners[3] = y
    
    width = corners[2] - corners[0]
    height = corners[3] - corners[1]

    if width < 0 or height < 0:
        print(0)
    else:
        print(width * height)

if __name__ == '__main__':
    main()

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

p1 = (0, 0)
p2 = (w, h)

for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        if p1[0] < x:
            p1 = (x, p1[1])
    elif a == 2:
        if p2[0] > x:
            p2 = (x, p2[1])
    elif a == 3:
        if p1[1] < y:
            p1 = (p1[0], y)
    elif a == 4:
        if p2[1] > y:
            p2 = (p2[0], y)

area = (max(p2[0]-p1[0], 0))*(max(p2[1]-p1[1], 0))
print(area)

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

Solution (Python):
W,H,N=map(int,input().split())
l=[list(map(int,input().split())) for i in range(N)]
l_s,b_s = 0,0
r_s,u_s = W,H
for i in range(N):
    if l[i][2]==1 and l_s < l[i][0]:
        l_s =l[i][0]
    elif l[i][2]==2 and r_s > l[i][0]:
        r_s = l[i][0]
    elif l[i][2]==3 and b_s < l[i][1]:
        b_s = l[i][1]
    elif l[i][2]==4 and u_s > l[i][1]:
        u_s = l[i][1]

if (r_s-l_s)>0 and (u_s-b_s)>0:
    print((r_s-l_s)*(u_s-b_s))
else :
    print("0")

Solution (Python):
import numpy as np
w,h,n=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]

a=np.zeros((h,w))

for i in range(n):
    lis=li[i]
    if lis[2]==1:
        a[:,:lis[0]]=1
    elif lis[2]==2:
        a[:,lis[0]:]=1
    elif lis[2]==3:
        a[:lis[1],:]=1
    elif lis[2]==4:
        a[lis[1]:,:]=1

print(np.count_nonzero(a==0))

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np

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

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

maps = np.zeros([H+1, W+1])

for this_order in inputs:
    if this_order[2] == 1:
        maps[0:, :this_order[0]+1] = 1
    elif this_order[2] == 2:
        maps[0:, this_order[0]+1:] = 1
    elif this_order[2] == 3:
        maps[:this_order[1]+1] = [1] * (W+1)
    else:
        maps[this_order[1]+1:] = [1] * (W+1)

ans = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if maps[i][j] == 0:
            ans += 1
print(ans)

Solution (Python):
W, H, N = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
M = [[0] * W for i in range(H)]
for x in X:
    if x[2] == 1:
        for i in range(0, x[0]):
            for j in range(H):
                M[j][i] = 1
    elif x[2] == 2:
        for i in range(x[0], W):
            for j in range(H):
                M[j][i] = 1
    elif x[2] == 3:
        for i in range(0, x[1]):
            for j in range(W):
                M[i][j] = 1
    elif x[2] == 4:
        for i in range(x[1], H):
            for j in range(W):
                M[i][j] = 1
c = 0
for i in range(W):
    for j in range(H):
        if M[j][i] == 0:
            c += 1
print(c)

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

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))


a,b,c  = cin()
p = -1
q = 1e9
r = -1
s = 1e9
for i in range(c):
  x,y,z = cin()
  if z==1:
    p = max(x,p)
  elif z==2:
    q = min(x,q)
  elif z==3:
    r = max(r,y)
  else:
    s = min(s,y)

if p==-1:
    p = 0
if q==1e9:
    q = a
if r==-1:
    r=0
if s==1e9:
    s=b

ans = (q-p)*(s-r)
if p>q or r>s:
    print(0)
else:
    print(ans)

Solution (Python):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))



def main():
    w, h, n = ns()

    max_x = -1
    min_x = INF
    max_y = -1
    min_y = INF

    for _ in range(n):
        x, y, a = ns()

        if a == 1:
            max_x = max(max_x, x)
        elif a == 2:
            min_x = min(min_x, x)
        elif a == 3:
            max_y = max(max_y, y)
        elif a == 4:
            min_y = min(min_y, y)

    if max_x == -1:
        max_x = 0
    if min_x == INF:
        min_x = w
    if max_y == -1:
        max_y = 0
    if min_y == INF:
        min_y = h

    len_x = max(0, min_x - max_x)
    len_y = max(0, min_y - max_y)

    print(len_x * len_y)


if __name__ == '__main__':
    main()

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

WX=[0,W]
HY=[0,H]

i=0
while i<N:
    if XYA[i][2]==1:
        WX[0]=max(WX[0],XYA[i][0])
    elif XYA[i][2]==2:
        WX[1]=min(WX[1],XYA[i][0])
    elif XYA[i][2]==3:
        HY[0]=max(HY[0],XYA[i][1])
    elif XYA[i][2]==4:
        HY[1]=min(HY[1],XYA[i][1])
    i+=1

ans=max(0,WX[1]-WX[0])*max(0,HY[1]-HY[0])
print(ans)

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

X = Y = 0

for i in range(0, 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())

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

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

if x1 >= x2 or y1 >= y2:
    print(0)
else:
    print(abs(x1-x2)*abs(y1-y2))

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

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

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

D_LEFT = 1
D_RIGHT = 2
D_BOTTOM = 3
D_TOP = 4

for x, y, direction in points:
    if direction == D_RIGHT:
        right = min(right, x)
    elif direction == D_LEFT:
        left = max(left, x)
    elif direction == D_BOTTOM:
        bottom = max(bottom, y)
    elif direction == D_TOP:
        top = min(top, y)

print(max(0, (right - left)) * (max(0, (top - bottom))))

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

white_check = list()
for a in range(0, h):
    white_check.append([1]*w)

for i in range(0, n):
    a = l[i][2]
    height = l[i][1]
    width = l[i][0]

    if a == 1:
        for y in range(0, h):
            for x in range(0, width):
                white_check[y][x] = 0
    elif a == 2:
        for y in range(0, h):
            for x in range(width, w):
                white_check[y][x] = 0
    elif a == 3:
        for y in range(0, height):
            for x in range(0, w):
                white_check[y][x] = 0
    else:
        for y in range(height, h):
            for x in range(0, w):
                white_check[y][x] = 0

s = 0

for a in range(h):
    s += sum(white_check[a])

print(s)

Solution (Python):
W, H, N = [int(i) for i in input().split()]
xx = []
yy = []
aa = []
for _ in range(N):
    x, y, a = [int(i) for i in input().split()]
    xx.append(x)
    yy.append(y)
    aa.append(a)

xs, ys = 0, 0
xe, ye = W, H
for i in range(N):
    if aa[i] == 1:
        xs = max(xs, xx[i])
    elif aa[i] == 2:
        xe = min(xe, xx[i])
    elif aa[i] == 3:
        ys = max(ys, yy[i])
    else:
        ye = min(ye, yy[i])

if xs < xe and ys < ye:
    print((xe - xs) * (ye - ys))
else:
    print(0)

Solution (Python):

def myAnswer(W:int,H:int,N:int,X:list,Y:list,A:list) -> int:
   startX = 0
   endX = W
   startY = 0
   endY = H
   for x,y,a in zip(X,Y,A):
      if(a == 1):
         startX = max(startX,x)
      elif(a == 2):
         endX = min(endX,x)
      elif(a == 3):
         startY = max(startY,y)
      elif(a == 4):
         endY = min(endY,y)
   
   return 0 if(startX > endX or startY > endY) else (endX - startX) * (endY - startY)

def modelAnswer():
   return
def main():
   W,H,N = map(int,input().split())
   X = []
   Y = []
   A = []
   for _ in range(N):
      x,y,a = map(int,input().split())
      X.append(x)
      Y.append(y)
      A.append(a)
   print(myAnswer(W,H,N,X,Y,A))
if __name__ == '__main__':
   main()

Solution (Python):

def myAnswer(W:int,H:int,N:int,X:list,Y:list,A:list) -> int:
   startX = 0
   endX = W
   startY = 0
   endY = H
   for x,y,a in zip(X,Y,A):
      if(a == 1 and startX < x):
         startX = x
      elif(a == 2 and endX > x):
         endX = x
      elif(a == 3 and startY < y):
         startY = y
      elif(a == 4 and endY > y):
         endY = y
   
   
   return 0 if(startX > endX or startY > endY) else (endX - startX) * (endY - startY)

def modelAnswer():
   return
def main():
   W,H,N = map(int,input().split())
   X = []
   Y = []
   A = []
   for _ in range(N):
      x,y,a = map(int,input().split())
      X.append(x)
      Y.append(y)
      A.append(a)
   print(myAnswer(W,H,N,X,Y,A))
if __name__ == '__main__':
   main()

Solution (Python):
w, h, n = map(int, input().split())
left = 0
right = w
down = 0
up = 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:
        down = max(down, y)
    elif a == 4:
        up = min(up, y)

    if right - left <= 0 or up - down <= 0:
        print(0)
        exit()

ans = (right - left) * (up - down)
print(ans)

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

S = [[0 for j in range(W)] for i in range(H)]

for k in range(N):
  if X[k][2]==1:
    for i in range(H):
      for j in range(X[k][0]):
        S[i][j]=1
    
  elif X[k][2]==2:
    for i in range(H):
      for j in range(X[k][0],W):
        S[i][j]=1
    
  elif X[k][2]==3:
    for i in range(X[k][1]):
      for j in range(W):
        S[i][j]=1
    
  elif X[k][2]==4:
    for i in range(X[k][1],H):
      for j in range(W):
        S[i][j]=1
    
z=0
for i in range(H):
  z+=S[i].count(0)
print(z)

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

Solution (Python):
w,h,n = map(int,input().split())
xyn_list = [list(map(int,input().split())) 
            for nesya in range(n)]
hoge1 = 0
hoge2 = w
hoge3 = 0
hoge4 = h
for xyn in xyn_list:
  a = xyn[2]
  if a == 1:
    if hoge1 < xyn[0]:
      hoge1 = xyn[0]
  elif a == 2:
    if hoge2 > xyn[0]:
      hoge2 = xyn[0]
  elif a ==3:
    if hoge3 < xyn[1]:
      hoge3 = xyn[1]
  else:
    if hoge4 > xyn[1]:
      hoge4 = xyn[1]
if hoge4 > hoge3 and hoge2 > hoge1:
  ans = (hoge4-hoge3)*(hoge2-hoge1)
else:
  ans = 0
print(ans)

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

x_axis = [0, W]
y_axis = [0, H]

for x, y, a in xya:
    if a == 1 and x_axis[0] <= x:
        x_axis[0] = x

    elif a == 2 and x <= x_axis[1]:
        x_axis[1] = x

    elif a == 3 and y_axis[0] <= y:
        y_axis[0] = y

    elif a == 4 and y <= y_axis[1]:
        y_axis[1] = y

if x_axis[1] - x_axis[0] <=0 or y_axis[1] - y_axis[0] <=0:
    print(int(0))

else:
    print((x_axis[1] - x_axis[0]) * (y_axis[1] - y_axis[0]))

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7


w,h,n = map(int,input().split())
whiteXmin = 0
whiteXmax = w
whiteYmin = 0
whiteYmax = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        whiteXmin = max(x,whiteXmin)
    if a == 2:
        whiteXmax = min(x,whiteXmax)
    if a == 3:
        whiteYmin= max(y,whiteYmin)
    if a == 4:
        whiteYmax = min(y,whiteYmax)

if whiteXmax - whiteXmin < 0 or whiteYmax-whiteYmin < 0:
    print(0)
    sys.exit()
print((whiteXmax-whiteXmin)*(whiteYmax-whiteYmin))

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

xmin,xmax,ymin,ymax = 0,w,0,h

for a in A:
  if a[2] == 1:
    xmin = max(xmin, a[0])
  if a[2] == 2:
    xmax = min(xmax, a[0])
  if a[2] == 3:
    ymin = max(ymin, a[1])
  if a[2] == 4:
    ymax = min(ymax, a[1])
    
S = (xmax-xmin) * (ymax-ymin)
if S < 0 or xmin > xmax or ymin > ymax:
  S = 0
print(S)

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

if xl >= xu or yl >= yu:
  print(0)
else:
  print((xu-xl)*(yu-yl))

Solution (Python):
W, H, N = list(map(int, input().split()))
A = []
for _ in range(N):
  A.append(list(map(int, input().split())))
  
xmax, xmin, ymax, ymin = W, 0, H, 0
for a in A:
  if a[2] == 1:
    xmin = max(xmin, a[0])
  if a[2] == 2:
    xmax = min(xmax, a[0])
  if a[2] == 3:
    ymin = max(ymin, a[1])
  if a[2] == 4:
    ymax = min(ymax, a[1])
    
S = (xmax-xmin) * (ymax-ymin)
if S < 0 or xmin > xmax or ymin > ymax:
  S = 0
print(S)

Solution (Python):
w,h,n=map(int,input().split())
x_min=0
x_max=w
y_min=0
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)
  
print( max(0,x_max-x_min)*max(0,y_max-y_min) )

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    W, H, N = map(int, readline().split())
    xl = 0
    xr = W
    yl = 0
    yh = H
    for _ in range(N):
        x, y, a = map(int, readline().split())
        if a==1:
            xl = max(xl,x)
        elif a==2:
            xr = min(xr,x)
        elif a==3:
            yl = max(yl,y)
        else:
            yh = min(yh,y)
    print(max(xr-xl,0)*max(yh-yl,0))

if __name__ == '__main__':
    main()

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

Xleft = 0
Xright = W
Ylow = 0
Yhigh = H
for X,Y,A in rows:
    if A == 1:
        Xleft = max(X,Xleft)
    elif A == 2:
        Xright = min(X,Xright)
    elif A == 3:
        Ylow = max(Y,Ylow)
    else:
        Yhigh = min(Y,Yhigh)

ans = max(Yhigh-Ylow,0) * max(Xright-Xleft,0)
print(ans)

Solution (Python):
def resolve():
    '''
    code here
    '''
    W, H, N = [int(item) for item in input().split()]
    query = [[int(item) for item in input().split()] for _ in range(N)]

    x_low = 0
    x_high = W
    y_low = 0
    y_high = H

    for x, y, a in query:
        if a == 1:
            x_low = max(x_low, x)
        elif a == 2:
            x_high = min(x_high, x)
        elif a == 3:
            y_low = max(y_low, y)
        else:
            y_high = min(y_high, y)

        
        
        
    
    
    
    
    

    x_delta = x_high - x_low
    y_delta = y_high - y_low

    if x_delta >= 0 and y_delta >= 0:
        print(x_delta*y_delta)
    else:
        print(0)

if __name__ == "__main__":
    resolve()

Solution (Python):

import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache

readline=sys.stdin.readline
sys.setrecursionlimit(2000000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)


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

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

for i in range(N):
    if A[i] == 1 and WL <= X[i]:
        WL = X[i]
    elif A[i] == 2 and W >= X[i]:
        W = X[i]
    elif A[i] == 3 and HL <= Y[i]:
        HL = Y[i]
    elif A[i] == 4 and H >= Y[i]:
        H = Y[i]

if W - WL <= 0 or H - HL <= 0:
    print(0)
    exit()

print((W - WL) * (H - HL))

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

painting = []
for i in range(h):
    li = [1]*w
    painting.append(li)


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):
                painting[j][k] = 0
    elif a == 2:
        for j in range(h):
            for k in range(x,w):
                painting[j][k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(w):
                painting[j][k] = 0
    elif a == 4:
        for j in range(y,h):
            for k in range(w):
                painting[j][k] = 0

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

print(ans)

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

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

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

print(sum(sum(f) for f in F))

Solution (Python):
W,H,N = map(int,input().split())
X = [i for i in range(W+1)]
Y = [i for i in range(H+1)]

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

Solution (Python):
def nurie(x, y, a):
    if a == 1:
        for i in range(x):
            for j in range(H):
                A[i][j] = 1
    if a == 2:
        for i in range(x, W):
            for j in range(H):
                A[i][j] = 1
    if a == 3:
        for i in range(W):
            for j in range(y):
                A[i][j] = 1
    if a == 4:
        for i in range(W):
            for j in range(y, H):
                A[i][j] = 1

def cal_area(A):
    count = 0
    for i in range(W):
        for j in range(H):
            if A[i][j] == 0:
                count += 1
    return count

W, H, N = map(int, input().split())
A = [[0]*H for i in range(W)]

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

print(cal_area(A))

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())
xya = [list(map(int,input().split())) for i in range(n)]

ans = [[1]*h for _ in range(w)]

for i in range(n):
    if xya[i][2] == 1:
        for j in range(xya[i][0]):
            for k in range(h):
                ans[j][k] = 0
    elif xya[i][2] == 2:
        for j in range(xya[i][0],w):
            for k in range(h):
                ans[j][k] = 0
    elif xya[i][2] == 3:
        for j in range(xya[i][1]):
            for k in range(w):
                ans[k][j] = 0
    else:
        for j in range(xya[i][1],h):
            for k in range(w):
                ans[k][j] = 0

total = 0
for i in ans:
    total += sum(i)
print(total)

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

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

box = [[True for i in range(w)]for j in range(h)]
for i in range(n):
    if xya[i][2] == 1:
        for j in range(xya[i][0]):
            for k in range(h):
                box[k][j] = False
    elif xya[i][2] == 2:
        for j in range(xya[i][0], w):
            for k in range(h):
                box[k][j] = False
    elif xya[i][2] == 3:
        for j in range(w):
            for k in range(xya[i][1]):
                box[k][j] = False
    else:
        for j in range(w):
            for k in range(xya[i][1], h):
                box[k][j] = False

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

print(ans)

Solution (Python):
from sys import stdin


def ind_cnv(x,y,xlim):
    return x+y*xlim


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    W, H, N = list(map(int,_in[0].split(' ')))  
    x_y_a_arr = []
    for i in range(N):
        _ = list(map(int,_in[i+1].split(' ')))  
        x_y_a_arr.append(_)
    
    colored = [0]*(H*W)
    for x,y,a in x_y_a_arr:
        x -= 1
        y -= 1
        if a==1:
            for _x in range(x+1):
                for _y in range(H):
                    colored[ind_cnv(_x,_y,W)] = 1
        elif a==2:
            for _x in range(x+1,W):
                for _y in range(H):
                    colored[ind_cnv(_x,_y,W)] = 1
        elif a==3:
            for _x in range(W):
                for _y in range(y+1):
                    colored[ind_cnv(_x,_y,W)] = 1
        elif a==4:
            for _x in range(W):
                for _y in range(y+1,H):
                    colored[ind_cnv(_x,_y,W)] = 1
    cnt = colored.count(0)
    
    print(cnt)

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

l = 0
r = w
t = h
b = 0


for i, aa in enumerate(a):
    if aa == 1:
        l = max(l,x[i])
    elif aa == 2:
        r = min(r,x[i])

    elif aa == 3:
        b = max(b,y[i])
    elif aa == 4:
        t = min(t,y[i])

ans = max(0,(r-l) * (t-b))
if r-l <= 0 or t-b <= 0:
    ans = 0
print(ans)

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

for i in range(n):
    x,y,a = map(int,input().split())
    
    if a == 1:
        for j in range(h):
            pic[j][:x] = [1]*len(pic[j][:x])
            
    if a == 2:
        for j in range(h):
            pic[j][x:] = [1]*len(pic[j][x:])
            
    if a == 3:
         for j in range(1,h+1):
            if j < y+1:
                pic[-j] = [1] * w
                
    if a == 4:
        for j in range(1,h+1):
            if j > y:
                pic[-j] = [1] * w
                
ans = 0

for i in pic:
    ans += i.count(0)
    
print(ans)