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-----
5 4 2
2 1 1
3 3 4

-----Sample Output-----
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.

Difficulty: introductory

Starter code:

Solutions:
def main():
    w, h, n = list(map(int, input().split()))

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

    for _ in range(n):
        x, y, a = list(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((
        (x_max - x_min) * (y_max - y_min)
        if x_min < x_max and y_min < y_max else 0
    ))


def __starting_point():
    main()

__starting_point()

W,H,N=map(int,input().split())
A,B,C,D=[0],[W],[0],[H]

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        A.append(x)
    elif a==2:
        B.append(x)
    elif a==3:
        C.append(y)
    elif a==4:
        D.append(y)

W=min(B)-max(A)
H=min(D)-max(C)

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

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



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.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y1.append(y)
  elif a == 4:
    y2.append(y)

left = max(x1)
right = min(x2)
bottom = max(y1)
top = min(y2)

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

# coding = SJIS

w, h, n = map(int, input().split())
points = []
area = [0, w, 0, h]

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

for i in range(n):
    if points[i][2] == 1:
        area[0] = max(area[0], points[i][0])
    if points[i][2] == 2:
        area[1] = min(area[1], points[i][0])
    if points[i][2] == 3:
        area[2] = max(area[2], points[i][1])
    if points[i][2] == 4:
        area[3] = min(area[3], points[i][1])

ans = max(0, (area[1] - area[0])) * max(0, (area[3] - area[2]))

print(ans)

W,H,N=map(int,input().split())
l,r,b,t=0,W,0,H
for _ in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        l=max(l,x)
    elif a==2:
        r=min(r,x)
    elif a==3:
        b=max(b,y)
    else:
        t=min(t,y)
if l<r and b<t:
    print((r-l)*(t-b))
else:
    print(0)

w,h,n=map(int,input().split())
s=0
b=w
t=0
c=h

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    s=max(s,x)
  elif a==2:
    b=min(b,x)
  elif a==3:
    t=max(t,y)
  else:
    c=min(c,y)
if b>s and c>t:
   print((b-s)*(c-t))
else:
  print(0)

import numpy as np


def main():
    w, h, n = list(map(int, input().split()))
    xyas = [list(map(int, input().split())) for _ in range(n)]
    board = np.array([[0 for i in range(w)] for j in range(h)])
    for x, y, a in xyas:
        if a == 1:
            board[:, :x] = 1
        elif a == 2:
            board[:, x:] = 1
        elif a == 3:
            board[-y:, :] = 1
        elif a == 4:
            board[:-y, :] = 1
    ans = (w*h) - np.sum(board)
    print(ans)


def __starting_point():
    main()

__starting_point()

W,H,N = map(int,input().split())
a = []
for i in range(N):
    b = list(map(int,input().split()))
    a.append(b)
xs = 0
xe = W
ys = 0
ye = H
for i in range(N):
    if a[i][2] == 1 and xs < a[i][0]:
        xs = a[i][0]
    elif a[i][2] == 2 and xe > a [i][0]:
        xe = a[i][0]
    elif a[i][2] == 3 and ys < a[i][1]:
        ys = a[i][1]
    elif a[i][2] == 4 and ye > a[i][1]:
        ye = a[i][1]
if xs < xe:
    w = xe - xs
else:
    w = 0
if ys < ye:
    h = ye - ys
else:
    h = 0
print(w*h)

w,h,n = map(int, input().split())
x1 = [0] #1 left border of white area
x2 = [w] #2
y1 = [0] #3
y2 = [h] #4
for i in range(n):
  x,y,a = map (int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y1.append(y)
  elif a ==4:
    y2.append(y)

left = max(x1)
right = min(x2)
bottom = max(y1)
top = min(y2)


ans =max(0, right - left)*max(0, top - bottom)

print(ans)

W, H, N  = map(int,input().split()) 
l = 0; r = W; u = H; d = 0 

for i in range(N):
    x, y, a = map(int,input().split()) 
    if a == 1:
        l = max(l,x) 
    elif a == 2:
        r = min(r,x) 
    elif a == 3:
        d = max(d,y) 
    else:
        u = min(u,y) 

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

w, h, n = map(int,input().split())
L = [list(map(int,input().split())) for i in range(n)]
x1 = 0
x2 = w
y1 = 0
y2 = h
for i in range(n):
    if L[i][2] == 1:
        x1 = max(L[i][0], x1)
    if L[i][2] == 2:
        x2 = min(L[i][0], x2)
    if L[i][2] == 3:
        y1 = max(L[i][1], y1)
    if L[i][2] == 4:
        y2 = min(L[i][1], y2)
        
ans = 0
if x2>=x1 and y2>=y1:
    ans = (x2-x1)*(y2-y1)
print(ans)

w, h, n = list(map(int, input().split()))
x_pos = [0, w]
y_pos = [0, h]
for _ in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        x_pos[0] = max(x_pos[0], x)
    elif a == 2:
        x_pos[1] = min(x_pos[1], x)
    elif a == 3:
        y_pos[0] = max(y_pos[0], y)
    else:
        y_pos[1] = min(y_pos[1], y)
ans = max(0, (x_pos[1] - x_pos[0])) * max(0, (y_pos[1] - y_pos[0]))
print(ans)


W, H, N = list(map(int, input().split()))
bl_x, tr_x, bl_y, tr_y = 0, W, 0, H
for i in range(N):
	x, y, a = list(map(int, input().split()))
	if a == 1:
		bl_x = max(bl_x, x)
	elif a == 2:
		tr_x = min(tr_x, x)
	elif a == 3:
		bl_y = max(bl_y, y)
	elif a == 4:
		tr_y = min(tr_y, y)
print((max(tr_x - bl_x, 0) * max(tr_y - bl_y, 0)))


W, H, N = list(map(int, input().split()))
X_Y_A = [list(map(int, input().split())) for _ in range(N)]
oX = 0
oY = 0
for x, y, a in X_Y_A:
    if a == 1:
        oX = max(x, oX)
    elif a == 2:
        W = min(x, W)
    elif a == 3:
        oY = max(y, oY)
    else:
        H = min(y, H)
# print(W, oX, H, oY)
print((max(0, W-oX)*max(0, H-oY)))


import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


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

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

    for i in range(n):
        x,y,a = i_map()
        if a == 1:
            left = max(left,x)
        elif a == 2:
            right = min(right, x)
        elif a == 3:
            down = max(down, y)
        else:
            up = min(up, y)
    print((max((up-down),0)*max((right-left),0)))

def __starting_point():
    main()

__starting_point()

import sys
imput=sys.stdin.read
w,h,n=map(int,input().split())
t=[list(map(int,input().split())) for i in range(n)]
su=[]
st=[]
sv=[]
sw=[]
sux=svy=0
stx=w
swy=h
for j in range(n):
    if t[j][2]==1:
        su.append(t[j][0])
        sux=max(su)
    elif t[j][2]==2:
        st.append(t[j][0])
        stx=min(st)
    elif t[j][2]==3:
        sv.append(t[j][1])
        svy=max(sv)
    else:
        sw.append(t[j][1])
        swy=min(sw)
if sux-stx>=0 or svy-swy>=0:
    print(0)
else:
    print((stx-sux)*(swy-svy))

w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
x, y, a = zip(*xya)
xl, xr, yb, yt = 0, w, 0, h
for i in range(n):
    if   a[i] == 1: xl = max(xl, x[i])
    elif a[i] == 2: xr = min(xr, x[i])
    elif a[i] == 3: yb = max(yb, y[i])
    else:           yt = min(yt, y[i])
print((xr-xl)*(yt-yb)*(xr>xl and yt>yb))

lst = input().split()

W = int(lst[0])
H = int(lst[1])
N = int(lst[2])

field = [([0] * W)] * H

L = []

for i in range(N):
   L = input().split()
   if L[2] == '1':
      for j in range(H):
         for k in range(int(L[0])):
            field[j][k] = 1
   elif L[2] == '2':
      for j in range(H):
         for k in range(int(L[0]), W):
            field[j][k] = 1
   elif L[2] == '3':
      for j in range(int(L[1])):
         field[j] = [1] * W
   elif L[2] == '4':
      for j in range(int(L[1]), H):
         field[j] = [1] * W

ans = 0

for s in field:
   ans += s.count(0)

print(ans)

import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    w,h,n = LI()
    board = [[1]*h for _ in range(w)]

    for _ in range(n):
        x,y,a = LI()
        if a == 1:
            for i in range(x):
                board[i] = [0 for _ in range(h)]
        elif a == 2:
            for i in range(x,w):
                board[i] = [0 for _ in range(h)]
        elif a == 3:
            for i in range(w):
                for j in range(y):
                    board[i][j] = 0
        elif a == 4:
            for i in range(w):
                for j in range(y,h):
                    board[i][j] = 0

    ans = 0
    for line in board:
        ans += sum(line)

    print(ans)

    # print(*board,sep="\n")
main()            


w,h,n=[int(i) for i in input().split()]
#二次元配列の作成
list_2d=[[0]*w for i in range(h)]


def nurie(x,y,a):
   if a==1:
       for i in range(h):
           for j in range(x):
               list_2d[i][j]=1
   elif a==2:
       for i in range(h):
           for j in range(x,w):
               list_2d[i][j]=1
               

   elif a==3:
       for i in range(y):
           for j in range(w):
               list_2d[i][j]=1
              
   else:
       for i in range(y,h):
           for j in range(w):
               list_2d[i][j]=1
   return list_2d
               
for i in range(n):
   x,y,a=[int(i) for i in input().split()]
   nurie(x,y,a)
   
sum=0
for i in range(h):
   sum+=list_2d[i].count(0)
   
print(sum)

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)
  else:
    y2 = min(y2,y)
if x1 >= x2 or y1 >= y2:
  print(0)
else:
  print(w*h-h*(x1+w-x2)-(x2-x1)*(y1+h-y2))

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

w, h, n = list(map(int, input().split()))
r_w = w
l_w = 0
u_h = h
d_h = 0

for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        l_w = max(l_w, x)
    elif a == 2:
        r_w = min(r_w, x)
    elif a == 3:
        d_h = max(d_h, y)
    elif a == 4:
        u_h = min(u_h, y)

res = max(0, r_w - l_w) * max(0, u_h - d_h)
print(res)


w,h,n = map(int,input().split())
data = list(input().split() for i in range(n))
x_1 = 0
x_2 = w
y_1 = 0
y_2 = h
for i in range(n):
    if int(data[i][2]) == 1:
        if int(data[i][0]) > x_1:
            x_1 = int(data[i][0])
    elif int(data[i][2]) == 2:
        if int(data[i][0]) < x_2:
            x_2 = int(data[i][0])
    elif int(data[i][2]) == 3:
        if int(data[i][1]) > y_1:
            y_1 = int(data[i][1])
    else:
        if int(data[i][1]) < y_2:
            y_2 = int(data[i][1])
if x_2 - x_1 <= 0 or y_2 - y_1 <= 0:
    print(0)
else:
    print((x_2 - x_1) * (y_2 - y_1))

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

ans=[0,W,0,H]

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

S=(ans[1]-ans[0])*(ans[3]-ans[2])  

if (ans[1]-ans[0])<0:
    print((0))
elif (ans[3]-ans[2])<0:
    print((0))
else:
    print(S)


W, H, N  = map(int,input().split()) 
l = 0; r = W; u = H; d = 0 

for i in range(N):
    x, y, a = map(int,input().split()) 
    if a == 1:
        l = max(l,x) 
    elif a == 2:
        r = min(r,x) 
    elif a == 3:
        d = max(d,y) 
    else:
        u = min(u,y) 

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

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())
    
