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())
x_max=W
x_min=0
y_max=H
y_min=0
for i in range(N):
  li=list(map(int,input().split()))
  if li[2]==1 and li[0]>x_min:
    x_min=li[0]
  elif li[2]==2 and li[0]<x_max:
    x_max=li[0]
  elif li[2]==3 and li[1]>y_min:
    y_min=li[1]
  elif li[2]==4 and li[1]<y_max:
    y_max=li[1]
    

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

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

Solution (Python):
w, h, n = map(int,input().split())
arr = [[0 for i in range(w)] for j in range(h)]
sums = 0
for i in range(n):
  x, y, a = map(int,input().split())
  if a == 1:
    for i in range(x):
      for j in range(h):
        arr[j][i] = 1
  elif a == 2:
    for i in range(x,w):
      for j in range(h):
        arr[j][i] = 1
  elif a == 3:
    for i in range(y):
      for j in range(w):
        arr[i][j] = 1
  else:
    for i in range(y,h):
      for j in range(w):
        arr[i][j] = 1
for i in arr:
  sums += i.count(0)
print(sums)

Solution (Python):

w, h, n = [int(el) for el in input().split(' ')]
field = [[int(el) for el in input().split(' ')] for i in range(n)]

left = 0
right = w
top = h
bottom = 0

for i in range(n):
    if field[i][2] == 1:
        left = max(left, field[i][0])
    if field[i][2] == 2:
        right = min(right, field[i][0])
    if field[i][2]  == 3:
        bottom = max(bottom, field[i][1])
    if field[i][2] == 4:
        top = min(top, field[i][1])
print(max(top - bottom, 0) * max(right - left, 0))

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())
anslist = [[1 for i in range(H)] for j in range(W)]
for i in range(N):
  if a[i] == 1:
    for k in range(x[i]):
      for l in range(H):
        anslist[k][l] = 0
  elif a[i] == 2:
     for k in range(x[i], W):
      for l in range(H):
        anslist[k][l] = 0
  elif a[i] == 3:
     for k in range(W):
      for l in range(y[i]):
        anslist[k][l] = 0
  elif a[i] == 4:
     for k in range(W):
      for l in range(y[i],H):
        anslist[k][l] = 0
print(sum([sum(anslist[i]) for i in range(W)]))

Solution (Python):
w,h,n = map(int,input().split())
data = []
for i in range(n):
    data.append(list(map(int,input().split())))
map_data = [[0 for i in range(w)] for j in range(h)]
for i in range(n):
    if data[i][2] == 1:
       for j in range(h):
           for k in range(0,data[i][0]):
               map_data[j][k] = 1
    elif data[i][2] == 2:
       for j in range(h):
           for k in range(data[i][0],w):
               map_data[j][k] = 1
    elif data[i][2] == 3:
       for j in range(0,data[i][1]):
           for k in range(w):
               map_data[j][k] = 1
    else:
       for j in range(data[i][1],h):
           for k in range(w):
               map_data[j][k] = 1
ans = 0
for i in range(h):
    ans += map_data[i].count(0)
print(ans)

Solution (Python):
w, h, n = list(map(int, input().split()))
al, xl, yl = [0 for i in range(n)], [0 for i in range(n)], [0 for i in range(n)]
for i in range(n):
	x,y,a = list(input().split())
	xl[i] = int(x)
	yl[i] = int(y)
	al[i] = a

total = w*h
d = {"1": 0, "2": w, "3": 0, "4": h}
for i in range(n):
	if al[i] == "1":
		if xl[i] > d["1"]:
			d["1"] = xl[i]
	elif al[i] == "2":
		if xl[i] < d["2"]:
			d["2"] = xl[i]
	elif al[i] == "3":
		if yl[i] > d["3"]:
			d["3"] = yl[i]
	else:
		if yl[i] < d["4"]:
			d["4"] = yl[i]
if (d["2"]-d["1"]) <= 0 or (d["4"]-d["3"]) <= 0:
	print(0)
else:
	print((d["2"]-d["1"]) * (d["4"]-d["3"]))

Solution (Python):
w, h, n = map(int, input().split())
a_r = w
a_l = 0
a_u = h
a_d = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        a_l = max(a_l, x)
    elif a == 2:
        a_r = min(a_r, x)
    elif a == 3:
        a_d = max(a_d, y)
    else:
        a_u = min(a_u, y)


