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
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')



 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]




w,h,n=mii()

mat=np.array([[1]*w for _ in range(h)])

for _ in range(n):
    x,y,a=mii()
    if a==1:
        mat[:,:x]=0
    elif a==2:
        mat[:,x:]=0
    elif a==3:
        mat[:y,:]=0
    else:
        mat[y:,:]=0

print(np.sum(mat))

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

wl=0
wr=W
hd=0
hu=H
for x,y,a in xya:
    if a==1:
        wl=max(wl,x)
    elif a==2:
        wr=min(wr,x)
    elif a==3:
        hd=max(hd,y)
    else:
        hu=min(hu,y)

ans=max(wr-wl,0)*max(hu-hd,0)
print(ans)

Solution (Python):
w,h,n = map(int,input().split())
xs = 0
ys = 0
xe = w
ye = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 2:
        xe = min(xe,x)
    elif a == 1:
        xs = max(xs,x)
    elif a == 4:
        ye = min(ye,y)
    else:
        ys = max(ys,y)
if xs < xe and ys < ye:
    print(abs(xs-xe)*abs(ys-ye))
else:
    print(0)

Solution (Python):



import sys
import numpy




def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(Width, Height, Point, x_position, y_position, control_id):
    result = 0
    
    surface = numpy.zeros((Width, Height), dtype=numpy.int)
    
    
    
    for j in range(0, Point, +1):
        if control_id[j] == 1:
            for x in range(0, x_position[j], +1):
                for y in range(0, Height, +1):
                    surface[x][y] = 1
        elif control_id[j] == 2:
            for x in range(x_position[j], Width, +1):
                for y in range(0, Height, +1):
                    surface[x][y] = 1
        elif control_id[j] == 3:
            for x in range(0, Width, +1):
                for y in range(0, y_position[j], +1):
                    surface[x][y] = 1
        else:  
            for x in range(0, Width, +1):
                for y in range(y_position[j], Height, +1):
                    surface[x][y] = 1
    
    for x in range(0, Width, +1):
        for y in range(0, Height, +1):
            if surface[x][y] == 0:
                result = result + 1
    return result


if __name__ == "__main__":
    W, H, N = MI()
    x_position = list()
    y_position = list()
    control_id = list()
    for j in range(0, N, +1):
        x_tmp, y_tmp, a_tmp = MI()
        x_position.append(x_tmp)
        y_position.append(y_tmp)
        control_id.append(a_tmp)
    print("{}".format(solver(W, H, N, x_position, y_position, control_id)))

Solution (Python):
w,h,n = list(map(int,input().split()))
minX = 0
maxX = w
minY = 0
maxY = h
for i in range(n):
    x, y, a = 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)

print(max(0, maxX-minX)*max(0, maxY-minY))

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

o,p,q,r = 0,0,0,0
for _ in range(n):
  x,y,a = map(int, input().split())
  if a == 1:
    o = max(o, x)
  elif a == 2:
    p = max(p, w-x)
  elif a == 3:
    q = max(q, y)
  elif a == 4:
    r = max(r, h-y)

w -= o+p
h -= q+r
if w <= 0 or h <= 0:
  print(0)
else:
  print(w*h)

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

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

min_x = 0
max_x = w
min_y = 0
max_y = h

for i in range(n):
  if s[i][2] == 1:
    if s[i][0] > min_x:
      min_x = s[i][0]

  elif s[i][2] == 2:
    if s[i][0] < max_x:
      max_x = s[i][0]
      
  elif s[i][2] == 3:
    if s[i][1] > min_y:
      min_y = s[i][1]
      
  else:
    if s[i][1] < max_y:
      max_y = s[i][1]

if (max_x - min_x) > 0 and (max_y - min_y) > 0:
  print((max_x - min_x) * (max_y - min_y))
  
else:
  print(0)

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)
    elif a == 2:
        maxX =min(maxX, x)
    elif a == 3:
        minY = max(minY, y)
    elif a == 4:
        maxY = min(maxY, y)

print(max(0, maxX-minX)*max(0, maxY-minY))

