import itertools



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

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

res=[[True for j in range(H)] for i in range(W)]

for j in range(H):

    for i in range(W):

        for k in range(N):

            if (i<xya[k][0] and xya[k][2]==1) or (i>=xya[k][0] and xya[k][2]==2) or (j<xya[k][1] and xya[k][2]==3) or (j>=xya[k][1] and xya[k][2]==4):

                res[i][j]=False

                break

res2=list(itertools.chain.from_iterable(res))



print((res2.count(True)))

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

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



first=[0,0]

last=[W,H]



for i in range(N):

    if first[0]<xya[i][0] and xya[i][2]==1:

        first[0]=xya[i][0]

    if last[0]>xya[i][0] and xya[i][2]==2:

        last[0]=xya[i][0]

    if first[1]<xya[i][1] and xya[i][2]==3:

        first[1]=xya[i][1]

    if last[1]>xya[i][1] and xya[i][2]==4:

        last[1]=xya[i][1]



area=0

if last[0]<=first[0] or last[1]<=first[1]:

    pass

else:

    area=(last[0]-first[0])*(last[1]-first[1])



print(area)

import itertools

W, H, N = list(map(int, input().split()))
xya = [list(map(int, input().split())) for i in range(N)]
res = [[True for j in range(H)] for i in range(W)]
for j in range(H):
    for i in range(W):
        for k in range(N):
            if (
                (i < xya[k][0] and xya[k][2] == 1)
                or (i >= xya[k][0] and xya[k][2] == 2)
                or (j < xya[k][1] and xya[k][2] == 3)
                or (j >= xya[k][1] and xya[k][2] == 4)
            ):
                res[i][j] = False
                break
res2 = list(itertools.chain.from_iterable(res))
print((res2.count(True)))

W, H, N = list(map(int, input().split()))
xya = [list(map(int, input().split())) for i in range(N)]
first = [0, 0]
last = [W, H]
for i in range(N):
    if first[0] < xya[i][0] and xya[i][2] == 1:
        first[0] = xya[i][0]
    if last[0] > xya[i][0] and xya[i][2] == 2:
        last[0] = xya[i][0]
    if first[1] < xya[i][1] and xya[i][2] == 3:
        first[1] = xya[i][1]
    if last[1] > xya[i][1] and xya[i][2] == 4:
        last[1] = xya[i][1]
area = 0
if last[0] <= first[0] or last[1] <= first[1]:
    pass
else:
    area = (last[0] - first[0]) * (last[1] - first[1])
print(area)

-import itertools - -res = [[True for j in range(H)] for i in range(W)] -for j in range(H): -    for i in range(W): -        for k in range(N): -            if ( -                (i < xya[k][0] and xya[k][2] == 1) -                or (i >= xya[k][0] and xya[k][2] == 2) -                or (j < xya[k][1] and xya[k][2] == 3) -                or (j >= xya[k][1] and xya[k][2] == 4) -            ): -                res[i][j] = False -                break -res2 = list(itertools.chain.from_iterable(res)) -print((res2.count(True))) +first = [0, 0] +last = [W, H] +for i in range(N): +    if first[0] < xya[i][0] and xya[i][2] == 1: +        first[0] = xya[i][0] +    if last[0] > xya[i][0] and xya[i][2] == 2: +        last[0] = xya[i][0] +    if first[1] < xya[i][1] and xya[i][2] == 3: +        first[1] = xya[i][1] +    if last[1] > xya[i][1] and xya[i][2] == 4: +        last[1] = xya[i][1] +area = 0 +if last[0] <= first[0] or last[1] <= first[1]: +    pass +else: +    area = (last[0] - first[0]) * (last[1] - first[1]) +print(area)