print(max(0, a_r - a_l) * max(0, a_u - a_d))

Solution (Python):

import sys, math, fractions, itertools


def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    xmin = W
    xmax = 0
    ymin = H
    ymax = 0
    for i in range(N):
        if a[i] == 1:
            xmax = max(xmax, x[i])
        elif a[i] == 2:
            xmin = min(xmin, x[i])
        elif a[i] == 3:
            ymax = max(ymax, y[i])
        else:
            ymin = min(ymin, y[i])
    print((max(ymin - ymax, 0))* max(xmin - xmax, 0))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  
    H = int(next(tokens))  
    N = int(next(tokens))  
    x = [int()] * (N)  
    y = [int()] * (N)  
    a = [int()] * (N)  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)

if __name__ == '__main__':
    main()

Solution (Python):
W,H,N = map(int,input().split())
x1mx = 0
x2mi = W
y3mx = 0
y4mi = H

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if x > x1mx:
            x1mx =x
    elif a == 2:
        if x < x2mi:
            x2mi =x
    elif a == 3:
        if y > y3mx:
            y3mx =y
    elif a ==4:
        if y < y4mi:
            y4mi =y

if x1mx >=x2mi or  y3mx >= y4mi:
    print(0)
else:
    print((x2mi - x1mx)*(y4mi - y3mx))

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

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):
                fld[j][k] = 1
    elif a == 2:
        for j in range(h):
            for k in range(x,w):
                fld[j][k] = 1
    elif a == 3:
        for j in range(w):
            for k in range(y):
                fld[k][j] = 1
    else:
        for j in range(w):
            for k in range(y,h):
                fld[k][j] = 1

cnt = 0
for i in range(h):
    for j in range(w):
        if fld[i][j] == 0:
            cnt += 1
print(cnt)

Solution (Python):
W,H,N = map(int,input().split())
bo = [[0]*W]*H
for i in range(N):
    x,y,z = map(int,input().split())
    if z == 1:
        for j in range(H):
            for k in range(x):
                bo[j][k] = 1
    elif z == 2:
        for j in range(H):
            for k in range(x,W,1):
                bo[j][k] = 1
    elif z == 3:
        for j in range(y):
            bo[j] = [1]*W
    else:
        for j in range(H-1,y-1,-1):
            bo[j] = [1]*W

sum = 0

for i in range(H-1,-1,-1):
    sum += bo[i][:].count(1)
print((W*H)-sum)

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import bisect



def main():
    width, high, num = map(int, input().split())
    data = [[0 for i in range(width)] for j in range(high)]

    for i in range(num):
        x, y, a = map(int, input().split())
        if a == 1:
            for j in range(high):
                for k in range(x):
                    data[j][k] = 1
        elif a == 2:
            for j in range(high):
                for k in range(x, width):
                    data[j][k] = 1
        elif a == 3:
            for j in range(y):
                for k in range(width):
                    data[j][k] = 1
        elif a == 4:
            for j in range(y, high):
                for k in range(width):
                    data[j][k] = 1

        

    
    

    ans = 0
    for i in range(high):
        ans += data[i].count(0)

    print(ans)





if __name__ == '__main__':
    main()

Solution (Python):
import itertools

w, h, n = map(int, input().split())
x = [None] * n
y = [None] * n
a = [None] * n
for i in range(n):
    x[i], y[i], a[i] = map(int, input().split())


area = [[False] * h for _ in range(w)]
for i in range(n):
    for p, q in itertools.product(range(w), range(h)):
        if a[i] == 1 and p < x[i]:  area[p][q] = True
        if a[i] == 2 and p >= x[i]: area[p][q] = True
        if a[i] == 3 and q < y[i]:  area[p][q] = True
        if a[i] == 4 and q >= y[i]: area[p][q] = True

print(sum(sum(1 for v in row if not v) for row in area))

Solution (Python):
import numpy as np


w, h, n = map(int, input().split())
m = np.zeros((h, w), int)
while n:
    x, y, a = map(int, input().split())
    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):
import numpy as np
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())

check = [[0]*W for _ in range(H)]

