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())
u, U, v, V = 0, W, 0, H
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        u = max(u,x)
    if a == 2:
        U = min(U,x)
    if a == 3:
        v = max(v,y)
    if a == 4:
        V = min(V,y)
f = lambda x:x if x > 0 else 0
print(f(U-u)*f(V-v))

Solution (Python):
import numpy as np

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a==1:
        area[:x, :] = 1
    elif a==2:
        area[x:, :] = 1
    elif a==3:
        area[:, :y] = 1
    else:
        area[:, y:] = 1

print((w*h) - int(area.sum()))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    W, H, N = map(int, input().split())
    mat = [[1] * 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):
                    mat[i][j] = 0
        if a == 2:
            for i in range(H):
                for j in range(x, W):
                    mat[i][j] = 0
        if a == 3:
            for i in range(y):
                for j in range(W):
                    mat[i][j] = 0
        if a == 4:
            for i in range(y, H):
                for j in range(W):
                    mat[i][j] = 0
    ans = 0
    for i in range(H):
        for j in range(W):
            ans += mat[i][j]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
W, H, N = map(int, input().split())
bl_x, tr_x, bl_y, tr_y = 0, W, 0, H
for i in range(N):
	x, y, a = map(int, input().split())
	if a == 1:
		bl_x = max(bl_x, x)
	elif a == 2:
		tr_x = min(tr_x, x)
	elif a == 3:
		bl_y = max(bl_y, y)
	elif a == 4:
		tr_y = min(tr_y, y)
print(max(tr_x - bl_x, 0) * max(tr_y - bl_y, 0))

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    w,h,n = LI()
    board = [[1]*h for _ in range(w)]

    for _ in range(n):
        x,y,a = LI()
        if a == 1:
            for i in range(x):
                board[i] = [0 for _ in range(h)]
        elif a == 2:
            for i in range(x,w):
                board[i] = [0 for _ in range(h)]
        elif a == 3:
            for i in range(w):
                for j in range(y):
                    board[i][j] = 0
        elif a == 4:
            for i in range(w):
                for j in range(y,h):
                    board[i][j] = 0

    ans = 0
    for line in board:
        ans += sum(line)

    print(ans)

    
main()

Solution (Python):



def main():
    w, h, n = map(int, input().split())
    r = [[0] * 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):
                    r[j][k] = 1
        elif a == 2:
            for j in range(x, w):
                for k in range(h):
                    r[j][k] = 1
        elif a == 3:
            for j in range(w):
                for k in range(y):
                    r[j][k] = 1
        elif a == 4:
            for j in range(w):
                for k in range(y, h):
                    r[j][k] = 1
    ans = 0
    for i in range(w):
        for j in range(h):
            if r[i][j] == 0:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
w, h, n = map(int, input().split())
loc = [input() for _ in range(n) ]

def black(x, y, i):
    if i == 1:
        mtx[:x,] = 0
    elif i == 2:
        mtx[x:,] = 0
    elif i == 3:
        mtx[:, :y] = 0
    elif i == 4:
        mtx[:, y:] = 0

        
mtx = np.ones((w, h), dtype=int)
for l in loc:
    x, y, i = map(int, l.split())
    black(x, y, i)
print(mtx.sum())

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

