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())
x1=0
x2=W
y1=0
y2=H
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x,x1)
    if a==2:
        x2=min(x,x2)
    if a==3:
        y1=max(y,y1)
    if a==4:
        y2=min(y,y2)
if x1<x2 and y1<y2:
    print((x2-x1)*(y2-y1))
else:
    print(0)

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

x1 = 0
x2 = W
y1 = 0
y2 = H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x1 < x:
            x1 = x
    elif a == 2:
        if x2 > x:
            x2 = x
    elif a == 3:
        if y1 < y:
            y1 = y
    elif a == 4:
        if y2 > y:
            y2 = y

if x1 > x2 or y1 > y2:
    print(0)
else:
    print((x2 - x1) * (y2 - y1))

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    w,h,n = f()

    xmin = 0
    xmax = w

    ymin = 0
    ymax = h
    for i in range(n):
        x,y,a = f()
        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))


solve()

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

Solution (Python):
w, h, n = map(int, input().split())
x1, x2, y1, y2 = [0], [w], [0], [h]
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y1.append(y)
  else:
    y2.append(y)
print(max(min(x2) - max(x1), 0) * max((min(y2) - max(y1)), 0))

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

x1, x2, y3, y4 = [0], [w], [0], [h]

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x1.append(x)
    elif a == 2:
        x2.append(x)
    elif a == 3:
        y3.append(y)
    else:
        y4.append(y)

print(max(min(x2) - max(x1), 0) * max(min(y4) - max(y3), 0))

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

Solution (Python):
import itertools
import math
W,H,N  =list(map(int,input().split(" ")))
hoko = [0,W,0,H]
l = 0
r = W
ue = H
sita = 0

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

    if a ==1:
      if l < x:
          l = x
    if a == 2:
        if r > x:
            r = x

    if a == 4:
        if ue > y:
            ue = y
    if a == 3:
        if sita < y:
            sita = y

if (r-l) < 0 and (ue-sita) < 0:
    print(0)
else:
    print(max(0,  (r-l) * (ue-sita)   ))

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

w, h = 0, 0
for x, y, a in [[int(i) for i in input().split()] for _ in range(N)]:
    if a == 1:
        w = max(w, x)
    if a == 2:
        W = min(W, x)
    if a == 3:
        h = max(h, y)
    if a == 4:
        H = min(H, y)

print(max(0, W - w) * max(0, H - h))

Solution (Python):
W, H, N = map(int, input().split())
ans = W * H
t, b, l, r = H, 0, 0, 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:
        t = min(t, y)
print(max(0, (t - b)) * max(0, (r - l)))

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

Solution (Python):
w, h, n = list(map(int, input().split()))
xl, xr, yd, yu = 0, w, 0, h
for _ in range(n):
    x, y, a = list(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)

if xr > xl and yu > yd:
    print((xr - xl) * (yu - yd))
else:
    print(0)

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

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

x_min = y_min = 0
x_max = W
y_max = H
for i 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)
    else:
        y_max = min(y_max, y)
print(max(x_max - x_min, 0) * max(y_max - y_min, 0))

Solution (Python):

"""
B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
https://atcoder.jp/contests/abc047/tasks/abc047_b

"""
import sys


def solve(W, H, N, points):
    grid = [[1]*W for _ in range(H)]
    for x, y, a in points:
        if a == 1:
            for cy, row in enumerate(grid):
                for cx in range(x):
                    row[cx] = 0
        elif a == 2:
            for cy, row in enumerate(grid):
                for cx in range(x, W):
                    row[cx] = 0
        elif a == 3:
            for cy in range(y):
                grid[cy] = [0]*W
        elif a == 4:
            for cy in range(y, H):
                grid[cy] = [0]*W

    return sum([sum(row) for row in grid])


def main(args):
    W, H, N = map(int, input().split())
    points = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(W, H, N, points)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

x1 = 0
x2 = W
y1 = 0
y2 = H

for n in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        x1 = max(x,x1)
    elif a == 2:
        x2 = min(x,x2)
    elif a == 3:
        y1 = max(y,y1)
    elif a == 4:
        y2 = min(y,y2)

print(max(x2-x1,0)*max(y2-y1,0))