for i in range(N):
    if a[i] == 1:
        for j in range(H):
            k = 0
            while k != x[i]:
                check[j][k] = 1
                k += 1
    if a[i] == 2:
        for j in range(H):
            k = x[i]
            while k != W:
                check[j][k] = 1
                k += 1
    if a[i] == 3:
        k = 0
        while k != y[i]:
            for j in range(W):
                check[k][j] = 1
            k += 1
    if a[i] == 4:
        k = y[i]
        while k != H:
            for j in range(W):
                check[k][j] = 1
            k += 1


ans = 0

for i in range(H):
    tmp = check[i].count(0)
    ans += tmp

print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    x0, x1 = 0, W
    y0, y1 = 0, H
    for i in range(N):
        if a[i] == 1:
            x0 = max(x0, x[i])
        if a[i] == 2:
            x1 = min(x1, x[i])
        if a[i] == 3:
            y0 = max(y0, y[i])
        if a[i] == 4:
            y1 = min(y1, y[i])
    if x1 <= x0 or y1 <= y0:
        ret = 0
    else:
        ret = (x1 - x0) * (y1 - y0)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  
    H = int(next(tokens))  
    N = int(next(tokens))  
    x = [int()] * (N)  
    y = [int()] * (N)  
    a = [int()] * (N)  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)

if __name__ == '__main__':
    main()

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

Solution (Python):
w,h,n = map(int,input().split())
l = []
for i in range(n):
  l.append(list(map(int,input().split())))
xmin = 0
ymin = 0
xmax = w
ymax = h
for i in range(n):
  if l[i][-1] == 1:
    xmin = max([xmin,l[i][0]])
  elif l[i][-1] == 2:
    xmax = min([xmax,l[i][0]])
  elif l[i][-1] == 3:
    ymin = max([ymin,l[i][1]])
  else:
    ymax = min([ymax,l[i][1]])
if ymax <= ymin or xmax <= xmin:
  S = 0
else:
  S = (ymax-ymin)*(xmax-xmin)
print (S)

Solution (Python):
W,H,N=map(int,input().split())
D=[list(map(int,input().split()))for _ in range(N)]
sx=0
sy=0
lx=W
ly=H
for d in D:
  if d[2]==1:
    sx=max(sx,d[0])
    
  elif d[2]==2:
    lx=min(lx,d[0])
    
  elif d[2]==3:
    sy=max(sy,d[1])
  else:
    ly=min(ly,d[1])
if lx<=sx or ly<=sy:
  print(0)
else:
  print((lx-sx)*(ly-sy))

Solution (Python):
W,H,M = map(int, input().split())
maxX,minX,maxY,minY = W, 0, H ,0
for i in range(M):
  x, y, a = map(int, input().split())
  if a == 1 and x > minX:
    minX = x
  elif a == 2 and x < maxX:
    maxX = x
  elif a == 3 and y > minY:
    minY = y
  elif a == 4 and y < maxY:
    maxY = y

  
xl = maxX - minX
yl = maxY - minY
if xl > 0 and yl > 0:
  print(xl * yl)
else:
  print(0)

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)
print(max(0, w-x_min) * max(0, h-y_min))

Solution (Python):
w, h, n = map(int, input().split())
area = []
for i in range(h):
    temp = [0] * w
    area.append(temp)
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(x):
            for k in range(h):
                area[k][j] = 1
    elif a == 2:
        for j in range(x, w):
            for k in range(h):
                area[k][j] = 1
    elif a == 3:
        for j in range(w):
            for k in range(y):
                area[k][j] = 1
    else:
        for j in range(w):
            for k in range(y, h):
                area[k][j] = 1
count = 0
for i in range(w):
    for j in range(h):
        if area[j][i] == 0:
            count += 1
print(count)

Solution (Python):
import numpy as np
import sys
from collections import Counter
W, H, N = map(int, input().split())

grid = np.array([[0] * W] * H)

for n in range(N):
    tmp_w, tmp_h, a = map(int, input().split())
    if a == 1:
        grid.T[: tmp_w] = 1
    if a == 2:
        grid.T[tmp_w:] = 1
    if a == 3:
        grid[0: tmp_h] = 1
    if a == 4:
        grid[tmp_h: ] = 1
    

