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 = (int(i) for i in input().split())
p1 = [0,0]
p2 = [W,0]
p3 = [0,H]
p4 = [W,H]
for i in range(N):
    x, y, a = (int(i) for i in input().split())
    if a == 1:
        p1[0] = max(p1[0],x)
        p2[0] = max(p2[0],x)
        p3[0] = max(p3[0],x)
        p4[0] = max(p4[0],x)
    elif a == 2:
        p1[0] = min(p1[0],x)
        p2[0] = min(p2[0],x)
        p3[0] = min(p3[0],x)
        p4[0] = min(p4[0],x)
    elif a == 3:
        p1[1] = max(p1[1],y)
        p2[1] = max(p2[1],y)
        p3[1] = max(p3[1],y)
        p4[1] = max(p4[1],y)
    elif a == 4:
        p1[1] = min(p1[1],y)
        p2[1] = min(p2[1],y)
        p3[1] = min(p3[1],y)
        p4[1] = min(p4[1],y)
print(abs(p2[0]-p1[0]) * abs(p4[1]-p2[1]))

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

mask = {}
for i in range(1, 5):
  if i%2 == 1:
    mask[i] = 0
  elif i == 2:
    mask[i] = W
  elif i == 4:
    mask[i] = H

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    mask[a] = max(x, mask[a])
  elif a == 2:
    mask[a] = min(x, mask[a])
  elif a == 3:
    mask[a] = max(y, mask[a])
  elif a == 4:
    mask[a] = min(y, mask[a])


if mask[1] >= mask[2] or mask[3] >= mask[4]:
  ans = 0
else:
  ans =  (mask[1] - mask[2]) * (mask[3] - mask[4])
print(ans)

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

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


print(c)

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

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

def main():
    W,H,N = map(int, input().split())
    x0 = 0
    y0 = 0
    x1 = W
    y1 = H
    for _ 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)
    w = max(0, x1-x0)
    h = max(0, y1-y0)
    print(w*h)

if __name__ == '__main__':
    main()

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

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

boundary=[0,0,W,H]

for i in range(N):
  a=xya[i][2]
  if a==1:
    if boundary[0]<xya[i][0]:
      boundary[0]=xya[i][0]
  elif a==2:
    if boundary[2]>xya[i][0]:
      boundary[2]=xya[i][0]
  elif a==3:
    if boundary[1]<xya[i][1]:
      boundary[1]=xya[i][1]
  else:
    if boundary[3]>xya[i][1]:
      boundary[3]=xya[i][1]
  if boundary[0]>=boundary[2] or boundary[1]>=boundary[3]:
    break

print(max(0,(boundary[2]-boundary[0])*(boundary[3]-boundary[1])))

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

for i in xya:
  if i[2] == 1:
    if lx < i[0]:
      lx = i[0]
  elif i[2] == 2:
    if rx >i[0]:
      rx = i[0]
  elif i[2] == 3:
    if dy < i[1]:
      dy = i[1]
  else:
    if uy > i[1]:
      uy = i[1]
if lx >= rx or uy < dy:
  print(0)
else:
  print((rx -lx) * (uy -dy))

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

r, l, u, d = 0, w, 0, h

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

	if a == 1:
		r = max(r, x)
	if a == 2:
		l = min(l, x)
	if a == 3:
		u = max(u, y)
	if a == 4:
		d = min(d, y)

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

Solution (Python):
import numpy as np
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for i in range(n)]
x=[xya[i][0] for i in range(n)]
y=[xya[i][1] for i in range(n)]
a=[xya[i][2] for i in range(n)]
s=np.array([[1]*w]*h)

for i in range(n):
  for j in range(h):
    for k in range(w):
      if a[i]==1 and k<x[i]:
        s[j,k]=0
      elif a[i]==2 and k>=x[i]:
        s[j,k]=0
      elif a[i]==3 and j<y[i]:
        s[j,k]=0
      elif a[i]==4 and j>=y[i]:
        s[j,k]=0
