Problem:
 Score : 200 points    Problem Statement 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 1 5 4 2
2 1 1
3 3 4      Sample Output 1 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 .       Sample Input 2 5 4 3
2 1 1
3 3 4
1 4 2      Sample Output 2 0  It is possible that the whole region within the rectangle is painted black.       Sample Input 3 10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3      Sample Output 3 64

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

left, bottom = 0, 0
right, top = W, H

for x, y, a in (map(int, input().split()) for _ in range(N)):
  
  if a == 1:
    left = max(left, x)
  elif a == 2:
    right = min(right, x)
  elif a == 3:
    bottom = max(bottom, y)
  else:
    top = min(top, y)

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

Solution (Python):
w,h,n = map(int,input().split())
q = 0
z = 0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        if z <= x:
            z = x
    if a == 2:
        if w >= x:
            w = x
    if a == 3:
        if q <= y:
            q = y
    if a == 4:
        if h >= y:
            h = y
if w-z >= 0 and h-q >= 0:
    print((w-z)*(h-q))
else:
    print(0)

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

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

s1 = 0
s2 = w
t1 = 0
t2 = h

for i in range(n):
    if li[i][2] == 1:
        s1 = max(li[i][0],s1)
    if li[i][2] == 2:
        s2 = min(li[i][0],s2)
    if li[i][2] == 3:
        t1 = max(li[i][1],t1)
    if li[i][2] == 4:
        t2 = min(li[i][1],t2)

if s2-s1 < 0 or t2-t1 < 0:
    print(0)
    exit()
        
ans = (s2-s1) * (t2-t1)

print(ans if ans > 0 else 0)

Solution (Python):
w, h, n = map(int, input().split(" "))
xyas = [map(int, input().split(" ")) for i in range(n)]

X = 0
X1 = w
Y = 0
Y1 = h
for x, y, a in xyas:
    if a == 1:
        X = max(X, x)
        X1 = max(X1, x)
    elif a == 2:
        X = min(X, x)
        X1 = min(X1, x)
    elif a == 3:
        Y = max(Y, y)
        Y1 = max(Y1, y)
    else:
        Y = min(Y, y)
        Y1 = min(Y1, y)

print(abs(X - X1) * abs(Y - Y1))

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

p0 = [0, 0]
p1 = [W, H]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if p0[0] < x:
            p0[0] = x
    elif a == 2:
        if p1[0] > x:
            p1[0] = x
    elif a == 3:
        if p0[1] < y:
            p0[1] = y
    elif a == 4:
        if p1[1] > y:
           p1[1] = y

x = p1[0]-p0[0]
y = p1[1]-p0[1]
if x < 0:
    x = 0
if y < 0:
    y = 0

print(x * y)

Solution (Python):
import numpy as np
row = input().split()
W = int(row[0])
H = int(row[1])
N = int(row[2])
row2 = [input().split() for i in range(N)]
f = np.vectorize(int)
x = f(row2)
white = [0,0,W,H]
for i in x:
    if i[2] == 1 and white[0] < i[0]:
        white[0] = i[0]
    if i[2] == 2 and white[2] > i[0]:
        white[2] = i[0]
    if i[2] == 3 and white[1] < i[1]:
        white[1] = i[1]
    if i[2] == 4 and white[3] > i[1]:
        white[3] = i[1]
x_dis = white[2]- white[0]
y_dis = white[3]- white[1]
if x_dis >= 0 and y_dis >= 0:
    print(x_dis*y_dis)
else:
    print(0)

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

L = 0
R = W
D = 0
U = H

for _ in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    L = max(L,x)
  if a == 2:
    R = min(R,x)
  if a == 3:
    D = max(D,y)
  if a == 4:
    U = min(U,y)

x = max(0,R-L)
y = max(0,U-D)
answer = x*y

print(answer)

Solution (Python):
w,h,n=map(int,input().split())
a=[[0],[w],[0],[h]]
for i in range(n):
    arr = list(map(int,input().split()))
    if arr[2]==1:a[0].append(arr[0])
    if arr[2]==2:a[1].append(arr[0])
    if arr[2]==3:a[2].append(arr[1])
    if arr[2]==4:a[3].append(arr[1])
