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: Wrong Answer

Solution code:
# Problem: https://atcoder.jp/contests/abc047/tasks/abc047_b
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(Width, Height, op_count, x_list, y_list, op_list):
    result = 0
    x_label_max = Width
    x_label_min = 0
    y_label_max = Height
    y_label_min = 0
    for j in range(0, op_count):
        real_ope = op_list[j]
        if real_ope == 1:
            x_label_min = x_list[j]
        if real_ope == 2:
            x_label_max = x_list[j]
        if real_ope == 3:
            y_label_min = y_list[j]
        if real_ope == 4:
            y_label_max = y_list[j]
    resultWidth = x_label_max - x_label_min
    resultHeight = y_label_max - y_label_min
    if resultWidth < 0:
        resultWidth = 0
    if resultHeight < 0:
        resultHeight = 0
    result = resultWidth * resultHeight
    return result


if __name__ == "__main__":
    W, H, N = MI()
    x_list = list()
    y_list = list()
    op_list = list()
    for _ in range(0, N, +1):
        tmp_x, tmp_y, tmp_op = MI()
        x_list.append(tmp_x)
        y_list.append(tmp_y)
        op_list.append(tmp_op)
    print("{}".format(solver(W, H, N, x_list, y_list, op_list)))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(n)]
plx = 0
ply = 0
prx = w
pry = h
for x,y,a in lists:
    if a == 1:
        if plx < x:
            plx = x
    elif a == 2:
        if prx > x:
            prx = x
    elif a == 3:
        if ply < y:
            ply = y
    elif a == 4:
        if pry > y:
            pry = y
px = (prx - plx)
py = (pry - ply)
ans = px * py
if ans < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(n)]
plx = 0
ply = 0
prx = w
pry = h
for x,y,a in lists:
    if a == 1:
        if plx <= x:
            plx = x
    elif a == 2:
        if prx >= x:
            prx = x
    elif a == 3:
        if ply <= y:
            ply = y
    elif a == 4:
        if pry >= y:
            pry = y
px = (prx - plx)
py = (pry - ply)
ans = px * py
if ans <= 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(n)]
plx = 0
ply = 0
prx = w
pry = h
for x,y,a in lists:
    if a == 1:
        if plx < x:
            plx = x
    elif a == 2:
        if prx > x:
            prx = x
    elif a == 3:
        if ply < y:
            ply = y
    elif a == 4:
        if pry > y:
            pry = y
px = (prx - plx)
py = (pry - ply)
ans = px * py
if ans <= 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(n)]
plx = 0
ply = 0
prx = w
pry = h
for x,y,a in lists:
    if a == 1:
        plx = x
    elif a == 2:
        prx = x
    elif a == 3:
        ply = y
    elif a == 4:
        pry = y
px = (prx - plx)
py = (pry - ply)
ans = px * py
if ans <= 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
W,H,N = map(int,input().split())
L,R,D,U = 0,W,0,H

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

print(max(0,(R-L)*(U-D)))

Submission status: Wrong Answer

Solution code:
X,Y,N=map(int,input().split())
max_X=X
max_Y=Y
current_min_x=0
current_min_y=0
current_max_x=X
current_max_y=Y
xy=[list(map(int,input().split())) for _ in range(N)]
for x,y,a in xy:
  n=0
  if a==1:
    current_min_x=max(current_min_x, x)
  elif a==2:
    current_max_x=min(current_max_x, x)
  elif a==3:
    current_min_y=max(current_min_y, y)
  elif a==4:
    current_max_y=min(current_max_y, y)
result=(current_max_x-current_min_x)*(current_max_y-current_min_y)
print(result if result >= 0 else 0)

Submission status: Wrong Answer