print(sum(sum(s)))

Solution (Python):

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

R = 0
L = W
U = 0
D = H
for i in range(N):
    x,y,a = map(int,input().split())
    
    if a == 1:
        R = max(R,x)
    if a == 2:
        L = min(L,x)
    if a == 3:
        U = max(U,y)
    if a == 4:
        D = min(D,y)
        
dw = max(0,L-R)
dh = max(0,D-U)
print(dw*dh)

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

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

dw = max(xwyh[1] - xwyh[0], 0)
dh = max(xwyh[3] - xwyh[2], 0)

print(dw * dh)

Solution (Python):
W, H, N = map(int, input().split())
ver_left = [0]
ver_right = [W]
hor_down = [0]
hor_up = [H]

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        ver_left.append(x)
    elif a == 2:
        ver_right.append(x)
    elif a == 3:
        hor_down.append(y)
    elif a == 4:
        hor_up.append(y)

ver_left.sort()
ver_right.sort()
hor_down.sort()
hor_up.sort()

ans = max(0, ver_right[0]-ver_left[-1]) * max(0, hor_up[0]-hor_down[-1])

print(ans)

Solution (Python):

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

R = 0
L = W
U = 0
D = H
for i in range(N):
    x,y,a = map(int,input().split())
    
    if a == 1:
        R = max(R,x)
    if a == 2:
        L = min(L,x)
    if a == 3:
        U = max(U,y)
    if a == 4:
        D = min(D,y)
        
dw = max(0,L-R)
dh = max(0,D-U)
print(dw*dh)

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 




 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    W,H,N = inputMap()
    x_hidari = 0
    x_migi = W
    y_shita = 0
    y_ue = H
    
    for i in range(N):
        x,y,a = inputMap()
        
        if a == 1:
            if x_hidari < x:
                x_hidari = x
        elif a == 2:
            if x_migi > x:
                x_migi = x
        elif a == 3:
            if y_shita < y:
                y_shita = y
        else:
            if y_ue > y:
                y_ue = y
                
    
    xxx = x_migi-x_hidari
    yyy = y_ue-y_shita
    if xxx < 0 or yyy < 0:
        print(0)
        sys.exit()
    
    print(xxx * yyy)
    
    
if __name__ == "__main__":
	main()

Solution (Python):
whn = input().split()
w = int(whn[0])
h = int(whn[1])
n = int(whn[2])

x = []
y = []
a = []

for i in range(n):
	xya = input().split()
	x.append(int(xya[0]))
	y.append(int(xya[1]))
	a.append(int(xya[2]))

wo = 0
ho = 0
for i in range(n):
	if a[i] == 1:
		if wo < x[i]:
			wo = x[i]
			
	if a[i] == 2:
		if x[i] < w:
			w = x[i]
			
	if a[i] == 3:
		if ho < y[i]:
			ho = y[i]
		
	if a[i] == 4:
		if y[i] < h:
			h = y[i]
		
		
if w <= wo or h <= ho:
	ans = 0
else:
	ans = (w - wo)*(h - ho)

print(ans)

Solution (Python):
w,h,n=list(map(int,input().split()))
max_1=0
max_2=w
max_3=0
max_4=h
for i in range(n):
  x,y,a=list(map(int,input().split()))
  if(a==1):
    if(max_1<x):
      max_1=x
  elif(a==2):
    if(max_2>x):
      max_2=x
  elif(a==3):
    if(max_3<y):
      max_3=y
  else:
    if(max_4>y):
      max_4=y

x=max_2-max_1
y=max_4-max_3
if(x<0):
  x=0
if(y<0):
  y=0
print(x*y)

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

Solution (Python):
W, H, N = map(int, input().split())
square = [0, W, 0, H]

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and square[a - 1] < x:
        square[a - 1] = x
    elif a == 2 and square[a - 1] > x:
        square[a - 1] = x
    elif a == 3 and square[a - 1] < y:
        square[a - 1] = y
    elif a == 4 and square[a - 1] > y:
        square[a - 1] = y

