

def re(x,y,a,rect):

    if a==1:

        for i in range(1,len(rect)):

            rect[i][1:x+1]=[0]*x

    elif a==2:

        for i in range(1,len(rect)):

            rect[i]=rect[i][:x+1]+[0]*(len(rect[i])-x-1)

    elif a==3:

        for i in range(1,y+1):

            rect[i]=[0]*(len(rect[y]))

    else:

        for i in range(y+1,len(rect)):

            rect[i]=[0]*(len(rect[y]))

        

    return rect







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

rect=[[0]*(w+1)]

for i in range(h):

    rect+=[[0]+[1]*w]



for j in range(n):

    x,y,a=list(map(int,input().split()))

    rect=re(x,y,a,rect)





cnt=0

for k in range(h+1):

    cnt+=sum(rect[k])

print(cnt)



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

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

for i in range(n):

    x,y,a=list(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)

print((max(0,right-left)*max(0,up-down)))
def re(x, y, a, rect):
    if a == 1:
        for i in range(1, len(rect)):
            rect[i][1 : x + 1] = [0] * x
    elif a == 2:
        for i in range(1, len(rect)):
            rect[i] = rect[i][: x + 1] + [0] * (len(rect[i]) - x - 1)
    elif a == 3:
        for i in range(1, y + 1):
            rect[i] = [0] * (len(rect[y]))
    else:
        for i in range(y + 1, len(rect)):
            rect[i] = [0] * (len(rect[y]))
    return rect


w, h, n = list(map(int, input().split()))
rect = [[0] * (w + 1)]
for i in range(h):
    rect += [[0] + [1] * w]
for j in range(n):
    x, y, a = list(map(int, input().split()))
    rect = re(x, y, a, rect)
cnt = 0
for k in range(h + 1):
    cnt += sum(rect[k])
print(cnt)

w, h, n = list(map(int, input().split()))
left, right, down, up = 0, w, 0, h
for i in range(n):
    x, y, a = list(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)
print((max(0, right - left) * max(0, up - down)))

-def re(x, y, a, rect): +w, h, n = list(map(int, input().split())) +left, right, down, up = 0, w, 0, h +for i in range(n): +    x, y, a = list(map(int, input().split())) -        for i in range(1, len(rect)): -            rect[i][1 : x + 1] = [0] * x +        left = max(left, x) -        for i in range(1, len(rect)): -            rect[i] = rect[i][: x + 1] + [0] * (len(rect[i]) - x - 1) +        right = min(right, x) -        for i in range(1, y + 1): -            rect[i] = [0] * (len(rect[y])) -    else: -        for i in range(y + 1, len(rect)): -            rect[i] = [0] * (len(rect[y])) -    return rect - - -w, h, n = list(map(int, input().split())) -rect = [[0] * (w + 1)] -for i in range(h): -    rect += [[0] + [1] * w] -for j in range(n): -    x, y, a = list(map(int, input().split())) -    rect = re(x, y, a, rect) -cnt = 0 -for k in range(h + 1): -    cnt += sum(rect[k]) -print(cnt) +        down = max(down, y) +    elif a == 4: +        up = min(up, y) +print((max(0, right - left) * max(0, up - down)))