Solution (Python):
W,H,N = [int(x) for x in input().split()]
xya = [[int(x) for x in input().split()]for _ in range(N)]
rectangle = [[1 for _ in range(W)]for _ in range(H)]
cnt = 0
for i in xya:
    if(i[2]==1):
        for y,li in enumerate(rectangle):
            for x in range(i[0]):
                rectangle[y][x] = 0
    elif(i[2]==2):
        for y,li in enumerate(rectangle):
            for x in range(i[0],W):
                rectangle[y][x] = 0
    elif(i[2]==3):
        for y in range(i[1]):
            rectangle[y] = [0]*W
    else:
        for y in range(i[1],H):
            rectangle[y] = [0]*W
for i in rectangle:
    cnt += sum(i)
print(cnt)

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

l, r = 0, w
high, low = h, 0

for i 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:
        low = max(low, y)
    if a == 4:
        high = min(high, y)
w = r - l
h = high - low

print(w * h if w > 0 and h > 0 else 0)

Solution (Python):
w, h, n = map(int, input().split())
a = [0, w, 0, h]
for i in range(n):
    xi, yi, ai = map(int, input().split())
    if ai == 1:
        a[0] = max(xi, a[0])
    elif ai == 2:
        a[1] = min(xi, a[1])
    elif ai == 3:
        a[2] = max(yi, a[2])
    else:
        a[3] = min(yi, a[3])
print(max(0, a[1] - a[0]) * max(0, a[3] - a[2]))

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

try:one = sorted(list(filter(lambda x:x[2]==1, xya)), key=lambda x:x[0])[-1][0]
except: one = 0
try: two = sorted(list(filter(lambda x:x[2]==2, xya)), key=lambda x:x[0])[0][0]
except: two = w
try: three = sorted(list(filter(lambda x:x[2]==3, xya)), key=lambda x:x[1])[-1][1]
except: three = 0
try: four = sorted(list(filter(lambda x:x[2]==4, xya)), key=lambda x:x[1])[0][1]
except: four = h

print(max(0,two-one) * max(0,four-three))

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

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)
if xmax <= xmin or ymax <= ymin:
  print(0)
else:
  print((xmax-xmin)*(ymax-ymin))

Solution (Python):

w, h, n = list(map(int, input().rstrip().split()))
ans = [0, 0, w, h]
for i in range(n):
    x, y, a = list(map(int, input().rstrip().split()))
    if ans[0] < ans[2] and ans[1] < ans[3]:
        if a == 1:
            ans[0] = max(ans[0], x)
        elif a == 2:
            ans[2] = min(ans[2], x)
        elif a == 3:
            ans[1] = max(ans[1], y)
        else:
            ans[3] = min(ans[3], y)
    else:
        print(0)
        break
else:
    res = (ans[2] - ans[0]) * (ans[3] - ans[1])
    print(res if res >= 0 else 0)

Solution (Python):

w, h, n = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(n)]
ans = [0, 0, w, h]
for i in range(n):
    a = lst[i][2]
    if ans[0] < ans[2] and ans[1] < ans[3]:
        if a == 1:
            ans[0] = max(ans[0], lst[i][0])
        elif a == 2:
            ans[2] = min(ans[2], lst[i][0])
        elif a == 3:
            ans[1] = max(ans[1], lst[i][1])
        else:
            ans[3] = min(ans[3], lst[i][1])
    else:
        print(0)
        break
else:
    res = (ans[2] - ans[0]) * (ans[3] - ans[1])
    print(res if res >= 0 else 0)

Solution (Python):
w,h,n = map(int,input().split())
stx = 0
sty = 0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        stx = max(stx,x)
    if a == 2:
        w = min(w,x)
    if a == 3:
        sty = max(sty,y)
    if a == 4:
        h = min(h,y)
if w-stx<=0 or h-sty<=0:
    ans = 0
else:
    ans = (w-stx)*(h-sty)
print(ans)

Solution (Python):
w,h,n=map(int,input().split())
xm,xM,ym,yM=0,w,0,h
xya=[[int(i) for i in input().split()] for i in range(n)]
for i in range(n):
    x,y,a=xya[i][0],xya[i][1],xya[i][2]
    if a==1 and xm<x:
        xm=x
    elif a==2 and xM>x:
        xM=x
    elif a==3 and ym<y:
        ym=y
    elif a==4 and yM>y:
        yM=y
if ym>=yM or xm>=xM:
    print(0)