Solution (Python):
import numpy as np
W,H,N=map(int,input().split())
A=np.zeros((W,H))
B=[list(map(int,input().split())) for _ in range(N)]
for b in B:
    if b[2]==1:
        A[:b[0],:]=1
    elif b[2]==2:
        A[b[0]:,:]=1
    elif b[2]==3:
        A[:,:b[1]]=1
    elif b[2]==4:
        A[:,b[1]:]=1
print(np.count_nonzero(A==0))

Solution (Python):
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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 LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	w, h, n = LI()
	left_x, right_x, lower_y, upper_y = 0, w, 0, h
	for _ in range(n):
		x, y, a = LI()
		if a == 1:
			left_x = max(x, left_x)
		elif a == 2:
			right_x = min(x, right_x)
		elif a == 3:
			lower_y = max(y, lower_y)
		elif a == 4:
			upper_y = min(y, upper_y)
	if right_x > left_x and upper_y > lower_y:
		print((right_x-left_x)*(upper_y-lower_y))
	else:
		print(0)


if __name__ == '__main__':
    main()

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

rect = [["W" for i in range(W)] for j in range(H)]

for x in check:
    if x[2] == 1:
        for h1 in range(H):
            for w1 in range(x[0]):
                rect[h1][w1] = "B"

    elif x[2] == 2:
        for h2 in range(H):
            for w2 in range(x[0], W, 1):
                rect[h2][w2] = "B"
    elif x[2] == 3:
        for h3 in range(x[1]):
            for w3 in range(W):
                rect[h3][w3] = "B"

    elif x[2] == 4:
        for h3 in range(x[1], H, 1):
            for w3 in range(W):
                rect[h3][w3] = "B"


count = 0
for y in rect:
    count += y.count("W")
print(count)

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

def isBlack(h, w):
    for x, y, a in XYA:
        if a == 1 and w < x:
            return True
        if a == 2 and w >= x:
            return True
        if a == 3 and h < y:
            return True
        if a == 4 and h >= y:
            return True
    return False

ans = H * W
for w in range(W):
    for h in range(H):
        ans -= 1 if isBlack(h, w) else 0
print(ans)

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

A = [[0]*w for i in range(h)]

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        for i in range(h):
            for j in range(x):
                A[i][j] = 1
    elif a == 2:
        for i in range(h):
            for j in range(x,w):
                A[i][j] = 1
    elif a == 3:
        for i in range(y):
            for j in range(w):
                A[i][j] = 1                
    else:            
        for i in range(y,h):
            for j in range(w):
                A[i][j] = 1                

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

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

y_min=0
y_max=h
x_min=0
x_max=w

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x_min=max(x_min,x)
  if 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)

y_ok=y_max-y_min
x_ok=x_max-x_min

if y_ok>=0 and x_ok>=0:
  print(y_ok*x_ok)
else:
  print(0)

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

y_min = 0
y_max = h

x_min = 0
x_max = w

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

  if a == 1:
    x_min = max(x_min, x)

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

white = (y_max - y_min) * (x_max - x_min)
if (y_max - y_min)>=0 and (x_max - x_min)>=0:
  print(max(white, 0))
else:
  print(0)

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

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


x_left,x_right = 0, W
y_under, y_up = 0,H

for i in range(N):
    x,y = lst[i][0], lst[i][1]
    if lst[i][2] == 1:
        if x_left < x: 
            x_left = x
    elif lst[i][2] == 2:
        if x_right > x:
            x_right = x
            if x_right == 0:
                print(0)
                exit()
    elif lst[i][2] == 3:
        if y_under < y:
            y_under = y
    elif lst[i][2] == 4:
        if y_up > y:
            y_up = y
            if y_up == 0:
                print(0)
                exit()

yoko = x_right - x_left
tate = y_up - y_under
if tate * yoko <= 0:
    print(0)
else:
    print(tate * yoko)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

W, H, N = mapint()
x1, y1 = 0, 0
x2, y2 = W, H
for _ in range(N):
    x, y, a = mapint()
    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)

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

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:
        X[0] = max(X[0], x)
    elif a == 2:
        X[1] = min(X[1], x)
    elif a == 3:
        Y[0] = max(Y[0], y)
    else:
        Y[1] = min(Y[1], y)