print(Counter((grid.reshape(1, W * H).tolist())[0])[0])

Solution (Python):
W, H, N = map(int, input().split())
Xmax, Xmin, Ymax, Ymin = W, 0, H, 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > Xmin:
        Xmin = x
    elif a == 2 and x < Xmax:
        Xmax = x
    elif a == 3 and y > Ymin:
        Ymin = y
    elif a == 4 and y < Ymax:
        Ymax = y

if Xmax - Xmin > 0 and Ymax - Ymin > 0:
    print((Xmax-Xmin) * (Ymax - Ymin))
else:
    print(0)

Solution (Python):
W, H, N = map(int,input().split())
xmin,xmax,ymin,ymax = 0,W,0,H
for _ in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if x > xmin:
            xmin = x
    elif a == 2:
        if x < xmax:
            xmax = x
    elif a == 3:
        if y > ymin:
            ymin = y
    else:
        if y < ymax:
            ymax = y


if xmax-xmin > 0 and ymax-ymin > 0:
    print((xmax-xmin)*(ymax-ymin))
else:
    print(0)

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

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

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

Solution (Python):

import sys
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

w, h, n = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
square = np.zeros((h, w), dtype="int16")

for i in l:
    if (i[2] == 1):
        square[:, :i[0]] = 1
    elif (i[2] == 2):
        square[:, i[0]:] = 1
    elif (i[2] == 3):
        square[:i[1], :] = 1
    else:
        square[i[1]:, :] = 1

print(w*h-np.sum(square))

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    w, h, N = map(int, input().split())
    xya = [list(map(int, input().split())) for i in range(N)]


    top = h
    bottom = 0
    left = 0
    right = w
    for i in range(N):
        x, y, a = xya[i]
        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)
    
    if bottom >= top or left >= right:
        print(0)
    else:
        print((top-bottom)*(right-left))




if __name__ == "__main__":
    main()

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

wl = 0
wr = W
hu = H
hl = 0

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1 and x > wl:
        wl = x
    elif a == 2 and x < wr:
        wr = x
    elif a == 3 and y > hl:
        hl =y
    elif a == 4 and y < hu:
        hu = y
    
if wl>wr or hl>hu:
    print(0)
else:
    print((wr-wl)*(hu-hl))

Solution (Python):
W, H, N = map(int, input().split())
x0, x1, y0, y1 = 0, W, 0, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x0 = max(x0, x)
    if a == 2:
        x1 = min(x1, x)
    if a == 3:
        y0 = max(y0, y)
    if a == 4:
        y1 = min(y1, y)

if x1 > x0 and y1 > y0:
    print((x1 - x0) * (y1 - y0))
else:
    print(0)

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

Solution (Python):
h, w, n = map(int, input().split())
a = [[0] * w for _ in range(h)]

while n > 0:
  n -= 1
  y, x, z = map(int, input().split())
  if z == 1:
    for i in range(y):
      for j in range(w):
        a[i][j] = 1
    continue
  if z == 2:
    for i in range(y, h):
      for j in range(w):
        a[i][j] = 1
    continue
  if z == 3:
    for i in range(h):
      for j in range(x):
        a[i][j] = 1
    continue
  for i in range(h):
    for j in range(x, w):
      a[i][j] = 1

print(w * h - sum(sum(it) for it in a))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b, c = LI()
    if a == b + c:
        print("Yes")
    elif b == a + c:
        print("Yes")
    elif c == a + b:
        print("Yes")
    else:
        print("No")
    return


def B():
    W, H, n = LI()
    wh = [[0, W], [0, H]]
    for _ in range(n):
        x, y, a = LI()
        wha = wh[a > 2]
        x = y if a > 2 else x
        wha[0] = max(x, wha[0]) * (a % 2) or wha[0]
        wha[1] = wha[1] * (a % 2) or min(x, wha[1])
        if wha[0] >= wha[1]:
            print(0)
            return
    print(max(0, (wh[0][1] - wh[0][0]) * (wh[1][1] - wh[1][0])))
    return


def C():
    return


def D():
    return


if __name__ == '__main__':
    B()

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

if x1 > x0 and y1 > y0:
	print((x1 - x0) * (y1 - y0))
else:
	print(0)

