qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
N,x = map(int,input().split())
a = list(map(int, input().split()))
cnt = 0

if a[0] > x:
    a[0] = x
    cnt = a[0]-x

for i in range(1,N):
    if a[i-1] + a[i] > x:
        cnt += (a[i] - (x - a[i-1]))
        a[i] = x - a[i-1]
        
print(cnt)

# Fixed code:
n, x = map(int, input().split())
a = [0] + list(map(int, input().split()))
cnt = 0
for i in range(n) :
  if(a[i] + a[i+1] > x) :
    cnt += (a[i] + a[i+1]) - x
    a[i+1] -= (a[i] + a[i+1]) - x
print(cnt)
# Buggy code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
count=0
if l[i]>m:
  count+=m-l[i]
  l[i]=m
for i in range(1,n):
  if l[i-1]+l[i]>m:
    count+=l[i]+l[i-1]-m
    l[i]=m-l[i-1]   
print(count)

# Fixed code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
count=0
if l[0]>m:
  count+=-m+l[0]
  l[0]=m
for i in range(1,n):
  if l[i-1]+l[i]>m:
    count+=l[i]+l[i-1]-m
    l[i]=m-l[i-1]   
print(count)
# Buggy code:
n, x = map(int, input().split())
a = input().split()

original_number, min_number = 0, 0

for i in range(n):
  original_number += int(a[i])
  
a[0] = x
for i in range(n - 1):
  if int(a[i]) + int(a[i + 1]) > x:
    while True:
      a[i + 1] = int(a[i + 1]) - 1
      if int(a[i]) + int(a[i + 1]) == x:
        break

for i in range(n):
  min_number += int(a[i])
  
ans = original_number - min_number
print(ans)

# Fixed code:
n, x = map(int, input().split())
a = input().split()

original_number, min_number = 0, 0

for i in range(n):
  original_number += int(a[i])
  
if int(a[0]) > x:
  a[0] = x
for i in range(n - 1):
  if int(a[i]) + int(a[i + 1]) > x:
    a[i + 1] = x - int(a[i])

for i in range(n):
  min_number += int(a[i])
  
ans = original_number - min_number
print(ans)
# Buggy code:
w, h, n = map(int, input().split())
L = []
for i in range(n):
  L.append([int(i) for i in input().split()])
Z = [[1]*w for i in range(h)]

print(Z)

for i in range(n):
  if L[i][2] == 1:
    for j in range(h):
      for k in range(w):
        if k < L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 2:
    for j in range(h):
      for k in range(w):
        if k >= L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 3:
    for j in range(h):
      for k in range(w):
        if j < L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 4:
    for j in range(h):
      for k in range(w):
        if j >= L[i][0]:
          Z[j][k] = 0
print(Z)
          
out = 0
for i in range(h):
  for j in range(w):
    out += Z[i][j]
print(out)

# Fixed code:
w, h, n = map(int, input().split())
L = []
for i in range(n):
  L.append([int(i) for i in input().split()])
Z = [[1]*w for i in range(h)]

for i in range(n):
  if L[i][2] == 1:
    for j in range(h):
      for k in range(w):
        if k < L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 2:
    for j in range(h):
      for k in range(w):
        if k >= L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 3:
    for j in range(h):
      for k in range(w):
        if j < L[i][1]:
          Z[j][k] = 0
  elif L[i][2] == 4:
    for j in range(h):
      for k in range(w):
        if j >= L[i][1]:
          Z[j][k] = 0
          
out = 0
for i in range(h):
  for j in range(w):
    out += Z[i][j]
print(out)
# Buggy code:
whn = list (map(int, input().split()))
x = 0
y = 0

for i in range(whn[2]):
    if x >= whn[0] or y >= whn[1]:
        print(0)
        break
    xya = list(map(int,input().split()))
    if xya[2] == 1:
        x = max(x, xya[0])
    elif xya[2] == 2:
        whn[0] = min(whn[0], xya[0])
    elif xya[2] == 3:
        y = max(y, xya[0])
    else:
        whn[1] = min(whn[1], xya[1])

