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(" "))
Lx = [1 for i in range(W)]
Ly = [1 for i in range(H)]
 
for i in range(N):
  xi,yi,ai = map(int,input().split(" "))
  if ai ==1:
    for j in range(xi):
      Lx[j] = 0
         
  if ai ==2:
    for j in range(xi,W):
      Lx[j] = 0
    
  if ai ==3:
    for j in range(yi):
      Ly[j] = 0
    
  if ai ==4:
    for j in range(yi,H):
      Ly[j] = 0
x = sum(Lx)
y = sum(Ly)
 
print(x*y)

Solution (Python):
W,H,N = map(int,input().split())
limit = {'top': H, 'right': W, 'down': 0, 'left': 0}
for _ in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    if x > limit['left']:
      limit['left'] = x
  elif a == 2:
    if x < limit['right']:
      limit['right'] = x
  elif a == 3:
    if y > limit['down']:
      limit['down'] = y
  elif a == 4:
    if y < limit['top']:
      limit['top'] = y
height = limit['top'] - limit['down']
width = limit['right'] - limit['left']
if (height > 0) and (width > 0):
  print(height * width)
else:
  print(0)

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

top, bottom, left, right = H, 0, 0, W

for x, y, a in I:
	if a == 1:
		left = max(left, x)
	if a == 2:
		right = min(right, x)
	if a == 3:
		bottom = max(bottom, y)
	if a == 4:
		top = min(top, y)
	

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

Solution (Python):
w,h,n=map(int, input().split());
x,y=0,0
for i in '1'*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())
xyan = [map(int, input().split()) for _ in range(N)]


ws = [False] * W
hs = [False] * H

for x, y, a in xyan:
    if a == 1:
        for i in range(0, x):
            ws[i] = True
    elif a == 2:
        for i in range(x, W):
            ws[i] = True
    elif a == 3:
        for i in range(0, y):
            hs[i] = True
    elif a == 4:
        for i in range(y, H):
            hs[i] = True

print(len([w for w in ws if not w]) * len([h for h in hs if not h]))

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

sx = 0
sy = 0
ex = w
ey = h
for x,y,a in xya:
    if a == 1:
        sx = max(sx,x)
    if a == 2:
        ex = min(ex,x)
    if a == 3:
        sy = max(sy,y)
    if a == 4:
        ey = min(ey,y)

if ex-sx > 0 and ey-sy > 0:
    print((ex-sx)*(ey-sy))
else:
    print(0)

