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())
min_X, max_X = 0, w
min_Y, max_Y = 0, h

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        min_X = max(x, min_X)
    elif a == 2:
        max_X = min(x, max_X)
    elif a == 3:
        min_Y = max(y, min_Y)
    elif a == 4:
        max_Y = min(y, max_Y)

W = max(0, max_X - min_X)
H = max(0, max_Y - min_Y)
print(W*H)

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

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

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

w_l = x_max - x_min
h_l = y_max - y_min

if w_l > 0 and h_l > 0:
    print(w_l * h_l)
else:
    print(0)

Solution (Python):
W, H, N = map(int, input().split())
minx, maxx = 0, W
miny, maxy = 0, H

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        minx = max(x, minx)
    elif a == 2:
        maxx = min(x, maxx)
    elif a == 3:
        miny = max(y, miny)
    elif a == 4:
        maxy = min(y, maxy)

width = max(0, maxx-minx)
height = max(0, maxy-miny)

print(width*height)

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

for i in range(len(xya)):
    if 1<=xya[i][2]<=2:
        for j in range(1,3):
            if xya[i][2]==j:
                lst[j-1].append(xya[i][0])
    else:
        for j in range(3,5):
            if xya[i][2]==j:
                lst[j-1].append(xya[i][1])

if min(lst[1])>=max(lst[0]):
    bla_width = w-min(lst[1])+max(lst[0])
else:
    bla_width = w

if min(lst[3])>=max(lst[2]):
    bla_height = h-min(lst[3])+max(lst[2])
else:
    bla_height = h

whi_area = (w-bla_width)*(h-bla_height)
print(whi_area)

Solution (Python):
W, H, N = map(int, input().split())
sx, sy, ex, ey = 0, 0, W, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = max([x, sx])
    elif a == 2:
        ex = min([x, ex])
    elif a == 3:
        sy = max([y, sy])
    else:
        ey = min([y, ey])

w, h = ex-sx, ey-sy
if w < 0 or h < 0:
    print(0)
else:
    print((ex-sx)*(ey-sy))

Solution (Python):
def main():
    W, H, N = (int(i) for i in input().split())
    seen = [[True]*W for h in range(H)]

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

    ans = 0
    for i in range(H):
        for j in range(W):
            if seen[i][j]:
                ans += 1
    print(ans)
    


if __name__ == '__main__':
    main()

Solution (Python):
w, h, n = map(int, input().split())
XYA = []
for _ in range(n):
    x, y, a = map(int, input().split())
    XYA.append((x,y,a))

x_one_max = 0
x_two_min = w
y_three_max = 0
y_four_min = h

for i in range(n):
    if XYA[i][2] == 1:
        x_one_max = max(XYA[i][0], x_one_max)
    elif XYA[i][2] == 2:
        x_two_min = min(XYA[i][0], x_two_min)
    elif XYA[i][2] == 3:
        y_three_max = max(XYA[i][1], y_three_max)
    elif XYA[i][2] == 4:
        y_four_min = min(XYA[i][1], y_four_min)

x_dif = x_two_min - x_one_max
y_dif = y_four_min - y_three_max
if x_dif <= 0 or y_dif <= 0:
    ans = 0
else:
    ans = x_dif * y_dif
print(ans)

Solution (Python):
import numpy as np

w, h, n = map(int, input().split())
grid = np.array([[0] * w for _ in range(h)])



def F(grid, x, y, a):
    if a == 1:
        grid[:, :x] = 1
    elif a == 2:
        grid[:, x:] = 1
    elif a == 3:
        grid[:y, :] = 1
    elif a == 4:
        grid[y:, :] = 1


for i in range(n):
    x, y, a = map(int, input().split())
    F(grid, x, y, a)
    
print(np.count_nonzero(grid == 0))

Solution (Python):
import sys


