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



Sample input:
5 4 2
2 1 1
3 3 4


Sample output:
9

Submission status: Runtime Error

Solution code:
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

    for n in range(n)def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

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

        if a == 1:
            x_min = max(x_min, x)
        elif a == 2:
            x_max = min(x_max, x)
        elif a == 3:
            y_min = max(y_min, y)
        elif a == 4:
            y_max = min(y_max, y)

    print(max(0, x_max - x_min) * max(0, y_max - y_min))

        # 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
        # 
        # if (x_max <= x_min) or (y_max <= y_min):
        #     print(0)
        #     return

    # print((x_max - x_min) * (y_max - y_min))

if __name__ == "__main__":

    main()
:
        x, y, a = map(int, input().split())

        if a == 1:
            x_min = max(x_min, x)
        elif a == 2:
            x_max = min(x_max, x)
        elif a == 3:
            y_min = max(y_max, y)
        elif a == 4:
            y_max = min(y_max, y)

    print(max(0, x_max - x_min) * max(0, y_max - y_min))

        # 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
        # 
        # if (x_max <= x_min) or (y_max <= y_min):
        #     print(0)
        #     return

    # print((x_max - x_min) * (y_max - y_min))

if __name__ == "__main__":

    main()

Submission status: Runtime Error

Solution code:
import sys

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

ans = (r - l) * (u - d)
if r - l < 0 or u - d < 0
    ans = 0 
print(max(ans, 0))

Submission status: Runtime Error

Solution code:
W, H, N = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(N)]
area = [[0]*W for _ in range(H)]
cnt = 0

for i in x:
    if i[2] == 1:
        for j in range(H):
            for k in range(i[0]):
                area[j][k] = 1   
    elif i[2] == 2:
        for j in range(H):
            for k in range(i[0],H):
                area[j][k] = 1
    elif i[2] == 3:
        for j in range(i[1]):
            for k in range(W):
                area[j][k] = 1
    else:
        for j in range(i[1],H):
            for k in range(W):
                area[j][k] = 1
for i in range(H):
    for j in range(W):
        if area[i][j] == 0:
            cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
W, H, N = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(N)]
area = [[0]*W for _ in range(H)]
cnt = 0

for i in x:
    if i[2] == 1:
        for j in range(H):
            for k in range(i[0]):
                area[j][k] = 1   
    elif i[2] == 2:
        for j in range(H):
            for k in range(i[0],H):
                area[j][k] = 1
    elif i[2] == 3:
        for j in range(i[1]):
            for k in range(W):
                area[j][k] = 1
    else:
        for j in range(i[1],H):
            for k in range(W):
                area[j][k] = 1
print(area)

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
W, H, N = map(int, raw_input().split())

x_arr = [0] * N
y_arr = [0] * N
a_arr = [0] * N
for idx in range(0, N):
  x_arr[idx], y_arr[idx], a_arr[idx] = map(int, raw_input().split())

x_zero = 0
x_inf = W
y_zero = 0
y_inf = H
a_max_min = [x_zero, x_inf, y_zero, y_inf]

for idx in range(0, N):
  a_tmp = a_arr[idx]
  if a_tmp == 1:
    a_max_min[0] = max(a_max_min[0], x_arr[idx])
  elif a_tmp == 2:
    a_max_min[1] = min(a_max_min[1], x_arr[idx])
  elif a_tmp == 3:
    a_max_min[2] = max(a_max_min[2], y_arr[idx])
  elif a_tmp == 4:
    a_max_min[3] = min(a_max_min[3], y_arr[idx])

