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

rw = w

rh = h



points = []

for x in range(w):

  rows = []

  for y in range(h):

    rows.append(0)

  points.append(rows)



for i in range(n):

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

  if a == 1:

    for row_index, row in enumerate(points):

      for col_index, col in enumerate(row):

        if row_index < x:

          points[row_index][col_index] = 1

  if a == 2:

    for row_index, row in enumerate(points):

      for col_index, col in enumerate(row):

        if row_index >= x:

          points[row_index][col_index] = 1

  if a == 3:

    for row_index, row in enumerate(points):

      for col_index, col in enumerate(row):

        if col_index < y:

          points[row_index][col_index] = 1

  if a == 4:

    for row_index, row in enumerate(points):

      for col_index, col in enumerate(row):

        if col_index >= y:

          points[row_index][col_index] = 1



count = 0

for row_index, row in enumerate(points):

  for col_index, col in enumerate(row):

    if points[row_index][col_index] == 0:

      count += 1

print(count)
def main():

  w, h, n = input_list()

  

  points = []

  for x in range(w):

    row = [True]*h

    points.append(row)

      

  for _ in range(n):

    x, y, a = input_list()

    if a == 1:

      for px, row in enumerate(points):

        for py, v in enumerate(row):

          if px+1 <= x:

            points[px][py] = False

    if a == 2:

      for px, row in enumerate(points):

        for py, v in enumerate(row):

          if px+1 > x:

            points[px][py] = False

    if a == 3:

      for px, row in enumerate(points):

        for py, v in enumerate(row):

          if py+1 <= y:

            points[px][py] = False

    if a == 4:

      for px, row in enumerate(points):

        for py, v in enumerate(row):

          if py+1 > y:

            points[px][py] = False

  ans = 0

  for p in points:

    ans += p.count(True)

  print(ans)



def input_list():

  return list(map(int, input().split()))



import math

main()
w, h, n = list(map(int, input().split()))
rw = w
rh = h
points = []
for x in range(w):
    rows = []
    for y in range(h):
        rows.append(0)
    points.append(rows)
for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        for row_index, row in enumerate(points):
            for col_index, col in enumerate(row):
                if row_index < x:
                    points[row_index][col_index] = 1
    if a == 2:
        for row_index, row in enumerate(points):
            for col_index, col in enumerate(row):
                if row_index >= x:
                    points[row_index][col_index] = 1
    if a == 3:
        for row_index, row in enumerate(points):
            for col_index, col in enumerate(row):
                if col_index < y:
                    points[row_index][col_index] = 1
    if a == 4:
        for row_index, row in enumerate(points):
            for col_index, col in enumerate(row):
                if col_index >= y:
                    points[row_index][col_index] = 1
count = 0
for row_index, row in enumerate(points):
    for col_index, col in enumerate(row):
        if points[row_index][col_index] == 0:
            count += 1
print(count)

def main():
    w, h, n = input_list()
    points = []
    for x in range(w):
        row = [True] * h
        points.append(row)
    for _ in range(n):
        x, y, a = input_list()
        if a == 1:
            for px, row in enumerate(points):
                for py, v in enumerate(row):
                    if px + 1 <= x:
                        points[px][py] = False
        if a == 2:
            for px, row in enumerate(points):
                for py, v in enumerate(row):
                    if px + 1 > x:
                        points[px][py] = False
        if a == 3:
            for px, row in enumerate(points):
                for py, v in enumerate(row):
                    if py + 1 <= y:
                        points[px][py] = False
        if a == 4:
            for px, row in enumerate(points):
                for py, v in enumerate(row):
                    if py + 1 > y:
                        points[px][py] = False
    ans = 0
    for p in points:
        ans += p.count(True)
    print(ans)


def input_list():
    return list(map(int, input().split()))


import math

main()

-w, h, n = list(map(int, input().split())) -rw = w -rh = h -points = [] -for x in range(w): -    rows = [] -    for y in range(h): -        rows.append(0) -    points.append(rows) -for i in range(n): -    x, y, a = list(map(int, input().split())) -    if a == 1: -        for row_index, row in enumerate(points): -            for col_index, col in enumerate(row): -                if row_index < x: -                    points[row_index][col_index] = 1 -    if a == 2: -        for row_index, row in enumerate(points): -            for col_index, col in enumerate(row): -                if row_index >= x: -                    points[row_index][col_index] = 1 -    if a == 3: -        for row_index, row in enumerate(points): -            for col_index, col in enumerate(row): -                if col_index < y: -                    points[row_index][col_index] = 1 -    if a == 4: -        for row_index, row in enumerate(points): -            for col_index, col in enumerate(row): -                if col_index >= y: -                    points[row_index][col_index] = 1 -count = 0 -for row_index, row in enumerate(points): -    for col_index, col in enumerate(row): -        if points[row_index][col_index] == 0: -            count += 1 -print(count) +def main(): +    w, h, n = input_list() +    points = [] +    for x in range(w): +        row = [True] * h +        points.append(row) +    for _ in range(n): +        x, y, a = input_list() +        if a == 1: +            for px, row in enumerate(points): +                for py, v in enumerate(row): +                    if px + 1 <= x: +                        points[px][py] = False +        if a == 2: +            for px, row in enumerate(points): +                for py, v in enumerate(row): +                    if px + 1 > x: +                        points[px][py] = False +        if a == 3: +            for px, row in enumerate(points): +                for py, v in enumerate(row): +                    if py + 1 <= y: +                        points[px][py] = False +        if a == 4: +            for px, row in enumerate(points): +                for py, v in enumerate(row): +                    if py + 1 > y: +                        points[px][py] = False +    ans = 0 +    for p in points: +        ans += p.count(True) +    print(ans) + + +def input_list(): +    return list(map(int, input().split())) + + +import math + +main()