def solve(inp):
    (W, H, N) = map(int, inp.readline().split(' '))
    XYA = [list(map(int, inp.readline().split(' '))) for i in range(N)]

    sx = sy = 0
    ex = W
    ey = H
    for (x, y, a) in XYA:
        if a == 1:
            sx = max(sx, x)
        elif a == 2:
            ex = min(ex, x)
        elif a == 3:
            sy = max(sy, y)
        else:
            ey = min(ey, y)

    dx = max(0, ex - sx)
    dy = max(0, ey - sy)

    return str(dx * dy)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

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

graph = list()
for x in range(0, w + 1):
    graph.append([0 for y in range(0, h + 1)])

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

    if a == 1:
        for dx in range(0, x):
            for dy in range(0, h + 1):
                graph[dx][dy] = 1

    if a == 2:
        for dx in range(x + 1, w + 1):
            for dy in range(0, h + 1):
                graph[dx][dy] = 1

    if a == 3:
        for dx in range(0, w + 1):
            for dy in range(0, y):
                graph[dx][dy] = 1

    if a == 4:
        for dx in range(0, w + 1):
            for dy in range(y + 1, h + 1):
                graph[dx][dy] = 1

all = True
min_x = 1000
max_x = -1
min_y = 1000
max_y = -1
for x in range(0, w + 1):
    
    for y in range(0, h + 1):
        if graph[x][y] == 0:
            all = False
            min_x = min(min_x, x)
            max_x = max(max_x, x)
            min_y = min(min_y, y)
            max_y = max(max_y, y)

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

Solution (Python):
W,H,N=map(int,input().split())
l=[["w" for i in range(W)] for j in range(H)]
for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    for i in range(x):
      for j in range(H):
        l[j][i]="b"
  elif a==2:
    for i in range(x,W):
      for j in range(H):
        l[j][i]="b"
  elif a==3:
    for i in range(y):
      for j in range(W):
        l[i][j]="b"
  else:
    for i in range(y,H):
      for j in range(W):
        l[i][j]="b"
cnt=0
for i in range(H):
  cnt+=l[i].count("w")
print(cnt)

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

X, Y = [0, w], [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        X[0] = max(X[0], x)
    if a == 2:
        X[1] = min(X[1], x)
    if a == 3:
        Y[0] = max(Y[0], y)
    if a == 4:
        Y[1] = min(Y[1], y)

if X[1]-X[0] <= 0 or Y[1]-Y[0] <= 0:
    print(0)
else:
    print((X[1] - X[0]) * (Y[1] - Y[0]))

Solution (Python):
w,h,n = map(int,input().split())
p = [[int(i) for i in input().split()] for i in range(n)]
a = 0
b = 0
c = w
d = h

for i in range(n):
    if p[i][2] == 1:
        a = max(a, p[i][0])            
    elif p[i][2] == 2:
        c = min(c, p[i][0])
    elif p[i][2] == 3:
        b = max(b, p[i][1])
    else:
        d = min(d, p[i][1])

if c > a and d > b:
    ans = (c-a)*(d-b)
else:
    ans = 0

print(ans)

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

minx, maxx = 0, w
miny, maxy = 0, h

for x, y, a  in coords:
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    elif a == 4:
        maxy = min(maxy, y)

if minx > maxx or miny > maxy:
    print(0)
else:
    print((maxx-minx)*(maxy-miny))

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

pic = [[1 for _ in range(w)] for _ in range(h)]

for x, y, a in coords:
    if a == 1:
        for row in pic:
            for i in range(x):
                row[i] = 0

    elif a == 2:
        for row in pic:
            for i in range(x, w):
                row[i] = 0

    elif a == 3:
        for i in range(y):
            for j in range(w):
                pic[i][j] = 0

    elif a == 4:
        for i in range(y, h):
            for j in range(w):
                pic[i][j] = 0
    

print(sum(sum(i) for i in pic))

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

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        xl.append(x)
    elif a==2:
        xr.append(x)
    elif a==3:
        yd.append(y)
    else:
        yu.append(y)
if max(xl)>=min(xr) or max(yd)>=min(yu):
    print(0)
else:
    xb=max(xl)+w-min(xr)
    yb=max(yd)+h-min(yu)
    print(h*w-xb*h-yb*w+xb*yb)

Solution (Python):
W,H,N = map(int,input().split())
x_a=0
y_a=0
x_b=W
y_b=H
for i in range(N):
  x,y,a = map(int,input().split())
  if a ==1:
    x_a=max(x_a,x)
  elif a ==2:
    x_b=min(x_b,x)
  elif a==3:
    y_a=max(y_a,y)
  elif a==4:
    y_b=min(y_b,y)
print((x_b-x_a)*(y_b-y_a) if x_b-x_a > 0 and y_b-y_a > 0 else '0')

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

r = W
l = 0
m = H
n = 0

for _ in range(N):
    x, y , a = map(int,input().split())
    if a == 1:
        l = max(x,l)
    if a == 2:
        r = min(x,r)
    if a == 3:
        n = max(y,n)
    if a == 4:
        m = min(y,m)

if l >= r or n >= m:
    print(0)
else:
    print((r-l)*(m-n))

Solution (Python):
w,h,n = map(int,input().split())
min_x = min_y = 0
max_x = w
max_y = 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)
    elif a == 4:
        max_y = min(max_y, y)