print(max((square[1] - square[0]), 0) * max((square[3] - square[2]), 0))

Solution (Python):
def solve():
  w,h,n = (int(i) for i in input().split())
  lx = 0
  ly = 0
  rx = w
  ry = h
  for i in range(n):
    x,y,a = (int(i) for i in input().split())
    if a == 1:
      lx = max(lx,x)
    elif a == 2:
      rx = min(rx,x)
    elif a == 3:
      ly = max(ly,y)
    else:
      ry = min(ry,y)
  print(max(0,(rx-lx))*max(0,(ry-ly)))
solve()

Solution (Python):
w,h,n=map(int,input().split())
xl, xr=0, w
yd, yu=0, h

for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    xl=max(xl, x)
  elif a==2:
    xr=min(xr, x)
  elif a==3:
    yd=max(yd, y)
  else:
    yu=min(yu, y)
  

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

Solution (Python):
from sys import stdin
W, H, N = map(int, input().split())
data = [stdin.readline().rstrip().split() for _ in range(N)]
A1 = []
A2 = []
A3 = []
A4 = []
for i in range(len(data)):
  if data[i][2] == "1":
    A1.append(int(data[i][0]))
  elif data[i][2] == "2":
    A2.append(int(data[i][0]))
  elif data[i][2] == "3":
    A3.append(int(data[i][1]))
  elif data[i][2] == "4":
    A4.append(int(data[i][1]))
max_W = max([W-max(A1, default=0)-(W-min(A2, default=W)),0])
max_H =max([H-max(A3, default=0)-(H-min(A4, default=H)),0])
print(max_W * max_H)

Solution (Python):
w, h, n = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]
 
x1 = 0
x2 = w
y1 = 0
y2 = h
for i in range(n):
	if a[i][2] == 1:
		x1 = max(x1, a[i][0])
	elif a[i][2] == 2:
		x2 = min(x2, a[i][0])
	elif a[i][2] == 3:
		y1 = max(y1,a[i][1])
	elif a[i][2] == 4:
		y2 = min(y2, a[i][1])

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

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

xmin,xmax = 0,W
ymin,ymax = 0,H
for n in range(N):
  x,y,a = map(int,input().split())
  if a==1:
    xmin = max(xmin,x)
  elif a==2:
    xmax = min(xmax,x)
  elif a==3:
    ymin = max(ymin,y)
  elif a==4:
    ymax = min(ymax,y)


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

Solution (Python):
import sys
x,y,nums = map(int,input().split())
points = [0] *nums
x1,y1 = 0,0
x2,y2 = x,y

for i in range (nums):
    points[i] = list(map(int,input().split()))

for i in range (nums):

    if points[i][2] == 1:
        if x1 < points[i][0]:
            x1 = points[i][0]

    elif points[i][2] == 2:
        if x2 > points[i][0]:
            x2 = points[i][0]

    elif points[i][2] == 3:
        if y1 < points[i][1]:
            y1 = points[i][1]

    elif points[i][2] == 4:
        if y2 > points[i][1]:
            y2 = points[i][1]

if  (x1 + (x - x2)) >= x or (y1 + (y - y2)) >= y:
    print(0)
    sys.exit()

result = (x - (x1 + ( x - x2))) * (y -(y1 + (y - y2)))
print(result)

Solution (Python):
W, H, N = map(int, input().split())
lx = 0
rx = W
dy = 0
uy = H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        lx = max(lx, x)
    elif a == 2:
        rx = min(rx, x)
    elif a == 3:
        dy = max(dy, y)
    elif a == 4:
        uy = min(uy, y)
if 0 > rx - lx or 0 > uy - dy:
    print(0)
else:
    print((rx - lx) * (uy - dy))

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