xmin = 0
xmax = W
ymin = 0
ymax = H

for i in range(N):
    if a[i] == 1:
        xmin = max(x[i], xmin)
    elif a[i] == 2:
        xmax = min(x[i], xmax)
    elif a[i] == 3:
        ymin = max(y[i], ymin)
    else:
        ymax = min(y[i], ymax)

height = ymax - ymin
width = xmax - xmin

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

W,H,N= list(map(int,input().split()))
Black = [[True for _ in range(W)] for i in range(H)]
for i in range(N):
    x,y,a = list(map(int,input().split()))
    for j in range(H):
        for k in range(W):
            if a == 1:
                if k < x:
                    Black[j][k] = False
            elif a == 2:
                if k >= x:
                    Black[j][k] = False
            elif a == 3:
                if j < y:
                    Black[j][k] = False
            elif a == 4:
                if j >= y:
                    Black[j][k] = False
                    #print(Black)

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





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

list = [0, w, 0, h]

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

if list[0] > list[1] or list[2] > list[3]:
    print(0)
else:
    print((list[0] - list[1]) * (list[2] - list[3]))

w, h, n = list(map(int, input().split()))
sw = 0
sh = 0
for _ in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        sw = max(sw, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        sh = max(sh, y)
    elif a == 4:
        h = min(h, y)
if sw < w and sh < h:
    print(((w-sw) * (h-sh)))
else:
    print((0))


#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-10-09 21:12:23 +0900
# LastModified: 2020-10-09 21:32:50 +0900
#


import os
import sys
import numpy as np
# import pandas as pd


def main():
    W, H, N = list(map(int, input().split()))
    square = [[0, W], [0, H]]
    for _ in range(N):
        x, y, a = list(map(int, input().split()))
        if a == 1 and square[0][0] < x:
            square[0][0] = x

        elif a == 2 and square[0][1] > x:
            square[0][1] = x

        elif a == 3 and square[1][0] < y:
            square[1][0] = y

        elif a == 4 and square[1][1] > y:
            square[1][1] = y

    if square[0][0] >= square[0][1] or \
            square[1][0] >= square[1][1]:
        print((0))
        return
    print(((square[0][1]-square[0][0])*(square[1][1]-square[1][0])))


def __starting_point():
    main()

__starting_point()

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

xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):

    if array[i][2] == 1:
        xmin = max(xmin, array[i][0])
    elif array[i][2] == 2:
        xmax = min(xmax, array[i][0])
    elif array[i][2] == 3:
        ymin = max(ymin, array[i][1])
    elif array[i][2] == 4:
        ymax = min(ymax, array[i][1])