if max(a[0])>=min(a[1]) or max(a[2])>=min(a[3]):
    print(0)
else:print((min(a[1])-max(a[0]))*(min(a[3])-max(a[2])))

Solution (Python):
def main():
    w,h,n = map(int,input().split(' '))
    x_y_a=[]
    for i in range(n):
        x_y_a.append(list(map(int,input().split(' '))))

    up = [i[1] for i in x_y_a if i[2] == 4]+[h]
    down = [i[1] for i in x_y_a if i[2] == 3]+[0]
    left = [i[0]for i in x_y_a if i[2] == 1]+[0]
    right = [i[0] for i in x_y_a if i[2] == 2]+[w]
    if min(up)-max(down) < 0 or min(right) - max(left) < 0:
        ans = 0
    else:
        ans = (min(up)-max(down))*(min(right)-max(left))
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):
w, h, n = map(int, input().split())
xmin = 0
xmax = w
ymin = 0
ymax = h
for i in range(n):
    x, y, a = map(int, input().split())
    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(ymax-ymin, 0))

Solution (Python):
W,H,N=map(int, input().split())
xmin=0
xmax=W
ymin=0
ymax=H
for i in range(N):
  x,y,a=map(int, input().split())
  if a==1 and xmin < x:
    xmin=x
  elif a==2 and xmax > x:
    xmax=x
  elif a==3 and ymin < y:
    ymin=y
  elif a==4 and ymax > y:
    ymax=y
x = max([0, xmax-xmin])
y = max([0, ymax-ymin])
print(x*y)

Solution (Python):
W, H, N = map(int, input().split())
ans = W*H
L_x = 0
D_y = 0


for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x >= W:
            ans = 0
            break
        elif L_x <= x < W:
            L_x = x

    elif a == 2:
        if x <= L_x:
            ans = 0
            break
        elif L_x <= x <= W:
            W = x

    elif a == 3:
        if H <= y:
            ans = 0
            break
        elif D_y <= y < H:
            D_y = y

    else:
        if y <= D_y:
            ans = 0
            break
        elif D_y < y <= H:
            H = y
if ans == 0:
    print(ans)
else:
    print((H - D_y) * (W - L_x))

Solution (Python):
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

    for n in range(n):
        x, y, a = 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)
        elif a == 4:
            y_max = min(y_max, y)

    print(max(0, x_max - x_min) * max(0, y_max - y_min))

        
        
        
        
        
        
        
        
        
        
        
        

    

if __name__ == "__main__":

    main()

Solution (Python):
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

    for n in range(n):
        x, y, a = 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)
        elif a == 4:
            y_max = min(y_max, y)

    print(max(0, x_max - x_min) * max(0, y_max - y_min))

        
        
        
        
        
        
        
        
        
        
        
        

    

if __name__ == "__main__":

    main()

Solution (Python):
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

    for n in range(n):
        x, y, a = 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)
        elif a == 4:
            y_max = min(y_max, y)

    print(max(0, (x_max - x_min)) * max(0, (y_max - y_min)))

        
        
        
        
        
        
        
        
        
        
        
        

    

if __name__ == "__main__":

    main()

Solution (Python):
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

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

        if (a == 1) and (x > x_min):
            x_min = x
        elif (a == 2) and (x < x_max):
            x_max = x
        elif (a == 3) and (y > y_min):
            y_min = y
        elif (a == 4) and (y < y_max):
            y_max = y

        if (x_max <= x_min) or (y_max <= y_min):
            print(0)
            return

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

if __name__ == "__main__":

    main()

Solution (Python):
w,h,n=map(int,input().split())
x1=0
y1=0
x2=w
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)
    elif a==4:
        y2=min(y2,y)
print(max(0,(x2-x1))*max(0,(y2-y1)))

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


s = [[1 for i in range(w)] for j in range(h)]

    

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

cnt = 0
for i in s:
    cnt += sum(i)