Solution (Python):
a, b, c = map(int, input().split())
maxX = a
maxY = b
minX = minY = 0
for i in range(c):
    x, y, z = map(int, input().split())
    if z == 1:
        minX = max(minX, x)
    elif z == 2:
        maxX = min(maxX, x)
    elif z == 3:
        minY = max(minY, y)
    elif z == 4:
        maxY = min(maxY, y)
if minX >= maxX or minY >= maxY:
    print(0)
else:
    print(abs(minX - maxX) * abs(minY - maxY))

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

a,b=0,0
for i in range(n):
    if l[i][2]==1:a=max(a,l[i][0])
    elif l[i][2]==2:w=min(w,l[i][0])
    elif l[i][2]==3:b=max(b,l[i][1])
    else:h=min(h,l[i][1])

print(max(0,w-a)*max(0,h-b))

Solution (Python):
x, y, n = map(int, input().split())
input = [list(map(int, input().split())) for _ in range(n)] 
xmax = x
xmin = 0
ymax = y
ymin = 0
for i in input:
    type = i[2]
    if type == 1 and (i[0] > xmin):
        xmin = i[0]
    elif type == 2 and (i[0] < xmax):
        xmax = i[0]
    elif type == 3 and (i[1] > ymin):
        ymin = i[1]
    elif type == 4 and (i[1] < ymax):
        ymax = i[1]
if (xmax > xmin) and (ymax > ymin):
    print((xmax - xmin)*(ymax - ymin))
else:
    print(0)

Solution (Python):
from operator import itemgetter

w, h, n = map(int, input().split())
binary = [[0 for _ in range(h)] for i in range(w)]

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

total = 0
for i in range(len(binary)):
    total += binary[i].count(0) 
print(total)

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

Solution (Python):
w,h,n=map(int,input().split())
s=[[1]*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(x):
            for k in range(h):
                s[k][j]=0
                
    elif a==2:
        for j in range(x,w):
            for k in range(h):
                s[k][j]=0        
    elif a==3:
        for j in range(w):
            for k in range(y):
                s[k][j]=0  
    elif a==4:
        for j in range(w):
            for k in range(y,h):
                s[k][j]=0  
    
ss=[]
for i in s:
    ss.extend(i)

print(ss.count(1))

Solution (Python):
W, H, N = map(int, input().split())
ws, we, hs, he = 0, W, 0, H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        ws = max(ws, x)
    elif a == 2:
        we = min(we, x)
    elif a == 3:
        hs = max(hs, y)
    elif a == 4:
        he = min(he, y)
if we >= ws and he >= hs:
    res = (we - ws)*(he - hs)
else:
    res = 0
print(res)

Solution (Python):
w,h,n=map(int,input().split())
x_1=[0]
x_2=[w]
y_1=[0]
y_2=[h]

for _ in range(n):
    tmp_x,tmp_y,tmp_a=map(int,input().split())
    if tmp_a==1:
        x_1.append(tmp_x)
    elif tmp_a==2:
        x_2.append(tmp_x)
    elif tmp_a==3:
        y_1.append(tmp_y)
    elif tmp_a==4:    
        y_2.append(tmp_y)
        
ans=max(0,(min(x_2)-max(x_1)))*max(0,(min(y_2)-max(y_1)))

print(ans)

Solution (Python):

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

maxx = W
minx = 0
maxy = H
miny = 0

for i in range(N):

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

    if a == 1:

        minx = max(minx,x)

    if a == 2:

        maxx = min(maxx,x)
        
    if a == 3:

        miny = max(miny,y)

    if a == 4:

        maxy = min(maxy,y)


print ( max (0,maxx-minx) * max (0,maxy-miny))

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

minx = 0
miny = 0
MAXx = W
MAXy = H

for k in range(N):
    if list[k][2] == 1:
        minx = max(list[k][0], minx)
    elif list[k][2] == 2:
        MAXx = min(list[k][0], MAXx)
    elif list[k][2] == 3:
        miny = max(list[k][1], miny)
    elif list[k][2] == 4:
        MAXy = min(list[k][1], MAXy)

if MAXx - minx < 0 or MAXy - miny < 0:
    print(0)
else:
    print((MAXx - minx) * (MAXy - miny))

Solution (Python):
w, h, n = map(int, input().split())
arr = [[int(i) for i in input().split()] for j in range(n)]
x1, y1, x2, y2 = 0, 0, w, h

for x, y, a in arr:
    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(x2-x1, 0) * max(y2-y1, 0))

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