area = (xmax-xmin)*(ymax-ymin)
if area <= 0 or xmax < xmin or ymax < ymin:
    print(0)
else:
    print(area)

#!/usr/bin/env python3


def main():
    W, H, N = list(map(int, input().split()))
    X = Y = 0
    for i in range(N):
        x, y, a = list(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)))


main()


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

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


url = "https://atcoder.jp//contests/abc047/tasks/abc047_b"

def main():
    w, h, n = list(map(int, input().split()))
    xya = [list(map(int, input().split())) for _ in range(n)]
    x, y = [0, w], [0, h]
    for low in xya:
        if low[2] == 1 and x[0] < low[0]:
            x[0] = low[0]
        elif low[2] == 2 and x[1] > low[0]:
            x[1] = low[0]
        elif low[2] == 3 and y[0] < low[1]:
            y[0] = low[1]
        elif low[2] == 4 and y[1] > low[1]:
            y[1] = low[1]
    xs = x[1] - x[0]
    ys = y[1] - y[0]
    if xs < 0 or ys < 0:
        print((0))
    else:
        ans = xs * ys
        print(ans)



def __starting_point():
    main()

__starting_point()

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

sx = [0, w]
sy = [0, h]

for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        sx[0] = max(sx[0], x)
    if a == 2:
        sx[1] = min(sx[1], x)
    if a == 3:
        sy[0] = max(sy[0], y)
    if a == 4:
        sy[1] = min(sy[1], y)

print((max(0, max(0, (sx[1] - sx[0])) * max(0, (sy[1] - sy[0])))))


W, H, N = [int(x) for x in input().split()]

x_min = 0
x_max = W
y_min = 0
y_max = H

