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:
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1 and x[i] > w[0]:
        for j in range(x[i]):
            if j in w: w.remove(j)
    if a[i]==2 and x[i] < w[-1]:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            if j in w: w.remove(j)
    if a[i]==3 and y[i] > h[0]:
        for j in range(y[i]):
            if j in h: h.remove(j)
    if a[i]==4 and y[i] < h[-1]:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            if j in h: h.remove(j)

if len(w)==0 or len(h)==0:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Submission status: Runtime Error

Solution code:
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1:
        for j in range(x[i]):
            if j in w: w.remove(j)
    if a[i]==2:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            if j in w: w.remove(j)
    if a[i]==3:
        for j in range(y[i]):
            if j in h: h.remove(j)
    if a[i]==4:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            if j in h: h.remove(j)

if len(w)==0 or len(h)==0:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Submission status: Runtime Error

Solution code:
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1 and x[i] > w[0]:
        for j in range(x[i]):
            w.remove(j)
    if a[i]==2 and x[i] < w[-1]:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            w.remove(j)
    if a[i]==3 and y[i] > h[0]:
        for j in range(y[i]):
            h.remove(j)
    if a[i]==4 and y[i] < h[-1]:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            h.remove(j)

if len(w)==0 or len(h)==0 or len(w)==1 or len(h)==1:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Submission status: Runtime Error

Solution code:
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1 and x[i] > w[0]:
        for j in range(x[i]):
            w.remove(j)
    if a[i]==2 and x[i] < w[-1]:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            w.remove(j)
    if a[i]==3 and y[i] > h[0]:
        for j in range(y[i]):
            h.remove(j)
    if a[i]==4 and y[i] < h[-1]:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            h.remove(j)

if len(w)==0 or len(h)==0:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Submission status: Runtime Error

Solution code:
W, H, N = map(int,input().split())
#白い領域の端
l = 0
r = W
u = H
d = 0
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        l = max(x,l)
    elif a == 2:
        r = min(x,r)
    elif a == 3:
        d = max(y,d)
    else:
        u = min(y,u)