X = [[i+1, "w"] for i in range(W)]
Y = [[i+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(len(X)):
            if X[j][0] <= x:
                X[j][1] = "b"
    elif a == 2:
        for j in range(len(X)):
            if X[j][0] > x:
                X[j][1] = "b"
    elif a == 3:
        for j in range(len(Y)):
            if Y[j][0] <= y:
                Y[j][1] = "b"
    elif a == 4:
        for j in range(len(Y)):
            if Y[j][0] > y:
                Y[j][1] = "b"
x_w = 0
y_w = 0
for i in range(len(X)):
    if X[i][1] == "w":
        x_w += 1
for i in range(len(Y)):
    if Y[i][1] == "w":
        y_w += 1
print(x_w * y_w)

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

Solution (Python):
w, h, n = map(int, input().split())
ans = [[0 for _ in range(w)] for _ in range(h)]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(h):
            ans[j][:x] = [1 for _ in range(x)]
    if a == 2:
        for j in range(h):
            ans[j][x:] = [1 for _ in range(w-x)]
    if a == 3:
        for j in range(h-y,h):
            ans[j] = [1 for _ in range(w)]
    if a == 4:
        for j in range(h-y):
            ans[j] = [1 for _ in range(w)]
cnt = 0
for k in ans:
    cnt += k.count(0)
print(cnt)

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

print(max(0, W-oX)*max(0, H-oY))

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

point_list = []
for h in range(H):
  list_ = []
  for w in range(W):
    list_.append(1)
  point_list.append(list_)

for input_ in input_list:
  x, y, a = input_
  if a == 1:
    for h in range(H):
      for i in range(x):
        point_list[h][i] = 0
  if a == 2:
    for h in range(H):
      for i in range(x, W):
        point_list[h][i] = 0
  if a == 3:
    for i in range(y):
      for w in range(W):
        point_list[i][w] = 0
  if a == 4:
    for i in range(y, H):
      for w in range(W):
        point_list[i][w] = 0

ans = sum([sum(point) for point in point_list])
print(ans)

Solution (Python):
w,h,n=map(int,input().split())
max_x,min_x,max_y,min_y=w,0,h,0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    min_x=max(min_x,x)
  elif a==2:
    max_x=min(max_x,x)
  elif a==3:
    min_y=max(min_y,y)
  elif a==4:
    max_y=min(max_y,y)
print(max(0,max_x-min_x)*max(0,max_y-min_y))

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

a1,a2,a3,a4 = -1,101,-1,101
for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    a1 = max(a1,x)
  elif a == 2:
    a2 = min(a2,x-1)
  elif a == 3:
    a3 = max(a3,y)
  else:
    a4 = min(a4,y-1)
    
mass = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
  for j in range(W):
    if i < a3 or a4 < i:
      mass[i][j] += 1
    if j < a1 or a2 < j:
      mass[i][j] += 1
      
cnt = 0
for k in mass:
  cnt += k.count(0)
  
print(cnt)

Solution (Python):
w, h, n = map(int, input().split())
right, left, lower, upper = 0, w, 0, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        right = max(right, x)
    if a == 2:
        left = min(left, x)
    if a == 3:
        lower = max(lower, y)
    if a == 4:
        upper = min(upper, y)

a = left - right
b = upper - lower

if a <= 0 or b <= 0:
    print(0)
else:
    print(a*b)

Solution (Python):



def main():
    W, H, N = map(int, input().split())
    X = Y = 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)
        else:
            H = min(H, y)
    print(max(W - X, 0) * max(H - Y, 0))


main()

Solution (Python):
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


w, h, n = inintm()

ll = [0,0]
rh = [w,h]

for i in range(n):
    x, y, a = inintm()
    if a == 1:
        ll[0] = max(ll[0], x)
    elif a == 2:
        rh[0] = min(rh[0], x)
    elif a == 3:
        ll[1] = max(ll[1], y)
    else:
        rh[1] = min(rh[1], y)

if rh[0]-ll[0] < 0 or rh[1]-ll[1] < 0:
    print(0)
else:
    print((rh[0]-ll[0])*(rh[1]-ll[1]))

Solution (Python):
num_line = input().split(" ")
x_num = int(num_line[0])
y_num = int(num_line[1])
num = int(num_line[2])

tangle = [[1]*x_num for i in range(y_num)]



for i in range(num):
    line = input().split(" ")
    x_tem = int(line[0])
    y_tem = int(line[1])
    index = int(line[2])
    
    if(index == 1):
        for j in range(y_num):
            for k in range(x_tem):
                tangle[j][k] = 0
        
        
    elif(index == 2):
        for j in range(y_num):
            for k in range(x_num - x_tem):
                tangle[j][k + x_tem] = 0
        
        
    elif(index == 3):
        for j in range(y_tem):
            for k in range(x_num):
                tangle[j][k] = 0
        
        
    else:
        for j in range(y_num - y_tem):
            for k in range(x_num):
                tangle[j + y_tem][k] = 0
        
        
result = 0
for i in range(y_num):
    for j in range(x_num):
        result += tangle[i][j]
        
print(result)

Solution (Python):
W,H,N = map(int,input().split())
X=Y=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)
    else:
        H = min(H,y)
print(max(W-X,0)*max(H-Y,0))

Solution (Python):
W,H,N = map(int,input().split())
a = []
for i in range(N):
    b = list(map(int,input().split()))
    a.append(b)
xs = 0
xe = W
ys = 0
ye = H
for i in range(N):
    if a[i][2] == 1 and xs < a[i][0]:
        xs = a[i][0]
    elif a[i][2] == 2 and xe > a [i][0]:
        xe = a[i][0]
    elif a[i][2] == 3 and ys < a[i][1]:
        ys = a[i][1]
    elif a[i][2] == 4 and ye > a[i][1]:
        ye = a[i][1]