answer = min(W*H, max(0, ((a_max_min[1] - a_max_min[0]) * (a_max_min[3] - a_max_min[2])))

print(answer)

# https://atcoder.jp/contests/abc047/tasks/abc047_b

Submission status: Runtime Error

Solution code:
xmax,ymax,N=map(int,input().split())
xmin=0
ymin=0

for i in range(N+1):
    x,y,a=map(int,input().split())
    if a==1:
        xmin=max(xmin,x)
    elif a==2:
        xmax=min(xmax,x)
    elif a==3:
        ymin=max(ymin,y)
    else:
        ymax=min(ymax,y)
print(max(0,(xmax-xmin)*(ymax-ymin)))

Submission status: Runtime Error

Solution code:
XYA = [[int(i) for i in input().split()] for j in range(N)]

white_l = 0
white_un = 0
white_r = W
white_up = H

for x,y,a in XYA:
    if a == 1:
        white_l = x
    elif a == 2:
        white_r = x
    elif a == 3:
        white_un = y
    else:
        white_up = y

print(max(0,(white_up-white_un)*(white_r-white_l)))

Submission status: Runtime Error

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

x1, x2, y3, y4 = [], [], [], []

for _ 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:
    y3.append(y)
  else:
    y4.append(y)

print(max(min(w, min(x2)) - max(max(x1), 0), 0) * max(min(h, min(y4)) - max(max(y3), 0), 0))

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
xya = []
for _ in range(N):
  xya.append( list( map(int, input().split() ) ) )
  
W_0 = H_0 = 0
  
for i in range(N):
  
  if xya[i][2] == 1
    W_0 =  xya[i][0]
    
  elif xya[i][2] == 2:
    W = xya[i][0]
    
  elif xya[i][2] == 3:
    H_0 = xya[i][1]
    
  elif xya[i][2] == 4:
    H = xya[i][1]
    
  if (W - W_0 == 0) or (H - H_0 == 0):
    break
    
print(max([(W - W_0)*(H - H_0), 0]))

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
xya = []
for _ in range(N):
  xya.append( list( map(int, input().split() ) ) )
  
W_0 = H_0 = 0
  
for i in range(N):
  
  if xya[i][2] == 1:
    W_0 =  xya[i][0]
    
  else if xya[i][2] == 2:
    W = xya[i][0]
    
  else if xya[i][2] == 3:
    H_0 = xya[i][1]
    
  else if xya[i][2] == 4:
    H = xya[i][1]
    
  if (W - W_0 == 0) or (H - H_0 == 0):
    break
    
print(max([(W - W_0)*(H - H_0), 0]))

Submission status: Runtime Error

Solution code:
w,h,n = map(int,input().split())
cl = np.zeros((w, h) , dtype = int)
for i in range(n):
    x, y, a, = map(int,input().split())
    if a ==1: 
        cl[:x, :] = 1
    if a ==2: 
        cl[x:, :] = 1
    if a ==3:
        cl[:, :y] = 1
    if a ==4:
        cl[:, y:] = 1
print(w * h - np.sum(cl))

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
X, Y = 0, 0
for i in range(N+1):
  x, y, a = map(int, input().split())
  if a == 1:
    X = max(X, x)
  elif a == 2:
    W = min(W, x)
  elif a == 3:
    Y = max(Y, y)
  elif a == 4:
    H = min(H, y)
ans = max(0, (W-X)*(H-Y))
print(ans)

Submission status: Runtime Error

Solution code:
w,h,n = map(int,input().split())))
for i in range(n):
    a=list(map(int,input().split()))))
    if a[-1]==1:
        w-=a[0]
    elif a[-1]==2:
        w = a[0]
    elif a[-1]==3:
        h-=a[1]
    elif a[-1]==4:
        h = a[1]
print(h*w)

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
L1 = []
L2 = []
L3 = []
L4 = []
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        L1.append(x)
    if a == 2:
        L2.append(x)      
    if a == 3:
        L3.append(y)
    if a == 4:
        L4.append(y)
        
if L1 != []:
    x_min = min(L1)
else:
    x_min = 0
    
if L2 != []:
    x_max = min(L2)
else:
    x_max = W
    
if L3 != []:
    y_min = min(L3)
else:
    y_min = 0
    
if L4 != []:
    y_min = min(L4)
else:
    y_min = H
    
x_len = min(0, x_max-x_min)
y_len = min(0, y_max-y_min)
print(x_len * y_len)

Submission status: Runtime Error

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

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

x_max = max([i[0] for i in l if i[2] == 1])
x_min = min([i[0] for i in l if i[2] == 2])
y_max = max([i[1] for i in l if i[2] == 3])
y_min = min([i[1] for i in l if i[2] == 4])

x = min(x_max+(W-x_min),W)
y = min(y_max+(H-y_min),H)