else:
    print((xM-xm)*(yM-ym))

Solution (Python):
W, H, N = map(int, input().split())
xya = []
for _ in range(N):
  xya.append( list( map(int, input().split() ) ) )
  
W_0 = H_0 = 0
  
for i in range(N):
  
  if xya[i][2] == 1:
        if W_0 < xya[i][0]:
            W_0 =  xya[i][0]
    
  elif xya[i][2] == 2:
        if W > xya[i][0]:
            W = xya[i][0]
    
  elif xya[i][2] == 3:
        if H_0 < xya[i][1]:
            H_0 = xya[i][1]
    
  elif xya[i][2] == 4:
        if H > xya[i][1]:
            H = xya[i][1]
    
  if (W - W_0 <= 0) or (H - H_0 <= 0):
    break
    
print(max([(W - W_0)*(H - H_0), 0]))

Solution (Python):
W, H, N = map(int, input().split())
area = []
for i in range(1, H + 1):
    area.append([1 for n in range(W)])

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for _x in range(0, x):
            for h in range(0, H):
                area[h][_x] = 0
    if a == 2:
        for _x in range(x, W):
            for h in range(0, H):
                area[h][_x] = 0
    if a == 3:
        for _y in range(0, y):
            for w in range(0, W):
                area[_y][w] = 0
    if a == 4:
        for _y in range(y, H):
            for w in range(0, W):
                area[_y][w] = 0
print(sum([item for sublist in area for item in sublist]))

Solution (Python):
from collections import deque
W, H, N = map(int, input().split())
X = deque()
Y = deque()
A = deque()
for _ in range(N):
    x, y, a = map(int, input().split())
    X.append(x)
    Y.append(y)
    A.append(a)
a1 = 0
a2 = W
a3 = 0
a4 = H
for i in range(N):
    Ai = A.popleft()
    if Ai == 1:
        a1 = max(a1, X[i])
    elif Ai == 2:
        a2 = min(a2, X[i])
    elif Ai == 3:
        a3 = max(a3, Y[i])
    elif Ai == 4:
        a4 = min(a4, Y[i])
if a1 >= a2 or a3 >= a4:
    print(0)
else:
    print((a2 - a1) * (a4 - a3))

Solution (Python):
W,H,N=map(int,input().split())
L,D=0,0
for _ in [0]*N:
    x,y,a=map(int,input().split())
    if a==1:
        L=max(L,x)
    elif a==2:
        W=min(W,x)
    elif a==3:
        D=max(D,y)
    else:
        H=min(H,y)
print(max(0,(H-D))*max(0,(W-L)))

Solution (Python):
w,h,n = map(int,input().split())
x=[]
y=[]
a=[]
for i in range(n):
    x1,y1,a1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    a.append(a1)
x_max=w
x_min=0
y_max=h
y_min=0
for i in range(n):
    if a[i]==1:
        x_min = max(x_min,x[i])
    elif a[i]==2:
        x_max = min(x_max,x[i])
    elif a[i]==3:
        y_min = max(y_min,y[i])
    elif a[i]==4:
        y_max = min(y_max,y[i])
ans = (x_max-x_min)*(y_max-y_min)
if x_max < x_min or y_max < y_min:
    print(0)
else:
    print((x_max-x_min)*(y_max-y_min))

Solution (Python):
W,H,N=map(int,input().split())
X=[0]*W
Y=[0]*H
A=[]
for i in range(N):
    A.append([int(i) for i in input().split()])


for i in range(N):
    if A[i][2]==1:
        for j in range(A[i][0]):
            X[j]=1
    elif A[i][2]==2:
        for j in range(A[i][0],W):
            X[j]=1
    elif A[i][2]==3:
        for j in range(A[i][1]):
            Y[j]=1
    elif A[i][2]==4:
        for j in range(A[i][1],H):
            Y[j]=1
print(X.count(0)*Y.count(0))

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

Solution (Python):
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_min, x)
  elif a == 2:
    x_max = min(x_max, x)
  elif a == 3:
    y_min = max(y_min, y)
  else:
    y_max = min(y_max, y)
if x_max > x_min and y_max > y_min:
  print((x_max-x_min)*(y_max-y_min))
else:
  print('0')

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

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    X = max(X, x)
  elif a == 2:
    W = min(W, x)
  elif a == 3:
    Y = max(Y, y)
  elif a == 4:
    H = min(H, y)
    