print((whn[0]-x)*(whn[1]-y))


# Fixed code:
whn = list (map(int, input().split()))
x = 0
y = 0
flag = 0

for i in range(whn[2]):
    xya = list(map(int,input().split()))
    if xya[2] == 1:
        x = max(x, xya[0])
    elif xya[2] == 2:
        whn[0] = min(whn[0], xya[0])
    elif xya[2] == 3:
        y = max(y, xya[1])
    else:
        whn[1] = min(whn[1], xya[1])
    if x >= whn[0] or y >= whn[1]:
        print(0)
        flag += 1
        break
        
if flag == 0:
    print((whn[0]-x)*(whn[1]-y))
# Buggy code:
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())

X1 = 0
X2 = 0
Y1 = 0
Y2 = 0

x1, x2, y1, y2 = 0, 0, 0, 0

X = 0
Y = 0

entire = W * H

for i in range(N):
    if a[i]==1 and X1<x[i]:
        x1 = x[i] * H
        X1 += x[i]
    elif a[i]==2 and X2<(W-x[i]):
        x2 = (W-x[i]) * H
        X2 += W - x[i]
    elif a[i]==3 and Y1<y[i]:
        y1 = y[i] * W
        Y1 += y[i]
    elif a[i]==4 and Y2<(H-y[i]):
        y2 = (H-y[i]) * W
        Y2 += H - y[i]

#if 
#entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))#
#
#if entire<=0:
#    print('0')
#else:
#    print(entire)

if X1 >= X2 or Y1 >= Y2:
    print('0')
else:
    entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))
    print(entire)

# Fixed code:
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())

X1 = 0
X2 = 0
Y1 = 0
Y2 = 0

x1, x2, y1, y2 = 0, 0, 0, 0

X = 0
Y = 0

entire = W * H

for i in range(N):
    if a[i]==1 and X1<x[i]:
        x1 = x[i] * H
        X1 = x[i]
    elif a[i]==2 and X2<(W-x[i]):
        x2 = (W-x[i]) * H
        X2 = W - x[i]
    elif a[i]==3 and Y1<y[i]:
        y1 = y[i] * W
        Y1 = y[i]
    elif a[i]==4 and Y2<(H-y[i]):
        y2 = (H-y[i]) * W
        Y2 = H - y[i]

if (X1 + X2) >= W or (Y1 + Y2) >= H:
    print('0')
else:
    entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))

#if entire<=0:
#    print('0')
#else:
    print(entire)
# Buggy code:
w,h,n=map(int,input().split())
xa=[]
xb=[]
ya=[]
yb=[]
for i in range(n):
  x1,y1,a1=map(int,input().split())
  if a1==1:
    xa.append(x1)
  elif a1==2:
    xb.append(x1)
  elif a1==3:
    ya.append(y1)
  elif a1==4:
    yb.append(y1)

if max(xb)<=max(xa) or max(yb)<=max(ya):
  print(0)
else:
  print((max(xb)-max(xa))*(max(yb)-max(ya)))

# Fixed code:
w,h,n=map(int,input().split())
xa=[0]
xb=[w]
ya=[0]
yb=[h]
for i in range(n):
  x1,y1,a1=map(int,input().split())
  if a1==1:
    xa.append(x1)
  elif a1==2:
    xb.append(x1)
  elif a1==3:
    ya.append(y1)
  elif a1==4:
    yb.append(y1)

if min(xb)<=max(xa) or min(yb)<=max(ya):
  print(0)
else:
  print((min(xb)-max(xa))*(min(yb)-max(ya)))
# Buggy code:
W, H, N = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]

X = [0, W]
Y = [0, H]

for l in lst:
    if l[2] == 1 and X[0] < l[0]:
        X[0] = l[0]
    elif l[2] == 2 and l[0] < X[1]:
        X[1] = l[0]
    elif l[2] == 3 and Y[0] < l[1]:
        Y[0] = l[1]
    elif lst[2] == 4 and l[1] < Y[1]:
        Y[1] = l[1]