print(cnt)

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

d = {'1': 0,
	 '2': W,
	 '3': 0,
	 '4': H}
for i in range(N):
	x, y, a = list(map(int, input().split()))
	if a == 1:
		if x > d['1']:
			d['1'] = x
	elif a == 2:
		if x < d['2']:
			d['2'] = x
	elif a == 3:
		if y > d['3']:
			d['3'] = y
	else:
		if y < d['4']:
			d['4'] = y
if d['1'] > d['2'] or d['3'] > d['4']:
	print(0)
else:
	print((d['2']-d['1']) * (d['4']-d['3']))

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

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

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

    if a == 1:
        if x > x_min:
            x_min = x
    elif a == 2:
        if x < x_max:
            x_max = x
    elif a == 3:
        if y > y_min:
            y_min = y
    else:
        if y < y_max:
            y_max = y

width = x_max - x_min
height = y_max - y_min
if width > 0 and height > 0:
    print(width * height)
else:
    print(0)

Solution (Python):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

W, H, N = list(map(int, sys.stdin.readline().split()))
X, Y, A = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

board = np.ones((W, H), dtype=bool)
for x, y, a in zip(X, Y, A):
    if a == 1:
        board[:x, :] = 0
    if a == 2:
        board[x:, :] = 0
    if a == 3:
        board[:, :y] = 0
    if a == 4:
        board[:, y:] = 0
print(board.sum())

Solution (Python):
W, H, N = map(int, input().split())
points = [tuple(map(int, input().split())) for _ in range(N)]
left_bottom = (0, 0)
right_top = (W, H)
for x, y, a in points:
    if a == 1: left_bottom = (max(x, left_bottom[0]), left_bottom[1])
    elif a == 2: right_top = (min(x, right_top[0]), right_top[1])
    elif a == 3: left_bottom = (left_bottom[0], max(y, left_bottom[1]))
    else: right_top = (right_top[0], min(y, right_top[1]))
width = max(right_top[0] - left_bottom[0], 0)
height = max(right_top[1] - left_bottom[1], 0)
print(width*height)

Solution (Python):
W, H, N = map(int, input().split())
xl, yl, xr, yr = 0, 0, W, H
for _ 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:
        yr = min(yr, y)

if xl < xr and yl < yr:
    print(int((xr - xl) * (yr - yl)))
else:
    print(0)

Solution (Python):
W,H,N = map(int,input().split())
point = [list(map(int,input().split())) for i in range(N)]
x_min = 0
x_max = W
y_min = 0
y_max = H

for i in point:
    if i[2] == 1:
        x_min = max(x_min,i[0])
    elif i[2] == 2:
        x_max = min(x_max,i[0])
    elif i[2] == 3:
        y_min = max(y_min,i[1])
    else:
        y_max = min(y_max,i[1])

x_line = x_max - x_min
y_line = y_max - y_min

if x_line > 0 and y_line > 0:
    print(x_line*y_line)
else:
    print(0)

Solution (Python):
o1=0
o2=0
oo1=0
oo2=0
w,h,n=map(int,input().split())
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        oo1=max(o1+x,oo1)
    elif a==2:
        w=min(x,w)
    elif a==3:
        oo2=max(o2+y,oo2)
    else:h=min(y,h)
if oo1>=w or oo2>=h:
    print(0)
else:print((w-oo1)*(h-oo2))

Solution (Python):
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
x1 = 0
x2 = W
y3 = 0
y4 = H
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
    if a[i] == 1:
        if x1 < x[i]:
            x1 = x[i]
    elif a[i] == 2:
        if x2 > x[i]:
            x2 = x[i]
    elif a[i] == 3:
        if y3 < y[i]:
            y3 = y[i]
    elif a[i] == 4:
        if y4 > y[i]:
            y4 = y[i]

if x2-x1 <=0 or y4-y3 <= 0:
    print(0)
else:
    print((x2-x1)*(y4-y3))

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

b = 0
t = H
l = 0
r = W

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:
    b = max(b, y)
  else:
    assert a==4
    t = min(t, y)