print(W*H - x*H - y*W + x*y)

Submission status: Runtime Error

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

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

x_min = min([i[0] for i in l if i[2] == 1])
x_max = max([i[0] for i in l if i[2] == 2])
y_min = min([i[1] for i in l if i[2] == 3])
y_max = max([i[1] for i in l if i[2] == 4])

print((W - max(0,x_max-x_min)) * (H - max(0,y_max-y_min)))

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
record=[]
xmin=[]
xmax=[]
ymin=[]
ymax=[]

for i in range(n):
    x,y,a=list(map(int,input().split()))
    record.append([x,y,a])
    
for i in range(n):
    if record[i][2] == 1:
        xmin.append(record[i][0])
    elif record[i][2] == 2:
        xmax.append(record[i][0])
    elif record[i][2] == 3:
        ymin.append(record[i][1])
    else:
        ymax.append(record[i][1])

if xmax==[]:
    X=w-max(xmin)
elif ymax==[]:
    X=min(xmax)-0
else:
    X=min(xmax)-max(xmin)

if ymax==[]:
    Y=h-max(ymin)
elif ymin==[]:
    Y=min(ymax)-0
else:
    Y=min(ymax)-max(ymin)
    
print(X*Y) if (X > 0 and Y > 0) else print(0)

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
record=[]
xmin=[]
xmax=[]
ymin=[]
ymax=[]
for i in range(n):
    x,y,a=list(map(int,input().split()))
    record.append([x,y,a])
for i in range(n):
    if record[i][2] == 1:
        xmin.append(record[i][0])
    elif record[i][2] == 2:
        xmax.append(record[i][0])
    elif record[i][2] == 3:
        ymin.append(record[i][1])
    else:
        ymax.append(record[i][1])
if xmax==[]:
    X=w-max(xmin)
elif ymax==[]:
    X=min(xmax)-0
else:
    X=min(xmax)-max(xmin)

if ymax==[]:
    Y=h-max(ymin)
elif ymin==[]:
    Y=min(ymax)-0
else:
    Y=min(ymax)-max(ymin)
    
print(X*Y) if (X > 0 and Y > 0) else print(0)

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
record=[]
xmin=[]
xmax=[]
ymin=[]
ymax=[]
for i in range(n):
    x,y,a=list(map(int,input().split()))
    record.append([x,y,a])
for i in range(n):
    if record[i][2] == 1:
        xmin.append(record[i][0])
    elif record[i][2] == 2:
        xmax.append(record[i][0])
    elif record[i][2] == 3:
        ymin.append(record[i][1])
    else:
        ymax.append(record[i][1])
X=min(xmax)-max(xmin)
Y=min(ymax)-max(ymin)
print(X*Y) if (X > 0 and Y > 0) else print(0)

Submission status: Runtime Error

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

x1 = 0
x2 = W
y3 = 0
y4 = H

for x,y,a in xya:
  if a == 1:
    x1 = max(x1, x)
  elif a == 2:
    x2 = min(x2, x)
  elif a == 3:
    y3 = max(y3, y)
  elif a == 4:
    y4 = min(y4, y)
else:
  if x2 <= x1 or y4 <= y3:
    print(0)
  else:
    print((x2-X1)*(y4-y3))

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
z = [list(map(int, input().split())) for _ in range(N)]
one, two, three, four = [], [], [], []
for i in range(N):
	if z[i][2] == 1:
		one.append(z[i][0])
	elif z[i][2] == 2:
		two.append(z[i][0])
	elif z[i][2] == 3:
		three.append(z[i][1])
	else:
		four.append(z[i][1])
w = W - max(one) - (W - min(two))
h = H - max(three) - (H - min(four))
if w > 0 and h > 0:
	print(w * h)
else:
	print(0)

Submission status: Runtime Error

Solution code:
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(list(int(input())))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

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

Submission status: Runtime Error

Solution code:
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(int(input()))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

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

Submission status: Runtime Error

Solution code:
W, H, N = map(int,input().split())
Map = np.ones((H, W),dtype = int)
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        Map[:,:x] = 0
    elif a == 2:
        Map[:,x:] = 0
    elif a == 3:
        Map[:y,:] = 0
    else:
        Map[y:,:] = 0