width = X[1] - X[0]
height = Y[1] - Y[0]

if width >= 0 and height >= 0:
    print(width * height)
else:
    print(0)

# Fixed code:
W, H, N = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]

W_ = [0, W] 
H_ = [0, H]

for l in lst:
    if l[2] == 1 and W_[0] < l[0]:
        W_[0] = l[0]
    elif l[2] == 2 and l[0] < W_[1]:
        W_[1] = l[0]
    elif l[2] == 3 and H_[0] < l[1]:
        H_[0] = l[1]
    elif l[2] == 4 and l[1] < H_[1]:
        H_[1] = l[1]
        
width = W_[1] - W_[0] if W_[1] - W_[0] > 0 else 0
height = H_[1] - H_[0] if H_[1] - H_[0] > 0 else 0

print(width * height)
# Buggy code:
W, H, N = map(int, input().split())

white = [0, W, 0, H]

points = [[int(i) for i in input().split()] for j in range(N)]

for point in points:
    if point[2] == 1:
        if point[0] > white[0]:
            white[0] = point[0]
    if point[2] == 2:
        if point[0] < white[1]:
            white[1] = point[0]
    if point[2] == 3:
        if point[1] > white[2]:
            white[2] = point[1]
    if point[2] == 4:
        if point[1] < white[3]:
            white[3] = point[1]

w = white[1] - white[0]
h = white[3] - white[2]

if w > 0 and h > 0:
    print(result)
else:
    print(0)

# Fixed code:
W, H, N = map(int, input().split())

white = [0, W, 0, H]

points = [[int(i) for i in input().split()] for j in range(N)]

for point in points:
    if point[2] == 1:
        if point[0] > white[0]:
            white[0] = point[0]
    if point[2] == 2:
        if point[0] < white[1]:
            white[1] = point[0]
    if point[2] == 3:
        if point[1] > white[2]:
            white[2] = point[1]
    if point[2] == 4:
        if point[1] < white[3]:
            white[3] = point[1]

w = white[1] - white[0]
h = white[3] - white[2]

if w > 0 and h > 0:
    print(w * h)
else:
    print(0)
# Buggy code:
inp = list(map(int,input().split()))
left_max=0
right_min=inp[0]
upper_min=inp[1]
lower_max=0

for i in range(inp[2]):
    inin = list(map(int,input().split()))
    if inin[2] == 1 and inin[0]>left_max:
        left_max=inin[0]
    if inin[2] == 2 and inin[0]<right_min:
        right_min=inin[0]
    if inin[2] == 4 and inin[1]<upper_min:
        upper_min=inin[1]
    if inin[2] == 3 and inin[1]>lower_max:
        lower_max=inin[1]

print((right_min-left_max)*(upper_min-lower_max))
  

# Fixed code:
inp = list(map(int,input().split()))
left_max=0
right_min=inp[0]
upper_min=inp[1]
lower_max=0

for i in range(inp[2]):
    inin = list(map(int,input().split()))
    if inin[2] == 1 and inin[0]>left_max:
        left_max=inin[0]
    if inin[2] == 2 and inin[0]<right_min:
        right_min=inin[0]
    if inin[2] == 4 and inin[1]<upper_min:
        upper_min=inin[1]
    if inin[2] == 3 and inin[1]>lower_max:
        lower_max=inin[1]
left_max=min(left_max,right_min)
upper_min=max(upper_min,lower_max)
print((right_min-left_max)*(upper_min-lower_max))
# Buggy code:
# coding: utf-8
W, H, N = map(int, input().split())
max_x, max_y = W, H
min_x, min_y = 0, 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if min_x <= x:
            min_x = x
        elif max_x <= x:
            max_x = 0
    elif a == 2:
        if max_x >= x:
            max_x = x
    elif a == 3:
        if min_y <= y:
            min_y = y
        elif max_y >= y:
            max_y = 0
    else:
        if max_y >= y:
            max_y = y
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)