if xs < xe:
    w = xe - xs
else:
    w = 0
if ys < ye:
    h = ye - ys
else:
    h = 0
print(w*h)

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

xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):

    if array[i][2] == 1:
        xmin = max(xmin, array[i][0])
    elif array[i][2] == 2:
        xmax = min(xmax, array[i][0])
    elif array[i][2] == 3:
        ymin = max(ymin, array[i][1])
    elif array[i][2] == 4:
        ymax = min(ymax, array[i][1])
area = (xmax-xmin)*(ymax-ymin)
if area <= 0 or xmax < xmin or ymax < ymin:
    print(0)
else:
    print(area)

Solution (Python):
W, H, N = [int(x) for x in input().split()]
x_min, x_max, y_min, y_max = 0, W, 0, H
num_lists = [[int(x) for x in input().split()] for _ in range(N)]

for num_list in num_lists:
    if num_list[2] == 1 and num_list[0] > x_min:
        x_min = num_list[0]
    if num_list[2] == 2 and num_list[0] < x_max:
        x_max = num_list[0]
    if num_list[2] == 3 and num_list[1] > y_min:
        y_min = num_list[1]
    if num_list[2] == 4 and num_list[1] < y_max:
        y_max = num_list[1]

if x_min > x_max or y_min > y_max:
    print(0)
else:
    print((x_max-x_min)*(y_max-y_min))

Solution (Python):


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

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

for _ in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        bottom = max(bottom, y)
    elif a == 4:
        top = min(top, y)

if top <= bottom or right <= left:
    print(0)
else:
    print((right - left) * (top - bottom))

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

Solution (Python):
W,H,N=map(int,input().split())
A,B,C,D=[0],[W],[0],[H]

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        A.append(x)
    elif a==2:
        B.append(x)
    elif a==3:
        C.append(y)
    elif a==4:
        D.append(y)

W=min(B)-max(A)
H=min(D)-max(C)

if W<0 or H<0:
    ans=0
else:
    ans=H*W
print(ans)

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

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


def nurie(x,y,a):
   if a==1:
       for i in range(h):
           for j in range(x):
               list_2d[i][j]=1
   elif a==2:
       for i in range(h):
           for j in range(x,w):
               list_2d[i][j]=1
               

   elif a==3:
       for i in range(y):
           for j in range(w):
               list_2d[i][j]=1
              
   else:
       for i in range(y,h):
           for j in range(w):
               list_2d[i][j]=1
   return list_2d
               
for i in range(n):
   x,y,a=[int(i) for i in input().split()]
   nurie(x,y,a)
   
sum=0
for i in range(h):
   sum+=list_2d[i].count(0)
   
print(sum)

Solution (Python):
w,h,n=map(int, input().split()) 
lx=0
ly=0
rx=w
ry=h

for i in range(n):
   x,y,a=map(int, input().split())
   
   if a==1:
       if lx<x:
           lx=x
   elif a==2:
       if rx>x:
           rx=x
           
   elif a==3:
       if ly<y:
           ly=y
   
   else:
       if ry>y:
           ry=y

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

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


X=Y=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)
  else:
    H=min(H,y)


print(max(W-X,0)*max(H-Y,0))

Solution (Python):
w,h,n = map(int, input().split())
s = [[1 for i in range(w)] for j in range(h)]
b = [[1,2,3,4,5],[6,7,8,9,10]]
alist = []
for i in range(n):
    x,y,a = map(int, input().split())
    alist.append(a)
    if a == 1:
        for j in range(h):
            for k in range(0,x):
                s[j][k] = 0
    if a == 2:
        for j in range(h):
            for k in range(x,w):
                s[j][k] = 0
    if a == 3:
        for k in range(w):
            for j in range(0,y):
                s[j][k] = 0
    if a == 4:
        for k in range(w):
            for j in range(y,h):
                s[j][k] = 0
ans = 0
for i in range(h):
    ans = ans + s[i].count(1)
print(ans)

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

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

    for _ 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(
        (x_max - x_min) * (y_max - y_min)
        if x_min < x_max and y_min < y_max else 0
    )


if __name__ == '__main__':
    main()

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

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

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

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

for i in range(N):
    x, y, a = [int(x) for x in 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)

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

print(area)