print(Map.sum())

Submission status: Runtime Error

Solution code:
W, H, N = map(int,input().split())
Map = np.ones((H, W),dtype = int)
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        Map[:,:x] = 0
    elif a == 2:
        Map[:,x:] = 0
    elif a == 3:
        Map[:y,:] = 0
    else:
        Map[y:,:] = 0
print(Map.sum())

Submission status: Runtime Error

Solution code:
w,h,n=[int(i) for i in input().split(' ')]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=[int(i) for i in input().split(' ')]
  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)
print(max(0,(y2-y1)*(x2-x1))

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
x1 = y1 = a1 = 0
xmin = 0
xmax = W
ymin = 0
ymax = H
for _ in range(N):
  x2, y2, a2 = map(int, input().split())
  if (a2 = 1):
    xmin = max(x2, xmin)
  if (a2 = 2):
    xmax = min(x2, xmax)
  if (a2 = 3):
    ymin = max(y2, ymin)
  if (a2 = 4):
    ymax = min(y2, ymax)
  if (xmax<= xmin or ymax <= ymin):
    print(0)
    exit()
print((xmax - xmin) * (ymax - ymin))

Submission status: Runtime Error

Solution code:
W,H,N = map(int,input().split(" "))
Lx = [1 for i in range(N)]
Ly = [1 for i in range(N)]

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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
W,H,N=map(int,input().split(' '))
info = [[],[],[],[]] #min_x,max_x,min_y,max_y
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))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
x_b, x_u, y_l, y_r = 0, H, 0, W
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((x_r - x_l) * (y_u - y_b))

Submission status: Runtime Error

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

x1 = 0
x2 = W
y1 = 0
y2 = H
rectangle_S = W*H
black_S = 0
judge = 1 #1:黒部分全部でない,0:黒部分全部

for i in range(N):
  x,y,a = map(int,input().split())
  if(a == 1):
    if(x < x1):
     balck_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
     x2 = x2   
  elif(a == 3):
    if(y < y1):
     balck_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
     break
    elif(y1 <= y <= y2):
     black_S += (y2-y)*(x2-x1)
     y2 = y
    elif(y2 < y):
     black_S += 0
     y2 = y2
  #print(x1,x2,y1,y2,black_S)
if(judge == 0):
  print(0)
else:
  print(rectangle_S - black_S)

Submission status: Runtime Error

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

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

for i in range(N):
  x,y,a = map(int,input().split())
  if(a == 1):
    if(x < x1):
     balck_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
     break
    elif(x1 <= x <= x2):
     black_S += (x2-x)*(y2-y1)
     x2 = x
    elif(x2 < x):
     black_S += 0
     x2 = x2   
  elif(a == 3):
    if(y < y1):
     balck_S += 0
     y1 = y1
    elif(y1 <= y <= y2):
     black_S += (y-y1)*(x2-x1)
     y1 = y
    elif(y2 < y):
     black_S = W*H
     break     
  elif(a == 4):
    if(y < y1):
     black_S = W*H
     break
    elif(y1 <= y <= y2):
     black_S += (y2-y)*(x2-x1)
     y2 = y
    elif(y2 < y):
     black_S += 0
     y2 = y2
  #print(x1,x2,y1,y2,black_S)
  
print(rectangle_S - black_S)

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().spllit())
a = [list(map(int, input().split())) for i in range(N)]
x, y = 0, 0
for i in a:
    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]
if ((W-x)<=0) or ((H-y)<=0):
    print(0)
else:
    print((W-x)*(H-y))

Submission status: Runtime Error

Solution code:
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 for i in range(w)]
ans=0
for i in range(h):
  ans+=A[i].count(0)
print(ans)

Submission status: Runtime Error

Solution code:
whn = list (map(int, input().split()))
x = 0
y = 0

for i in range(len(whn[2])):
    xya = list(map(int,input().split()))
    if xya[2] == 1:
        x = max(x, xya[0])
    elif xya[2] == 2:
        whn[0] = min(whn[0], xya[0])
    elif xya[2] == 3:
        y = max(y, xya[0])
    else:
        whn[1] = min(whn[1], xya[1])

print((whn[0]-x)*(whn[1]-y))