l, r, d, u = 0, W, 0, H
for _ 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 :
        d = max(d, y)
    else :
        u = min(u, y)

if l <= r and d <= u :
    print((r - l) * (u - d))
else :
    print(0)

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

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


for list in list:
    if list[2] == 1:
        x_min = max(list[0], x_min)
    elif list[2] == 2:
        x_max = min(list[0], x_max)
    elif list[2] == 3:
        y_min = max(list[1], y_min)
    else:
        y_max = min(list[1], y_max)
 
ans = max((x_max - x_min), 0) * max((y_max - y_min), 0)
print(ans)

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

x_min = 0
y_min = 0
x_max = w
y_max = h
for a in coord_list:
    if a[2] == 1:
        x_min = max(a[0], x_min)
    elif a[2] == 2:
        x_max = min(a[0], x_max)
    elif a[2] == 3:
        y_min = max(a[1], y_min)
    elif a[2] == 4:
        y_max = min(a[1], y_max)

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

Solution (Python):
from sys import stdin
W,H,N = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])

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

for i in data:
    if i[2] == 1:
        x1 = max(x1,i[0])
    if i[2] == 2:
        x2 = min(x2,i[0])
    if i[2] == 3:
        y1 = max(y1,i[1])
    if i[2] == 4:
        y2 = min(y2,i[1])

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

Solution (Python):
w,h,n = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
xmin = 0
ymin = 0
xmax = w
ymax = h
for i in range(n):
    if l[i][2] == 1:
        xmin = max([xmin,l[i][0]])
    elif l[i][2] == 2:
        xmax = min([xmax,l[i][0]])
    elif l[i][2] == 3:
        ymin = max([ymin,l[i][1]])
    elif l[i][2] == 4:
        ymax = min([ymax,l[i][1]])
if xmax <= xmin or ymax <= ymin:
    print(0)
else:
    print((xmax - xmin) * (ymax - ymin))

Solution (Python):



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

m = [[False]*w for _ in range(h)]

for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        for i in range(h):
            for j in range(x):
                m[i][j] = True
    elif a == 2:
        for i in range(h):
            for j in range(x,w):
                m[i][j] = True
    elif a == 3:
        for i in range(y):
            for j in range(w):
                m[i][j] = True
    elif a == 4:
        for i in range(y,h):
            for j in range(w):
                m[i][j] = True
ans = 0
for i in range(h):
    for j in range(w):
        if m[i][j] == False:
            ans += 1
print(ans)

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

Solution (Python):



def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [tuple(map(typ, input().split())) if m > 1 else typ(input()) for _ in range(n)]


def main():
    W, H, N = read_h()
    pts = read_v(N, m=3)
    rec = [0, 0, W, H]

    for x, y, a in pts:
        if a == 1:
            rec[0] = max(rec[0], x)
        elif a == 2:
            rec[2] = min(rec[2], x)
        elif a == 3:
            rec[1] = max(rec[1], y)
        elif a == 4:
            rec[3] = min(rec[3], y)

        if rec[2] - rec[0] <= 0 or rec[3] - rec[1] <= 0:
            print(0)
            return

    ans = (rec[2] - rec[0]) * (rec[3] - rec[1])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [tuple(map(typ, input().split())) if m > 1 else typ(input()) for _ in range(n)]


def main():
    W, H, N = read_h()
    pts = read_v(N, m=3)
    area = [[0, 0], [W, H]]

    for x, y, a in pts:
        if a == 1 and area[0][0] < x:
            area[0][0] = x
        elif a == 2 and area[1][0] > x:
            area[1][0] = x
        elif a == 3 and area[0][1] < y:
            area[0][1] = y
        elif a == 4 and area[1][1] > y:
            area[1][1] = y

        if area[1][0] - area[0][0] <= 0 or area[1][1] - area[0][1] <= 0:
            print(0)
            return

    ans = (area[1][0] - area[0][0]) * (area[1][1] - area[0][1])
    print(ans)


if __name__ == '__main__':
    main()