Solution (Python):
w, h, n = map(int, input().split())
b = [0, 0]
c = [w, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if b[0] < x:
            b[0] = x
    elif a == 2:
        if c[0] > x:
            c[0] = x
    elif a == 3:
        if b[1] < y:
            b[1] = y
    else:
        if c[1] > y:
            c[1] = y
d = max(0, (c[0] - b[0])) * max(0, (c[1] - b[1]))
print(d)

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(x,xmin)
    elif a==2:
        xmax=min(x,xmax)
    elif a==3:
        ymin=max(y,ymin)
    else:
        ymax=min(y,ymax)
print(max(0,xmax-xmin)*max(0,ymax-ymin))

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

Solution (Python):
X, Y, N = map(int, input().split())
lst = [[0 for i in range(X)] for j in range(Y)]

for i in (range(N)):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(Y):
            for k in range(x):
                lst[j][k] = 1
    elif a == 2:
        for j in range(Y):
            for k in range(X-1, x-1, -1):
                lst[j][k] = 1
    elif a == 3:
        for j in range(y):
            for k in range(X):
                lst[j][k] = 1
    elif a == 4:
        for j in range(Y-1, y-1, -1):
            for k in range(X):
                lst[j][k] = 1

count = 0
for i in lst:
    count += i.count(0)
print(count)

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

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

min_x, min_y, max_x, max_y = 0, 0, w, h
for _ in range(n):
    x, y, a = map(int, input().split())

    if a == 1:
        min_x = max(min_x, x)
    elif a == 2:
        max_x = min(max_x, x)
    elif a == 3:
        min_y = max(min_y, y)
    else:
        max_y = min(max_y, y)

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

Solution (Python):
def main():
    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:
            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)
    
    S = max((W-X),0) * max((H-Y),0)
    print(S)
if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

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

X=Y=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)
    else:
        H=min(H,y)

S=max((W-X),0)*max((H-Y),0)

print(S)

Solution (Python):
w, h, n = map(int, input().split())
W = [1] * w
H = [1] * h

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

Solution (Python):
w , h , n=map(int, input().split())
W = [1]*w
H = [1]*h

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

Solution (Python):
W,H,N = (int(T) for T in input().split())
XYA = [[0],[W],[0],[H]]
for TN in range(0,N):
    X,Y,A = (int(T) for T in input().split())
    if A in [1,2]:
        XYA[A-1].append(X)
    else:
        XYA[A-1].append(Y)
CW = min(XYA[1])-max(XYA[0])
CH = min(XYA[3])-max(XYA[2])
if CW>=0 and CH>=0:
    print(CW*CH)
else:
    print(0)

Solution (Python):
w,h,n=map(int,input().split())
c=[]
for i in range(n):
    x,y,a=map(int,input().split())
    c.append([x,y,a])
s=w*h
ans=0
for j in range(s):
    x=j%w
    y=j//w
    t=0
    for i in range(n):
        if c[i][2]==1:
            if x<c[i][0]:
                t+=1
                break
        if c[i][2]==2:
            if x>=c[i][0]:
                t+=1
                break
        if c[i][2]==3:
            if y<c[i][1]:
                t+=1
                break
        if c[i][2]==4:
            if y>=c[i][1]:
                t+=1
                break
    if t==0:
        ans+=1
print(ans)

Solution (Python):
W,H,N = map(int,input().split())
a1 = []
a2 = []
a3 = []
a4 = []
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)
a1.sort(reverse=True)
a2.sort()
a3.sort(reverse=True)
a4.sort()
if a1:
    l = a1[0]
else:
    l = 0
if a2:
    r = a2[0]
else:
    r = W
if a3:
    d = a3[0]
else:
    d = 0
if a4:
    u = a4[0]
else:
    u = H
if r >= l and u >= d:
    print((r-l)*(u-d))
else:
    print(0)

Solution (Python):
W,H,N=list(map(int, input().split()))
wl=[0]
wh=[W]
hl=[0]
hh=[H]
for i in range(N):
  l=list(map(int, input().split()))
  if l[2]==1:
    wl.append(l[0])
  elif l[2]==2:
    wh.append(l[0])
  elif l[2]==3:
    hl.append(l[1])
  else:
    hh.append(l[1])
w=min(wh)-max(wl)
h=min(hh)-max(hl)
if w>0 and h>0:
  print(w*h)
else:
  print(0)

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

l, r, b, t = 0, w, 0, h
for x, y, a in xya:
    if a == 1:
        l = max(x, l)
    elif a == 2:
        r = min(x, r)
    elif a == 3:
        b = max(y, b)
    elif a == 4:
        t = min(y, t)