if max_x <= min_x or max_y <= min_y:
    print(0)
else:
    print((max_x-min_x)*(max_y-min_y))

Solution (Python):
w, h, n = map(int, input().split())
p, q, r, s = 0, 0, w, h
for i in range(n):
   x, y, a = map(int, input().split())

   if (a == 1):
      if (x > p):
         p = x
   elif (a == 2):
      if (x < r):
         r = x
   elif (a == 3):
      if (y > q):
         q = y
   else:
      if (y < s):
         s = y

if (r < p or s < q):
   print(0)
else:
   print((r - p)* (s - q))

Solution (Python):


import sys
input = sys.stdin.readline

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

L = 0
B = 0
R,T = W,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:
        B = max(B,y)
    elif a == 4:
        T = min(T,y)

res = (R-L) * (T-B)



if (R-L <= 0) or (T-B <= 0):
    print(0)
else:
    print(res)

Solution (Python):
xya=[]
whn=list(map(int,input().split()))
for i in range(whn[2]):
    xya.append(list(map(int,input().split())))

threshold=[0,whn[0],0,whn[1]]
for i in range(whn[2]):
    if xya[i][2]==1:
        if xya[i][0]>threshold[0]:
            threshold[0]=xya[i][0]
    elif xya[i][2]==2:
        if xya[i][0]<threshold[1]:
            threshold[1]=xya[i][0]
    elif xya[i][2]==3:
        if xya[i][1]>threshold[2]:
            threshold[2]=xya[i][1]
    else:
        if xya[i][1]<threshold[3]:
            threshold[3]=xya[i][1]