Solution code:
X,Y,N=map(int,input().split())
max_X=X
max_Y=Y
current_min_x=0
current_min_y=0
current_max_x=X
current_max_y=Y
xy=[list(map(int,input().split())) for _ in range(N)]
for x,y,a in xy:
  n=0
  if a==1:
    current_min_x=max(current_min_x, x)
  elif a==2:
    current_max_x=min(current_max_x, x)
  elif a==3:
    current_min_y=max(current_min_y, y)
  elif a==4:
    current_max_y=min(current_max_y, y)
result=(current_max_x-current_min_x)*(current_max_y-current_min_y)
print(result if result > 0 else 0)

Submission status: Wrong Answer

Solution code:
X,Y,N=map(int,input().split())
max_X=X
max_Y=Y
current_min_x=0
current_min_y=0
current_max_x=X
current_max_y=Y
xy=[list(map(int,input().split())) for _ in range(N)]
for x,y,a in xy:
  n=0
  if a==1:
    current_min_x=max(0, x)
  elif a==2:
    current_max_x=min(x, max_X)
  elif a==3:
    current_min_y=max(0, y)
  elif a==4:
    current_max_y=min(y, max_Y)
result=(current_max_x-current_min_x)*(current_max_y-current_min_y)
print(result if result > 0 else 0)

Submission status: Wrong Answer

Solution code:
import numpy as np
W,H,N=map(int,input().split())
A=np.zeros((W,H))
B=[list(map(int,input().split())) for _ in range(N)]
print(B)
for b in B:
    if b[2]==1:
        A[:b[0],:]=1
    elif b[2]==2:
        A[b[0]:,:]=1
    elif b[2]==3:
        A[:,:b[1]]=1
    elif b[2]==4:
        A[:,b[1]:]=1
print(np.count_nonzero(A==0))

Submission status: Wrong Answer

Solution code:
import numpy as np
W,H,N=map(int,input().split())
A=np.zeros((W,H))
B=[list(map(int,input().split())) for _ in range(N)]
print(B)
for b in B:
    if b[2]==1:
        A[:b[0],:]=1
    elif b[2]==2:
        A[b[0]:,:]=1
    elif b[2]==3:
        A[:,:b[1]]=1
    elif b[2]==4:
        A[:,b[1]:]=1
    print(A)
print(np.count_nonzero(A==0))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	w, h, n = LI()
	left_x, right_x, lower_y, upper_y = 0, w, 0, h
	for _ in range(n):
		x, y, a = LI()
		if a == 1:
			left_x = x
		elif a == 2:
			right_x = x
		elif a == 3:
			lower_y = y
		elif a == 4:
			upper_y = y
	if right_x > left_x and upper_y > lower_y:
		print((right_x-left_x)*(upper_y-lower_y))
	else:
		print(0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

#とりうるx,yの範囲
y_min = 0
y_max = h

x_min = 0
x_max = w

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)

white = (y_max - y_min) * (x_max - x_min)
if white>=0:
  print(max(white, 0))
else:
  print(0)

Submission status: Wrong Answer

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

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


x_left,x_right = 0, W
y_under, y_up = 0,H

for i in range(N):
    x,y = lst[i][0], lst[i][1]
    if lst[i][2] == 1:
        if x_left < x:
            x_left = x
    elif lst[i][2] == 2:
        if x_right > x:
            x_right = x
    elif lst[i][2] == 3:
        if y_under < y:
            y_under = y
    elif lst[i][2] == 4:
        if y_up > y:
            y_up = y

yoko = x_right - x_left
tate = y_up - y_under
if tate * yoko <= 0:
    print(0)
else:
    print(tate * yoko)

Submission status: Wrong Answer

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

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


x_left,x_right = 0, W
y_under, y_up = 0,H

for i in range(N):
    x,y = lst[i][0], lst[i][1]
    if lst[i][2] == 1:
        x_left = x
    elif lst[i][2] == 2:
        x_right = x
    elif lst[i][2] == 3:
        y_under = y
    elif lst[i][2] == 4:
        y_up = y

