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())

s = [input() for i in range(N)]
S = []
for i in range(N):
    S.append(list(map(int, s[i].split())))

lst = [[1 for i in range(W)] for j in range(H)]

for i in range(N):
    if S[i][2] == 1:
        for j in range(0,S[i][0]):
            for k in range(H):
                lst[k][j] = 0
    if S[i][2] == 2:
        for j in range(S[i][0],W):
            for k in range(H):
                lst[k][j] = 0
    if S[i][2] == 3:
        for j in range(0,S[i][1]):
            for k in range(W):
                lst[j][k] = 0
    if S[i][2] == 4:
        for j in range(S[i][1],H):
            for k in range(W):
                lst[j][k] = 0

print(sum(lst,[]).count(1))

Solution (Python):
if __name__ == "__main__":
    W, H, N = map(int, input().split())
    XYA = [list(map(int, input().split())) for _ in range(N)]

    grid = [[0]*(W + 1) for _ in range(H + 1)]
    for x, y, a in XYA:
        sx = 1
        sy = 1
        fx = W
        fy = H
        if a == 1:
            fx = x
        elif a == 2:
            sx = x + 1
        elif a == 3:
            fy = y
        else:
            sy = y + 1
        for i in range(sx, fx + 1):
            for j in range(sy, fy + 1):
                grid[j][i] = 1
    ans = W*H
    for i in range(1, W + 1):
        for j in range(1, H + 1):
            if grid[j][i]:
                ans -= 1
    print(ans)

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

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

X_min = 0
X_max = W
Y_min = 0
Y_max = H

for i in range(N):
  x,y,a=map(int, input().split())
  if a==1: X_min = max(X_min, x)
  if a==2: X_max = min(X_max, x)
  if a==3: Y_min = max(Y_min, y)
  if a==4: Y_max = min(Y_max, y)
print(max([(X_max-X_min),0])*max([(Y_max-Y_min),0]))

Solution (Python):
W,H,N = map(int,input().split())
x_max = W
x_min = 0
y_max = H
y_min = 0
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1 and x>x_min:
        x_min = x
    elif a==2 and x<x_max:
        x_max = x
    elif a==3 and y>y_min:
        y_min = y
    elif a==4 and y<y_max:
        y_max = y
print((x_max-x_min)*(y_max-y_min) if x_max-x_min>=0 and y_max-y_min>=0 else 0)

Solution (Python):
def resolve():
	w, h, n = map(int, input().split())
	area = [[True]*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):
				for k in range(x):
					area[j][k] = False
		elif a == 2:
			for j in range(h):
				for k in range(x, w):
					area[j][k] = False
		elif a == 3:
			for j in range(y):
				for k in range(w):
					area[j][k] = False
		elif a == 4:
			for j in range(y, h):
				for k in range(w):
					area[j][k] = False
	ans = 0
	for r in area:
		ans += r.count(True)
	print(ans)
resolve()

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

min_x = 0
max_x = W
min_y = 0
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)
    else:
        max_y = min(max_y, y)

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

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

def main():
    W, H, N = map(int, readline().rstrip().split())
    p = [[1] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, readline().rstrip().split())
        if a == 1:
            for yi in range(H):
                for xi in range(x):
                    p[yi][xi] = 0
        elif a == 2:
            for yi in range(H):
                for xi in range(x, W):
                    p[yi][xi] = 0
        elif a == 3:
            for xi in range(W):
                for yi in range(y):
                    p[yi][xi] = 0
        else:
            for xi in range(W):
                for yi in range(y, H):
                    p[yi][xi] = 0
    
    print(sum([sum(l) for l in p]))


if __name__ == '__main__':
    main()

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

Solution (Python):
W,H,N = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(N)]
w1=0
h1=0
w2=W
h2=H

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

res = max((w2-w1),0)*max((h2-h1),0)
print(res)

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

left_x = bottom_y = 0
right_x = w
top_y = h
for x, y, a in xya:
    if a == 1:
        left_x = max(left_x, x)
    elif a == 2:
        right_x = min(right_x, x)
    elif a == 3:
        bottom_y = max(bottom_y, y)
    else:
        top_y = min(top_y, y)