# Fixed code:
# coding: utf-8
W, H, N = map(int, input().split())
min_x, max_x = 0, W
min_y, max_y = 0, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if max_x <= x:
            min_x, max_x = 0, 0
        elif min_x <= x:
            min_x = x
    elif a == 2:
        if min_x >= x:
            min_x, max_x = 0, 0
        elif x <= max_x:
            max_x = x
    elif a == 3:
        if max_y <= y:
            min_y, max_y = 0, 0
        elif min_y <= y:
            min_y = y
    else:
        if y <= min_y:
            min_y, max_y = 0, 0
        elif y <= max_y:
            max_y = y
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)
# Buggy code:
W, H, N = map(int, input().split())
W0 = 0
H0 = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        W0 = x
    elif a == 2:
        W = x
    elif a == 3:
        H0 = y
    elif a == 4:
        H = y
if W-W0 < 0 or H-H0 <0:
    print(0)
print((W-W0)*(H-H0))

# Fixed code:
W, H, N = map(int, input().split())
W0 = 0
H0 = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and W0 < x:
        W0 = x
    elif a == 2 and x < W:
        W = x
    elif a == 3 and H0 < y:
        H0 = y
    elif a == 4 and y < H:
        H = y
if W-W0 < 0 or H-H0 <0:
    print(0)
    exit()
print((W-W0)*(H-H0))
# Buggy code:
import sys

def nextrec(coor,pt):
    if coor[0]<=pt[0] and pt[0]<=coor[2] and coor[1]<=pt[1] and pt[1]<=coor[3]:
        if pt[2]==1:
            coor[0]=pt[0]
        elif pt[2]==2:
            coor[2]=pt[0]
        elif pt[2]==3:
            coor[1]=pt[1]
        elif pt[2]==4:
            coor[3]=pt[1]
def main(w,h,n,pts):
    rec=[0,0,w,h]
    for x in range(n):
        nextrec(rec, pts[x])
    return (rec[0]-rec[2])*(rec[1]-rec[3])

w,h,n=map(int,sys.stdin.readline().strip().split())
pts=[list(map(int,sys.stdin.readline().strip().split())) \
    for x in range(n)]

print(main(w,h,n,pts))


# Fixed code:
import sys

def nextrec(coor,pt):
    if pt[2]==1:
        coor[0]=min(max(coor[0],pt[0]),coor[2])
    elif pt[2]==2:
        coor[2]=max(min(coor[2],pt[0]),coor[0])
    elif pt[2]==3:
        coor[1]=min(max(coor[1],pt[1]),coor[3])
    elif pt[2]==4:
        coor[3]=max(min(coor[3],pt[1]),coor[1])
def main(w,h,n,pts):
    rec=[0,0,w,h]
    for x in range(n):
        nextrec(rec,pts[x])
    return (rec[0]-rec[2])*(rec[1]-rec[3])

w,h,n=map(int,sys.stdin.readline().strip().split())
pts=[list(map(int,sys.stdin.readline().strip().split())) \
    for x in range(n)]

print(main(w,h,n,pts))
# Buggy code:
w,h,n=map(int,input().split())
p,s,r,s=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p=max(p,x)
  elif a==2:
    q=min(q,x)
  elif a==3:
    r=max(r,y)
  elif a==4:
    s=min(s,y)
print((p-q)*(r-s))
    

# Fixed code:
w,h,n=map(int,input().split())
p,q,r,s=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p=max(p,x)
  elif a==2:
    q=min(q,x)
  elif a==3:
    r=max(r,y)
  elif a==4:
    s=min(s,y)
print(max(0,q-p)*max(0,s-r))
# Buggy code:
w,h,n=map(int,input().split())
o=[0,0]
c=[w,h]
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    o[0]=x if o[0]<x
  elif a==2:
    c[0]=x if c[0]>x
  elif a==3:
    o[1]=y if o[1]<y
  else:
    c[1]=y if c[1]>y
if o[0]<c[0] and o[1]<c[1]:
  print((c[0]-o[0])*(c[1]-o[1]))
else:
  print(0)