print( max(t-b, 0) * max(r-l, 0) )

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

W, H, N =  nl()

left = 0
right = W
top = H
bottom = 0

for i in range(N):
    x, y, a = nl()
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        bottom = max(bottom, y)
    else:
        top = min(top, y)

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

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

xya = [0]*N
for i in range(N):
    xya[i] = map(int, input().split())
WH = []
for h in range(H):
    w = [0]*W
    WH.append(w)

for x,y,a in xya:
    if a == 1:
        for w in WH:
            for i in range(0,x):
                w[i] = 1
    elif a == 2:
        for w in WH:
            for i in range(x,W):
                w[i] = 1
    elif a == 3:
        for i in range(0,y):
            w = WH[i]
            for j in range(len(w)):
                w[j] = 1
    elif a == 4:
        for i in range(y,H):
            w = WH[i]
            for j in range(len(w)):
                w[j] = 1

result = 0
for w in WH:
    result += sum(w)
print(W*H - result)

Solution (Python):
def abc():
    w, h, n = map(int, input().split())
    field = [[1] * w] * h
    for i in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            for f in field:
                f[:x] = [0] * x
        if a == 2:
            for f in field:
                f[x:] = [0] * (w - x)
        if a == 3:
            for j in range(y):
                field[j] = [0] * w
        if a == 4:
            for j in range(y, h):
                field[j] = [0] * w
    ans = 0
    for f in field:
        ans += sum(f)
    print(ans)


abc()

Solution (Python):
w, h, n = [ int(v) for v in input().split() ]
u, d, l, r = h, 0, 0, w

for i in range(n):
    x, y, a = [ int(v) for v in input().split() ]
    if a == 1 and x >= l:
        l = x
    elif a == 2 and x <= r:
        r = x
    elif a == 3 and y >= d:
        d = y
    elif a == 4 and y <= u:
        u = y



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

Solution (Python):
W, H, N = map(int, input().split())
L = [(0, 0)]
R = [(W, H)]
U = [(W, H)]
D = [(0, 0)]

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        L.append((x, y))
    if a == 2:
        R.append((x, y))
    if a == 3:
        D.append((x, y))
    if a == 4:
        U.append((x, y))

L.sort(key=lambda x: x[0])
R.sort(key=lambda x: x[0])
U.sort(key=lambda x: x[1])
D.sort(key=lambda x: x[1])

print(max(R[0][0] - L[-1][0], 0) * max(U[0][1] - D[-1][1], 0))

Solution (Python):
w,h,n=map(int,input().split())
width=[0,w]
height=[0,h]
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    if width[0]<x:
      width[0]=x
  elif a==2:
    if width[1]>x:
      width[1]=x
  elif a==3:
    if height[0]<y:
      height[0]=y
  elif a==4:
    if height[1]>y:
      height[1]=y
X=width[1]-width[0]
Y=height[1]-height[0]
if X>0 and Y>0:
  print(X*Y)
else:
  print(0)

Solution (Python):
W,H,N = [int(i) for i in input().split()]

min_x = W
max_x = 0
min_y = H
max_y = 0
for i in range(N):
    x,y,a = [int(i) for i in 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)

if min_x <= max_x or min_y <= max_y:
    print(0)
else:
    print((min_x-max_x)*(min_y-max_y))

Solution (Python):
W, H, N = map(int, input().split())
W0, H0 = 0, 0

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

    if a == 1:
        W0 = max(W0, x)
    elif a == 2:
        W = min(W, x)
    elif a == 3:
        H0 = max(H0, y)
    else:
        H = min(H, y)


X = max(0, W - W0)
Y = max(0, (H - H0))

print(X * Y)

Solution (Python):
from subprocess import*
call(('python3','-c',"""
import numpy
I=lambda:map(int,input().split())
W,H,N=I()
m=numpy.zeros((H,W),int)
while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1
print(W*H-m.sum())
"""))

Solution (Python):
w,h,n = map(int, input().split())
x1,y1 = 0, 0
x2, y2 = w, 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)
    elif a == 4:
        y2 = min(y2, y)