if right_x <= left_x or top_y <= bottom_y:
    print(0)
else:
    print((right_x - left_x) * (top_y - bottom_y))

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

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

def view(now):
    s = ''
    now = list(reversed(now))
    for i in range(h):
        for j in range(w):
            s += str(now[i][j])
        else:
            s += '\n'
    return s
mapp = [[1]*(w)] * (h)

for i in range(n):
    if xy[i][2] == 1 or xy[i][2] == 2:
        for j in range(h):
            if xy[i][2] == 1:
                mapp[j][:xy[i][0]] = [0]*xy[i][0]

            elif xy[i][2] == 2:
                mapp[j][xy[i][0]:] = [0]*(w-xy[i][0])

    elif xy[i][2] == 3:
        for s in range(xy[i][1]):
            mapp[s] = [0] * w

    elif xy[i][2] == 4:
        for s in range(xy[i][1],h):
            mapp[s] = [0] * w

    
ans = 0
for i in range(h):
    ans += mapp[i].count(1)
print(ans)

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

Solution (Python):


def main():
    w, h, n = map(int, input().split())
    left = 0
    right = w
    top = 0
    bottom = h
    for i in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            left = max(left, x)
        elif a == 2:
            right = min(right, x)
        elif a == 3:
            top = max(top, y)
        else:
            bottom = min(bottom, y)
    res = max(0, right - left) * max(0, bottom - top)
    print(res)

if __name__ == "__main__":
    main()

Solution (Python):
W, H, N = map(int,input().split())
left = 0
right = W
bottom = 0
top = H
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        bottom = max(bottom, y)
    else:
        top = min(top, y)
ans = (right - left) * (top - bottom)
if left > right or bottom > top:
    ans = 0
print(ans)

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 == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        maxy = min(maxy, y)

    ans = (maxx - minx) * (maxy - miny)
print(ans if minx < maxx and miny < maxy else 0)

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

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

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

ans = max(0, r - l) * max(0, u - d)

print(ans)

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

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

ans = 0
for i in range(h):
    for j in range(w):
        if area[i][j] == 0: ans += 1

print(ans)

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

L = 0
R = W
D = 0
U = H

for _ in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    L = max(L,x)
  if a == 2:
    R = min(R,x)
  if a == 3:
    D = max(D,y)
  if a == 4:
    U = min(U,y)

x = max(0,R-L)
y = max(0,U-D)
answer = x*y

print(answer)

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

A=[0,w,0,h]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        A[0]=max(A[0],x)
    elif a==2:
        A[1]=min(A[1],x)
    elif a==3:
        A[2]=max(A[2],y)
    else:
        A[3]=min(A[3],y)

if (A[1]-A[0])<=0 or (A[3]-A[2])<=0:
    print(0)
else:
    print((A[1]-A[0])*(A[3]-A[2]))

Solution (Python):
W,H,N=map(int,input().split())
S=[0]*N; p=0
for i in range(N):
  x,y,a=map(int,input().split())
  S[i]=[x,y,a]

e=101;w=-1;n=101;s=-1
for i in range(N):
  if S[i][2]==1:
    w=max(w,S[i][0])
  elif S[i][2]==2:
    e=min(e,S[i][0])
  elif S[i][2]==3:
    s=max(s,S[i][1])
  elif S[i][2]==4:
    n=min(n,S[i][1])


for i in range(1,H+1):
  for j in range(1,W+1):
    if (j<=w and w>0) or (j>e and e<101) or (i>n and n<101) or (i<=s and s>0):
      p=p+1

print(W*H-p)

Solution (Python):
from sys import stdin
import sys

[W, H, N] = list(map(int, stdin.readline().rstrip().split()))


Ws = 0
We = W

Hs = 0
He = H


A = []
for i in range(N):
    A.append(list(map(int, stdin.readline().rstrip().split())))

for i in range(N):
    [x, y, a] = A[i]
    if a == 1:
        Ws = max(Ws, x)
    elif a == 2:
        We = min(We, x)
    elif a == 3:
        Hs = max(Hs, y)
    elif a == 4:
        He = min(He, y)