if X[0] >= X[1] or Y[0] >= Y[1]: print(0)
else: print(abs(X[0]-X[1])*abs(Y[0]-Y[1]))

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

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:
        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 r-l<=0 or u-d<=0:
    print(0)
else:
    print((r-l)*(u-d))

Solution (Python):
import sys
readline = sys.stdin.readline

W,H,N = map(int,readline().split())
minX = 0
minY = 0
maxX = W
maxY = H

for i in range(N):
  x,y,a = map(int,readline().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)

print(max(0,maxX - minX) * max(0,maxY - minY))

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

xl, xr, yd, 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:
        xr = min(xr, x)
    elif a == 3:
        yd = max(yd, y)
    else:
        yu = min(yu, y)

width = max(xr-xl, 0)
height = max(yu-yd, 0)
print(width*height)

Solution (Python):
[w, h, n] = list(map(int, input().split()))
list_x1 = []
list_x2 = []
list_y3 = []
list_y4 = []
for i in range(n):
  xya = list(map(int, input().split()))
  if xya[2] == 1:
    list_x1.append(xya[0])
  if xya[2] == 2:
    list_x2.append(xya[0])
  if xya[2] == 3:
    list_y3.append(xya[1])
  if xya[2] == 4:
    list_y4.append(xya[1])
try:
  min_x = min(list_x2)
except ValueError:
  pass  
try:
  max_x = max(list_x1)
except ValueError:
  pass  
try:
  min_y = min(list_y4)
except ValueError:
  pass  
try:
  max_y = max(list_y3)
except ValueError:
  pass  
try:
  w =min_x
except NameError:
  pass
try:
  w -= max_x
except NameError:
  pass
try:  
  h = min_y
except NameError:
  pass
try:
  h -= max_y
except NameError:
  pass
if w > 0 and h > 0:
  print(w*h)
else:
  print(0)

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

Solution (Python):
import numpy as np
W, H, N = map(int, input().split())
g = np.zeros((H, W))

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

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

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

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

X = 0 
Y = 0 

for j in range(N):
    if a[j][2] == 1: 
        if a[j][0] > X:
            X = a[j][0]
        else:
            pass
    elif a[j][2] == 2: 
        if a[j][0] < W:
            W = a[j][0]
        else:
            pass
    elif a[j][2] == 3: 
        if a[j][1] > Y:
            Y = a[j][1]
        else:
            pass
    elif a[j][2] == 4: 
        if a[j][1] < H:
            H = a[j][1]
        else:
            pass
    else:
        print('Error')

W = W - X
H = H - Y

if W <= 0:
    W = 0
else:
    pass

if H <= 0:
    H = 0
else:
    pass

ans = W * H
if ans <= 0:
    print(0)
else:
    print(ans)

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

x = list(range(0,w+1))
y = list(range(0,h+1))

for l in ls:
    if len(x)<=1 or len(y)<=1:
        break

    if l[2] == 2:
        x = [i for i in x if i <= l[0]]
    elif l[2] == 1:
        x = [i for i in x if i >= l[0]]
    elif l[2] == 4:
        y = [i for i in y if i <= l[1]]
    elif l[2] == 3:
        y = [i for i in y if i >= l[1]]

if len(x)<=1 or len(y)<=1:
    print(0)
else:
    x = max(x) - min(x)
    y = max(y) - min(y)
    print(x*y)

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

lstx = [[0], [W]]
lsty = [[0], [H]]

for i in range(N):
    x, y, a = map(int, input().split())
    if a==1 or a==2:
        lstx[a-1].append(x)
    else:
        lsty[a-3].append(y)

xmax = max(lstx[0])
xmin = min(lstx[1])
ymax = max(lsty[0])
ymin = min(lsty[1])

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

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 and x>l: l=x
    if a==2 and x<r: r=x
    if a==3 and y>d: d=y
    if a==4 and y<u: u=y