Solution (Python):
w,h,n=map(int,input().split())
l=[[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):
            l[i][:x]=[1]*x
    elif a==2:
        for i in range(h):
            l[i][x:]=[1]*(w-x)
    elif a==3:
        for i in range(h-1,h-y-1,-1):
            l[i]=[1]*w
    else:
        for i in range(h-y):
            l[i]=[1]*w
    
ans=0
for i in l:
    ans+=i.count(0)
print(ans)

Solution (Python):
def main():
    W, H, N = map(int, input().split())
    white = [[1]*H for _ in range(W)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        xr = range(W)
        yr = range(H)
        if a == 1:
            xr = range(x)
        elif a == 2:
            xr = range(x, W)
        elif a == 3:
            yr = range(y)
        else:
            yr = range(y, H)
        for i in xr:
            for j in yr:
                white[i][j] = 0
    print(sum([sum(x) for x in white]))


if __name__ == "__main__":
    main()

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

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

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

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

for i in range(n):
    if p[i][2] == 1:
        if p[i][0] > max_x:
            max_x = p[i][0]
        
    if p[i][2] == 2:
        if p[i][0] < min_x:
            min_x = p[i][0]
    
    if p[i][2] == 3:
        if p[i][1] > max_y:
            max_y = p[i][1]
    
    if p[i][2] == 4:
        if p[i][1] < min_y:
            min_y = p[i][1]
        
        
if max_x > min_x:
    new_x = 0
else:
    new_x = min_x - max_x
    
if max_y > min_y:
    new_y = 0
else:
    new_y = min_y - max_y
    
print(new_x*new_y)

Solution (Python):
W,H,N=list(map(int,input().split()))
ten=[list(map(int,input().split())) for _ in range(N)]
base=[[0,0,1],[0,0,3],[W,H,2],[W,H,4]]
ten.extend(base)
onemax=max(i[0] for i in ten if i[2]==1)
twomin=min(i[0] for i in ten if i[2]==2)
thrmax=max(i[1] for i in ten if i[2]==3)
foumin=min(i[1] for i in ten if i[2]==4)
if (twomin-onemax)>0 and (foumin-thrmax) >0:
    print((twomin-onemax)*(foumin-thrmax))
else:print(0)

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

L, R = 0, W
D, T = 0, H

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        if L < x:
            L = x
    elif a == 2:
        if x < R:
            R = x
    elif a == 3:
        if D < y:
            D = y
    elif a == 4:
        if y < T:
            T = y

if (R - L) > 0 and (T - D) > 0:
    print((R - L) * (T - D))
elif (R - L) > 0 and (T - D) < 0:
    print((R - L))
elif (R - L) < 0 and (T - D) > 0 > 0:
    print(T - D)
else:
    print(0)

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())
xya = [list(map(int, input().split())) for i in range(N)]

ld = [0,0]
ru = [W,H]

flag = True
for x,y,a in xya:
    if a == 1:
        if ld[0] < x: ld[0] = x
    if a == 2:
        if ru[0] > x: ru[0] = x
    if a == 3:
        if ld[1] < y: ld[1] = y
    if a == 4:
        if ru[1] > y: ru[1] = y
    tate = ru[1] - ld[1]
    yoko = ru[0] - ld[0]
    if tate <= 0 or yoko <= 0:
        flag = False
        break

if flag:
    print(tate*yoko)
else:
    print(0)

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

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

hdot = [1 for h in range(H)]
wdot = [1 for w in range(W)]

for a in A:
    if a[2] == 1:
        for w in range(W):
            if w < a[0]:
                wdot[w] = 0
    elif a[2] == 2:
        for w in range(W):
            if w >= a[0]:
                wdot[w] = 0
    elif a[2] == 3:
        for h in range(H):
            if h < a[1]:
                hdot[h] = 0
    elif a[2] == 4:
        for h in range(H):
            if h >= a[1]:
                hdot[h] = 0

print(sum(hdot)*sum(wdot))

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

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

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

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

Solution (Python):
W,H,N=map(int,input().split(' '))
info = [[0],[W],[0],[H]] 
for i in range(N):
  x,y,a=map(int,input().split(' '))
  info[a-1].append([x,y][(a-1)//2])
print(max(min(info[1])-max(info[0]),0)*max(min(info[3])-max(info[2]),0))

Solution (Python):
import numpy as np

W, H, N = map(int, input().split())
xlist = np.zeros(N,dtype=int)
ylist = np.zeros(N,dtype=int)
alist = np.zeros(N,dtype=int)
for i in range(N):
    xlist[i], ylist[i], alist[i] = map(int, input().split())
rectangular = np.zeros((H, W))
for i in range(N):
    if alist[i] == 1:
        rectangular[:,:xlist[i]] = 1
    if alist[i] == 2:
        rectangular[:,xlist[i]:] = 1
    if alist[i] == 3:
        rectangular[:ylist[i],:] = 1
    if alist[i] == 4:
        rectangular[ylist[i]:,:] = 1
print(sum(sum(rectangular < 1)))

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

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

rec = [[0 for i in range(W)] for j in range(H)]

for x,y,a in _input:
    if a == 1:
        for i in range(H):
            for j in range(x):
                rec[i][j] = 1

    elif a == 2:
        for i in range(H):
            for j in range(x,W):
                rec[i][j] = 1

    elif a == 3:
        for i in range(y):
            for j in range(W):
                rec[i][j] = 1
    
    else:
        for i in range(y,H):
            for j in range(W):
                rec[i][j] = 1

res = 0
for i in range(H):
    for j in range(W):
        if rec[i][j] == 0:
            res += 1

print(res)

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

for _ in range(N):
    x,y,a = map(int,input().split())
    if a==1:
        w = max(x,w)
    elif a==2:
        W = min(x,W)
    elif a==3:
        h = max(y,h)
    else:
        H = min(y,H)
        
if h<H and w<W:
    print((W-w)*(H-h))
else:
    print(0)

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

s = [0,0]
t = [w, h]
for x, y, a in xya:
    if a == 1:
        s[0] = max(s[0], x)
    elif a == 2:
        t[0] = min(t[0], x)
    elif a == 3:
        s[1] = max(s[1], y)
    elif a == 4:
        t[1] = min(t[1], y)

if s[0] >= t[0] or s[1] >= t[1]:
    print(0)
else:
    print((t[0] - s[0]) * (t[1] - s[1]))

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

xmin,xmax,ymin,ymax = 0,w,0,h

for x,y,a in p:
    if a == 1:
        if x > xmin:
            xmin = x

    elif a == 2:
        if x < xmax:
            xmax = x

    elif a == 3:
        if y > ymin:
            ymin = y

    elif a == 4:
        if y < ymax:
            ymax = y

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

Solution (Python):
w,h,n = map(int, input().split())
a=0
b=0
listA=[]
while True:
  try:
    listA.append(list(map(int,input().split())))
  except:
    break;
for i in range(n):
  if listA[i-1][2]==1 and listA[i-1][0]>a:
    a = listA[i-1][0]
  elif listA[i-1][2]==2 and listA[i-1][0]<w:
    w = listA[i-1][0]
  elif listA[i-1][2]==3 and listA[i-1][1]>b:
    b = listA[i-1][1]
  elif listA[i-1][2]==4 and listA[i-1][1]<h:
    h = listA[i-1][1]
if w-a>0 and h-b>0:
  print((w-a)*(h-b))
else:
  print(0)

Solution (Python):
W, H, N = [int(x) for x in input().split()]
L = [[int(y) for y in input().split()] for _ in range(N)]
xmin = 0
xmax = W
ymin = 0
ymax = H

for i in range(N):
    if L[i][2] == 1 and L[i][0] > xmin:
        xmin = L[i][0]
    elif L[i][2] == 2 and L[i][0] < xmax:
        xmax = L[i][0]
    elif L[i][2] == 3 and L[i][1] > ymin:
        ymin = L[i][1]
    elif L[i][2] == 4 and L[i][1] < ymax:
        ymax = L[i][1]

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

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

xl, xr, yl, yh = 0, W, 0, H

for xi, yi, ai in p:
  if ai == 1:
    if xl < xi:
      xl = xi
  if ai == 2:
    if xr > xi:
      xr = xi
  if ai == 3:
    if yl < yi:
      yl = yi
  if ai == 4:
    if yh > yi:
      yh = yi

if xr -xl < 0 or yh - yl < 0:
  ans = 0
else:
  ans = (xr - xl) * (yh - yl)
print(ans)

Solution (Python):
""" AtCoder """

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

w = 0
h = 0

for i in range(N):
    if xya[i][2] == 1:
        if w < xya[i][0]:
            w = xya[i][0]
    elif xya[i][2] == 2:
        if W > xya[i][0]:
            W = xya[i][0]
    elif xya[i][2] == 3:
        if h < xya[i][1]:
            h = xya[i][1]
    else:
        if H > xya[i][1]:
            H = xya[i][1]

ans = (H - h) * (W - w)

if H - h < 0 or W - w < 0:
    print(0)
else:
    print(ans)

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

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

sx, sy, ex, ey = 0, 0, W, 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)
    elif a == 4:
        ey = min(ey, y)
    
result = max(ex - sx, 0) * max(ey - sy, 0)
print(result)

Solution (Python):
W, H, N = map(int, input().rstrip().split(' '))
sq = [[0 for i in range(W)] for j in range(H)]
for i in range(N):
    x, y, a = map(int, input().rstrip().split(' '))
    if a == 1:
        
        for j in range(H):
            for k in range(0, x):
                sq[j][k] = 1

    elif a == 2:
        
        for j in range(H):
            for k in range(x, W):
                sq[j][k] = 1
    elif a == 3:
        
        for j in range(y):
            for k in range(W):
                sq[j][k] = 1
    elif a == 4:
        
        for j in range(y, H):
            for k in range(W):
                sq[j][k] = 1


result = 0 
for i in range(H):
    for j in range(W):
        if sq[i][j] == 0:
            result += 1


print(result)

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

area = [ [ 0 for _ in range(W) ] for _ in range(H) ]
for xya in xyas:
    x, y, a = xya
    if a == 1:
        for i in range(x):
            for j in range(H):
                area[j][i] = 1
    elif a == 2:
        for i in range(x, W):
            for j in range(H):
                area[j][i] = 1
    elif a == 3:
        for i in range(W):
            for j in range(y):
                area[j][i] = 1
    else:
        for i in range(W):
            for j in range(y, H):
                area[j][i] = 1
ans = 0
for s in area:
    for t in s:
        if t == 0:
            ans += 1

print(ans)

Solution (Python):
w,h,n = map(int,input().split())
mdx = [0]
pdx = [w]
mdy = [0]
pdy = [h]
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        mdx.append(x)
    elif a == 2:
        pdx.append(x)
    elif a == 3:
        mdy.append(y)
    else:
        pdy.append(y)
print(max(0,min(pdx)-max(mdx))*max(0,min(pdy)-max(mdy)))

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

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

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

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

left = 0
right = w
down = 0
up = h

for xya in xya_s:
    if xya[2] == 1:
        if left < xya[0]:
            left = xya[0]
    elif xya[2] == 2:
        if xya[0] < right:
            right = xya[0]
    elif xya[2] == 3:
        if xya[1] > down:
            down = xya[1]
    else:
        if xya[1] < up:
            up = xya[1]
if right - left > 0 and up - down > 0:
    print((right - left) * (up - down))
else:
    print(0)

Solution (Python):
w,h,n=[int(i) for i in input().split()]
a1=[0]
a2=[w]
a3=[0]
a4=[h]
for i in range(n):
    x,y,a=[int(j) for j in input().split()]
    if a==1:
        a1.append(x)
    elif a==2:
        a2.append(x)
    elif a==3:
        a3.append(y)
    else:
        a4.append(y)

a1a2=sorted(a2)[0]-sorted(a1)[-1]
a3a4=sorted(a4)[0]-sorted(a3)[-1]
if a1a2>0 and a3a4>0:
    ans=a1a2*a3a4
else:
    ans=0
print(ans)

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

Solution (Python):
W, H, N = map(int, input().split())
area = [[0]*W for _ in range(H)]
x, y, a = [], [], []
for _ in range(N):
    xi, yi, ai = map(int, input().split())
    x.append(xi)
    y.append(yi)
    a.append(ai)


def show(area):
    for line in area:
        print(line)
    print("-----")


for i in range(N):
    
    if a[i] == 1:
        for j in range(H):
            for k in range(x[i]):
                area[j][k] = 1
    if a[i] == 2:
        for j in range(H):
            for k in range(x[i], W):
                area[j][k] = 1
    if a[i] == 3:
        for j in range(H-y[i], H):
            for k in range(W):
                area[j][k] = 1
    if a[i] == 4:
        for j in range(0, H-y[i]):
            for k in range(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 = []
for i in range(N):
  L.append(list(map(int,input().split())))
A = [0]
B = [W]
C = [0]
D = [H]
for i in range(N):
  if L[i][2] == 1:
    A.append(L[i][0])
  elif L[i][2] == 2:
    B.append(L[i][0])
  elif L[i][2] == 3:
    C.append(L[i][1])
  else:
    D.append(L[i][1])
A.sort()
A.reverse()
B.sort()
C.sort()
C.reverse()
D.sort()
w = 0
h = 0
if A[0] <= B[0]:
  w = B[0]-A[0]
else:
  w = 0
if C[0] <= D[0]:
  h = D[0]-C[0]
else:
  h = 0
print(w*h)

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_tmp, y_tmp, a_tmp = map(int,input().split())
    if a_tmp == 1:
        x_min = max(x_tmp, x_min)
    elif a_tmp == 2:
        x_max = min(x_tmp, x_max)
    elif a_tmp == 3:
        y_min = max(y_tmp, y_min)
    else:
        y_max = min(y_tmp, 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())
l = [0, w, 0, h]
for i in range(n):
  x, y, a = map(int, input().split())
  if (a == 1):
    l[0] = max(l[0], x)
  elif (a == 2):
    l[1] = min(l[1], x)
  elif (a == 3):
    l[2] = max(l[2], y)
  else:
    l[3] = min(l[3], y)
print(max(0, (l[1] - l[0])) * max(0, (l[3] - l[2])))

Solution (Python):
right, top, n = map(int, input().split())
list = [list(map(int, input().split())) for i in range(n)]
bottom, left = 0, 0

for i in range(n):
    if list[i][2] == 1:
        left = max(list[i][0], left)
    elif list[i][2] == 2:
        right = min(list[i][0], right)
    elif list[i][2] == 3:
        bottom = max(list[i][1], bottom)
    else:
        top = min(list[i][1], top)

area = (top - bottom) * (right - left)

print(area if top - bottom > 0 and right - left > 0 else 0)

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


field = [[1 for _ in range(H)] for _ in range(W)]
x = [0]*N
y = [0]*N
a = [0]*N
for i in range(N):
    x[i], y[i], a[i] = [int(n) for n in input().split()]
    if(a[i] == 1):
        for k in range(x[i]):
            field[k] = [0 for _ in range(H)]
    elif(a[i] == 2):
        for k in range(x[i],W):
            field[k] = [0 for _ in range(H)]
    elif(a[i] == 3):
        for k in range(W):
            for j in range(y[i]):
                field[k][j] = 0
    elif(a[i] == 4):
        for k in range(W):
            for j in range(y[i],H):
                field[k][j] = 0
    
        
ans = 0
for i in range(W):
    ans+=sum(field[i])
    
print(ans)

Solution (Python):
w,h,n = map(int,input().split())
pos_list = [map(int,input().split()) for _ in range(n)]
s = [0,0]
f = [w,h]
for x,y,a in pos_list:
    if a == 1:
        s[0] = max(s[0],x)
    elif a == 2:
        f[0] = min(f[0],x)
    elif a == 3:
        s[1] = max(s[1],y)
    elif a == 4:
        f[1] = min(f[1],y)

if f[0]-s[0] <= 0 or f[1] - s[1] <= 0:
    print(0)
else:
    print((f[0]-s[0])*(f[1]-s[1]))

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

yoko = [0,w]
tate = [0,h]

for i in range(n):
  if info [i][2]==1 and yoko[0]<info[i][0]:
    yoko[0]=info[i][0]
  elif info [i][2]==2 and yoko[1]>info[i][0]:
    yoko[1]=info[i][0]
  elif info [i][2]==3 and tate[0]<info[i][1]:
    tate[0]=info[i][1]
  elif info [i][2]==4 and tate[1]>info[i][1]:
    tate[1]=info[i][1]

len_yoko = yoko[1]-yoko[0]
len_tate = tate[1]-tate[0]
if len_yoko<=0 or len_tate<=0:
  print(0)
else:
  print(len_tate*len_yoko)

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

x1 = 0
x2 = W
y1 = 0
y2 = H
rectangle_S = W*H
black_S = 0
judge = 1 

for i in range(N):
  x,y,a = map(int,input().split())
  if(a == 1):
    if(x < x1):
     black_S += 0
     x1 = x1
    elif(x1 <= x <= x2):
     black_S += (x-x1)*(y2-y1)
     x1 = x
    elif(x2 < x):
     black_S = W*H
     break      
  elif(a == 2):
    if(x < x1):
     black_S = W*H
     judge = 0 
    elif(x1 <= x <= x2):
     black_S += (x2-x)*(y2-y1)
     x2 = x
    elif(x2 < x):
     black_S += 0
     
  elif(a == 3):
    if(y < y1):
     black_S += 0
     y1 = y1
    elif(y1 <= y <= y2):
     black_S += (y-y1)*(x2-x1)
     y1 = y
    elif(y2 < y):
     black_S = W*H
     judge = 0   
  elif(a == 4):
    if(y < y1):
     black_S = W*H
     judge = 0 
    elif(y1 <= y <= y2):
     black_S += (y2-y)*(x2-x1)
     y2 = y
    elif(y2 < y):
     black_S += 0
     

if(judge == 0):
  print(0)
else:
  print(rectangle_S - black_S)

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

Solution (Python):

W, H, N = map(int, input().split())
grid = [[0, W], [0, H]]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if grid[0][0] < x:
            grid[0][0] = x
    elif a == 2:
        if grid[0][1] > x:
            grid[0][1] = x
    elif a == 3:
        if grid[1][0] < y:
            grid[1][0] = y
    else:
        if grid[1][1] > y:
            grid[1][1] = y
ans = (grid[0][1] - grid[0][0]) * (grid[1][1] - grid[1][0])
if grid[0][0] > grid[0][1] or grid[1][0] > grid[1][1]:
    ans = 0
print(ans)

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

Solution (Python):
import sys
W,H,N=map(int,input().split())
wide=[0,W]
height=[0,H]

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        wide[0]=max(wide[0],x)
    elif a==2:
        wide[1]=min(wide[1],x)
    elif a==3:
        height[0]=max(height[0],y)
    elif a==4:
        height[1]=min(height[1],y)
w_len=wide[1]-wide[0]
h_len=height[1]-height[0]
s=w_len*h_len
if h_len<0 or w_len<0:
    print(0)
else:
    print(s)

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

for j in range(n):
  x,y,a = (int(k) for k in input().split())
  if a == 1 and sq[0] < x:
    sq[0] = x
  elif a == 2 and sq[2] > x:
    sq[2] = x
  elif a == 3 and sq[1] < y:
    sq[1] = y
  elif a == 4 and sq[3] > y:
    sq[3] = y
if sq[2]-sq[0] > 0 and sq[3]-sq[1] > 0:
  answer = (sq[2]-sq[0])*(sq[3]-sq[1])
print(answer)

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

Solution (Python):
W, H, N = map(int, input().split())
p = [0, 0]
q = [W, H]
for _ in [0]*N:
    x, y, a = map(int, input().split())
    if a == 1:
        p[0] = max(p[0], x)
    elif a == 2:
        q[0] = min(q[0], x)
    elif a == 3:
        p[1] = max(p[1], y)
    elif a == 4:
        q[1] = min(q[1], y)

if q[0] - p[0] < 0 or q[1] - p[1] < 0:
    print(0)
else:
    print((q[0] - p[0])*(q[1] - p[1]))

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

Solution (Python):

w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(n):
    xi,yi,ai=map(int,input().split())
    x.append(xi)
    y.append(yi)
    a.append(ai)

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


for i in range(n):
    if a[i] == 1:
        for j in range(x[i]):
            for k in range(h):
                dot[k][j]=1
    if a[i] == 2:
        for j in range(x[i],w):
            for k in range(h):
                dot[k][j]=1
    if a[i] == 3:
        for j in range(y[i]):
            for k in range(w):
                dot[j][k]=1
    if a[i] == 4:
        for j in range(y[i],h):
            for k in range(w):
                dot[j][k]=1
    

print(sum(dot,[]).count(0))

Solution (Python):
w,h,n=map(int,input().split())
A=[[0 for i in range(w)] for j in range(h)]
for i in range(n):
  a,b,c=map(int,input().split())
  if c==1:
    for i in range(h):
      for j in range(a):
        A[i][j]=1
  elif c==2:
    for i in range(h):
      for j in range(w-a):
        A[i][j+a]=1
  elif c==3:
    for i in range(b):
      A[i]=[1 for i in range(w)]
  else:
    for i in range(h-b):
      A[h-i-1]=[1 for i in range(w)]
ans=0
for i in range(h):
  ans+=A[i].count(0)
print(ans)

Solution (Python):
W,H,N = map(int,input().split())
xl = yd = 0
xr = W
yu = H
for _ in range(N):
    X,Y,A = map(int,input().split())
    if A == 1:xl = max(X,xl)
    elif A == 2:xr = min(X,xr)
    elif A == 3:yd = max(Y,yd)
    elif A == 4:yu = min(Y,yu)
s = max(0,(xr-xl)) * max(0,(yu-yd))
print(s)

Solution (Python):
w,h,n = map(int,input().split())
dots = [list(map(int,input().split())) for i in range(n)]
xl = [dots[i] for i in range(n) if dots[i][2] == 1]
xr = [dots[i] for i in range(n) if dots[i][2] == 2]
yd = [dots[i] for i in range(n) if dots[i][2] == 3]
yu = [dots[i] for i in range(n) if dots[i][2] == 4]

kfunc1 = lambda x : x[0]
kfunc2 = lambda y : y[1]

xxl = max(xl,key = kfunc1,default = [0,0,0])
xxr = min(xr,key = kfunc1,default = [w,0,0])
yyd = max(yd,key = kfunc2,default = [0,0,0])
yyu = min(yu,key = kfunc2,default = [0,h,0])

if xxl[0] >= xxr[0] or yyd[1] >= yyu[1]: print(0)
else : print((xxr[0]-xxl[0])*(yyu[1]-yyd[1]))

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

Solution (Python):
w, h, n = map(int, input().split())
a = [[int(i) for i in input().split()] for j in range(n)]
s = [0,w]
t = [0,h]
for i in range(n):
    if a[i][2] == 1:
        s[0] = max(s[0],a[i][0])
    elif a[i][2] == 2:
        s[1] = min(s[1],a[i][0])
    elif a[i][2] == 3:
        t[0] = max(t[0],a[i][1])
    else:
        t[1] = min(t[1],a[i][1])
print(max(0,(s[1]-s[0]))*max(0,(t[1]-t[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 == 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)