for i in range(N):
    x, y, a = [int(x) for x in 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: # a == 4
        y_max = min(y_max, y)

area = max(0, x_max - x_min) * max(0, y_max - y_min)

print(area)

whn = list(map(int, input().split()))
w, h, n = whn[0], whn[1], whn[2]
xyas = [list(map(int, input().split())) for _ in range(n)]
c = [[1 for _ in range(h)] for _ in range(w)]
# 塗りつぶされた部分を1にしていく
for xya in xyas:
    x, y, a = xya[0], xya[1], xya[2]
    if a == 1:
        for i in range(x):
            c[i] = [0 for _ in range(h)]
    elif a == 2:
        for i in range(x, w):
            c[i] = [0 for _ in range(h)]
    elif a == 3:
        for i in range(w):
            for j in range(y):
                c[i][j] = 0
    elif a == 4:
        for i in range(w):
            for j in range(y, h):
                c[i][j] = 0

print((sum([sum(c2) for c2 in c])))


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

# 左下の座標
X=Y=0

for i in range(N):
  # 入力
  x,y,a=list(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)))
        


w,h,n = map(int,input().split())
chk = [0]*101
wx = [1]*w
wy = [1]*h
for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        wx[:x] = chk[:x]
    elif a==2:
        wx[x:] = chk[x+1:w-1]
    elif a==3:
        wy[:y] = chk[:y]
    else:
        wy[y:] = chk[y+1:h-1]
ws = wx.count(1)*wy.count(1)

print(ws)

w,h,n = map(int,input().split())
b,c,d,e = 0,w,0,h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b = max(b,x)
    elif a == 2:
        c = min(c,x)
    elif a == 3:
        d = max(d,y)
    else:
        e = min(e,y)
print(max(c-b,0)*max(e-d,0))

w,h,n = list(map(int,input().split()))
xl = []
yl = []
al = []
for _ in range(n):
  x,y,a = list(map(int,input().split()))
  xl.append(x)
  yl.append(y)
  al.append(a)

sx = 0
gx = w
sy = 0
gy = h

for i in range(len(al)):
  if al[i] == 1 and sx < xl[i]:
      sx = xl[i]
      if sx > gx:
        print((0))
        return
  elif al[i] == 2 and gx > xl[i]:
      gx = xl[i]
      if sx > gx:
        print((0))
        return
  elif al[i] == 3 and sy < yl[i]:
      sy = yl[i]
      if sy > gy:
        print((0))
        return
  elif al[i] == 4 and gy > yl[i]:
      gy = yl[i]
      if sy > gy:
        print((0))
        return
  if i == len(al)-1:
    print(((gx-sx)*(gy-sy)))
    


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:
        p.append(x)
    elif a == 2:
        q.append(x)
    elif a == 3:
        r.append(y)
    else:
        s.append(y)
if max(p) <= min(q) and max(r) <= min(s):
    print((min(q) - max(p))*(min(s) - max(r)))
else:
    print(0)

w,h,n=list(map(int,input().split()))
i,j=0,0
for _ in range(n):
    x,y,a=list(map(int,input().split()))
    if a==1:
        i=max(i,x)
    elif a==2:
        w=min(w,x)
    elif a==3:
        j=max(j,y)
    else:
        h=min(h,y)
print(((w-i)*(h-j) if w>i and h>j else 0))


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

w_min, w_max, h_min, h_max = 0, w, 0, h

for i in range(n):
    if plots[i][2] == 1:
        w_min = max(w_min, plots[i][0])
    elif plots[i][2] == 2:
        w_max = min(w_max, plots[i][0])
    elif plots[i][2] == 3:
        h_min = max(h_min, plots[i][1])
    else:
        h_max = min(h_max, plots[i][1])

print((max(0, (w_max - w_min)) * max(0, (h_max - h_min))))


w , h , n=map(int, input().split())
W = [1]*w
H = [1]*h

for i in range(n):
    x,y,a=map(int, input().split())
    if a == 1:
        for i in range(x):
            W[i] = 0
    if a == 2 :
        for i in range(x,w):
            W[i] = 0
    if a == 3:
        for i in range(y):
            H[i] = 0
    if a == 4:
        for i in range(y,h):
            H[i] = 0
print(sum(W)*sum(H))

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

cnt = 0
for i in ans:
  cnt += sum(i)
print((h*w - cnt))


num_line = input().split(" ")
x_num = int(num_line[0])
y_num = int(num_line[1])
num = int(num_line[2])

tangle = [[1]*x_num for i in range(y_num)]

#print(tangle)

for i in range(num):
    line = input().split(" ")
    x_tem = int(line[0])
    y_tem = int(line[1])
    index = int(line[2])
    
    if(index == 1):
        for j in range(y_num):
            for k in range(x_tem):
                tangle[j][k] = 0
        #print(tangle)            
        
    elif(index == 2):
        for j in range(y_num):
            for k in range(x_num - x_tem):
                tangle[j][k + x_tem] = 0
        #print(tangle)
        
    elif(index == 3):
        for j in range(y_tem):
            for k in range(x_num):
                tangle[j][k] = 0
        #print(tangle)
        
    else:
        for j in range(y_num - y_tem):
            for k in range(x_num):
                tangle[j + y_tem][k] = 0
        #print(tangle)
        
result = 0
for i in range(y_num):
    for j in range(x_num):
        result += tangle[i][j]
        
print(result)

w, h, n = list(map(int, input().split()))
ans = [[0 for _ in range(w)] for _ in range(h)]
for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        for j in range(h):
            ans[j][:x] = [1 for _ in range(x)]
    if a == 2:
        for j in range(h):
            ans[j][x:] = [1 for _ in range(w-x)]
    if a == 3:
        for j in range(h-y,h):
            ans[j] = [1 for _ in range(w)]
    if a == 4:
        for j in range(h-y):
            ans[j] = [1 for _ in range(w)]