if (W-X) < 0 or (H-Y) < 0:
  print(0)
else:
  print((W-X)*(H-Y))

Solution (Python):
W,H,N = map(int, input().split())
ans = [[1 for _ in range(W)] for _ in range(H)]

for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        for i in range(H):
            for j in range(x):
                ans[i][j] = 0
    if a == 2:
        for  i in range(H):
            for j in range(x, W):
                ans[i][j] = 0
    if a == 3:
        for i in range(y):
            for j in range(W):
                ans[i][j] = 0
    if a == 4:
        for i in range(y, H):
            for j in range(W):
                ans[i][j] = 0
print(sum([sum(ans[i]) for i in range(H)]))

Solution (Python):
W,H,N=map(int,input().split())
ans=[[1 for _ in range(W)] for _ in range(H)]

for i in range(N):
    x,y,a=map(int,input().split())
    if a == 1:
        for i in range(H):
            for j in range(x):
                ans[i][j] = 0
    if a == 2:
        for i in range(H):
            for j in range(x,W):
                ans[i][j] = 0
    if a == 3:
        for i in range(y):
            for j in range(W):
                ans[i][j] = 0
    if a == 4:
        for i in range(y,H):
            for j in range(W):
                ans[i][j] = 0
                
print(sum([sum(ans[i]) for i in range(H)]))

Solution (Python):
W, H, N = map(int, input().split())
P = [None] * N
A = [0] * N
for i in range(N):
    x, y, A[i] = map(int, input().split())
    P[i] = (x, y)

left = max({P[i][0] for i in range(N) if A[i] == 1} | {0})
right = min({P[i][0] for i in range(N) if A[i] == 2} | {W})
bottom = max({P[i][1] for i in range(N) if A[i] == 3} | {0})
top = min({P[i][1] for i in range(N) if A[i] == 4} | {H})
if right <= left or top <= bottom:
    print(0)
else:
    print((right - left) * (top - bottom))

Solution (Python):
w, h, n = [int(i) for i in input().split()]
xl = 0
xr = w
yt = h
yb = 0
for ni in range(n):
  x, y, a =[int(i) for i in input().split()]
  if a == 1:
    xl = max(x,xl)
  elif a == 2:
    xr = min(x,xr)
  elif a == 3:
    yb = max(y,yb)
  elif a == 4:
    yt = min(y,yt)
if xl > xr or yb > yt:
  print(0)
else:
  print((xr-xl)*(yt-yb))

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

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

L1 = []
L2 = []
L3 = []
L4 = []
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        L1.append(x)
    if a == 2:
        L2.append(x)      
    if a == 3:
        L3.append(y)
    if a == 4:
        L4.append(y)


if L1 != []:
    x_min = max(L1)
else:
    x_min = 0
    
if L2 != []:
    x_max = min(L2)
else:
    x_max = W
    
if L3 != []:
    y_min = max(L3)
else:
    y_min = 0
    
if L4 != []:
    y_max = min(L4)
else:
    y_max = H


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

Solution (Python):
import copy

w, h, n = [int(n) for n in input().split()]

a1 = [0]
a2 = [w]
a3 = [0]
a4 = [h]

for i in range(n):
    x, y, a = [int(n) for n in input().split()]
    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    elif a == 4:
        a4.append(y)

x1, x2, y3, y4 = max(a1), min(a2), max(a3), min(a4)

if x1 < x2 and y3 < y4:
    s = (x2 - x1) * (y4 - y3)
else:
    s = 0

print(s)

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

Solution (Python):
W,H,N = map(int,input().split())
board = [[0]*W for i in range(H)]
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        for j in range(H):
            for k in range(x):
                board[j][k]=1
    if a == 2:
        for j in range(H):
            for k in range(x,W):
                board[j][k]=1
    if a == 3:
        for j in range(W):
            for k in range(y):
                board[k][j]=1
    if a == 4:
        for j in range(W):
            for k in range(y,H):
                board[k][j]=1
ans = 0
for i in range(H):
    ans += board[i].count(0)
print(ans)

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

i = 0
rx = W
ry = H
lx = 0
ly = 0
while i < N:
    if a[i] == 1:
        lx = max(x[i],lx)
    elif a[i] == 2:
        rx = min(x[i],rx)
    elif a[i] == 3:
        ly = max(y[i],ly)
    elif a[i] == 4:
        ry = min(y[i],ry)
    i += 1