if (x2 - x1 < 0) or (y2 - y1 < 0):
    print(0)
else:
    print(max((x2 - x1) * (y2 - y1), 0))

Solution (Python):
import sys

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

ans = (r - l) * (u - d)
if r - l < 0 or u - d < 0:
    ans = 0
print(max(ans, 0))

Solution (Python):
import numpy as np
w, h, n = map(int, input().split())
arr = np.zeros((w, h))
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        arr[:x] = np.ones((x, h))
    elif a == 2:
        arr[x:] = np.ones((w - x, h))
    elif a == 3:
        arr[:, :y] = np.ones((w, y))
    elif a == 4:
        arr[:, y:] = np.ones((w, h - y))
print(int(w * h - np.sum(arr)))

Solution (Python):
w, h, n = map(int, input().split(' '))
x_mi = 0
x_ma = w
y_mi = 0
y_ma = h
for _ in range(n):
    x, y, a = map(int, input().split(' '))
    if a == 1:
        if x_mi < x:
            x_mi = x
    if a == 2:
        if x_ma > x:
            x_ma = x
    if a == 3:
        if y_mi < y:
            y_mi = y
    if a == 4:
        if y_ma > y:
            y_ma = y
if y_ma - y_mi <=0 or x_ma - x_mi <= 0:
    print(0)
else:
    print((x_ma - x_mi)*(y_ma - y_mi))

Solution (Python):
xmax,ymax,N=map(int,input().split())
xmin=0
ymin=0

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

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

L = 0
R = W
D = 0
U = H

for _ in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    L = max(L,x)
  if a == 2:
    R = min(R,x)
  if a == 3:
    D = max(D,y)
  if a == 4:
    U = min(U,y)

x = max(0,R-L)
y = max(0,U-D)
answer = x*y

print(answer)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())


W, H, N = mi()


H = [0, H]
W = [0, W]

for i in range(N):
  x, y, a = mi()
  if a == 1:
    W[0] = max(x,W[0])
  elif a == 2:
    W[1] = min(x,W[1])
  elif a == 3:
    H[0] = max(y,H[0])
  else:
    H[1] = min(y,H[1])

print(max((H[1]-H[0]),0)*max((W[1]-W[0]),0))

Solution (Python):


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

w1 = int(w)
h1 = int(h)

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

ar = [[0]*w for i in range(h)]

for x, y, aa in a:
    x -= 1
    y -= 1
    if aa == 1:
        for i in range(h):
            for j in range(w):
                if j <= x:
                    ar[i][j] += 1
    if aa == 2:
        for i in range(h):
            for j in range(w):
                if j > x:
                    ar[i][j] += 1
    if aa == 3:
        for i in range(h):
            for j in range(w):
                if i <= y:
                    ar[i][j] += 1
    if aa == 4:
        for i in range(h):
            for j in range(w):
                if i > y:
                    ar[i][j] += 1

print(sum(ar, []).count(0))

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

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

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

    if a == 1 and X[0] < x:
        X[0] = x
    elif a == 2 and x < X[1]:
        X[1] = x
    elif a == 3 and Y[0] < y:
        Y[0] = y
    elif a == 4 and y < Y[1]:
        Y[1] = y
    
if X[1] > X[0] and Y[1] > Y[0]:
    result = (X[1] - X[0]) * (Y[1] - Y[0])
else:
    result = 0

print(result)

Solution (Python):
w,h,n=map(int,input().split())
A1=[0]
A2=[w]
A3=[0]
A4=[h]
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    A1.append(x)
  elif a==2:
    A2.append(x)
  elif a==3:
    A3.append(y)
  else:
    A4.append(y)
if min(A2)>max(A1) and min(A4)>max(A3):
  print((min(A2)-max(A1))*(min(A4)-max(A3)))
else:
  print(0)

Solution (Python):
w,h,n=map(int,input().split())
A1=[0]
A2=[w]
A3=[0]
A4=[h]
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    A1.append(x)
  elif a==2:
    A2.append(x)
  elif a==3:
    A3.append(y)
  else:
    A4.append(y)