cnt = 0
for k in ans:
    cnt += k.count(0)
print(cnt)


import numpy as np
W,H,N = list(map(int, input().split()))
X = [[0 for _ in range(W)] for  _ in range(H)]
for i in range(N):
    x,y,a = list(map(int,input().split()))
    if a == 1:#より左黒
        for j in range(H):
            X[j][:x] = [1 for _ in range(x)]
    elif a == 2:
        for j in range(H):
            X[j][x:] = [1 for _ in range(W-x)]
    elif a == 3:#より下黒
        for j in range(H-y,H):
            X[j] = [1 for _ in range(W)]
    else:
        for j in range(H-y):
            X[j] = [1 for _ in range(W)]
ans = 0
for k in X:
    ans += k.count(0)
print(ans)


import numpy as np

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)

S=max((W-X),0)*max((H-Y),0)

print(S)

w, h, n = map(int, input().split())
l = [[0]*w for _ in range(h)]
count = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(h):
            for j in range(x):
                if l[i][j] == 0:
                    l[i][j] = 1
                    count += 1
    if a == 2:
        for i in range(h):
            for j in range(x,w):
                if l[i][j] == 0:
                    l[i][j] = 1
                    count += 1
    if a == 3:
        for i in range(y):
            for j in range(w):
                if l[i][j] == 0:
                    l[i][j] = 1
                    count += 1
    if a == 4:
        for i in range(y,h):
            for j in range(w):
                if l[i][j] == 0:
                    l[i][j] = 1
                    count += 1

print(w*h - count)           

w,h,n=list(map(int,input().split()))
ox,oy=0,0
for i in range(n):
    x,y,a=list(map(int,input().split()))
    if a==1:
        if ox<x:
            ox=x
    elif a==2:
        if w>x:
            w=x
    elif a==3:
        if oy<y:
            oy=y
    else:
        if h>y:
            h=y
print((max(w-ox,0)*max(h-oy,0)))


class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i - 1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n - m] * self.finv[m] % self.mod) % self.mod
        
def iparse():
    return list(map(int, input().split()))


def __starting_point():
    w, h, n = iparse()
    xmax = w
    xmin = 0
    ymin = 0
    ymax = h
    for i in range(n):
        x, y, a = iparse()
        
        if a == 1:
            xmin = max(xmin,x)
        if a == 2:
            xmax = min(xmax,x)
        if a == 3:
            ymin = max(ymin,y)
        if a == 4:
            ymax = min(ymax,y)
        
    print((max(xmax-xmin,0)*(max(0,ymax-ymin))))
__starting_point()

import numpy as np
w, h, n = map(int, input().split())
loc = [input() for _ in range(n) ]

def black(x, y, i):
    if i == 1:
        mtx[:x,] = 0
    elif i == 2:
        mtx[x:,] = 0
    elif i == 3:
        mtx[:, :y] = 0
    elif i == 4:
        mtx[:, y:] = 0

        
mtx = np.ones((w, h), dtype=int)
for l in loc:
    x, y, i = map(int, l.split())
    black(x, y, i)
print(mtx.sum())

w,h,n=map(int,input().split())
a=[[int(i)for i in input().split()]for j in range(n)]
S=[[0,w],[0,h]]
for i in a:
    if i[2]==1:
        S[0][0]=max(i[0],S[0][0])

    if i[2]==2:
        S[0][1]=min(i[0],S[0][1])

    if i[2]==3:
        S[1][0]=max(i[1],S[1][0])

    if i[2]==4:
        S[1][1]=min(i[1],S[1][1])

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

W, H, N = [int(x) for x in input().split()]
x_min, x_max, y_min, y_max = 0, W, 0, H
num_lists = [[int(x) for x in input().split()] for _ in range(N)]

for num_list in num_lists:
    if num_list[2] == 1 and num_list[0] > x_min:
        x_min = num_list[0]
    if num_list[2] == 2 and num_list[0] < x_max:
        x_max = num_list[0]
    if num_list[2] == 3 and num_list[1] > y_min:
        y_min = num_list[1]
    if num_list[2] == 4 and num_list[1] < y_max:
        y_max = num_list[1]

if x_min > x_max or y_min > y_max:
    print(0)
else:
    print((x_max-x_min)*(y_max-y_min))

from typing import List


def answer(w: int, h: int, n: int, xyas: List[List[int]]) -> int:
    bottom_left_corner_of_white = {'x': 0, 'y': 0}
    top_right_corner_of_white = {'x': w, 'y': h}

    for xya in xyas:
        x, y, a = xya
        if a == 1:
            if bottom_left_corner_of_white['x'] < x:
                bottom_left_corner_of_white['x'] = x
        if a == 2:
            if x < top_right_corner_of_white['x']:
                top_right_corner_of_white['x'] = x
        if a == 3:
            if bottom_left_corner_of_white['y'] < y:
                bottom_left_corner_of_white['y'] = y
        if a == 4:
            if y < top_right_corner_of_white['y']:
                top_right_corner_of_white['y'] = y

    width_of_white = max(0, top_right_corner_of_white['x'] - bottom_left_corner_of_white['x'])
    height_of_white = max(0, top_right_corner_of_white['y'] - bottom_left_corner_of_white['y'])

    return width_of_white * height_of_white


def main():
    w, h, n = map(int, input().split())
    xyas = [list(map(int, input().split())) for _ in range(n)]
    print(answer(w, h, n, xyas))


def __starting_point():
    main()
__starting_point()

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

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