print(max(rx-lx,0)*max(ry-ly,0))

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

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

x_max = max([i[0] if i[2] == 1 else 0 for i in l])
x_min = min([i[0] if i[2] == 2 else W for i in l])
y_max = max([i[1] if i[2] == 3 else 0 for i in l])
y_min = min([i[1] if i[2] == 4 else H for i in l])

x = min(x_max+(W-x_min),W)
y = min(y_max+(H-y_min),H)

print(W*H - x*H - y*W + x*y)

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

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

xa = [0]
xb = [W]
ya = [0]
yb = [H]


for i in range(N):
    if a[i][2] == 1:
        xa.append(a[i][0])
    elif a[i][2] == 2:
        xb.append(a[i][0])
    elif a[i][2] == 3:
        ya.append(a[i][1])
    elif a[i][2] == 4:
        yb.append(a[i][1])

x1 = max(xa)
x2 = min(xb)
y1 = max(ya)
y2 = min(yb)
if x1 < x2 and y1 < y2:
    print((x2 - x1) * (y2 - y1))
else:
    print("0")

Solution (Python):
w,h,n=map(int,input().split())
record=[]
xmin=[]
xmax=[]
ymin=[]
ymax=[]

for i in range(n):
    x,y,a=list(map(int,input().split()))
    record.append([x,y,a])
    
for i in range(n):
    if record[i][2] == 1:
        xmin.append(record[i][0])
    elif record[i][2] == 2:
        xmax.append(record[i][0])
    elif record[i][2] == 3:
        ymin.append(record[i][1])
    else:
        ymax.append(record[i][1])

if xmax==[] and xmin==[]:
    X=w
elif xmax==[]:
    X=w-max(xmin)
elif xmin==[]:
    X=min(xmax)-0
else:
    X=min(xmax)-max(xmin)

if ymax==[] and ymin==[]:
    Y=h
elif ymax==[]:
    Y=h-max(ymin)
elif ymin==[]:
    Y=min(ymax)-0
else:
    Y=min(ymax)-max(ymin)
    
print(X*Y) if (X > 0 and Y > 0) else print(0)

Solution (Python):
W,H,N = map(int,input().split())
LIX = []
LIY = []
LIA = []
for i in range(N):
    A,B,C = map(int,input().split())
    LIX.append(A)
    LIY.append(B)
    LIA.append(C)
    
NUMX = []
NUMY = []
for i in range(W):
    NUMX += [i+1]
for i in range(H):
    NUMY += [i+1]
    
for i in range(N):
    if LIA[i] == 1:
        for j in range(LIX[i]):
            if j+1 in NUMX:
                NUMX.remove(j+1)
    if LIA[i] == 3:
        for j in range(LIY[i]):
            if j+1 in NUMY:
                NUMY.remove(j+1)
    if LIA[i] == 2:
        for j in range(LIX[i]+1, W+1):
            if j in NUMX:
                NUMX.remove(j)
    if LIA[i] == 4:
        for j in range(LIY[i]+1, H+1):
            if j in NUMY:
                NUMY.remove(j)
print(len(NUMX)*len(NUMY))

Solution (Python):
w,h,n = map(int,input().split())
xya = [list(map(int,input().split())) for _ in range(n)]
wzero,hzero = 0,0
for i in xya:
	if i[2] == 1:
		if wzero < i[0]:
			wzero = i[0]
	if i[2] == 2:
		if w  > i[0]:
			w = i[0]
	if i[2] == 3:
		if hzero < i[1]:
			hzero = i[1]
	if i[2] == 4:
		if h > i[1]:
			h = i[1]
print((h-hzero)*(w-wzero) if h-hzero >=0 and w-wzero>=0 else 0)

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

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

Solution (Python):


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

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

if xy[0][0]<xy[0][1] and xy[1][0]<xy[1][1]:
  print((xy[0][1]-xy[0][0])*(xy[1][1]-xy[1][0]))
else:
  print(0)

Solution (Python):
W, H, N = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
X1, X2, Y1, Y2 = 0, W, 0, H

for x, y, a in P:
    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)
else:
    if X2 <= X1 or Y2 <= Y1:
        print(0)
    else:
        print((X2 - X1) * (Y2 - Y1))