yoko = x_right - x_left
tate = y_up - y_under
if tate * yoko <= 0:
    print(0)
else:
    print(tate * yoko)

Submission status: Wrong Answer

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

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

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)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

X = 0 #左から引く領域
Y = 0 #下から引く領域

for j in range(N):
    if a[j][2] == 1: #xより小さい領域を塗りつぶす
        if a[j][2] > X:
            X = a[j][0]
        else:
            pass
    elif a[j][2] == 2: #xより大きい領域を塗りつぶす
        if a[j][0] < W:
            W = a[j][0]
        else:
            pass
    elif a[j][2] == 3: #yより小さい領域を塗りつぶす
        if a[j][1] > Y:
            Y = a[j][1]
        else:
            pass
    elif a[j][2] == 4: #yより大きい領域を塗りつぶす
        if a[j][1] < H:
            H = a[j][1]
        else:
            pass
    else:
        print('Error')

W = W - X
H = H - Y

if W <= 0:
    W = 0
else:
    pass

if H <= 0:
    H = 0
else:
    pass

ans = W * H
if ans <= 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

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

X = 0 #左から引く領域
Y = 0 #下から引く領域

for j in range(N):
    if a[j][2] == 1: #xより小さい領域を塗りつぶす
        if a[j][2] > X:
            X = a[j][0]
        else:
            pass
    elif a[j][2] == 2: #xより大きい領域を塗りつぶす
        if a[j][0] < W:
            W = a[j][0]
        else:
            pass
    elif a[j][2] == 3: #yより小さい領域を塗りつぶす
        if a[j][1] > Y:
            Y = a[j][1]
        else:
            pass
    elif a[j][2] == 4: #yより大きい領域を塗りつぶす
        if a[j][1] < H:
            H = a[j][1]
        else:
            pass
    else:
        print('Error')

W = W - X
H = H - Y

ans = W * H
if ans <= 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x_reg < x:
        x_reg = x
    if a == 2 and w > x:
        w = x
    if a == 3 and y_reg < y:
        y_reg = y
    if a == 4 and h > y:
        h = y

print(max(0, (w-x_reg)*(h-y_reg)))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
w = [0, W]
h = [0, H]
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    w[0] = x
  elif a == 2:
    w[1] = x
  elif a == 3:
    h[0] = y
  else:
    h[1] = y
wa = w[1] - w[0]
if wa < 0:
  wa = 0
ha = h[1] -h[0]
if ha < 0:
  ha = 0
ans = wa * ha
print(ans)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
W0=0
H0=0
for i in range(N):
    x1,y1,a1=map(int,input().split())
    if a1 ==1:
        W0=x1
    elif a1==2:
        W=x1
    elif a1==3:
        H0=y1
    elif a1==4:
        H=y1

if W-W0>0 and H-H0>0:
    print((W-W0)*(H-H0))
else:
    print(0)

Submission status: Wrong Answer

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

E = [0,W,0,H]