ans_w = s_w[1] - s_w[0]
ans_h = s_h[1] - s_h[0]
print((ans_w * (ans_w > 0)) * (ans_h * (ans_h > 0)))

import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


w, h, n = inintm()

ll = [0,0]
rh = [w,h]

for i in range(n):
    x, y, a = inintm()
    if a == 1:
        ll[0] = max(ll[0], x)
    elif a == 2:
        rh[0] = min(rh[0], x)
    elif a == 3:
        ll[1] = max(ll[1], y)
    else:
        rh[1] = min(rh[1], y)

if rh[0]-ll[0] < 0 or rh[1]-ll[1] < 0:
    print(0)
else:
    print((rh[0]-ll[0])*(rh[1]-ll[1]))

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

import sys

input = sys.stdin.readline

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

def __starting_point():
    main()

__starting_point()

w, h, n = map(int, input().split())
right, left, lower, upper = 0, w, 0, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        right = max(right, x)
    if a == 2:
        left = min(left, x)
    if a == 3:
        lower = max(lower, y)
    if a == 4:
        upper = min(upper, y)

a = left - right
b = upper - lower

if a <= 0 or b <= 0:
    print(0)
else:
    print(a*b)

W,H,N = (int(T) for T in input().split())
XYA = [[0],[W],[0],[H]]
for TN in range(0,N):
    X,Y,A = (int(T) for T in input().split())
    if A in [1,2]:
        XYA[A-1].append(X)
    else:
        XYA[A-1].append(Y)
CW = min(XYA[1])-max(XYA[0])
CH = min(XYA[3])-max(XYA[2])
if CW>=0 and CH>=0:
    print(CW*CH)
else:
    print(0)

#
# abc047 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5 4 2
2 1 1
3 3 4"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5 4 3
2 1 1
3 3 4
1 4 2"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3"""
        output = """64"""
        self.assertIO(input, output)


def resolve():
    W, H, N = list(map(int, input().split()))
    a = []
    ox = 0
    oy = 0
    for _ in range(N):
        a.append(list(map(int, input().split())))
    for i in range(N):
        if a[i][2] == 1:
            ox = max(a[i][0], ox)
        elif a[i][2] == 2:
            W = min(a[i][0], W)
        elif a[i][2] == 3:
            oy = max(a[i][1], oy)
        elif a[i][2] == 4:
            H = min(a[i][1], H)
    print((max(W-ox, 0)*max(H-oy, 0)))


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

w, h, n = map(int, input().split())
x_pos = [0, w]
y_pos = [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_pos[0] = max(x_pos[0], x)
    elif a == 2:
        x_pos[1] = min(x_pos[1], x)
    elif a == 3:
        y_pos[0] = max(y_pos[0], y)
    else:
        y_pos[1] = min(y_pos[1], y)
if x_pos[1] - x_pos[0] < 0 or y_pos[1] - y_pos[0] < 0:
    ans = 0
else:
    ans = (x_pos[1] - x_pos[0] ) * (y_pos[1] - y_pos[0])
print(ans)

W,H,N=map(int, input().split())
X=[0,W]
Y=[0,H]

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

if X[1]-X[0]<=0 or Y[1]-Y[0]<=0:
    area=0
else:
    area = max(0,(X[1]-X[0])*(Y[1]-Y[0]))
print(area)

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

W, H, N = map(int, input().split())
u, U, v, V = 0, W, 0, H
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        u = max(u,x)
    if a == 2:
        U = min(U,x)
    if a == 3:
        v = max(v,y)
    if a == 4:
        V = min(V,y)
f = lambda x:x if x > 0 else 0
print(f(U-u)*f(V-v))

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

a1,a2,a3,a4 = -1,101,-1,101
for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    a1 = max(a1,x)
  elif a == 2:
    a2 = min(a2,x-1)
  elif a == 3:
    a3 = max(a3,y)
  else:
    a4 = min(a4,y-1)
    
mass = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
  for j in range(W):
    if i < a3 or a4 < i:
      mass[i][j] += 1
    if j < a1 or a2 < j:
      mass[i][j] += 1
      
cnt = 0
for k in mass:
  cnt += k.count(0)
  
print(cnt)

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

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

xl, xr = 0, w
yl, yu = 0, h
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        xl = max(xl, x)
    elif a == 2:
        xr = min(xr, x)
    elif a == 3:
        yl = max(yl, y)
    else:
        yu = min(yu, y)
        
print((xr-xl)*(yu-yl)) if xl < xr and yl < yu else print(0)

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

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

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

w_l = 0
h_l = 0
for i in range(n):
    if a[i] == 1:
        if w_l < x[i]:
            w_l = x[i]
    elif a[i] == 2:
        if w > x[i]:
            w = x[i]
    elif a[i] == 3:
        if h_l < y[i]:
            h_l = y[i]
    elif a[i] == 4:
        if h > y[i]:
            h = y[i]
W = w - w_l
H = h - h_l
if W < 0 or H < 0:
    ans = 0
else:
    ans = W * H
print(ans)

H,W,N=map(int,input().split())
sita,hidari=0,0
ue,migi=W,H
for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    hidari=max(x,hidari)
  elif a==2:
    migi=min(migi,x)
  elif a==3:
    sita=max(sita,y)
  else:
    ue=min(ue,y)
print(max(0,(migi-hidari))*max(0,(ue-sita)))

W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(N)]
X=Y=0
for i in range(N):
    if xya[i][2] == 1:
        X = max(X,xya[i][0])
    if xya[i][2] == 2:
        W = min(W,xya[i][0])
    if xya[i][2] == 3:
        Y = max(Y,xya[i][1])
    if xya[i][2] == 4:
        H = min(H,xya[i][1])