if min(A2)>max(A1) and min(A4)>max(A3):
  print((min(A2)-max(A1))*(min(A4)-max(A3)))
else:
  print(0)

Solution (Python):
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())

ls = [0,w,0,h]
for i in range(n):
    if a[i]==1:
        ls[0] = max(ls[0],x[i])
    if a[i]==2:
        ls[1] = min(ls[1],x[i]) 
    if a[i]==3:
        ls[2] = max(ls[2],y[i])
    if a[i]==4:
        ls[3] = min(ls[3],y[i])

s  =max((ls[1]-ls[0]),0)*max((ls[3]-ls[2]),0)
print(int(s))

Solution (Python):
W,H,N=map(int,input().split())
data=[list(map(int,input().split())) for i in range(N)]
_W=0
_H=0
for i in data:
    if i[2]==1:
        _W=max(i[0],_W)
    if i[2]==2:
        W=min(W,i[0])
    if i[2]==3:
        _H=max(i[1],_H)
    if i[2]==4:
        H=min(H,i[1])

if W-_W<=0 or H-_H<=0:
    print(0)
    exit()
a=int((W-_W)*(H-_H))
if a>0:
    print(a)
else:
    print(0)

Solution (Python):

import numpy as np

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

for i in range(n):
    xi, yi, a = map(int, input().split())
    if a == 1: 
        rectangle[:xi, :] = 1
    elif a == 2: 
        rectangle[xi:, :] = 1
    elif a == 3: 
        rectangle[:, :yi] = 1
    else: 
        rectangle[:, yi:] = 1
print(int(w*h - np.sum(rectangle)))

Solution (Python):
import math
import fractions
import copy

def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)



right,up,n= (int(i) for i in input().split())       










left,down = (0,0)
for i in range(n):
    w,h,c =  (int(i) for i in input().split())
    if c == 1:
        left = max(w,left)
    if c == 2:
        right = min(w,right)
    if c == 3:
        down = max(down,h)
    if c == 4:
        up = min(up,h)
l = max(right-left,0)
w = max(up-down,0)
print(l*w)

Solution (Python):
w, h, n = map(lambda x: int(x), input().split(' '))
board = [[0] * h for i in range(w)]

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

    start_x = 0
    end_x = w
    start_y = 0
    end_y = h

    if a == 1:
        end_x = x
    if a == 2:
        start_x = x
    if a == 3:
        end_y = y
    if a == 4:
        start_y = y
    
    for j in range(start_x, end_x):
        for k in range(start_y, end_y):
            board[j][k] = 1

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

print(result)

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

x_min=0
y_min=0

for i in range(n):
        x,y,a=map(int,input().split())
        if a==1:
                x_min=max(x_min,x)

        elif a==2:
                w=min(w,x)

        elif a==3:
                y_min=max(y_min,y)

        elif a==4:
                h=min(h,y)


white=max(0,(w-x_min))*max(0,(h-y_min))

print(white)

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

x_min=0
y_min=0

for i in range(n):
        x,y,a=map(int,input().split())
        if a==1:
                x_min=max(x_min,x)

        elif a==2:
                w=min(w,x)

        elif a==3:
                y_min=max(y_min,y)

        elif a==4:
                h=min(h,y)


white=max(0,(w-x_min))*max(0,(h-y_min))

print(white)

Solution (Python):
w,h,n=map(int,input().split())
x=[0]*n
y=[0]*n
a=[0]*n
left=0
right=w
up=h
down=0

for i in range(n):
  x[i],y[i],a[i]=map(int,input().split())
for i in range(n):
  if a[i]==1:
    left=max(left,x[i])
  if a[i]==2:
    right=min(right,x[i])
  if a[i]==3:
    down=max(down,y[i])
  if a[i]==4:
    up=min(up,y[i])
if left>=right or down>=up:
  print(0)
else:
  print((right-left)*(up-down))

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

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

square = [[0 for i in range(W)] for i in range(H)]