print(max(0, r - l) * max(0, t - b))

Solution (Python):
w, h, n = map(int, input().split())
x_pos = [0, w]
y_pos = [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_pos[0] = max(x_pos[0], x)
    elif a == 2:
        x_pos[1] = min(x_pos[1], x)
    elif a == 3:
        y_pos[0] = max(y_pos[0], y)
    else:
        y_pos[1] = min(y_pos[1], y)
ans = max(0, (x_pos[1] - x_pos[0])) * max(0, (y_pos[1] - y_pos[0]))
print(ans)

Solution (Python):
w, h, n = map(int, input().split())
x_pos = [0, w]
y_pos = [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_pos[0] = max(x_pos[0], x)
    elif a == 2:
        x_pos[1] = min(x_pos[1], x)
    elif a == 3:
        y_pos[0] = max(y_pos[0], y)
    else:
        y_pos[1] = min(y_pos[1], y)
if x_pos[1] - x_pos[0] < 0 or y_pos[1] - y_pos[0] < 0:
    ans = 0
else:
    ans = (x_pos[1] - x_pos[0] ) * (y_pos[1] - y_pos[0])
print(ans)

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

sx = [0, w]
sy = [0, h]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        sx[0] = max(sx[0], x)
    if a == 2:
        sx[1] = min(sx[1], x)
    if a == 3:
        sy[0] = max(sy[0], y)
    if a == 4:
        sy[1] = min(sy[1], y)

print(max(0, max(0, (sx[1] - sx[0])) * max(0, (sy[1] - sy[0]))))

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

w_min, w_max, h_min, h_max = 0, w, 0, h

for i in range(n):
    if plots[i][2] == 1:
        w_min = max(w_min, plots[i][0])
    elif plots[i][2] == 2:
        w_max = min(w_max, plots[i][0])
    elif plots[i][2] == 3:
        h_min = max(h_min, plots[i][1])
    else:
        h_max = min(h_max, plots[i][1])

print(max(0, (w_max - w_min)) * max(0, (h_max - h_min)))

Solution (Python):


w, h, n = map(int, input().split())
points = []
area = [0, w, 0, h]

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

for i in range(n):
    if points[i][2] == 1:
        area[0] = max(area[0], points[i][0])
    if points[i][2] == 2:
        area[1] = min(area[1], points[i][0])
    if points[i][2] == 3:
        area[2] = max(area[2], points[i][1])
    if points[i][2] == 4:
        area[3] = min(area[3], points[i][1])

ans = max(0, (area[1] - area[0])) * max(0, (area[3] - area[2]))

print(ans)

Solution (Python):
H,W,N=map(int,input().split())
sita,hidari=0,0
ue,migi=W,H
for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    hidari=max(x,hidari)
  elif a==2:
    migi=min(migi,x)
  elif a==3:
    sita=max(sita,y)
  else:
    ue=min(ue,y)
print(max(0,(migi-hidari))*max(0,(ue-sita)))

Solution (Python):
W, H, N  = map(int,input().split()) 
l = 0; r = W; u = H; d = 0 

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(u-d, 0))

Solution (Python):
W, H, N  = map(int,input().split()) 
l = 0; r = W; u = H; d = 0 

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(u-d, 0))

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

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

for _ 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(
  (x_max - x_min) * (y_max - y_min)
  if x_min < x_max and y_min < y_max else 0
)

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

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

Solution (Python):
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(N)]
X=Y=0
for i in range(N):
    if xya[i][2] == 1:
        X = max(X,xya[i][0])
    if xya[i][2] == 2:
        W = min(W,xya[i][0])
    if xya[i][2] == 3:
        Y = max(Y,xya[i][1])
    if xya[i][2] == 4:
        H = min(H,xya[i][1])
print(max(W-X,0)*max(H-Y,0))

Solution (Python):
import numpy as np

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

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b[:,:x] = 1
    elif a == 2:
        b[:,x:] = 1
    elif a == 3:
        b[:y,:] = 1
    else:
        b[y:,:] = 1
print(np.count_nonzero(b < 1))

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

list = [0, w, 0, h]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and list[0] <= x:
        list[0] = x
    elif a == 2 and list[1] >= x:
        list[1] = x
    elif a == 3 and list[2] <= y:
        list[2] = y
    elif a == 4 and list[3] >= y:
        list[3] = y
    else:
        pass

if list[0] > list[1] or list[2] > list[3]:
    print(0)
else:
    print((list[0] - list[1]) * (list[2] - list[3]))