print(max(W-X,0)*max(H-Y,0))

def main():
    W,H,N = list(map(int,input().split()))
    X = 0 #a=1初期値
    Y = 0 #a=3初期値
    for _ in range(N):
        x,y,a = list(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)
        elif a == 4:
            H = min(H,y)
    #Sを求める
    S = max((W-X),0) * max((H-Y),0)
    print(S)
def __starting_point():
    main()


__starting_point()

w,h,n = map(int, input().split())
s = [[1 for i in range(w)] for j in range(h)]
b = [[1,2,3,4,5],[6,7,8,9,10]]
alist = []
for i in range(n):
    x,y,a = map(int, input().split())
    alist.append(a)
    if a == 1:
        for j in range(h):
            for k in range(0,x):
                s[j][k] = 0
    if a == 2:
        for j in range(h):
            for k in range(x,w):
                s[j][k] = 0
    if a == 3:
        for k in range(w):
            for j in range(0,y):
                s[j][k] = 0
    if a == 4:
        for k in range(w):
            for j in range(y,h):
                s[j][k] = 0
ans = 0
for i in range(h):
    ans = ans + s[i].count(1)
print(ans)

W, H, N = map(int, input().split())
x = []
y = []
a = []
X = [1]*W
Y = [1]*H
ans = 0
for _ in range(N):
    i, j, k = map(int, input().split())
    x.append(i)
    y.append(j)
    a.append(k)
for i in range(N):
    if a[i] == 1:
        for j in range(x[i]):
            X[j] = 0
    elif a[i] == 2:
        for j in range(x[i], W):
            X[j] = 0
    elif a[i] == 3:
        for j in range(y[i]):
            Y[j] = 0
    else:
        for j in range(y[i], H):
            Y[j] = 0
for i in range(H):
    for j in range(W):
        if X[j] and Y[i]:
            ans += 1
print(ans)

X, Y, N = list(map(int, input().split()))
lst = [[0 for i in range(X)] for j in range(Y)]

for i in (list(range(N))):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        for j in range(Y):
            for k in range(x):
                lst[j][k] = 1
    elif a == 2:
        for j in range(Y):
            for k in range(X-1, x-1, -1):
                lst[j][k] = 1
    elif a == 3:
        for j in range(y):
            for k in range(X):
                lst[j][k] = 1
    elif a == 4:
        for j in range(Y-1, y-1, -1):
            for k in range(X):
                lst[j][k] = 1

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



import sys
input = sys.stdin.readline


def read():
    W, H, N = list(map(int, input().strip().split()))
    XYA = []
    for i in range(N):
        x, y, a = list(map(int, input().strip().split()))
        XYA.append((x, y, a))
    return W, H, N, XYA


def solve(W, H, N, XYA):
    S = [[0 for j in range(W+1)] for i in range(H+1)]
    for x, y, a in XYA:
        if a == 1:
            lt, rt, lb, rb = (0, 0), (x, 0), (0, H), (x, H)
        elif a == 2:
            lt, rt, lb, rb = (x, 0), (W, 0), (x, H), (W, H)
        elif a == 3:
            lt, rt, lb, rb = (0, 0), (W, 0), (0, y), (W, y)
        elif a == 4:
            lt, rt, lb, rb = (0, y), (W, y), (0, H), (W, H)
        S[lt[1]][lt[0]] += 1
        S[rt[1]][rt[0]] -= 1
        S[lb[1]][lb[0]] -= 1
        S[rb[1]][rb[0]] += 1
    
    for i in range(H):
        for j in range(W+1):
            S[i+1][j] += S[i][j]
    for i in range(H+1):
        for j in range(W):
            S[i][j+1] += S[i][j]
    
    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == 0:
                ans += 1
    return ans


def __starting_point():
    inputs = read()
    print((solve(*inputs)))

__starting_point()

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

w,h,n=map(int,input().split())
answ=set(range(w+1)) 
ansh=set(range(w+1))
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    answ=answ & set(range(x,w+1))
  elif a==2:
    answ=answ & set(range(x+1))
  elif a==3:
    ansh=ansh & set(range(y,h+1))
  elif a==4:
    ansh=ansh & set(range(y+1))
if len(answ) == 0 or len(ansh)==0:
  print(0)
else:
  print((max(answ)-min(answ))*(max(ansh)-min(ansh)))

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

mp = [[0] * h for x in range(w)]

for i in range(n):
  if a[i][2] == 1:
    for j in range(a[i][0]):
      for k in range(h):
        mp[j][k] = 1
  elif a[i][2] == 2:
    for j in range(a[i][0],w):
      for k in range(h):
        mp[j][k] = 1
  elif a[i][2] == 3:
    for j in range(w):
      for k in range(a[i][1]):
        mp[j][k] = 1
  elif a[i][2] == 4:
    for j in range(w):
      for k in range(a[i][1],h):
        mp[j][k] = 1

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

print(res)

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

point_list = []
for h in range(H):
  list_ = []
  for w in range(W):
    list_.append(1)
  point_list.append(list_)

for input_ in input_list:
  x, y, a = input_
  if a == 1:
    for h in range(H):
      for i in range(x):
        point_list[h][i] = 0
  if a == 2:
    for h in range(H):
      for i in range(x, W):
        point_list[h][i] = 0
  if a == 3:
    for i in range(y):
      for w in range(W):
        point_list[i][w] = 0
  if a == 4:
    for i in range(y, H):
      for w in range(W):
        point_list[i][w] = 0