if (We - Ws) <= 0 or (He - Hs) <=0:
    print(0)
else:
    print((We - Ws) * (He - Hs))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    w,h,n = map(int, input().split())
    l,r,u,d = 0, w, h, 0
    for _ in range(n):
        x,y,a = map(int, input().split())
        if a==1:
            l = max(l, x)
        if a==2:
            r = min(r, x)
        if a==3:
            d = max(d, y)
        if a==4:
            u = min(u, y)
    if l < r and d < u:
        print((r-l)*(u-d))
    else:
        print(0)

if __name__ == '__main__':
    main()

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

for l in list_XY:
    if l[2] == 1:
        a = max(a, l[0])
    elif l[2] == 2:
        b = min(b, l[0])
    elif l[2] == 3:
        c = max(c, l[1])
    elif l[2] == 4:
        d = min(d, l[1])
ans = -1
if b > a and d > c:
    ans = (b-a)*(d-c)
else:
    ans = 0

print(ans)

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

for i in range(N):
    x, y, a = map(int, input().split())
    a -= 1
    if a <= 1:
        A[a].append(x)
    else:
        A[a].append(y)

x1 = max(A[0])
x2 = min(A[1])
y1 = max(A[2])
y2 = min(A[3])

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

Solution (Python):
W,H,N=map(int, input().split())
l=[]
for i in range(N):
  l.append(list(map(int, input().split())))
maxmin=[0,W,0,H]
for i in range(N):
  if l[i][2] == 1 and maxmin[0] < l[i][0]:
    maxmin[0] = l[i][0]
  elif l[i][2] == 2 and maxmin[1] > l[i][0]:
    maxmin[1] = l[i][0]
  elif l[i][2] == 3 and maxmin[2] < l[i][1]:
    maxmin[2] = l[i][1]
  elif l[i][2] == 4 and maxmin[3] > l[i][1]:
    maxmin[3] = l[i][1]
if maxmin[1]-maxmin[0] >= 0 and maxmin[3]-maxmin[2] >= 0:
  print((maxmin[1]-maxmin[0])*(maxmin[3]-maxmin[2]))
else:
  print(0)

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

white = [0, W, 0, H]

points = [[int(i) for i in input().split()] for j in range(N)]

for point in points:
    if point[2] == 1:
        if point[0] > white[0]:
            white[0] = point[0]
    if point[2] == 2:
        if point[0] < white[1]:
            white[1] = point[0]
    if point[2] == 3:
        if point[1] > white[2]:
            white[2] = point[1]
    if point[2] == 4:
        if point[1] < white[3]:
            white[3] = point[1]

w = white[1] - white[0]
h = white[3] - white[2]

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

Solution (Python):
w, h, n = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
xy = []
a = []
for i in range(n):
    xy.append([li[i][0], li[i][1]])
    a.append(li[i][2])

left, right = [0, 0], [w, h]

for i in range(n):
    if a[i] == 1:
        if left[0] < xy[i][0]:
            left[0] = xy[i][0]
    elif a[i] == 2:
        if right[0] > xy[i][0]:
            right[0] = xy[i][0]
    elif a[i] == 3:
        if left[1] < xy[i][1]:
            left[1] = xy[i][1]
    else:
        if right[1] > xy[i][1]:
            right[1] = xy[i][1]

if left[0] >= right[0] or left[1] >= right[1]:
    ans = 0
else:
    ans = (right[0]-left[0]) * (right[1]-left[1])
print(str(ans))

Solution (Python):
w, h, n = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
xy = []
a = []
for i in range(n):
    xy.append([li[i][0], li[i][1]])
    a.append(li[i][2])

left, right = [0, 0], [w, h]

for i in range(n):
    if a[i] == 1:
        if left[0] < xy[i][0]:
            left[0] = xy[i][0]
    elif a[i] == 2:
        if right[0] > xy[i][0]:
            right[0] = xy[i][0]
    elif a[i] == 3:
        if left[1] < xy[i][1]:
            left[1] = xy[i][1]
    else:
        if right[1] > xy[i][1]:
            right[1] = xy[i][1]

if left[0] >= right[0] or left[1] >= right[1]:
    ans = 0