for i in range(N):
    x,y,a = xya[i]
    if a == 1:
        for i in range(H):
            for j in range(x):
                square[i][j] = 1
    elif a == 2:
        for i in range(x,W):
            for j in range(H):
                square[j][i] = 1
    elif a == 3:
        for i in range(W):
            for j in range(y):
                square[j][i] = 1
    elif a == 4:
        for i in range(W):
            for j in range(y,H):
                square[j][i] = 1

black = 0
for i in range(H):
    black += sum(square[i])

print(H*W-black)

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


x_min=0
y_min=0

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

    if a==1:
        x_min=max(x_min,x)

    elif a==2:
        w=min(x,w)

    elif a==3:
        y_min=max(y_min,y)

    elif a==4:
        h=min(y,h)

print(max(0,w-x_min)*max(0,h-y_min))

Solution (Python):
w,h,n = map(int,input().split())
para = []
for i in range(n):
    para.append([i for i in map(int,input().split())])

x_r = [w]
x_l = [0]
y_r = [h]
y_l = [0]
for i in range(n):
    if para[i][2] == 1 : x_l.append(para[i][0])
    elif para[i][2] == 2 :x_r.append(para[i][0])
    elif para[i][2] == 3 : y_l.append(para[i][1])
    else: y_r.append(para[i][1])
x = min(x_r)-max(x_l)
y = min(y_r) - max(y_l)
if x >= 0 and y >= 0 : 
    print("{}".format(x*y))
else: print(0)

Solution (Python):

W, H , N = map(int, input().split())
xya = []
for i in range(N):
    xya.append(list(map(int, input().split())))
"""
面積を求めるには2点(原点と点(W, H))が分かれば良い
2点の移動を見る
"""

A = [0, 0]   
C = [W, H]   


def drow(x, y, a):
    if a == 1 and x >= A[0]:
        A[0] = x
    elif a == 2 and x <= C[0]:
        C[0] = x
    elif a == 3 and y >= A[1]:
        A[1] = y
    elif a == 4 and y <= C[1]:
        C[1] = y

flag = True
for i in range(N):   
    drow(xya[i][0], xya[i][1], xya[i][2])
    if A[0] >= C[0] or A[1] >= C[1]:   
        flag = False
        break
if flag:
    print((C[0]-A[0])*(C[1]-A[1]))
else:
    print(0)

Solution (Python):
w, h, n = map(int, input().split())
w1 = 0
h1 = 0
w2 = w
h2 = h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x > w1:
        w1 = x
    elif a == 2 and x < w2:
        w2 = x
    elif a == 3 and h1 < y:
        h1 = y
    elif a == 4 and h2 > y:
        h2 = y

ans = (w2 - w1) * (h2 - h1)
if w2 - w1 < 0 or h2 - h1 < 0:
    print(0)
else:
    print(ans)

Solution (Python):
w, h, n = map(int, input().split())
w1 = 0
h1 = 0
w2 = w
h2 = h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x > w1:
        w1 = x
    elif a == 2 and x < w2:
        w2 = x
    elif a == 3 and h1 < y:
        h1 = y
    elif a == 4 and h2 > y:
        h2 = y

ans = (w2 - w1) * (h2 - h1)
if w2 - w1 < 0 or h2 - h1 < 0:
    print(0)
else:
    print(ans)

Solution (Python):
W, H, N = map(int, input().split())
field = []
for i in range(0, W):
	lst = []
	for j in range(0, H):
		lst.append(1)
	field.append(lst)
for i in range(0, N):
	x, y, a = map(int, input().split())
	paint = []
	if a == 1: paint = [[0, x], [0, H]]
	elif a == 2: paint = [[x, W], [0, H]]
	elif a == 3: paint = [[0, W], [0, y]]
	elif a == 4: paint = [[0, W], [y, H]]
	for i in range(paint[0][0], paint[0][1]):
		for j in range(paint[1][0], paint[1][1]):
			field[i][j] = 0
cnt = 0
for i in range(0, W):
	for j in range(0, H):
		cnt += field[i][j]
print(cnt)