ans = sum([sum(point) for point in point_list])
print(ans)


import sys, math
from itertools import combinations as c, product as p
from collections import deque
sys.setrecursionlimit(10**9)


def si(): return input()
def ii(): return int(input())
def fi(): return float(input())
def lint(): return list(map(int, input().split()))
def lint_dec(): return list(map(lambda x:int(x) - 1, input().split()))
def lnstr(n): return [input() for _ in range(n)]
def lnint(n): return [int(input()) for _ in range(n)]
def lint_list(n): return [lint() for _ in range(n)]



############################################################
W, H, N = lint()
queue = lint_list(N)

xmin = max([x for x, y, a in queue if a == 1] + [0])
xmax = min([x for x, y, a in queue if a == 2] + [W])
ymin = max([y for x, y, a in queue if a == 3] + [0])
ymax = min([y for x, y, a in queue if a == 4] + [H])

print(max(0, xmax - xmin) * max(0, ymax - ymin))

W,H,N=list(map(int,input().split()))
white=[[1 for _ in range(H)] for _ in range(W)]

for i in range(N):
    x,y,a=list(map(int,input().split()))
    if a==1:
        for i in range(x):
            for j in range(H):
                white[i][j]=0
    elif a==2:
        for i in range(x,W):
            for j in range(H):
                white[i][j]=0
    elif a==3:
        for i in range(W):
            for j in range(y):
                white[i][j]=0
    else:
        for i in range(W):
            for j in range(y,H):
                white[i][j]=0
print((sum(sum(x) for x in white)))


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

max_x = 0
max_y = 0
min_x = W
min_y = H
for i in range(N):
    x, y, a = list(map(int, input().split()))
    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)
    else:
        min_y = min(min_y, y)

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


W, H, N = list(map(int, input().split()))
X = []
Y = []
A = []
field = [[0] * W for _ in range(H)]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    X.append(x)
    Y.append(y)
    A.append(a)

for i in range(N):
    if A[i] == 1:
        for j in range(X[i]):
            for k in range(H):
                field[k][j] = 1
    elif A[i] == 2:
        for j in range(X[i], W):
            for k in range(H):
                field[k][j] = 1
    elif A[i] == 3:
        for j in range(W):
            for k in range(Y[i]):
                field[k][j] = 1
    else:
        for j in range(W):
            for k in range(Y[i], H):
                field[k][j] = 1

Sum = 0
for i in range(W):
    for j in range(H):
        if field[j][i] == 0:
            Sum += 1

print(Sum)


w,h,n=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(n)]
 
x,y=0,0
for s,t,u in a:
    if u==1:
        x=max(x,s)
    elif u==2:
        w=min(w,s)
    elif u==3:
        y=max(y,t)
    else:
        h=min(h,t)
height=max(0,h-y)
width=max(0,w-x)
print(height*width)

w,h,n=list(map(int, input().split())) #初期値
lx=0
ly=0
rx=w
ry=h

for i in range(n):
   x,y,a=list(map(int, input().split()))
   
   if a==1:
       if lx<x:
           lx=x
   elif a==2:
       if rx>x:
           rx=x
           
   elif a==3:
       if ly<y:
           ly=y
   
   else:
       if ry>y:
           ry=y
# 出力
print((max(rx-lx,0)*max(ry-ly,0)))


# -*- coding: utf-8 -*-

W, H, N = list(map(int, input().split()))
xs = ys = 0
xe = W
ye = H
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1 and x > xs:
        xs = x
    elif a == 2 and x < xe:
        xe = x
    elif a == 3 and y > ys:
        ys = y
    elif a == 4 and y < ye:
        ye = y

w = xe - xs
h = ye - ys
if w > 0 and h > 0:
    ans = w * h
else:
    ans = 0

print(ans)


w, h, n = map(int, input().split())
x, y, a = [], [], []
for i in range(n):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)
zahyou = [[1 for _ in range(h)] for __ in range(w)]

def m1(d):
    for i in range(d):
        for j in range(h):
            zahyou[i][j] = 0

def m2(d):
    for i in range(w-d):
        for j in range(h):
            zahyou[i+d][j] = 0

def m3(d):
    for i in range(w):
        for j in range(d):
            zahyou[i][j] = 0

def m4(d):
    for i in range(w):
        for j in range(h-d):
            zahyou[i][j+d] = 0

for i in range(n):
    if a[i] == 1:
        m1(x[i])
    elif a[i] == 2:
        m2(x[i])
    elif a[i] == 3:
        m3(y[i])
    else:
        m4(y[i])

print(sum(map(sum,zahyou)))

w, h, n = map(int, input().split())
W = [1] * w
H = [1] * h

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

W,H,N = list(map(int, input().split()))
m = [[0]*W]*H
import numpy as np
arr = np.array(m)

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



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

sx, sy = 0, 0
for x, y, a in query:
    if a == 1:
        sx = max(sx, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        sy = max(sy, y)
    else:
        h = min(h, y)
print(max(0, w - sx) * max(0, h - sy))

import numpy as np

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

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

print(((w*h) - int(area.sum())))


import numpy as np

w,h,n = map(int,input().split())
b = np.zeros((h,w),dtype=np.int)

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b[:,:x] = 1
    elif a == 2:
        b[:,x:] = 1
    elif a == 3:
        b[:y,:] = 1
    else:
        b[y:,:] = 1
print(np.count_nonzero(b < 1))