area = [[0 for i in range(H)] for j in range(W)]
for xya in xya_list:
    x_i = xya[0]
    y_i = xya[1]
    a_i = xya[2]
    if a_i == 1:
        for x in range(W):
            for y in range(H):
                if x < x_i:
                    area[x][y] = 1
    if a_i == 2:
        for x in range(W):
            for y in range(H):
                if x >= x_i:
                    area[x][y] = 1
    if a_i == 3:
        for x in range(W):
            for y in range(H):
                if y < y_i:
                    area[x][y] = 1
    if a_i == 4:
        for x in range(W):
            for y in range(H):
                if y >= y_i:
                    area[x][y] = 1

ct = 0
for x in range(W):
    for y in range(H):
        if area[x][y] == 0:
            ct += 1
print(ct)

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)
rx = W - X
ry = H - Y
if rx < 0 or ry < 0:
    print(0)
else:
    print(rx * ry)

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)
block = [[True for i in range(W)]for j in range(H)]
for i in range(len(a)):
    if a[i] == 1:
        for j in range(x[i]):
            for k in range(H):
                block[k][j]=False
    elif a[i] == 2:
        for j in range(x[i],W):
            for k in range(H):
                block[k][j] = False
    elif a[i] == 3:
        for j in range(W):
            for k in range(y[i]):
                block[k][j]=False
    elif a[i] == 4:
        for j in range(W):
            for k in range(y[i],H):
                block[k][j]=False
count = 0
for i in range(W):
    for j in range(H):
        if block[j][i] == True:
            count+=1
print(count)

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)

block = [[True for i in range(W)]for j in range(H)]


    
    

for i in range(len(a)):
    if a[i] == 1:
        for j in range(x[i]):
            for k in range(H):
                block[k][j]=False
    elif a[i] == 2:
        for j in range(x[i],W):
            for k in range(H):
                block[k][j] = False
    elif a[i] == 3:
        for j in range(W):
            for k in range(y[i]):
                block[k][j]=False
    elif a[i] == 4:
        for j in range(W):
            for k in range(y[i],H):
                block[k][j]=False
count = 0

for i in range(W):
    for j in range(H):
        if block[j][i] == True:
            count+=1

print(count)

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

left_x = 0
right_x = w
bottom_y = 0
top_y = h

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

for x, y, a in xya:
    if a == 1:
        left_x = max(x, left_x)
    elif a == 2:
        right_x = min(x, right_x)
    elif a == 3:
        bottom_y = max(y, bottom_y)
    else:
        top_y = min(y, top_y)

    if left_x >= right_x or bottom_y >= top_y:
        print(0)
        exit()

ans = (right_x - left_x) * (top_y - bottom_y)
print(ans)

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

Solution (Python):
W, H, N = map(int, input().split())
l1 = 0
l2 = W
l3 = 0
l4 = H
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    l1 = max(l1, x)
  if a == 2:
    l2 = min(l2, x)
  if a == 3:
    l3 = max(l3, y)
  if a == 4:
    l4 = min(l4, y)
r = max(0, l2-l1)*max(0, l4-l3)
print(r)

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

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

mydic={}
mydic[1]=[0];mydic[2]=[w];mydic[3]=[0];mydic[4]=[h]
for i in range(n) :
  elem=li[i]
  x=elem[0];y=elem[1];a=elem[2]
  l=mydic[a]
  if a==1 or a==2:
    l.append(x)
  if a==3 or a==4:
    l.append(y)
x1=max(mydic[1])
x2=min(mydic[2])
y3=max(mydic[3])
y4=min(mydic[4])

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

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

for _ in range(N):
    xi,yi,a = map(int,input().split())
    if a==1:
        x = max(x,xi)
    elif a==2:
        W = min(xi,W)
    elif a==3:
        y = max(y,yi)
    else:
        H = min(H,yi)

print(0 if x>=W or y>=H else (W-x)*(H-y))

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

Solution (Python):
import sys
import bisect
input = sys.stdin.readline
 