if u>d and r>l: print((u-d)*(r-l))
else: print(0)

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x_reg < x:
        x_reg = x
    if a == 2 and w > x:
        w = x
    if a == 3 and y_reg < y:
        y_reg = y
    if a == 4 and h > y:
        h = y

x_edge = max(0, w-x_reg)
y_edge = max(0, h-y_reg)

print(x_edge*y_edge)

Solution (Python):
W, H, N = map(int, input().split())
w1 = 0
w2 = W
h1 = 0
h2 = H
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1 and w1 < x:
    w1 = x
  elif a == 2 and w2 > x:
    w2 = x
  elif a == 3 and h1 < y:
    h1 = y
  elif a == 4 and h2 > y:
    h2 = y
wa = w2 - w1
if wa < 0:
  wa = 0
ha = h2 - h1
if ha < 0:
  ha = 0
ans = wa * ha
print(ans)

Solution (Python):
w, h, n = map(int, input().split())
xl, xr = 0, w
yd, yu = 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x < xl:
            continue
        elif xl <= x <= xr:
            xl = x
        else:
            xl, xr = 0, 0 
    elif a == 2:
        if xr < x:
            continue
        elif xl <= x <= xr:
            xr = x
        else:
            xl, xr = 0, 0
    elif a == 3:
        if y < yd:
            continue
        elif yd <= y <= yu:
            yd = y
        else:
            yd, yu = 0, 0
    elif a == 4:
        if y > yu:
            continue
        elif yd <= y <= yu:
            yu = y
        else:
            yd, yu = 0, 0

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

Solution (Python):
W,H,N=map(int,input().split())
W0=0
H0=0
for i in range(N):
    x1,y1,a1=map(int,input().split())
    if a1 ==1 and W0<x1:
        W0=x1
    elif a1==2 and W>x1:
        W=x1
    elif a1==3 and H0<y1:
        H0=y1
    elif a1==4 and H>y1:
        H=y1

if W-W0>0 and H-H0>0:
    print((W-W0)*(H-H0))
else:
    print(0)

Solution (Python):

"""
Created on Thu Jun 11 17:09:47 2020

@author: sd18016
"""   

import sys

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

for i in range(N):
    x = list(map(int, input().split()))
    list_x.append(x)
    
O = [0,0]
MU = [W, H]

for i in range(N):
    if list_x[i][2] == 1:
        if list_x[i][0] > O[0]:
            O[0] = list_x[i][0]
    elif list_x[i][2] == 2:
        if list_x[i][0] < MU[0]:
            MU[0] = list_x[i][0]
    elif list_x[i][2] == 3:
        if list_x[i][1] > O[1]:
            O[1] = list_x[i][1]
    elif list_x[i][2] == 4:
        if list_x[i][1] < MU[1]:
            MU[1] = list_x[i][1]
            
W_ans = MU[0]-O[0]
H_ans = MU[1]-O[1]

if W_ans <0 or H_ans<0:
    print("0")
else:
    ans = W_ans*H_ans
    print(ans)
            



"""
for i in range(N):
    if list_x[i][2] == 1:
        de = list_x[i][0]
        S -= de*H
        W -= de
    elif list_x[i][2] == 2:
        de = W - list_x[i][0]
        S -= de*H
        W -= de
    elif list_x[i][2] == 3:
        de = list_x[i][1]
        S -= de*W
        H -= de
    else:
        de = H - list_x[i][1]
        S -= de*W
        H -= de

print(S)
"""

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

XW = [1] * W
YW = [1] * H

for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    XW[:x] = [0]*x
  elif a == 2:
    XW[x:] = [0]*(W-x)
  elif a == 3:
    YW[:y] = [0]*y
  elif a == 4:
    YW[y:] = [0]*(H-y)
print(sum(XW)*sum(YW))

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

E = [0,W,0,H]