for x,y,a in XYA:
  a -= 1
  XY = [x,y]
  if a % 2 == 1:
    E[a] = max(E[a],XY[a//2])
  else:
    E[a] = min(E[a],XY[a//2 - 1])
  
ans = 0
if E[0] < E[2] and E[1] < E[3]:
  ans = (E[2] - E[0]) * (E[3] - E[1])
  
print(ans)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
X1 = 0
X2 = W
Y1 = 0
Y2 = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if X1 <= x and x <= X2:
            X1 = x
        else:
            pass
    elif a == 2:
        if X1 <= x and x <= X2:
            X2 = x
        else:
            pass
    if a == 3:
        if Y1 <= y and y <= Y2:
            Y1 = y
        else:
            pass
    if a == 4:
        if Y1 <= y and y <= Y2:
            Y2 = y
        else:
            pass
if X1 >= X2 or Y1 >= Y2:
    print(0)
else:
    print((X2 - X1) * (Y2 - Y1))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
X1 = 0
X2 = W
Y1 = 0
Y2 = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if X1 <= a and a <= X2:
            X1 = x
        else:
            pass
    elif a == 2:
        if X1 <= a and a <= X2:
            X2 = x
        else:
            pass
    if a == 3:
        if Y1 <= a and a <= Y2:
            Y1 = y
        else:
            pass
    if a == 4:
        if Y1 <= a and a <= Y2:
            Y2 = y
        else:
            pass
if X1 >= X2 or Y1 >= Y2:
    print(0)
else:
    print((X2 - X1) * (Y2 - Y1))

Submission status: Wrong Answer

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

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))

# print("test")
# print(W,H,N)

#solve
xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        # Xiより小さいを黒
        xb = X[_]
    elif A[_] == 2:
        # Xiより大きいを黒
        xe = X[_]
    elif A[_] == 3:
        # Yiより小さいを黒
        yb = Y[_]
    else:
        # Yiより大きいを黒
        ye = Y[_]
    
    # check
    if (xe - xb) <= 0 or (ye - yb) <= 0:
        print(0)
        import sys
        sys.exit()

ans = (xe - xb) * (ye - yb)
print(ans)

Submission status: Wrong Answer

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

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))

# print("test")
# print(W,H,N)

#solve
xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        # Xiより小さいを黒
        xb = X[_]
    elif A[_] == 2:
        # Xiより大きいを黒
        xe = X[_]
    elif A[_] == 3:
        # Yiより小さいを黒
        yb = Y[_]
    else:
        # Yiより大きいを黒
        ye = Y[_]
    
    # check
    if xe - xb < 0 or ye - yb < 0:
        print(0)
        import sys
        sys.exit()

ans = (xe - xb) * (ye - yb)
print(ans)

Submission status: Wrong Answer

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

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))

# print("test")
# print(W,H,N)

#solve
xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        xb = X[_]
    elif A[_] == 2:
        xe = X[_]
    elif A[_] == 3:
        yb = Y[_]
    else:
        ye = Y[_]
    
    # check
    if xe - xb < 0 or ye - yb < 0:
        print(0)
        import sys
        sys.exit()

ans = (xe - xb) * (ye - yb)
print(ans)

Submission status: Wrong Answer

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

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))

#solve
xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        xb = X[_]
    elif A[_] == 2:
        xe = X[_]
    elif A[_] == 3:
        yb = Y[_]
    else:
        ye = Y[_]

ans = (xe - xb) * (ye - yb)
print(ans if ans >= 0 else 0)

Submission status: Wrong Answer

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

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

for i in range(n):
    if square_info[i][2] == 1:
        min_x = square_info[i][0]
    elif square_info[i][2] == 2:
        max_x = square_info[i][0]
    elif square_info[i][2] == 3:
        min_y = square_info[i][1]
    elif square_info[i][2] == 4:
        max_y = square_info[i][1]
        
if max_x <= min_x or max_y <= min_y:
    print(0)
else:
    print((max_x - min_x)*(max_y - min_y))

Submission status: Wrong Answer

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

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

for i in range(n):
    if square_info[i][2] == 1:
        min_x = square_info[i][0]
    elif square_info[i][2] == 2:
        max_x = square_info[i][0]
    elif square_info[i][2] == 3:
        min_y = square_info[i][1]
    elif square_info[i][2] == 4:
        max_y = square_info[i][1]

print(max((max_x - min_x)*(max_y - min_y), 0))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
xl = 0
xr = w
yh = h
yr = 0
for i in range(n):
    if a[i][2] == 1:
        xl = max(xl,a[i][0])
    elif a[i][2] == 2:
        xr = min(xr,a[i][0])
    elif a[i][2] == 3:
        yr = max(yr,a[i][1])
    else:
        yh = min(yh,a[i][1])