def main():
    w,h,n = map(int,input().split())
    l=0
    b=0
    x=[0 for i in range(n)]
    y=[0 for i in range(n)]
    a=[0 for i in range(n)]
    for i in range(n):
        x[i],y[i],a[i] = map(int,input().split())
    for i in range(n):
        if(a[i]==1):
            l=max(l,x[i])
        elif(a[i]==2):
            w=min(w,x[i])
        elif(a[i]==3):
            b=max(b,y[i])
        else:
            h=min(h,y[i])
    wi=w-l
    he=h-b
    if(wi<0):
        wi=0
    if(he<0):
        he=0
    ans=he*wi
    print(ans)
    
main()

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

xl = 0
xr = w
yu = h
yd = 0

for i in range(n):
    xi,yi,ai = map(int,input().split())
    if ai == 2:
        xr = min(xr,xi)
    elif ai == 1:
        xl = max(xl,xi)
    elif ai == 4:
        yu = min(yu,yi)
    else:
        yd = max(yd,yi)

print(max(0,xr-xl)*max(0,yu-yd))

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

grid = [[1]*W for i in range(H)]
def p():
    return
    for y in range(H)[::-1]:
        print(*grid[y])
    print()
for i in range(N):
    X, Y, a = map(int, input().split())
    if a == 1:
        for y in range(H):
            for x in range(X):
                grid[y][x] = 0
    elif a == 2:
        for y in range(H):
            for x in range(X, W):
                grid[y][x] = 0
    elif a == 3:
        for y in range(Y):
            for x in range(W):
                grid[y][x] = 0
    elif a == 4:
        for y in range(Y, H):
            for x in range(W):
                grid[y][x] = 0
    p()
print(sum(sum(grid[y]) for y in range(H)))

Solution (Python):
import numpy as np
w,h,n=map(int,input().split())
mass = np.ones([h,w])

for i in range(n):
  x,y,a = map(int,input().split())
  if a==1:
    mass[:,:x]=0
  if a==2:
    mass[:,x:]=0
  if a==3:
    mass[(h-y):,:]=0
  if a==4:
    mass[:(h-y),:]=0
  
check = np.sum(mass,axis=1)
check = np.sum(check,axis=0)
print(check)

Solution (Python):
import numpy as np
W, H, N = map(int, input().split())
colors = np.ones((W, H), np.int)
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        colors[:x, :] = 0
    elif a == 2:
        colors[x:, :] = 0
    elif a == 3:
        colors[:, :y] = 0
    elif a == 4:
        colors[:, y:] = 0
ans = colors.sum()

print(ans)

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

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

print(width.count(1)*height.count(1))

Solution (Python):
w,h,n = map(int,input().split())
x0 = 0
y0 = 0
x1 = w
y1 = 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)
print( max(0,(x1-x0)) * max(0,(y1-y0)) )

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

for i in range(N):
    if points[i][2] == 1 and points[i][0] > width[0]:
        width[0] = points[i][0]
    elif points[i][2] == 2 and points[i][0] < width[1]:
        width[1] = points[i][0]
    elif points[i][2] == 3 and points[i][1] > hight[0]:
        hight[0] = points[i][1]
    elif points[i][2] == 4 and points[i][1] < hight[1]:
        hight[1] = points[i][1]
    if width[0] >= width[1] or hight[0] >= hight[1]:
        print(0)
        exit()

area = (width[1] - width[0]) * (hight[1] - hight[0])
print(area)

Solution (Python):


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


D = {'t': H, 'b': 0, 'r': W, 'l': 0}

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:  
        D['l'] = max(D['l'], x)
    elif a == 2:  
        D['r'] = min(D['r'], x)
    elif a == 3:  
        D['b'] = max(D['b'], y)
    elif a == 4:  
        D['t'] = min(D['t'], y)

print(str((D['t']-D['b'])*(D['r']-D['l']))
      ) if D['t'] > D['b'] and D['r'] > D['l'] else print('0')

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

Xmin = 0
for xi in range(n):
    if x[xi][2] == 1:
        Xmin =max(Xmin,x[xi][0])

Xmax = w
for xj in range(n):
    if x[xj][2]==2:
        Xmax =min(Xmax,x[xj][0])