else:
    ans = (right[0]-left[0]) * (right[1]-left[1])
print(str(ans))

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

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

x = [0] * N
y = [0] * N
a = [0] * N

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

X1 = 0
X2 = 0
Y1 = 0
Y2 = 0

x1, x2, y1, y2 = 0, 0, 0, 0

X = 0
Y = 0

entire = W * H

for i in range(N):
    if a[i]==1 and X1<x[i]:
        x1 = x[i] * H
        X1 = x[i]
    elif a[i]==2 and X2<(W-x[i]):
        x2 = (W-x[i]) * H
        X2 = W - x[i]
    elif a[i]==3 and Y1<y[i]:
        y1 = y[i] * W
        Y1 = y[i]
    elif a[i]==4 and Y2<(H-y[i]):
        y2 = (H-y[i]) * W
        Y2 = H - y[i]

entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))

if X1+X2>=W or Y1+Y2>=H:
    print('0')
else:
    print(entire)

Solution (Python):
W,H,N = [int(x) for x in input().split()]
a = [0]
b = [W]
c = [0]
d = [H]
for i in range(N):
    l = [int(x) for x in input().split()]
    if l[2] == 1:
        a.append(l[0])
    elif l[2] == 2:
        b.append(l[0])
    elif l[2] == 3:
        c.append(l[1])
    else:
        d.append(l[1])
aa = max(a)
bb = min(b)
cc = max(c)
dd = min(d)
if aa-bb >= 0 or cc - dd >= 0:
    print(0)
else:
    print((bb-aa)*(dd-cc))

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())

X1 = 0
X2 = W
Y1 = 0
Y2 = H

for i in range(N):

    if a[i] == 1:
        X1 = max(X1, x[i])
    if a[i] == 2:
        X2 = min(X2, x[i])
    if a[i] == 3:
        Y1 = max(Y1, y[i])
    if a[i] == 4:
        Y2 = min(Y2, y[i])

if X1 >= X2 or Y1 >= Y2:
    print('0')
else:
    entire = (Y2-Y1) * (X2-X1)
    print(entire)

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())

X1 = 0
X2 = 0
Y1 = 0
Y2 = 0

x1, x2, y1, y2 = 0, 0, 0, 0

X = 0
Y = 0

entire = W * H

for i in range(N):
    if a[i]==1 and X1<x[i]:
        x1 = x[i] * H
        X1 = x[i]
    elif a[i]==2 and X2<(W-x[i]):
        x2 = (W-x[i]) * H
        X2 = W - x[i]
    elif a[i]==3 and Y1<y[i]:
        y1 = y[i] * W
        Y1 = y[i]
    elif a[i]==4 and Y2<(H-y[i]):
        y2 = (H-y[i]) * W
        Y2 = H - y[i]

if (X1 + X2) >= W or (Y1 + Y2) >= H:
    print('0')
else:
    entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))
    if entire<=0:
        print('0')
    else:
        print(entire)

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())

X1 = 0
X2 = 0
Y1 = 0
Y2 = 0

x1, x2, y1, y2 = 0, 0, 0, 0

X = 0
Y = 0

entire = W * H

for i in range(N):
    if a[i]==1 and X1<x[i]:
        x1 = x[i] * H
        X1 = x[i]
    elif a[i]==2 and X2<(W-x[i]):
        x2 = (W-x[i]) * H
        X2 = W - x[i]
    elif a[i]==3 and Y1<y[i]:
        y1 = y[i] * W
        Y1 = y[i]
    elif a[i]==4 and Y2<(H-y[i]):
        y2 = (H-y[i]) * W
        Y2 = H - y[i]

if (X1 + X2) >= W or (Y1 + Y2) >= H:
    print('0')
else:
    entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))




    print(entire)

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())

X1 = 0
X2 = W
Y1 = 0
Y2 = H

entire = W * H

for i in range(N):
    if a[i] == 1:
        X1 = max(X1, x[i])
    if a[i] == 2:
        X2 = min(X2, x[i])
    if a[i] == 3:
        Y1 = max(Y1, y[i])
    if a[i] == 4:
        Y2 = min(Y2, y[i])