w=max(threshold[1]-threshold[0],0)
h=max(threshold[3]-threshold[2],0)
print(w*h)

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

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(H+1):
            for k in range(x):
                rect[j][k] = 0
    elif a == 2:
        for j in range(H+1):
            for k in range(x+1, W+1):
                rect[j][k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(W+1):
                rect[j][k] = 0
    else:
        for j in range(y+1, H+1):
            for k in range(W+1):
                rect[j][k] = 0
                
ret = 0
for i in range(H):
    for j in range(W):
        if rect[i][j] and rect[i+1][j] and rect[i][j+1] and rect[i+1][j+1]:
            ret += 1
            
print(ret)

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

points = [list(map(int, input().split())) for _ in range(N)]
res = np.ones((W,H), dtype=np.int64)

for x, y, a in points:
    if a == 1:
        res[:x] = 0
    if a == 2:
        res[x:] = 0
    if a == 3:
        tmp = res[:, :y]
        res[:, :y] = 0
    if a == 4:
        tmp = res[:, y:]
        res[:, y:] = 0

print(res.sum())

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

points = [list(map(int, input().split())) for _ in range(N)]
res = 0

x1,y1 = [0,0]
x2,y2 = [W,H]

for x,y,a in points:
    if a == 1:
        x1 = max(x1, x)
    if a == 2:
        x2 = min(x2, x)
    if a == 3:
        y1 = max(y1, y)
    if a == 4:
        y2 = min(y2, y)

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

Solution (Python):
import numpy as np

W, H, N = map(int, input().split())
grid = np.ones((H, W), np.int64)

for _ in range(N):
  x, y, a = map(int, input().split())
  x -= 1
  y -= 1
  if a == 1:
    grid[:, :x+1] = 0
  if a == 2:
    grid[:, x+1:] = 0
  if a == 3:
    grid[-y-1:, :] = 0
  if a == 4:
    grid[:-y-1, :] = 0

print(np.sum(grid))

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

a1 = 0
a2 = w
a3 = 0
a4 = h
for _ in range(n):
   x,y,a = map(int,input().split())
   if a == 1:
      a1 = max(a1, x)
   if a == 2:
      a2 = min(a2, x)
   if a == 3:
      a3 = max(a3, y)
   if a == 4:
      a4 = min(a4, y)
a5 = max(a2 - a1, 0)
a6 = max(a4 -a3, 0)
print(a5*a6)

Solution (Python):
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
maxw=0
minw=w
maxh=0
minh=h
for i in range(n):
  if a[i][-1]==1:    
    maxw=max(a[i][0],maxw)
  elif a[i][-1]==2:
    minw=min(a[i][0],minw)
  elif a[i][-1]==3:    
    maxh=max(a[i][1],maxh)
  else:
    minh=min(a[i][1],minh)
    
haba=max(0,minw-maxw)
takasa=max(0,minh-maxh)

print(haba*takasa)

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

x1 = 0
x2 = w
y1 = 0
y2 = h

for i in range(n):
	if ls[i][2] == 1:
		if ls[i][0] >= x1:
			x1 = ls[i][0]
	elif ls[i][2] == 2:
		if ls[i][0] <= x2:
			x2 = ls[i][0]
	elif ls[i][2] == 3:
		if ls[i][1] >= y1:
			y1 = ls[i][1]
	elif ls[i][2] == 4:
		if ls[i][1] <= y2:
			y2 = ls[i][1]

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

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

Solution (Python):


w,h,n=map(int,input().split())
x_max=0
x_min=w
y_max=0
y_min=h
flg=[0]*4
for i in range(n):
    x_,y_,a=map(int,input().split())
    if a==1:
        x_max=max(x_,x_max)
        flg[0]=1
    elif a==2:
        x_min=min(x_,x_min)
        flg[1]=1
    elif a==3:
        y_max=max(y_,y_max)
        flg[2]=1
    else:
        y_min=min(y_,y_min)
        flg[3]=1
if x_max>=x_min or y_max>=y_min:
    print(0)
else:
    print((x_min-x_max)*(y_min-y_max))

Solution (Python):
W, H, N = map(int, raw_input().split())
x = []
y = []
a = []
for i in range(N):
    xi, yi, ai = map(int, raw_input().split())
    x.append(xi)
    y.append(yi)
    a.append(ai)

xs = set(range(W))
ys = set(range(H))
for i in range(N):
    xi, yi, ai = x[i], y[i], a[i]
    if ai == 1:
        xs -= set(range(xi))
    elif ai == 2:
        xs -= set(range(xi, W))
    elif ai == 3:
        ys -= set(range(yi))
    elif ai == 4:
        ys -= set(range(yi, H))
    else:
        continue
print len(xs) * len(ys)

Solution (Python):
import sys
input = sys.stdin.readline
xmax, ymax, N = [int(x) for x in input().split()]
X = []
for _ in range(N):
    X.append([int(x) for x in input().split()])
xmin = 0
ymin = 0
for i in X:
    x, y, a = i
    if a == 1:
        xmin = max(xmin, x)
    elif a == 2:
        xmax = min(xmax, x)
    elif a == 3:
        ymin = max(ymin, y)
    else:
        ymax = min(ymax, y)
if xmax <= xmin or ymax <= ymin:
    print(0)
else:
    print((xmax - xmin) * (ymax - ymin))

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

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

x_l, x_r, y_d, y_u = 0, w, 0, h
for x in a:
  if x[2] == 1 and x[0] > x_l:
    x_l = x[0]
  elif x[2] == 2 and x[0] < x_r:
    x_r = x[0]
  elif x[2] == 3 and x[1] > y_d:
    y_d = x[1]
  elif x[2] == 4 and x[1] < y_u:
    y_u = x[1]
if (x_r - x_l) <= 0 or (y_u - y_d) <= 0:
  print(0)
else:
  print((x_r - x_l) * (y_u - y_d))

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

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

import numpy as np

Z = np.zeros((H, W))

for i in AA:
    if i[2] == 1:
        Z[:, :i[0]] = 1
    
    elif i[2] == 2:
        Z[:, i[0]:] = 1
    
    elif i[2] == 3:
        Z[:i[1], :]= 1
        
    else:
        Z[i[1]:, :] = 1

print(W*H - np.count_nonzero(Z))

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

width = np.ones(w,dtype = np.int64)
height = np.ones(h,dtype = np.int64)

l = [[int(i) for i in input().split()] for _ in range(n)]

for i in l:
    if i[2] == 1:
        width[:i[0]] = 0
    elif i[2] == 2:
        width[i[0]:] = 0
    elif i[2] == 3:
        height[:i[1]] = 0
    else:
        height[i[1]:] = 0
        
width = np.count_nonzero(width)
height = np.count_nonzero(height)
print(width * height)

Solution (Python):
w,h,n=map(int,input().split())
g=[list(map(int,input().split())) for i in range(n)]
t1,t2,t3,t4=0,w,0,h
for i in range(n):
  if g[i][2]==1:
    t1=max(t1,g[i][0])
  elif g[i][2]==2:
    t2=min(t2,g[i][0])
  elif g[i][2]==3:
    t3=max(t3,g[i][1])
  else:
    t4=min(t4,g[i][1])
if t2<=t1 or t4<=t3:
  print(0)
else:
  print((t2-t1)*(t4-t3))

Solution (Python):
W,H,N = map(int,input().split())
xya = []
hx = W
lx = 0
hy = H
ly = 0
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        lx = max(lx,x)
    if a == 2:
        hx = min(hx,x)
    if a == 3:
        ly = max(ly,y)
    if a == 4:
        hy = min(hy,y)
print(max(0,max(0,(hx-lx))*max(0,(hy-ly))))

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

b = [[0 for _ in range(w)] for _ in range(h)]
for x, y, a in xya:
    if a == 1:
        for i in range(h):
            for j in range(x):
                b[i][j] = 1
    elif a == 2:
        for i in range(h):
            for j in range(x, w):
                b[i][j] = 1
    elif a == 3:
        for i in range(y):
            for j in range(w):
                b[i][j] = 1
    elif a == 4:
        for i in range(y, h):
            for j in range(w):
                b[i][j] = 1
ans = 0
for i in range(h):
    for j in range(w):
        if b[i][j] == 0:
            ans += 1
print(ans)

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

Solution (Python):
ew,eh,n=[int(x) for x in input().rstrip().split()]
fw=0
fh=0
ansx=0
ansy=0
for i in range(n):
    x,y,a=[int(x) for x in input().rstrip().split()]
    if(a==1):
        fw=max(fw,x)
    elif(a==2):
        ew=min(ew,x)
    elif (a==3):
        fh=max(fh,y)
    elif (a==4):
        eh=min(eh,y)

if(ew-fw<0):
    ansx=0
elif(eh-fh<0):
    ansy=0
else:

    ansx=ew-fw
    ansy=eh-fh

print(ansx*ansy)

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

Solution (Python):
import sys
w,h,n = map(int, sys.stdin.readline().split())

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

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = min(y, y_max)

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 = map(int, input().split())
xya = [[int(i) for i in input().split()] for j in range(N)]
x_0, y_0 = 0, 0
x_1, y_1 = W, H
for i in range(N):
    if xya[i][2] == 1:
        x_0 = max(x_0, xya[i][0])
    elif xya[i][2] == 2:
        x_1 = min(x_1, xya[i][0])
    elif xya[i][2] == 3:
        y_0 = max(y_0, xya[i][1])
    elif xya[i][2] == 4:
        y_1 = min(y_1, xya[i][1])
if x_0 < x_1 and y_0 < y_1:
    print((x_1 - x_0) * (y_1 - y_0))
else:
    print(0)

Solution (Python):
w,h,n=map(int,input().split())
l=[0,w,0,h]
for i in range(n):
  a,c,d=map(int,input().split())
  x= c if (d)//3 else a
  f=min if (d-1)%2 else max
  l[d-1]=f(l[d-1],x)
if l[0]<l[1] and l[2]<l[3]:
  print((l[1]-l[0])*(l[3]-l[2]))
else:print(0)

Solution (Python):
w,h,n=map(int,input().split())
info=[]
for i in range(n):
    x,y,a=map(int,input().split())
    info.append([x,y,a])
top,down,left,right=h,0,0,w
def calc(x,y,a):
    global top,down,left,right
    if a==1:
        if left<x:
            left=x
    elif a==2:
        if x<right:
            right=x
    elif a==3:
        if down<y:
            down=y
    else:
        if y<top:
            top=y
for i in range(n):
    calc(info[i][0],info[i][1],info[i][2])
    if top<=down:
        top,down=0,0
        break
    if right<=left:
        right,left=0,0
        break
    
    
print((top-down)*(right-left))

Solution (Python):
w, h, n = map(int, input().split())
w_2 = 0
h_2 = 0
order = []

for i in range(n):
    array = list(map(int, input().split()))
    order.append(array)

for i, j, a in order:
    if a == 1:
        w_2 = max(w_2, i)
    elif a == 2:
        w = min(w, i)
    elif a == 3:
        h_2 = max(h_2, j)
    else:
        h = min(h, j)

tate = h - h_2
yoko = w - w_2
if tate < 0 or yoko < 0:
    print(0)
    exit()
print(max(tate*yoko, 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())

max_W = W
max_H = H
S = W * H
sx, sy = 0, 0

for i in range(N):
    if a[i] == 1:
        if (x[i] - sx) * (max_H - sy) >= 0:
            S -= (x[i] - sx) * (max_H - sy)
            sx = x[i]
    elif a[i] == 2:
        if (max_W - x[i]) * (max_H - sy) >= 0:
            S -= (max_W - x[i]) * (max_H - sy)
            max_W = x[i]
    elif a[i] == 3:
        if (max_W - sx) * (y[i] - sy) >= 0:
            S -= (max_W - sx) * (y[i] - sy)
            sy = y[i]
    else:
        if (max_W - sx) * (max_H - y[i]) >= 0:
            S -= (max_W - sx) * (max_H - y[i])
            max_H = y[i]

if S < 0:
    S = 0

print(S)

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

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


f = [[0] * w for _ in range(h)]

for i in range(n):
    for x in range(w):
        for y in range(h):
            if xya[i][2] == 1 and x < xya[i][0]:
                f[y][x] = 1
            elif xya[i][2] == 2 and x >= xya[i][0]:
                f[y][x] = 1
            elif xya[i][2] == 3 and y < xya[i][1]:
                f[y][x] = 1
            elif xya[i][2] == 4 and y >= xya[i][1]:
                f[y][x] = 1

ans = 0
for i in range(h):
    for j in range(w):
        if f[i][j]:
            ans += 1
print(w * h - ans)

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

mw = 0
mh = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        mw = max(mw, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        mh = max(mh, y)
    elif a == 4:
        h = min(h, y)

print((w-mw)*(h-mh) if mw <= w and mh <= h else 0)

Solution (Python):

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

minx = 0
maxx = w
miny = 0
maxy = h

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

	if a == 2:
		maxx = min(maxx, x)
	elif a == 1:
		minx = max(minx, x)
	elif a == 4:
		maxy = min(maxy, y)
	else:
		miny = max(miny, y)

ans = (maxx - minx) * (maxy - miny)

if minx < maxx and miny < maxy:
	print(ans)
else:
	print(0)

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

Solution (Python):
import sys
import numpy as np 

I = np.array(sys.stdin.read().split(), dtype=np.int64)
w, h, n = I[:3]
x, y, a = I[3:].reshape(n, 3).T 

def main():
    l = 0
    r = w
    d = 0
    u = h
    if np.any(a == 1):
        l = np.amax(x[a == 1])
    if np.any(a == 2):
        r = np.amin(x[a == 2])
    if np.any(a == 3):
        d = np.amax(y[a == 3])
    if np.any(a == 4):
        u = np.amin(y[a == 4])
        
    if l > r or d > u:
        return 0
    return (r - l) * (u - d)

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):


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

def paint(mth,lis,w,h):
    if mth==1:
        for i in range(H):
            for j in range(w):
                l[i][j]=1
    elif mth==2:
        for i in range(H):
            for j in range(w,W):
                l[i][j]=1
    elif mth==3:
        for i in range(h):
            for j in range(W):
                lis[i][j]=1
    else:
        for i in range(h,H):
            for j in range(W):
                lis[i][j]=1
                
l=[[0]*W for i in range(H)]

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

ans=0
for i in range(H):
    for j in range(W):
        ans+=l[i][j]

print(H*W-ans)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(W, H, N, inputs):
    actions = list(map(string_to_int, inputs))
    white_x1 = 0
    white_x2 = W
    white_y1 = 0
    white_y2 = H

    for a in actions:
        if a[2] == 1:
            if white_x1 < a[0]:
                white_x1 = a[0]
        elif a[2] == 2:
            if white_x2 > a[0]:
                white_x2 = a[0]
        elif a[2] == 3:
            if white_y1 < a[1]:
                white_y1 = a[1]
        elif a[2] == 4:
            if white_y2 > a[1]:
                white_y2 = a[1]

    if white_x1 >= white_x2 or white_y1 >= white_y2:
        return 0
    return (white_x2 - white_x1) * (white_y2 - white_y1)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [W, H, N] = string_to_int(input())
    ret = solve(W, H, N, inputs(N))
    print(ret)

Solution (Python):

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


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


for n in range(N):
    
    X,Y,A = map(int, input().split())
    
    if A == 1:
        
        for y in range(0,H):
            for x in range(0,X):
                tmp[y][x] = 1

    if A == 2:
        
        for y in range(0,H):
            for x in range(X,W):
                tmp[y][x] = 1
                
    if A == 3:
        
        for y in range(0,Y):
            for x in range(0,W):
                tmp[y][x] = 1
                
    if A==4:
        
        for y in range(Y,H):
            for x in range(0,W):
                tmp[y][x] = 1



result = 0
for y in range(0,H):
    for x in range(0,W):
        if tmp[y][x] == 0:
            result += 1
print(result)

Solution (Python):

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


d = []
for _ in range(n):
  a = [int(i) for i in input().split()]
  d.append(a)



x1 = [0]
x2 = [w]
y1 = [0]
y2 = [h]

for i in range(n):
  if d[i][2] == 1:
    x1.append(d[i][0])
  if d[i][2] == 2:
    x2.append(d[i][0])
  if d[i][2] == 3:
    y1.append(d[i][1])
  if d[i][2] == 4:
    y2.append(d[i][1])

x1 = sorted(x1, reverse = True)[0]
x2 = sorted(x2)[0]
y1 = sorted(y1, reverse = True)[0]
y2 = sorted(y2)[0]

sum = (x2 - x1)*(y2 - y1)
if x2 - x1 >= 0 and y2 - y1 >= 0:
  print(sum)
else:
  print(0)

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

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

for i in range(N):
  x, y, a = [int(j) for j in input().split()]
  
  if a == 1:
    x_min = max(x, x_min)
  elif a == 2:
    x_max = min(x, x_max)
  elif a == 3:
    y_min = max(y, y_min)
  else:
    y_max = min(y, y_max)

width = x_max - x_min
height = y_max - y_min

if width > 0 and height > 0:
  print(width * height)
else:
  print(0)