Solution (Python):
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
 
x1 = 0 
x2 = W 
y3 = 0 
y4 = H 
 

for x,y,a in xya:
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y3 = max(y3, y)
    elif a == 4:
        y4 = min(y4, y)
else:
    
    if x2 <= x1 or y4 <= y3:
        print(0)
    else:
        print((x2-x1) * (y4-y3))

Solution (Python):
import sys
from collections import Counter

bw, bh = 0, 0
w, h, n = map(int, input().split())
xya_array = [list(map(int, input().split())) for _ in range(n)]

for i in xya_array:
    if i[2] == 1:
        bw = max(bw, i[0])
    elif i[2] == 2:
        w = min(w, i[0])
    elif i[2] == 3:
        bh = max(bh, i[1])
    elif i[2] == 4:
        h = min(h, i[1])

if w-bw < 0 or h-bh < 0:
    print(0)
else:
    print((w-bw)*(h-bh))

Solution (Python):
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]

x1 = 0 
x2 = W 
y3 = 0 
y4 = H 


for x,y,a in xya:
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y3 = max(y3, y)
    elif a == 4:
        y4 = min(y4, y)
else:
    
    if x2 <= x1 or y4 <= y3:
        print(0)
    else:
        print((x2-x1) * (y4-y3))

Solution (Python):
W, H, N = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
i, j = 0, 0
w, h = W, H
for x, y, a in L:
    if a == 1:
        i = max(i, x)
    if a == 2:
        w = min(w, x)
    if a == 3:
        j = max(j, y)
    if a == 4:
        h = min(h, y)
if w <= i or h <= j:
    print(0)
else:
    print((w - i) * (h - j))

Solution (Python):
W,H,N = map(int,input().split())
minx,maxx,miny,maxy = 0,W,0,H
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        minx = max(x,minx)
    if a == 2:
        maxx = min(x,maxx)
    if a == 3:
        miny = max(y,miny)
    if a == 4:
        maxy = min(y,maxy)
print(max(0, maxx - minx) * max(0, maxy - miny))

Solution (Python):
W,H,N = map(int,input().split())
rectangle = [[1 for i in range(W)] for j in range(H)]

def paint(x,y,a):
    if a == 1:
        for i in range(x):
            for j in range(H):
                rectangle[j][i] = 0
    if a == 2:
        for i in range(x,W):
            for j in range(H):
                rectangle[j][i] = 0
    if a == 3:
        for i in range(W):
            for j in range(y):
                rectangle[j][i] = 0
    if a == 4:
        for i in range(W):
            for j in range(y,H):
                rectangle[j][i] = 0


for i in range(N):
    x,y,a = map(int,input().split())
    paint(x,y,a)
ans = 0
for line in rectangle:
    ans += line.count(1)
print(ans)

Solution (Python):


def solve(W, H, N, X, Y, A):
    dp = [[0]*(W) for i in range(H)]
    count = 0
    
    for i in range(N):
        x_now, y_now, a_now = X[i], Y[i], A[i]
        if(a_now == 1):
            for i in range(H):
                for j in range(x_now):
                    dp[i][j] = 1
        if(a_now == 2):
            for i in range(H):
                for j in range(x_now, W):
                    dp[i][j] = 1
        if(a_now == 3):
            for i in range(y_now):
                for j in range(W):
                    dp[i][j] = 1
        if(a_now == 4):
            for i in range(y_now, H):
                for j in range(W):
                    dp[i][j] = 1
    
    for i in range(H):
        count += dp[i].count(0)
    print(count)
    
if __name__ == '__main__':
    W, H, N = map(int, input().split())
    X, Y, A = [], [], []
    for i in range(N):
        x, y, a = map(int, input().split())
        X.append(x)
        Y.append(y)
        A.append(a)
    
    solve(W, H, N, X, Y, A)

Solution (Python):
W, H, N = map(int, input().split())
xl, xh = (0, W)
yl, yh = (0, H)
for i in range(N):
    x, y, a = map(int, input().split())
    xl = max(xl, x) if (a==1) else xl
    xh = min(xh, x) if (a==2) else xh
    yl = max(yl, y) if (a==3) else yl
    yh = min(yh, y) if (a==4) else yh
print(max(xh-xl, 0)*max(yh-yl, 0))