if X1 >= X2 or Y1 >= Y2:
    print('0')
else:
    entire = (Y2-Y1) * (X2-X1)
    print(entire)

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

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

X_axis = [i for i in range(W+1)]
Y_axis = [j for j in range(H+1)]

def CalcSqueare(a,b):
    if len(a)==0 or len(b)==0:
        print(0)
    else:
        print((a[-1]-a[0]) * (b[-1] - b[0]))


for i in range(N):
    x_i,y_i,a_i =map(int,input().split())

    if a_i==1:
        X_axis = [x for x in X_axis if x>=x_i]
    elif a_i==2:
        X_axis = [x for x in X_axis if x<=x_i]
    elif a_i==3:
        Y_axis = [y for y in Y_axis if y>=y_i]
    else:
        Y_axis = [y for y in Y_axis if y<=y_i]

CalcSqueare(X_axis,Y_axis)

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

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

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

    for j in range(h): 
        for k in range(w): 
        
            if a==1:
                if k<x:
                    li[j][k]=1
            elif a==2:
                if k>=x:
                    li[j][k]=1
            elif a==3:
                if j<y:
                    li[j][k]=1
            else:
                if j>=y:
                    li[j][k]=1

ans=0
for tm in li:
    ans+=tm.count(0)

print(ans)

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

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

onelist = [0]
twolist = [w]
threelist = [0]
fourlist = [h]


for xl in xlist:
    if xl[2] == 1:
        onelist.append(xl[0])
    elif xl[2] == 2:
        twolist.append(xl[0])
    elif xl[2] == 3:
        threelist.append(xl[1])
    elif xl[2] == 4:
        fourlist.append(xl[1])

one = max(onelist)
two = min(twolist)
three = max(threelist)
four = min(fourlist)


if one > two:
    x = 0
else:
    x = two - one
if three > four:
    y = 0
else:
    y = four - three

if (x*y) < 0:
    print(0)
else:
    print(x*y)

Solution (Python):
def resolve():
	w, h, n = map(int, input().split())
	r = [[True]*w for _ in range(h)]
	for _ in range(n):
		ix, iy, a = map(int, input().split())
		if a == 1:
			for i in range(h):
				for j in range(ix):
					r[i][j] = False
		elif a == 2:
			for i in range(h):
				for j in range(ix, w):
					r[i][j] = False
		elif a == 3:
			for i in range(iy):
				for j in range(w):
					r[i][j] = False
		else:
			for i in range(iy, h):
				for j in range(w):
					r[i][j] = False
	ans = 0

	for row in r:
		for i in row:
			if i:
				ans += 1
	print(ans)
resolve()

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

sum = W*H

X1 = [0]
X2 = [W]
Y1 = [0]
Y2 = [H]
for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        X1.append(x)
    elif a == 2:
        X2.append(x)
    elif a == 3:
        Y1.append(y)
    else:
        Y2.append(y)

left = max(X1)
right = min(X2)
bottom = max(Y1)
top = min(Y2)

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

Solution (Python):
w,h,n=map(int,input().split())
x0=0
x1=w
y0=0
y1=h
for _ 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)
  elif a==4:
    y1=min(y1,y)
if y1-y0<=0 or x1-x0<=0:
  print(0)
else:
  print((y1-y0)*(x1-x0))

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

for i in range(N):
    X,Y,a = map(int,input().split())
    if a == 1:
        for i in range(H):
            for j in range(X):
                li[i][j] = 1
    elif a == 2:
        for i in range(H):
            for j in range(X,W):
                li[i][j] = 1
    elif a == 3:
        for i in range(Y):
            li[i] = [1]*W
    else:
        for i in range(Y,H):
            li[i] = [1]*W

counter = 0
for i in range(H):
    counter += li[i].count(0)

print(counter)

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

x_left = 0
x_right = w
y_upper = h
y_lower = 0
t = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_left = max(x, x_left)
    elif a == 2:
        x_right = min(x, x_right)
    elif a == 3:
        y_lower = max(y, y_lower)
    else:
        y_upper = min(y, y_upper)
    if x_left < x_right and y_lower < y_upper:
        continue
    else:
        t = 1
        break