x = xr - xl
y = yh - yr

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x1=0
x2=w
y1=0
y2=h

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if x1<x:
            x1=x
    elif a==2:
        if x<x2:
            x2=x
    elif a==3:
        if y1<y:
            y1=y
    else:
        if y<y2:
            y2=y

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x1=0
x2=w
y1=0
y2=h

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if x1<x:
            x1=x
    elif a==2:
        if x<x2:
            x2=x
    elif a==3:
        if y1<y:
            y1=y
    else:
        if y<y2:
            y2=y

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x1=0
x2=w
y1=0
y2=h

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if x1<x:
            x1=x
    elif a==2:
        if x<x2:
            x2=x
    elif a==3:
        if y1<y:
            y1=y
    else:
        if y<y2:
            y2=y

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x1=0
x2=w
y1=0
y2=h

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        x1=x
    elif a==2:
        x2=x
    elif a==3:
        y1=y
    else:
        y2=y

if (x2-x1)*(y2-y1)<0:
    print(0)
else:
    print(int((x2-x1)*(y2-y1)))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x1=0
x2=w
y1=0
y2=h

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        x1=x
    elif a==2:
        x2=x
    elif a==3:
        y1=y
    else:
        y2=y

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

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
ll_x, ll_y, tr_x, tr_y = 0, 0, w, h
for q in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        ll_x = max(ll_x, x)
    elif a == 2:
        tr_x = min(tr_x, x)
    elif a == 3:
        ll_y = max(ll_y, y)
    elif a == 4:
        tr_y = min(tr_y, y)
ans = (tr_x - ll_x) * (tr_y - ll_y)
print(ans if ans > 0 else 0)

Submission status: Wrong Answer

Solution code:
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)
xmin = 0
xmax = w
ymin = 0
ymax = h
for i in range(n):
  if a[i] == 1:
    xmin = x[i]
  elif a[i] == 2:
    xmax = x[i]
  elif a[i] == 3:
    ymin = y[i]
  else:
    ymax = y[i]
print(max(0, xmax - xmin) * max(0, ymax - ymin))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
ld = [0, 0]
ru = [w, h]
xya = []
for i in range(n):
  l = list(map(int, input().split()))
  xya.append(l)  

ans = 0
f = 0
for e in xya:
  x = e[0]
  y = e[1]
  a = e[2]
  if a == 1:
    ld[0] = x
  elif a == 2:
    ru[0] = x
  elif a == 3:
    ld[1] = y
  elif a == 4:
    ru[1] = y

  if ld[0] < ru[0] and ld[1] < ru[1]:
    next
  else:
    f = 1
    break

if f == 1:
  ans = 0
else:
  ans = abs(ru[0] - ld[0]) * abs(ru[1] - ld[1])
print(ans)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
ld = [0, 0]
ru = [w, h]
xya = []
for i in range(n):
  l = list(map(int, input().split()))
  xya.append(l)  

ans = 0
f = 0
for e in xya:
  x = e[0]
  y = e[1]
  a = e[2]
  if a == 1:
    ld[0] = x
  elif a == 2:
    ru[0] = x
  elif a == 3:
    ld[1] = y
  elif a == 4:
    ru[1] = y

  if ld[0] < ru[0] and ld[1] < ru[1]:
    next
  else:
    f = 1
    break

if f == 1:
  ans = 0
else:
  ans = (ru[0] - ld[0]) * (ru[1] - ld[1])
print(ans)

Submission status: Wrong Answer

Solution code:
W, H, count = map(int, input().split(" "))
W0 = 0
H0 = 0

li = [list(map(int, input().split(" "))) for s in range(count)]

for i in li:
  if i[2] == 1:
    if i[0] > W0:
      W0 = i[0]
  elif i[2] == 2:
    if i[0] < W:
      W = i[0]
  elif i[2] == 3:
    if i[1] > H0:
      H0 = i[1]
  elif i[2] == 4:
    if i[1] < H:
      H = i[1]