print(max((r-l),0)*max((u-d),0)

Submission status: Runtime Error

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

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

# raw White & Black
AllArea = []
for numline in range(H):
    rawWhite = []
    rawBlack = []
    for numraw in range(W):
        rawWhite.append("W")
        rawBlack.append("B")
    AllArea.append(rawWhite)

# coloring from white to Black
for n in range(N):
    if CoordinateList[n][2] == 1:
        if CoordinateList[n][0] == 0:
            pass
        else:
            for i in range(H):
                del AllArea[i][:(CoordinateList[n][0])]
                for numX in range(CoordinateList[n][0]):
                    AllArea[i].insert(0,"B")

    elif CoordinateList[n][2] == 2:
        if CoordinateList[n][0] == 0:
            print(0)
            exit()
        else:
            for i in range(H):
                del AllArea[i][(CoordinateList[n][0]):]
                for numX in range(CoordinateList[n][0]):
                    AllArea[i].append("B")

    elif CoordinateList[n][2] == 3:
        changeY = H - int(CoordinateList[n][1])
        if changeY == 0:
            print(0)
            exit()
        else:
            del AllArea[changeY:]
            for changeRaw in range(changeY):
                AllArea.append(rawBlack)

    elif CoordinateList[n][2] == 4:
        changeY = H - int(CoordinateList[n][1]) 
        if changeY == 0:
            pass
        else:
            del AllArea[:changeY]
            for changeRaw in range(changeY):
                AllArea.insert(0,rawBlack)
            
            
# counting 
AreaWhite = 0
for i in range(H):
    AreaWhite += AllArea[i].count("W")

print(AreaWhite)

Submission status: Runtime Error

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

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

# raw White & Black
AllArea = []
for numline in range(H):
    rawWhite = []
    rawBlack = []
    for numraw in range(W):
        rawWhite.append("W")
        rawBlack.append("B")
    AllArea.append(rawWhite)

# coloring from white to Black
for n in range(N):
    if CoordinateList[n][2] == 1:
        if CoordinateList[n][0] == 0:
             pass
        else:
            for i in range(H):
                del AllArea[i][:(CoordinateList[n][0])]
                for numX in range(CoordinateList[n][0]):
                    AllArea[i].insert(0,"B")

    elif CoordinateList[n][2] == 2:
        if CoordinateList[n][0] == 0:
            print(0)
            exit()
        else:
            for i in range(H):
                del AllArea[i][(CoordinateList[n][0]):]
                for numX in range(CoordinateList[n][0]):
                    AllArea[i].append("B")

    elif CoordinateList[n][2] == 3:
        changeY = H - int(CoordinateList[n][1])
        if changeY == 0:
            print(0)
            exit()
        else:
            del AllArea[changeY:]
            for changeRaw in range(changeY):
                AllArea.append(rawBlack)
         

    elif CoordinateList[n][2] == 4:
        changeY = H - int(CoordinateList[n][1]) 
        if changeY == 0:
            pass
        else:
            del AllArea[:changeY]
            for changeRaw in range(changeY):
                AllArea.insert(0,rawBlack)
            
            
# counting 
AreaWhite = 0
for i in range(H):
    AreaWhite += AllArea[i].count("W")

print(AreaWhite)

Submission status: Runtime Error

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

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

# raw White & Black
AllArea = []
for numline in range(H):
    rawWhite = []
    rawBlack = []
    for numraw in range(W):
        rawWhite.append("W")
        rawBlack.append("B")
    AllArea.append(rawWhite)

# coloring from white to Black
for n in range(N):
    if CoordinateList[n][2] == 1:
        for i in range(H):
            del AllArea[i][:(CoordinateList[n][0])]
            for numX in range(CoordinateList[n][0]):
                AllArea[i].insert(0,"B")

    elif CoordinateList[n][2] == 2:
        for i in range(H):
            del AllArea[i][(CoordinateList[n][0]):]
            for numX in range(CoordinateList[n][0]):
                AllArea[i].append("B")

    elif CoordinateList[n][2] == 3:
        changeY = H - int(CoordinateList[n][1])
        if changeY == 0:
            print(0)
            exit()
        else:
            del AllArea[changeY:]
            for changeRaw in range(changeY):
                AllArea.append(rawBlack)
         

    elif CoordinateList[n][2] == 4:
        changeY = H - int(CoordinateList[n][1]) 
        if changeY == 0:
            pass
        else:
            del AllArea[:changeY]

            for changeRaw in range(changeY):
                AllArea.insert(0,rawBlack)
            
            
# counting 
AreaWhite = 0
for i in range(H):
    AreaWhite += AllArea[i].count("W")

print(AreaWhite)

Submission status: Runtime Error

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

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

# raw White & Black
AllArea = []
for numline in range(H):
    rawWhite = []
    rawBlack = []
    for numraw in range(W):
        rawWhite.append("W")
        rawBlack.append("B")
    AllArea.append(rawWhite)

# coloring from white to Black
for n in range(N):
    if CoordinateList[n][2] == 1:
        for i in range(H):
            del AllArea[i][:(CoordinateList[n][0])]
            for numX in range(CoordinateList[n][0]):
                AllArea[i].insert(0,"B")

    elif CoordinateList[n][2] == 2:
        for i in range(H):
            del AllArea[i][(CoordinateList[n][0]):]
            for numX in range(CoordinateList[n][0]):
                AllArea[i].append("B")

    elif CoordinateList[n][2] == 3:
        changeY = H - int(CoordinateList[n][1])
        if changeY == 0:
            print(0)
            exit()
        else:
            del AllArea[changeY:]
            for changeRaw in range(changeY):
                AllArea.append(rawBlack)
         

    elif CoordinateList[n][2] == 4:
        changeY = H - int(CoordinateList[n][1]) 
        if changeY == 0:
            pass
        else:
            del AllArea[:changeY]
            print(range(changeY))
            for changeRaw in range(changeY):
                AllArea.insert(0,rawBlack)
            
            
# counting 
AreaWhite = 0
for i in range(H):
    AreaWhite += AllArea[i].count("W")

print(AreaWhite)

Submission status: Runtime Error

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

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

# raw White & Black
AllArea = []
for numline in range(H):
    rawWhite = []
    rawBlack = []
    for numraw in range(W):
        rawWhite.append("W")
        rawBlack.append("B")
    AllArea.append(rawWhite)

# coloring from white to Black
for n in range(N):
    if CoordinateList[n][2] == 1:
        for i in range(H):
            del AllArea[i][:(CoordinateList[n][0])]
            for numX in range(CoordinateList[n][0]):
                AllArea[i].insert(0,"B")
        #print(AllArea)
    elif CoordinateList[n][2] == 2:
        for i in range(H):
            del AllArea[i][(CoordinateList[n][0]):]
            for numX in range(CoordinateList[n][0]):
                AllArea[i].append("B")

        #print(AllArea)

    elif CoordinateList[n][2] == 3:
        changeY = H - int(CoordinateList[n][1])
        del AllArea[changeY:]
        for changeRaw in range(changeY):
            AllArea.append(rawBlack)
        #print(AllArea)

    elif CoordinateList[n][2] == 4:
        changeY = H - int(CoordinateList[n][1]) 
        del AllArea[:changeY]
        for changeRaw in range(changeY):
                AllArea.insert(0,rawBlack)
        #print(AllArea)

# counting 
AreaWhite = 0
for i in range(H):
    AreaWhite += AllArea[i].count("W")

#print(AllArea)
print(AreaWhite)

Submission status: Runtime Error

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

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

# raw White & Black
AllArea = []
for numline in range(H):
    rawWhite = []
    rawBlack = []
    for numraw in range(W):
        rawWhite.append("White")
        rawBlack.append("Black")
    AllArea.append(rawWhite)

# coloring from white to Black
for n in range(N):
    if CoordinateList[n][2] == 1:
        for i in range(H):
            del AllArea[i][:(CoordinateList[n][0])]
            for numX in range(CoordinateList[n][0]):
                AllArea[i].insert(0,"Black")
        #print(AllArea)
    elif CoordinateList[n][2] == 2:
        for i in range(H):
            del AllArea[i][(CoordinateList[n][0]):]
            for numX in range(CoordinateList[n][0]):
                AllArea[i].append("Black")

        #print(AllArea)

    elif CoordinateList[n][2] == 3:
        changeY = H - int(CoordinateList[n][1])
        del AllArea[changeY:]
        for changeRaw in range(changeY):
            AllArea.append(rawBlack)
        #print(AllArea)

    elif CoordinateList[n][2] == 4:
        changeY = H - int(CoordinateList[n][1]) 
        del AllArea[:changeY]
        for changeRaw in range(changeY):
                AllArea.insert(0,rawBlack)
        #print(AllArea)

# counting 
AreaWhite = 0
for i in range(H):
    AreaWhite += AllArea[i].count("White")

#print(AllArea)
print(AreaWhite)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    w, h, n = map(int, input().split())
    px = py = 0
    points = [[px, py], [w, h]]
    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            points[0][0] = max(px, x)
        elif a == 2:
            points[1][0] = min(w, x)
        elif a == 3:
            points[0][1] = max(py, y)
        elif a == 4:
            points[1][1] = min(h, y)

    print(max(0, points[1][0]-points[0][0])) * max(0, points[1][1]-points[0][1])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
[w,h,n]=list(map(int,input().split()))
risuto=[]
xmin=0
xmax=w
ymin=0
ymax=h
for i in range n:
	risuto.append(list(map(int,input().split())))
for i in range n:
	if risuto[i][2]==1 and risuto[i][0]>xmin:
		xmin=risuto[i][0]
	elif risuto[i][2]==2 and risuto[i][0]<xmax:
		xmax=risuto[i][0]
	elif risuto[i][2]==3 and risuto[i][1]>ymin:
		ymin=risuto[i][1]
	elif risuto[i][2]==4 and risuto[i][1]<ymax:
		ymax=risuto[i][1]
menseki=int((xmax-xmin)*(ymax-ymin))
print(menseki)

Submission status: Runtime Error

Solution code:
W,H,N=map(int,input().split())
X=[w for w in range(W+1)]
Y=[h for h in range(H+1)]
#print(X,Y)
for n in range(N):
    w,h,a=map(int,input().split())
    if a==1:
        X=[x for x in X if x>=w]
    elif a==2:
        X=[x for x in X if x<=w]
    elif a==3:
        Y=[y for y in Y if y>=h]
    else:
        Y=[y for y in Y if y<=h]
    #print(X,Y)
#print(max(0,(len(X)-1)*(len(Y)-1)))
print(max(0,(X[-1]-X[0])*(Y[-1]-Y[0])))

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
x = [x_i for x_i in range(w + 1)]
y = [y_i for y_i in range(h + 1)]
for l_e in l:
    if l_e[2] == 1:
        x = x[l_e[0]:]
    elif l_e[2] == 2:
        x = x[:l_e[0]]
    elif l_e[2] == 3:
        y = y[l_e[1]:]
    else:
        y = y[:l_e[1]]
print((x[-1] - x[0]) * (x[-1] - x[0]))

Submission status: Runtime Error

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

X = [0, W]
Y = [0, H]

for l in lst:
    if l[2] == 1 and X[0] < l[0]:
        X[0] = l[0]
    elif l[2] == 2 and l[0] < X[1]:
        X[1] = l[0]
    elif l[2] == 3 and Y[0] < l[1]:
        Y[0] = l[1]
    elif lst[2] == 4 and l[1] < Y[1]:
        Y[1] = l[1]

width = X[1] - X[0] if X[1] - X[0] > 0 else 0
height = Y[1] - Y[0] if Y[1] - Y[0] > 0 else 0

print(width * height)

Submission status: Runtime Error

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

X = [0, W]
Y = [0, H]

for l in lst:
    if l[2] == 1 and X[0] < l[0]:
        X[0] = l[0]
    elif l[2] == 2 and l[0] < X[1]:
        X[1] = l[0]
    elif l[2] == 3 and Y[0] < l[1]:
        Y[0] = l[1]
    elif lst[2] == 4 and l[1] < Y[1]:
        Y[1] = l[1]

width = X[1] - X[0]
height = Y[1] - Y[0]

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

Submission status: Runtime Error

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

X = [0, W]
Y = [0, H]

for l in lst:
    if l[2] == 1 and X[0] < l[0]:
        X[0] = l[0]
    elif l[2] == 2 and l[0] < X[1]:
        X[1] = l[0]
    elif l[2] == 3 and Y[0] < l[1]:
        Y[0] = l[1]
    elif lst[2] == 4 and l[1] < Y[1]:
        Y[1] = l[1]

width = X[1] - X[0]
height = Y[1] - Y[0]

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

x_s,y_s,a_s = [],[],[]
for i in range(N):
	x,y,a = map(int, input().split())
    x_s.append(x)
    y_s.append(y)
    a_s.append(a)
    
x_s = np.array(x_s)
y_s = np.array(y_s)
a_s = np.array(a_s)

if (a_s==1).sum()>=1:
  x_min = x_s[a_s==1].max()
else:
  x_min = 0
  
if (a_s==2).sum()>=1:
  x_max = x_s[a_s==2].min()
else:
  x_max = W
  
if (a_s==3).sum()>=1:
  y_min = y_s[a_s==3].max()
else:
  y_min = 0
  
if (a_s==4).sum()>=1:
  y_max = y_s[a_s==4].min()
else:
  y_max = H
  
if (x_min>=x_max)|(y_min>=y_max):
  ans = 0
else:
  ans = (x_max-x_min)*(y_max-y_min)
  
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

x_s,y_s,a_s = [],[],[]
for i in range(N):
	x,y,a = map(int, input().split())
    x_s.append(x)
    y_s.append(y)
    a_s.append(a)
    
x_s = np.array(x_s)
y_s = np.array(y_s)
a_s = np.array(a_s)

x_min = x_s[a_s==1].max()
x_max = x_s[a_s==2].min()
y_min = y_s[a_s==3].max()
y_max = y_s[a_s==4].min()

if (x_min>=x_max)|(y_min>=y_max):
  ans = 0
else:
  ans = (x_max-x_min)*(y_max-y_min)
  
print(int(ans))

Submission status: Runtime Error

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

x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
      x1=max(x1,x)
  elif a==2:
      x2=min(x2,x)
  elif a==3:
      y1=max(y1,y)
  else:
      y2=min(y2,y)
        
s=(x2-x1)*(y4-y3)
if s<0:
  print(0)
else:
  print(s)

Submission status: Runtime Error

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

ans=[0,0,w,h]
for i in range(n):
    if xya[i][2] == 1:
        if xya[i][0] >= ans[0]:
            ans[0] = xya[i][0]
    elif xya[i][2] == 2:
        if xya[i][0] <= ans[2]:
            ans[2] = xya[i][0]
    elif xya[i][2] == 3:
        if xya[i][1] >= ans[1]:
            ans[1] = xya[i][1]
    elif xya[i][2] == 4:
        if xya[i][1] <= ans[3]:
            ans[3] = xya[i][1]

print(0 if ans[2]-ans[0] <= 0 || ans[3]-ans[1] <= 0 else (ans[2]-ans[0])*(ans[3]-ans[1]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    W,H,N = inputMap()
    x_hidari = 0
    x_migi = W
    y_shita = 0
    y_ue = H
    
    for i in range(N):
        x,y,a = inputMap()
        
        if a == 1:
            if x_hidari < x:
                x_hidari = x
        elif a == 2:
            if x_migi > x:
                x_migi = x
        elif a == 3:
            if y_shita < y:
                y_shita = y
        else:
            if y_ue > y:
                y_ue = y
                
    #print("{} {} {} {}".format(x_hidari,x_migi,y_ue,y_shita))
    xxx = x_migi-x_hidari
    yyy = y_ue-y_shita
    if xxx < 0 or yyy < 0:
        print(0)
        sts.exit()
    
    print(xxx * yyy)
    
    
if __name__ == "__main__":
	main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
P= list(map(int,input().split()))
W = P[0]
H = P[1]
N = P[2]
A = []
B = []
C = []
D = []
for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    A.append(x)
  elif a == 2:
    x = 10-x
    B.append(x)
  elif a == 3:
    C.append(y)
  else:
    y = 10-y
    D.append(y)
    
a = max(A)
b = min(B)
c = max(C)
d = min(D)
 
w = W - (a+b)
h = H - (c+d)
print(w*h)

Submission status: Runtime Error

Solution code:
P= list(map(int,input.split()))
W = P[0]
H = P[1]
N = P[2]
A = []
B = []
C = []
D = []
for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    A.append(x)
  elif a == 2:
    x = 10-x
    B.append(x)
  elif a == 3:
    C.append(y)
  else:
    y = 10-y
    D.append(y)
    
a = max(A)
b = min(B)
c = max(C)
d = min(D)
 
w = W - (a+b)
h = H - (c+d)
print(w*h)

Submission status: Runtime Error

Solution code:
W,H,N = map(int,input.split())
A = []
B = []
C = []
D = []
for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    A.append(x)
  elif a == 2:
    x = 10-x
    B.append(x)
  elif a == 3:
    C.append(y)
  else:
    y = 10-y
    D.append(y)
    
a = max(A)
b = min(B)
c = max(C)
d = min(D)

w = W - (a+b)
h = H - (c+d)
print(w*h)

Submission status: Runtime Error

Solution code:
W,H,N = map(int,input().split())
bo = [[0]*W]*H
li = [list(map(int,input().split())) for i in range(N)]
for i in range(N):
    if li[i][2] == 1:
        for j in range(li[i][0]):
            bo[i][j] = 1
    elif li[i][2] == 2:
        for j in range(li[i][0],W,1):
            bo[i][j] = 1
    elif li[i][2] == 3:
        for j in range(li[i][1]):
            bo[j] = [1]*W
    else:
        for j in range(H-1,li[i][1]-1,-1):
            bo[j] = [1]*W

sum = 0

for i in range(H):
    sum += bo[i][:].count(1)
print((W*H)-sum)

Submission status: Runtime Error

Solution code:
import sys
W, H, N = map(int, input().split())
area = W * H

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

for n in range(N):
    tmp_w, tmp_h, a = map(int, input().split())
    if left <= tmp_w <= right and bottom <= tmp_h <= top:
        if a == 1:
            tmp_area = (tmp_w - left) * (top - bottom)
            area -= tmp_area
            left = tmp_w
        if a == 2:
            tmp_area = (right - tmp_w) * (top - bottom)
            area -= tmp_area
            right = tmp_w
        if a == 3:
            tmp_area = (tmp_h - bottom) * (right - left)
            area -= tmp_area
            bottom = tmp_h
        if a == 4:
            tmp_area = (top - tmp_h) * (right - left)
            area -= tmp_area
            top = tmp_h
    else:
        if a == 1:
            if tmp_w >= right:
                tmp_area = tmp_w * H
            else:
                tmp_area = 0
        if a == 2:
            if tmp_w <= left:
                tmp_area = (W - tmp_w) * H
            else:
                tmp_area = 0
        if a == 3:
            if tmp_h >= top:
                tmp_area = tmp_h * W
            else:
                tmp_area = 0
        if a == 4:
            if tmp_h <= bottom:
                tmp_area = (H - tmp_h) * W
            esle:
                tmp_area = 0
        area -= tmp_area
        if area < 0:
            print(0)
            sys.exit()
print(area)

Submission status: Runtime Error

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

A1=[]
A2=[]
A3=[]
A4=[]

for n in range(N):
    i,j,k = map(int,input().split())
    x.append(i)
    y.append(j)
    a.append(k)
a1,a2,a3,a4 = 0,0,0,0

for n in range(N):
    if a[n] == 1:
        A1.append(x[n])
        a1 = a1 + 1
    elif a[n] == 2:
        A2.append(x[n])
        a2 = a2 + 1
    elif a[n] == 3:
        A3.append(y[n])
        a3 = a3 + 1
    else:
        A4.append(y[n])
        a4 = a4 + 1

if a1 == 0 and a2 == 0:
    width = W
elif a1 == 0:
    width = min(A2)
elif a2 == 0:
    width = W - max(A1)
else:
    width = min(A2) - max(A1)
    if width <0:
        width = 0

if a3 == 0 and a4 == 0:
    height == H
elif a3 == 0:
    height =min(A4)
elif a4 ==0:
    height = H-max(A3)
else:
    height =min(A4) - max(A3)
    if width <0:
        width = 0

print(height*width)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if a == b + c:
        print("Yes")
    elif b == a + c:
        print("Yes")
    elif c == a + b:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    W, H, n = LI()
    wh = [[0, W], [0, H]]
    for _ in range(n):
        x, y, a = LI()
        wha = wh[a > 2]
        x = y if a > 2 else x
        wha[0] = max(x, wha[0]) * (a % 2) or wha[0]
        wha[1] = wha[1] * (a % 2) or min(x, wha[1])
        if wha[0] = wha[1]:
            print(0)
            return
    print(max(0, (wh[0][1] - wh[0][0]) * (wh[1][1] - wh[1][0])))
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Runtime Error

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

x_list = [i for i in range(w + 1)]
y_list = [i for i in range(h + 1)]

for a in coord_list:
    if a[-1] == 1:
        x_list = [i for i in x_list if i >= a[0]]
    elif a[-1] == 2:
        x_list = [i for i in x_list if i <= a[0]]
    elif a[-1] == 3:
        y_list = [i for i in y_list if i >= a[1]]
    elif a[-1] == 4:
        y_list = [i for i in y_list if i <= a[1]]

print((max(x_list) - min(x_list)) * (max(y_list) - min(y_list)))

Submission status: Runtime Error

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

xmin,ymin=0
xmax=w
ymax=h

for i in range(n):
    if a[i][2]==1:
        xmin=max([xmin,a[i][0]])
    elif a[i][2]==2:
        xmax=min([xmax,a[i][0]])
    elif a[i][2]==3:
        ymin=max([ymin,a[i][1]])
    else:
        ymax=min([ymax,a[i][1]])
ptint((xmax-xmin)*(ymax-ymin))

Submission status: Runtime Error

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

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

for x, y, a in 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)

print(max(0, right-left) * max(0, top-bottom))

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
o=[0,0]
c=[w,h]
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    o[0]=x if o[0]<x
  elif a==2:
    c[0]=x if c[0]>x
  elif a==3:
    o[1]=y if o[1]<y
  else:
    c[1]=y if c[1]>y
if o[0]<c[0] and o[1]<c[1]:
  print((c[0]-o[0])*(c[1]-o[1]))
else:
  print(0)