if t == 1:
    print(0)
else:
    print((x_right - x_left) * (y_upper - y_lower))

Solution (Python):





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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(len(dots)):
            for j in range(x):
                dots[i][j] = 1
    elif a == 2:
        for i in range(len(dots)):
            for j in range(x, w):
                dots[i][j] = 1
    elif a == 3:
        for i in range(y):
            dots[i] = [1]*w
    else:
        for i in range(y, h):
            dots[i] = [1]*w


cnt = 0
for i in range(h):
    cnt += dots[i].count(0)

print(cnt)

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

w = (w_max-w_min)
h = (h_max-h_min)
if (w > 0) and(h > 0):
    print(w*h)
    
else:
    print(0)

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

field = [['.' for _ in range(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(0, x):
                field[i][j] = '
    elif a == 2:
        for i in range(H):
            for j in range(x, W):
                field[i][j] = '
    elif a == 3:
        for i in range(0, y):
            for j in range(W):
                field[i][j] = '
    else:
        for i in range(y, H):
            for j in range(W):
                field[i][j] = '

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

Solution (Python):
icase=0
if icase==0:
    w,h,n=map(int,input().split())
    xy=[[1]*w for i in range(h)]
    for i in range(n):
        xi,yi,ai=map(int,input().split())
        if ai==1:
            for x  in range(xi):
                for y in range(h):
                    xy[y][x]=0
        elif ai==2:
            for x  in range(xi,w):
                for y in range(h):
                    xy[y][x]=0
        elif ai==3:
            for x  in range(w):
                for y in range(yi):
                    xy[y][x]=0
        elif ai==4:
            for x  in range(w):
                for y in range(yi,h):
                    xy[y][x]=0

    s=0
    for x in range(w):
        for y in range(h):
            s=s+xy[y][x]
    print(s)

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

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

for i in range(N):
  A = list(map(int, input().split()))
  a.append(A)

for j in a:
  if j[2] == 1:
    x[0] = max(x[0], j[0])
  elif j[2] == 2:
    x[1] = min(x[1], j[0])
  elif j[2] == 3:
    y[0] = max(y[0], j[1])
  else:
    y[1] = min(y[1], j[1])
    
if x[0] >= x[1] or y[0] >= y[1]:
  print('0')
else:
  ans = (x[1] - x[0]) * (y[1] - y[0])
  print(int(ans))

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 == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        maxy = min(maxy, y)
    
ans = (maxx - minx) * (maxy - miny)
print(ans if minx < maxx and miny < maxy else 0)

Solution (Python):
w,h,n=map(int,input().split())
xa=0
xb=w
ya=0
yb=h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        xa=max(x,xa)
    if a==2:
        xb=min(x,xb)
    if a==3:
        ya=max(y,ya)
    if a==4:
        yb=min(y,yb)
print(max((xb-xa)*max((yb-ya),0),0))

Solution (Python):
import sys
W, H, N = map(int, sys.stdin.readline().split(" "))
Map = [list(map(int,sys.stdin.readline().split(" "))) for i in range(N)]
L = 0
R = W
B = 0
T = H
 
for i in Map:
  if i[2] == 1:
    l = i[0]
    L = max(L, l)
  if i[2] == 2:
    r = i[0]
    R = min(R, r)
  if i[2] == 3:
    b = i[1]
    B = max(B, b)
  if i[2] == 4:
    t = i[1]
    T = min(T, t)
    
if R - L > 0 and T - B > 0:
  print((R - L) * (T - B))
else:
  print(0)

Solution (Python):
w, h, n = map(int, (input().split()))
x = [0, w]
y = [0, h]
A = []

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

for j in A:
    if j[2] == 1:
        x[0] = max(x[0], j[0])
    if j[2] == 2:
        x[1] = min(x[1], j[0])
    if j[2] == 3:
        y[0] = max(y[0], j[1])
    if j[2] == 4:
        y[1] = min(y[1], j[1])

if x[0] >= x[1] or y[0] >= y[1]:
    print("0")
else:
    print((x[1] - x[0]) * (y[1] - y[0]))