# Fixed code:
w,h,n=map(int,input().split())
o=[0,0]
c=[w,h]
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    o[0]=x if o[0]<x else o[0]
  elif a==2:
    c[0]=x if c[0]>x else c[0]
  elif a==3:
    o[1]=y if o[1]<y else o[1]
  else:
    c[1]=y if c[1]>y else c[1]
if o[0]<c[0] and o[1]<c[1]:
  print((c[0]-o[0])*(c[1]-o[1]))
else:
  print(0)
# Buggy code:
w,h,n=input().split()
W=int(w)
H=int(h)
N=int(n)
x=[]
y=[]
a=[]
S=W*H
for i in range(N):
  s=input().split()
  x.append(int(s[0]))
  y.append(int(s[1]))
  a.append(int(s[2]))
w=[0,0,0,0]
for i in range(N):
  if a[i]==1:
    w[0]=min(w[0],x[i])
  elif a[i]==2:
    w[1]=max(w[1],x[i])
  elif a[i]==3:
    w[2]=min(w[2],y[i])
  else:
    w[3]=max(w[3],y[i])
if w[0]-w[1]<=0 or w[2]-w[3]<=0:
  S=0
else:
  S=(w[0]-w[1])*(w[2]-w[3])
print(S)

# Fixed code:
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(N):
  s=input().split()
  x.append(int(s[0]))
  y.append(int(s[1]))
  a.append(int(s[2]))
w=[0,W,0,H]
for i in range(N):
  if a[i]==1:
    w[0]=max(w[0],x[i])
  elif a[i]==2:
    w[1]=min(w[1],x[i])
  elif a[i]==3:
    w[2]=max(w[2],y[i])
  else:
    w[3]=min(w[3],y[i])
if w[1]-w[0]<=0 or w[3]-w[2]<=0:
  S=0
else:
  S=(w[1]-w[0])*(w[3]-w[2])
print(S)
# Buggy code:
W,H,N=list(map(int,input().split()))
ten=[list(map(int,input().split())) for _ in range(N)]
base=[[0,0,1],[0,0,3],[W,H,2],[W,H,4]]
ten.extend(base)
onemax=max(i[0] for i in ten if i[2]==1)
twomin=min(i[0] for i in ten if i[2]==2)
thrmax=max(i[1] for i in ten if i[2]==3)
foumin=min(i[1] for i in ten if i[2]==4)
print((twomin-onemax)*(foumin-thrmax))

# Fixed code:
W,H,N=list(map(int,input().split()))
ten=[list(map(int,input().split())) for _ in range(N)]
base=[[0,0,1],[0,0,3],[W,H,2],[W,H,4]]
ten.extend(base)
onemax=max(i[0] for i in ten if i[2]==1)
twomin=min(i[0] for i in ten if i[2]==2)
thrmax=max(i[1] for i in ten if i[2]==3)
foumin=min(i[1] for i in ten if i[2]==4)
if (twomin-onemax)>0 and (foumin-thrmax) >0:
    print((twomin-onemax)*(foumin-thrmax))
else:print(0)
# Buggy code:
import numpy as np

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

xl = 0
xr = W
yu = H
yd = 0

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

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

ans = max(0,xr - xl) * max(0,yu - yd)

print(ans)


# Fixed code:
import numpy as np

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

xl = 0
xr = W
yu = H
yd = 0

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:
        yd = max(yd,y)
    else:
        yu = min(yu,y)

ans = max(0,xr - xl) * max(0,yu - yd)