print((W - W0) * (H - H0))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
left_x = 0
right_x = w
up_y = h
down_y = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        left_x = max(left_x, x)
    elif a == 2:
        right_x = min(right_x, x)
    elif a == 3:
        down_y = max(down_y, y)
    else:
        up_y = min(up_y, y)

ans = (right_x - left_x) * (up_y - down_y)
if ans < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

x_lt = 0
x_rt = W

y_lt = 0
y_rt = H

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x_lt = x
    elif a == 2:
        x_rt = x
    elif a == 3:
        y_lt = y
    else:
        y_rt = y

res = max(x_rt - x_lt, 0) * max(y_rt - y_lt, 0)

print(res)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
D = [0, W, 0, H]
#D={0:max 1:min 2:max 3:min}

for _ in range(N):
    x, y, a = map(int, input().split())
    if a==1:
        if x > D[0]:
            D[0] = x
    if a==2:
        if x < D[1]:
            D[1] = x
    if a==3:
        if y > D[2]:
            D[2] = y
    if a==4:
        if y < D[3]:
            D[3] = y
ANS = (D[1] - D[0])*(D[3] - D[2])
if ANS < 0:
    ANS = 0
print(ANS)

Submission status: Wrong Answer

Solution code:
def square() : 
  
  W , H, N = tuple(map(int, input().split()))
  
  leftrange = 0
  lowrange = 0
  rightrange = W
  upperrange = H
  
  for i in range(N) : 
    x, y, a = tuple(map(int, input().split()))
    if a == 1 :
      if x > leftrange : 
        leftrange = x
    if a == 2 : 
      if x < rightrange : 
        rightrange = x
    if a == 3 :
      if y > lowrange : 
        lowrange = y
    if a == 4 : 
      if y < upperrange : 
        upperrange = y
        
  return leftrange, rightrange, lowrange, upperrange

def answer(x1, x2, y1, y2) : 
  return (x2 - x1) * (y2 - y1)

def main() : 
  leftrange, rightrange, lowrange, upperrange = square()
  print(answer(leftrange, rightrange, lowrange, upperrange))
  
  
main()

Submission status: Wrong Answer

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

rx, uy = W, H
lx, dy = 0, 0
for v in P:
    x, y, a = v
    if a == 1:
        lx = x
    elif a == 2:
        rx = x
    elif a == 3:
        dy = y
    elif a == 4:
        uy = y
print(max(rx - lx, 0) * max(uy - dy, 0))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding : utf-8 -*- 

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


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

Submission status: Wrong Answer

Solution code:
# -*- coding : utf-8 -*- 

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


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

Submission status: Wrong Answer

Solution code:
import numpy as np

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


BW = np.zeros([H,W])

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        BW[:, :x] = 1
    elif a == 2:
        BW[:, x+1:] = 1
    elif a == 3:
        BW[H-y+1:, :] = 1
    elif a == 4:
        BW[:H-y, :] = 1
print(np.count_nonzero(BW-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
sq=[0,-w,0,-h]		#左端，右端，下端，上端
print(sq)
for i in range(n):
  x,y,b=map(int,input().split())
  dumy = [x,-x,y,-y]
  a=b-1
  if sq[a]<dumy[a]:
    sq[a]=dumy[a]


if -sq[1]-sq[0]<0:
  s=0
elif -sq[3]-sq[2]<0:
  s=0
else:
  s=(-sq[1]-sq[0])*(-sq[3]-sq[2])

print(s)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
sq=[0,-w,0,-h]		#左端，右端，下端，上端
print(sq)
for i in range(n):
  x,y,b=map(int,input().split())
  dumy = [x,-x,y,-y]
  a=b-1
  if sq[a]<dumy[a]:
    sq[a]=dumy[a]


if -sq[1]-sq[0]<0:
  s=0
elif -sq[2]-sq[3]<0:
  s=0
else:
  s=(-sq[1]-sq[0])*(-sq[3]-sq[2])

print(s)