Ymin = 0
for yi in range(n):
    if x[yi][2] == 3:
        Ymin =max(Ymin,x[yi][1])

Ymax = h
for yj in range(n):
    if x[yj][2]==4:
        Ymax =min(Ymax,x[yj][1])
S=print((Xmax-Xmin)*(Ymax-Ymin)*(Xmax>Xmin)*(Ymax>Ymin))

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

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

box = np.ones((H,W))
for _ in range(N):
  xi, yi, ai = map(int, input().split())
  if   ai == 1: box[  :  ,  :xi] = 0
  elif ai == 2: box[  :  ,xi:  ] = 0
  elif ai == 3: box[  :yi,  :  ] = 0
  elif ai == 4: box[yi:  ,  :  ] = 0
print(np.count_nonzero(box))

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

min_x = 0
max_x = w
min_y = 0
max_y = h

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and min_x < x:
        min_x = x
    if a == 2 and x < max_x:
        max_x = x
    if a == 3 and min_y < y:
        min_y = y
    if a == 4 and y < max_y:
        max_y = y

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

print(ans)

Solution (Python):
import numpy as np


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

for j in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        rectangle[:x, :] = 0
    elif a == 2:
        rectangle[x:, :] = 0

    elif a == 3:
        rectangle[:, :y] = 0

    elif a == 4:
        rectangle[:, y:] = 0

print(int(np.sum(rectangle)))

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

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

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

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

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

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

Solution (Python):
width, height, num = map(int, input().rstrip("\n").split())
area = [0, width, 0, height]
for _ in range(num):
    x, y, a = map(int, input().rstrip("\n").split())
    area[a - 1] = [max, min][(a - 1) % 2](area[a - 1], [x, y][a > 2])

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

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

for i in range(N):
    if points[i][2] == 1 and points[i][0] > width[0]:
        width[0] = points[i][0]
    elif points[i][2] == 2 and points[i][0] < width[1]:
        width[1] = points[i][0]
    elif points[i][2] == 3 and points[i][1] > hight[0]:
        hight[0] = points[i][1]
    elif points[i][2] == 4 and points[i][1] < hight[1]:
        hight[1] = points[i][1]
    if width[0] >= width[1] or hight[0] >= hight[1]:
        print(0)
        exit()

area = (width[1] - width[0]) * (hight[1] - hight[0])
print(area)

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(a[0],xi)
    elif ai == 2:
        a[1] = min(a[1],xi)
    elif ai == 3:
        a[2] = max(a[2],yi)
    else:
        a[3] = min(a[3],yi)

print(max(0,a[1]-a[0])*max(0,a[3]-a[2]))

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

w1 = 0
w2 = W
h1 = 0
h2 = H
ans = 0
tLst = [list(map(int, input().split())) for i in range(N)]

for i in range(N):
    if tLst[i][2] == 1:
        w1 = max(w1, tLst[i][0])
    elif tLst[i][2] == 2:
        w2 = min(w2, tLst[i][0])
    elif tLst[i][2] == 3:
        h1 = max(h1, tLst[i][1])
    elif tLst[i][2] == 4:
        h2 = min(h2, tLst[i][1])

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

Solution (Python):
W, H, N = map(int, input().split())
more_y = H
less_y = 0
more_x = W
less_x = 0
for _ in range(N):
  _x, _y, _type = map(int, input().split())
  if _type == 1:
    less_x = max(less_x, _x)
  elif _type == 2:
    more_x = min(more_x, _x)
  elif _type == 3:
    less_y = max(less_y, _y)
  else:
    more_y = min(more_y, _y)
if more_x <= less_x or more_y <= less_y:
  print(0)
else:
  print((more_x-less_x)*(more_y-less_y))

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

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x0 < x:
        x0 = x
    elif a == 2 and x < w:
        w = x
    elif a == 3 and y0 < y:
        y0 = y
    elif a == 4 and y < h:
        h = y

print(max(0, w - x0) * max(0, h - y0))

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

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

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

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