print(ans)
# Buggy code:
W,H,N=map(int,input().split(' '))
info = [[],[],[],[]] #min_x,max_x,min_y,max_y
for i in range(N):
  x,y,a=map(int,input().split(' '))
  info[a-1].append((x,y)[(a-1)//2])
print(max(min(info[1])-max(info[0]),0)*max(min(info[3])-max(info[2]),0))

# Fixed code:
W,H,N=map(int,input().split(' '))
info = [[0],[W],[0],[H]] #min_x,max_x,min_y,max_y
for i in range(N):
  x,y,a=map(int,input().split(' '))
  info[a-1].append([x,y][(a-1)//2])
print(max(min(info[1])-max(info[0]),0)*max(min(info[3])-max(info[2]),0))
# Buggy code:
w,h,n = map(int,input().split())
x,y = 0,0
X,Y = w,h
for i in range(n):
    a,b,c = map(int,input().split())
    if c == 1 and x < a:
        x = a
    elif c == 2 and a < X:
        X = a
    elif c == 3 and y < b:
        y = b
    elif c == 4 and b < Y:
        Y = b
print((X-x)*(Y-y))

# Fixed code:
w,h,n = map(int,input().split())
x,y = 0,0
X,Y = w,h
for i in range(n):
    a,b,c = map(int,input().split())
    if c == 1 and x < a:
        x = a
    elif c == 2 and a < X:
        X = a
    elif c == 3 and y < b:
        y = b
    elif c == 4 and b < Y:
        Y = b
print(max(X-x,0)*max(Y-y,0))
# Buggy code:
width, high, num = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(num)]

def rec(xl, yl, xh, yh, arr):
    if len(arr) == 0:
        if xl>xh or yl>yh:
            return 0
        else:
            return xh*yh
    if arr[0][2] == 1:
        xl = arr[0][0]
        arr = arr[1:len(arr)]
        return rec(xl, yl, xh, yh, arr)
    elif arr[0][2] == 2:
        xh = arr[0][0]
        arr = arr[1:len(arr)]
        return rec(xl, yl, xh, yh, arr)
    elif arr[0][2] == 3:
        yl = arr[0][1]
        arr = arr[1:len(arr)]
        return rec(xl, yl, xh, yh, arr)
    elif arr[0][2] == 4:
        yh = arr[0][1]
        arr = arr[1:len(arr)]
        return rec(xl, yl, xh, yh, arr)

print(rec(0, 0, width, high, arr))

# Fixed code:
width, high, num = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(num)]

def rec(xl, yl, xh, yh, arr):
    if xl>xh or yl>yh:
        return 0
    if len(arr) == 0:
        return (xh-xl)*(yh-yl)
    if arr[0][2] == 1:
        xl = max(arr[0][0], xl)
    elif arr[0][2] == 2:
        xh = min(arr[0][0], xh)
    elif arr[0][2] == 3:
        yl = max(arr[0][1], yl)
    elif arr[0][2] == 4:
        yh = min(arr[0][1], yh)
    arr = arr[1:len(arr)]
    return rec(xl, yl, xh, yh, arr)

print(rec(0, 0, width, high, arr))
# Buggy code:
w,h,n=map(int,input().split())
l=list(list(map(int,input().split()))for _ in range(n))
xl=0
xh=w
yl=0
yh=h
for i in range(n):
    if l[i][2]==1:xl=max(xl,l[i][0])
    if l[i][2]==2:xh=min(xh,l[i][0])
    if l[i][2]==3:yl=max(yl,l[i][1])
    if l[i][2]==4:yh=min(yh,l[i][1])
print((xh-xl)*(yh-yl))

# Fixed code:
w,h,n=map(int,input().split())
l=list(list(map(int,input().split()))for _ in range(n))
xl=0
xh=w
yl=0
yh=h
for i in range(n):
    if l[i][2]==1:xl=max(xl,l[i][0])
    if l[i][2]==2:xh=min(xh,l[i][0])
    if l[i][2]==3:yl=max(yl,l[i][1])
    if l[i][2]==4:yh=min(yh,l[i][1])
print(max((xh-xl),0)*max((yh-yl),0))
# Buggy code:
w,h,n=map(int,input().split())
pnt=[list(map(int,input().split())) for i in range(n)]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  if pnt[i][2]==1:
    x1=max(x1,pnt[i][0])
  if pnt[i][2]==2:
    x2=min(x2,pnt[i][1])
  if pnt[i][2]==3:
    y1=max(y1,pnt[i][0])
  if pnt[i][2]==4:
    y2=min(y2,pnt[i][1])
print(max(x2-x1,0)*max(y2-y1,0))

# Fixed code:
w,h,n=map(int,input().split())
pnt=[list(map(int,input().split())) for i in range(n)]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  if pnt[i][2]==1:
    x1=max(x1,pnt[i][0])
  if pnt[i][2]==2:
    x2=min(x2,pnt[i][0])
  if pnt[i][2]==3:
    y1=max(y1,pnt[i][1])
  if pnt[i][2]==4:
    y2=min(y2,pnt[i][1])
print(max(x2-x1,0)*max(y2-y1,0))
# Buggy code:
maxX, maxY, a = map(int, input().split())
minX = minY = 0
for i in range(a):
    x, y, b = map(int, input().split())
    if b == 1:
        minX = max(x, minX)
    elif b == 2:
        maxX = min(x, maxX)
    elif b == 3:
        minY = max(y, minY)
    elif b == 4:
        maxY = min(y, minY)
if maxX > minX and maxY > minY:
    print(((maxX - minX)*(maxY - minY)))
else:
    print(0)


# Fixed code:
maxX, maxY, a = map(int, input().split())
minX = 0
minY = 0
for i in range(a):
    x, y, b = map(int, input().split())
    if b == 1:
        minX = max(x, minX)
    elif b == 2:
        maxX = min(x, maxX)
    elif b == 3:
        minY = max(y, minY)
    elif b == 4:
        maxY = min(y, maxY)
if maxX > minX and maxY > minY:
    print((maxX - minX)*(maxY - minY))
else:
    print(0)
# Buggy code:
w,h,n = map(int, input().split())

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

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_max = x
    elif a == 2:
        x_min = x
    elif a == 3:
        y_max = y
    else:
        y_min = y

print((y_max-y_min) * (x_max-x_min))

# Fixed code:
w, h, n = map(int, input().split())

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = min(y, y_max)
print(max(y_max - y_min, 0) * max(x_max - x_min, 0))
# Buggy code:
w,h,n = map(int,input().split())
#x_list = [int(1) for i in range(w+1)]
#y_list = [int(1) for i in range(h+1)]
#print(x_list)
#print(y_list)
min_x = 0
max_x = w
min_y = 0
max_y = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        min_x = x
    elif a==2:
        max_x = x
    elif a==3:
        min_y = y
    else:
        max_y = y
if min_x > max_x or min_y > max_y:
    print(0)
else:
    print((max_x-min_y)*(max_y-min_y))

# Fixed code:
w,h,n = map(int,input().split())
#x_list = [int(1) for i in range(w+1)]
#y_list = [int(1) for i in range(h+1)]
#print(x_list)
#print(y_list)
min_x = 0
max_x = w
min_y = 0
max_y = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        min_x = max(min_x,x)
    elif a==2:
        max_x = min(max_x,x)
    elif a==3:
        min_y = max(min_y,y)
    else:
        max_y = min(max_y,y)
if min_x > max_x or min_y > max_y:
    print(0)
else:
    print((max_x-min_x)*(max_y-min_y))
# Buggy code:
w,h,n=[int(i) for i in input().split(' ')]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=[int(i) for i in 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)
print(max(0,(y2-y1)*(x2-x1))

# Fixed code:
w,h,n=[int(i) for i in input().split(' ')]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=[int(i) for i in 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 y2<=y1 or x2 <= x1:
  print(0)
else:
  print(max(0,(y2-y1)*(x2-x1)))
# Buggy code:
W,H,N = list(map(int,input().split()))

points = [list(map(int, input().split())) for _ in range(N)]
res = 0

x1,y1 = [0,0]
x2,y2 = [W,H]

for x,y,a in points:
    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 <= 0 or y-y1 <=0:
    print("0")
else:
    res = (x2-x1) * (y2 - y1)
    print(res)

# Fixed code:
W,H,N = list(map(int,input().split()))

points = [list(map(int, input().split())) for _ in range(N)]
res = 0

x1,y1 = [0,0]
x2,y2 = [W,H]

for x,y,a in points:
    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 <= 0 or y2-y1 <=0:
    print("0")
else:
    print((x2-x1)*(y2-y1))