for x,y,a in XYA:
  a -= 1
  XY = [x,y]
  if a % 2 == 0:
    E[a] = max(E[a],XY[a//2])
  else:
    E[a] = min(E[a],XY[a//2])

ans = 0
if E[0] < E[1] and E[2] < E[3]:
  ans = (E[1] - E[0]) * (E[3] - E[2])
  
print(ans)

Solution (Python):
w,h,n = map(int,input().split())
mode = [[0],[w],[0],[h]]
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        mode[0].append(x)
    elif a == 2:
        mode[1].append(x)
    elif a == 3:
        mode[2].append(y)
    else:
        mode[3].append(y)
b = [min(mode[1])-max(mode[0]),min(mode[3])-max(mode[2])]
print(b[0]*b[1] if (0 < b[0] and 0 < b[1]) else 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:
        if X1 <= x:
            X1 = x
        else:
            pass
    elif a == 2:
        if x <= X2:
            X2 = x
        else:
            pass
    if a == 3:
        if Y1 <= y:
            Y1 = y
        else:
            pass
    if a == 4:
        if y <= Y2:
            Y2 = y
        else:
            pass
if X1 >= X2 or Y1 >= Y2:
    print(0)
else:
    print((X2 - X1) * (Y2 - Y1))

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

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))





xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        
        xb = max([xb, X[_]])
    elif A[_] == 2:
        
        xe = min([xe, X[_]])
    elif A[_] == 3:
        
        yb = max([yb, Y[_]])
    else:
        
        ye = min([ye, Y[_]])
    
    
    if (xe - xb) <= 0 or (ye - yb) <= 0:
        print(0)
        import sys
        sys.exit()

ans = (xe - xb) * (ye - yb)
print(ans)

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

Solution (Python):

w, h, n = map(int, input().split())
square_info = [list(map(int, input().split())) for _ in range(n)]

min_x = 0
max_x = w
min_y = 0
max_y = h

for i in range(n):
    if square_info[i][2] == 1:
        min_x = max(min_x, square_info[i][0])
    elif square_info[i][2] == 2:
        max_x = min(max_x, square_info[i][0])
    elif square_info[i][2] == 3:
        min_y = max(min_y, square_info[i][1])
    else:
        max_y = min(max_y, square_info[i][1])

if max_x <= min_x or max_y <= min_y:
    print(0)
else:
    print((max_x - min_x)*(max_y - min_y))

Solution (Python):
w,h,n = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
xl = 0
xr = w
yh = h
yr = 0
for i in range(n):
    if a[i][2] == 1:
        xl = max(xl,a[i][0])
    elif a[i][2] == 2:
        xr = min(xr,a[i][0])
    elif a[i][2] == 3:
        yr = max(yr,a[i][1])
    else:
        yh = min(yh,a[i][1])

x = xr - xl
y = yh - yr

print(0 if x < 0 or y < 0 else x*y)

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:
        if x1<x:
            x1=x
    elif a==2:
        if x<x2:
            x2=x
    elif a==3:
        if y1<y:
            y1=y
    else:
        if y<y2:
            y2=y

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

Solution (Python):
w, h, n = map(int, input().split())
ll_x, ll_y, tr_x, tr_y = 0, 0, w, h
for q in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        ll_x = max(ll_x, x)
    elif a == 2:
        tr_x = min(tr_x, x)
    elif a == 3:
        ll_y = max(ll_y, y)
    elif a == 4:
        tr_y = min(tr_y, y)
ans = (tr_x - ll_x) * (tr_y - ll_y)
if (ll_x > tr_x) or (ll_y > tr_y):
    ans = 0
print(ans if ans > 0 else 0)

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

min_w = 0
max_w = w
min_h = 0
max_h = h

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        min_w = max(x,min_w)
    elif a == 2:
        max_w = min(x,max_w)
    elif a == 3:
        min_h = max(y,min_h)
    elif a == 4:
        max_h = min(y,max_h)

if (max_h - min_h) <= 0 or (max_w - min_w) <= 0:
    print(0)
else:
    print((max_h - min_h)*(max_w - min_w))

Solution (Python):
W,H,N=map(int,input().split())
m=[[0]*W for i in range(H)]
ans=W*H

def c(a,b):
    global ans
    if m[a][b]==0:
        m[a][b]=1
        ans-=1
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): c(j,k)
    if a==2:
        for j in range(H):
            for k in range(x,W): c(j,k)
    if a==3:
        for j in range(y):
            for k in range(W): c(j,k)
    if a==4:
        for j in range(y,H):
            for k in range(W):c(j,k)
print(ans)

Solution (Python):
w, h, n = map(int, input().split())
x = []
y = []
a = []
for i in range(n):
  xi, yi, ai = map(int, input().split())
  x.append(xi)
  y.append(yi)
  a.append(ai)
xmin = 0
xmax = w
ymin = 0
ymax = h
for i in range(n):
  if a[i] == 1:
    xmin = max(xmin, x[i])
  elif a[i] == 2:
    xmax = min(xmax, x[i])
  elif a[i] == 3:
    ymin = max(ymin, y[i])
  else:
    ymax = min(ymax, y[i])
print(max(0, xmax - xmin) * max(0, ymax - ymin))

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

ans = 0
f = 0
for e in xya:
  x = e[0]
  y = e[1]
  a = e[2]
  if a == 1:
    ld[0] = max(x, ld[0])
  elif a == 2:
    ru[0] = min(x, ru[0])
  elif a == 3:
    ld[1] = max(y, ld[1])
  elif a == 4:
    ru[1] = min(y, ru[1])

  if ld[0] < ru[0] and ld[1] < ru[1]:
    next
  else:
    f = 1
    break

if f == 1:
  ans = 0
else:
  ans = abs(ru[0] - ld[0]) * abs(ru[1] - ld[1])
print(ans)

Solution (Python):
def area(x1,y1,x2,y2):
    if x1 >= x2 or y1 >= y2:
        ans = 0
    else:
        ans = (x2-x1)*(y2-y1)
    return(ans)
w,h,n = map(int,input().split())
xy = [0]*n
for i in range(n):
    xy[i] = list(map(int,input().split()))

x1,y1 = 0,0
x2,y2 = w,h
for x,y,a in xy:
    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)
print(area(x1,y1,x2,y2))

Solution (Python):
W, H, count = map(int, input().split(" "))
W0 = 0
H0 = 0

li = [list(map(int, input().split(" "))) for s in range(count)]

for i in li:
  if i[2] == 1:
    if i[0] > W0:
      W0 = i[0]
  elif i[2] == 2:
    if i[0] < W:
      W = i[0]
  elif i[2] == 3:
    if i[1] > H0:
      H0 = i[1]
  elif i[2] == 4:
    if i[1] < H:
      H = i[1]
      
if W - W0 <= 0 or H - H0 <= 0:
  print(0)
else:
  print((W - W0) * (H - H0))

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

if right_x - left_x > 0 and up_y - down_y > 0:
    ans = (right_x - left_x) * (up_y - down_y)
else:
    ans = 0
print(ans)

Solution (Python):


w, h, n = map(int, input().split())
area = [[0] * 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(w):
                if j < x:
                    area[i][j] = 1

    if a == 2:
        for i in range(h):
            for j in range(w):
                if j >= x:
                    area[i][j] = 1

    if a == 3:
        for i in range(h):
            for j in range(w):
                if i < y:
                    area[i][j] = 1

    if a == 4:
        for i in range(h):
            for j in range(w):
                if i >= y:
                    area[i][j] = 1

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

print(ans)

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

x_lt = 0
x_rt = W

y_lt = 0
y_rt = H

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x_lt = max(x, x_lt)
    elif a == 2:
        x_rt = min(x, x_rt)
    elif a == 3:
        y_lt = max(y, y_lt)
    else:
        y_rt = min(y, y_rt)

res = max(x_rt - x_lt, 0) * max(y_rt - y_lt, 0)

print(res)

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


for _ in range(N):
    x, y, a = map(int, input().split())
    if a==1:
        if x > D[0]:
            D[0] = x
    if a==2:
        if x < D[1]:
            D[1] = x
    if a==3:
        if y > D[2]:
            D[2] = y
    if a==4:
        if y < D[3]:
            D[3] = y
ANS = (D[1] - D[0])*(D[3] - D[2])
if (D[1] - D[0] < 0) | (D[3] - D[2] < 0):
    ANS = 0
print(ANS)