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:
W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

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

    if a == 1:
        min_W = x
    elif a == 2:
        max_W = x
    elif a == 3:
        min_H = y
    else:
        max_H = y

if min_W > max_W or min_H > max_H:
    print(0)
else:
    print((max_H - min_H) * (max_W - min_W))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

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

    if a == 1:
        min_W = x
    elif a == 2:
        max_W = x
    elif a == 3:
        min_H = y
    else:
        max_H = y

print(max(((max_H - min_H) * (max_W - min_W)), 0))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

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

    if a == 1:
        min_W = x
    elif a == 2:
        max_W = x
    elif a == 3:
        min_H = y
    else:
        max_H = y

print((max_H - min_H) * (max_W - min_W))

Submission status: Wrong Answer

Solution code:
#B - すぬけ君の塗り絵 2 イージー

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

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

up = H
down = 0
left = 0
right = W

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

Submission status: Wrong Answer

Solution code:
#B - すぬけ君の塗り絵 2 イージー

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

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

up = H
down = 0
left = 0
right = W

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

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
A=[]
right=W
left=0
top=H
under=0

for i in range(N):
  A.append(list(map(int,input().split())))
  if A[i][2]==1:
    if left<A[i][0]:
      left=A[i][0]
  if A[i][2]==2:
    if right>A[i][0]:
      right=A[i][0]
  if A[i][2]==3:
    if under<A[i][1]:
      under=A[i][1]
  if A[i][2]==4:
    if top>A[i][1]:
      top=A[i][1]
if (top-under)*(right-left)>0:
  print((top-under)*(right-left))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
b = [0, 0, W, 0, H]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        b[a] = max(b[a], x)
    elif a == 2:
        b[a] = min(b[a], x)
    elif a == 3:
        b[a] = max(b[a], y)
    else:
        b[a] = min(b[a], y)
# print('b', b)
_W = b[2] - b[1]
_H = b[4] - b[3]
# print('_W, _H', _W, _H)
ans = _W * _H
print(0 if ans < 0 else ans)

Submission status: Wrong Answer

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

border = [0,W,0,H]

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    border[a-1] = max(border[a-1], x)
  elif a == 2:
    border[a-1] = min(border[a-1], x)
  elif a == 3:
    border[a-1] = max(border[a-1], y)
  elif a== 4:
    border[a-1] = min(border[a-1], y)

print(max((border[1] - border[0]) * (border[3] - border[2]), 0))

Submission status: Wrong Answer

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

border = [0,W,0,H]

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    border[a-1] = max(border[a-1], x)
  elif a == 2:
    border[a-1] = min(border[a-1], x)
  elif a == 3:
    border[a-1] = max(border[a-1], y)
  elif a== 4:
    border[a-1] = min(border[a-1], y)
  else:
    print("error")

print(max((border[1] - border[0]) * (border[3] - border[2]), 0))

Submission status: Wrong Answer

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

border = [0,9999,0,9999]

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    border[a-1] = max(border[a-1], x)
  elif a == 2:
    border[a-1] = min(border[a-1], x)
  elif a == 3:
    border[a-1] = max(border[a-1], y)
  elif a== 4:
    border[a-1] = min(border[a-1], y)
  else:
    print("error")

if border[1] == 9999:
  border[1] = W
if border[3] == 9999:
  border[3] = H

print(max((border[1] - border[0]) * (border[3] - border[2]), 0))

Submission status: Wrong Answer

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


#----------
W,H,N = list(map(int, input().rstrip().split()))
x_y_a = [list(map(int, input().rstrip().split())) for _ in range(N)]
#----------
x_max,y_max = W,H
x_min,y_min = 0,0

for x,y,a in x_y_a:
    if a == 1 and x_min < x:
        x_min = x
    elif a == 2 and x_max > x:
        x_max = x
    elif a == 3 and y_min < y:
        y_min = y
    elif a == 4 and y_max > y:
        y_max = y
    
area = (x_max - x_min) * (y_max - y_min)
if area < 0:
    area = 0

print(area)

Submission status: Wrong Answer

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


#----------
W,H,N = list(map(int, input().rstrip().split()))
x_y_a = [list(map(int, input().rstrip().split())) for _ in range(N)]
#----------
x_max,y_max = W,H
x_min,y_min = 0,0

for x,y,a in x_y_a:
    if a == 1:
        x_min = x
    elif a == 2:
        x_max = x
    elif a == 3:
        y_min = y
    elif a == 4:
        y_max = y
    
area = (x_max - x_min) * (y_max - y_min)
if area < 0:
    area = 0

print(area)

Submission status: Wrong Answer

Solution code:
#ABC047

w,h,n = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]

x = [0,w,0,h]#[l,r,b,t]

for i in range(n):
    if l[i][2] == 1 or l[i][2] == 2:
        x[l[i][2]-1] = l[i][0]
    else:
        x[l[i][2]-1] = l[i][1]
    #print(x)
    if x[0] >= x[1] or x[2] >= x[3]:
        print(0)
        break
        
if x[0] < x[1] and x[2] < x[3]:
    print((x[1]-x[0])*(x[3]-x[2]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
input_li = [list(map(int, input().split())) for i in range(N)]
dic = {"1" : 0, "2": W, "3" : 0, "4" : H}
for l in input_li :
    if l[2] == 1 and dic[str(l[2])] < l[0] :
        dic[str(l[2])] = l[0]
    if l[2] == 2 and dic[str(l[2])] > l[0] :
        dic[str(l[2])] = l[0]
    if l[2] == 3 and dic[str(l[2])] < l[1] :
        dic[str(l[2])] = l[1]
    if l[2] == 4 and dic[str(l[2])] > l[1] :
        dic[str(l[2])] = l[1]
print(max(0, (dic["2"] - dic["1"]) * (dic["4"] - dic["3"])))

Submission status: Wrong Answer

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

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

for i in range(n):
    xi,yi,ai = map(int, input().split())
    if ai == 1:
        xmin = xi
    if ai == 2:
        xmax = xi
    if ai == 3:
        ymin = yi
    if ai == 4:
        ymax = yi

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

Submission status: Wrong Answer

Solution code:
[W, H, N] = list(map(int, input().split()))
[x, y, a] = [ [], [], [] ]
for _ in range(N):
  input_line = list(map(int, input().split()))
  x.append(input_line[0])
  y.append(input_line[1])
  a.append(input_line[2])
area = []
for i in range(W+1):
  area.append([])
  for j in range(H+1):
    area[i].append("")
    
for i in range(N):
  if a[i] == 1:
    for X in range(x[i]+1):
      for Y in range(H+1):
        area[X][Y] = "f"
  if a[i] == 2:
    for X in range(x[i], W+1):
      for Y in range(H+1):
        area[X][Y] = "f"
  if a[i] == 3:
    for X in range(W+1):
      for Y in range(y[i]+1):
        area[X][Y] = "f"
  if a[i] == 4:
    for X in range(W+1):
      for Y in range(y[i], H+1):
        area[X][Y] = "f"
        
count = 0
for i in range(W+1):
  for j in range(H+1):
    if area[i][j] == "":
      count += 1
      
print(count)

Submission status: Wrong Answer

Solution code:
[W, H, N] = list(map(int, input().split()))
[x, y, a] = [ [], [], [] ]
for _ in range(N):
  input_line = list(map(int, input().split()))
  x.append(input_line[0])
  y.append(input_line[1])
  a.append(input_line[2])
area = []
for i in range(W+1):
  area.append([])
  for j in range(H+1):
    area[i].append("")
    
for i in range(N):
  if a[i] == 1:
    for X in range(x[i]):
      for Y in range(H+1):
        area[X][Y] = "f"
  if a[i] == 2:
    for X in range(x[i], W+1):
      for Y in range(H+1):
        area[X][Y] = "f"
  if a[i] == 3:
    for X in range(W+1):
      for Y in range(y[i]):
        area[X][Y] = "f"
  if a[i] == 4:
    for X in range(W+1):
      for Y in range(y[i], H+1):
        area[X][Y] = "f"
        
count = 0
for i in range(W+1):
  for j in range(H+1):
    if area[i][j] == "":
      count += 1
      
print(count)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(N):
    A,b,c=map(int,input().split())
    x.append(A)
    y.append(b)
    a.append(c)
S=W*H
cx=[1]*(W+1)
cy=[1]*(H+1)
for i in range(N):
    if a[i]==1:
        for j in range(x[i]):
            cx[j]=0
    if a[i]==2:
        for j in range(x[i]+1,W+1):
            cx[j]=0
    if a[i]==3:
        for j in range(y[i]):
            cy[j]=0
    if a[i]==4:
        for j in range(y[i]+1,H+1):
            cy[j]=0

lx=0
ly=0
for i in range(len(cx)):
    if cx[i]==1:
        lx+=1
for i in range(len(cy)):
    if cy[i]==1:
        ly+=1
ans=(lx-1)*(ly-1)
if lx<0 and ly<0:
    ans=0
ans=max(0,ans)
print(ans)

Submission status: Wrong Answer

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

a1 = [0,0]
a2 = [W,0]
a3 = [0,0]
a4 = [0,H]

for i in range(0,N):
  lst = [int(i) for i in input().split(" ")]
  if lst[2] == 1:
    a1[0] = max(a1[0],lst[0])
  elif lst[2] == 2:
    a2[0] = max(a2[0],lst[0])
  elif lst[2] == 3:
    a3[1] = max(a3[1],lst[1])
  elif lst[2] == 4:
    a4[1] = max(a4[1],lst[1])

print(max(0,a2[0]-a1[0])*max(0,a4[1]-a3[1]))

Submission status: Wrong Answer

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

a1 = [0,0]
a2 = [W,0]
a3 = [0,0]
a4 = [0,H]

for i in range(0,N):
  lst = [int(i) for i in input().split(" ")]
  if lst[2] == 1 and lst[0] > a1[0]:
    a1[0] = lst[0]
  elif lst[2] == 2 and lst[0] < a2[0]:
    a2[0] = lst[0]
  elif lst[2] == 3 and lst[1] > a3[1]:
    a3[1] = lst[1]
  elif lst[2] == 4 and lst[1] < a4[1]:
    a4[1] = lst[1]
    
print((a2[0]-a1[0])*(a4[1]-a3[1]))

Submission status: Wrong Answer

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

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

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and left <= x:
        left = x
    elif a == 2 and right >= x:
        right = x
    elif a == 3 and bottom <= y:
        bottom = y
    elif a == 4 and top >= y:
        top = y

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

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
lst_xya = [''.join(input().split()) for _ in range(N)]
sorted(lst_xya, key = lambda x: x[2])

x_min, y_min = (0, 0)
x_max, y_max = (W, H)

for _ in range(N):
    if lst_xya[-1][2] == '4':
        if y_max > int(lst_xya[-1][1]):
            y_max = int(lst_xya[-1][1])
        lst_xya.pop()
    elif lst_xya[-1][2] == '3':
        if y_min < int(lst_xya[-1][1]):
            y_min = int(lst_xya[-1][1])
        lst_xya.pop()
    elif lst_xya[-1][2] == '2':
        if x_max > int(lst_xya[-1][0]):
            x_max = int(lst_xya[-1][0])
        lst_xya.pop()
    else:
        if x_min < int(lst_xya[-1][0]):
            x_min = int(lst_xya[-1][0])
        lst_xya.pop()

S = (x_max - x_min) * (y_max - y_min)
if x_max - x_min < 0 and y_max - y_min < 0:
    print(0)
else:
    print(S if S > 0 else 0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
lst_xya = [''.join(input().split()) for _ in range(N)]
sorted(lst_xya, key = lambda x: x[2])

x_min, y_min = (0, 0)
x_max, y_max = (W, H)

for _ in range(N):
    if lst_xya[-1][2] == '4':
        if y_max > int(lst_xya[-1][1]):
            y_max = int(lst_xya[-1][1])
        lst_xya.pop()
    elif lst_xya[-1][2] == '3':
        if y_min < int(lst_xya[-1][1]):
            y_min = int(lst_xya[-1][1])
        lst_xya.pop()
    elif lst_xya[-1][2] == '2':
        if x_max > int(lst_xya[-1][0]):
            x_max = int(lst_xya[-1][0])
        lst_xya.pop()
    else:
        if x_min < int(lst_xya[-1][0]):
            x_min = int(lst_xya[-1][0])
        lst_xya.pop()

S = (x_max - x_min) * (y_max - y_min)
print(S if S > 0 else 0)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x, y, a = map(int, input().split())
blackRec = [[0, w], [0, h]]
for i in range(n):
    if a == 1 and blackRec[0][0] < x:
        blackRec[0][0] = x
    elif a == 2 and blackRec[0][1] > x:
        blackRec[0][1] = x
    elif a == 3 and blackRec[1][0] < y:
        blackRec[1][0] = y
    elif a == 4 and blackRec[1][1] > y:
        blackRec[1][1] = y
width = blackRec[0][1] - blackRec[0][0]
height = blackRec[1][1] - blackRec[1][0]
ans = width * height
if width < 0 or height < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
s = w * h
l = [0,0]
r = [w,h]

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        if l[0] < x:
            l[0] = x
    elif a == 2:
        if r[0] > x:
            r[0] = x
    elif a == 3:
        if l[1] < y:
            l[1] = y
    else:
        if r[1] > y:
            r[1] = y

tate = r[1] - l[1]
yoko = r[0] - l[0]
print(max(tate*yoko,0))

Submission status: Wrong Answer

Solution code:
# 入力 : Nセットの3個の数字
W, H, N = map(int, input().split())
list = [0 for i in range(0,N)]
for i in range(0,N) :
    x, y, a = map(int, input().split())
    list[i] = (x,y,a)

x_low = 0
x_high = W
y_low = 0
y_high = H

for i in range(0,N) :
    if list[i][2] == 1 :
        x_low = max(x_low, list[i][0])
    elif list[i][2] == 2 :
        x_high = min(x_high, list[i][0])
    elif list[i][2] == 3 :
        y_low = max(y_low, list[i][1])
    else :
        y_high = min(y_high, list[i][0])

area = (x_high - x_low) * (y_high - y_low)

if x_high < x_low or y_high < y_low :
    print(0)
else :
    print(area)

Submission status: Wrong Answer

Solution code:
# 入力 : Nセットの3個の数字
W, H, N = map(int, input().split())
list = [0 for i in range(0,N)]
for i in range(0,N) :
    x, y, a = map(int, input().split())
    list[i] = (x,y,a)

x_low = 0
x_high = W
y_low = 0
y_high = H

for i in range(0,N) :
    if list[i][2] == 1 :
        x_low = max(x_low, list[i][0])
    elif list[i][2] == 2 :
        x_high = min(x_high, list[i][0])
    elif list[i][2] == 3 :
        y_low = max(y_low, list[i][1])
    else :
        y_high = min(y_high, list[i][0])

area = (x_high - x_low) * (y_high - y_low)
if area>0 :
    print(area)
else :
    print(0)

Submission status: Wrong Answer

Solution code:
x, y, n = map(int, input().split())
wlist = []
for i in range(n):
    wlist.append(list(map(int, input().split())))
dst = []
x = [0, x]
y = [0, y]
for i in wlist:
    if i[2] == 1:
        x[0] = i[0] if i[0] > x[0] else x[0]
    elif i[2] == 2:
        x[1] = i[0] if i[0] < x[1] else x[1]
    elif i[2] == 3:
        y[0] = i[1] if i[1] > y[0] else y[0]
    else:
        y[1] = i[1] if i[1] < y[1] else y[1]
dst = (x[1]-x[0])*(y[1]-y[0])
dst = dst if dst >= 0 else 0
print(dst)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
min_x = 0
min_y = 0
max_x = w
max_y = h
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    min_x = x
  elif a == 2:
    max_x = x
  elif a == 3:
    min_y = y
  elif a == 4:
    max_y = y
print(max(0, max_x - min_x) * max(0, max_y-min_y))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
p,q=[1,w],[1,h]
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p[0]=max(p[0],x)
  elif a==2:
    p[1]=min(p[1],x)
  elif a==3:
    q[0]=max(q[0],y)
  else:
    q[1]=min(q[1],y)
s=(p[1]-p[0])*(q[1]-q[0])
print(s if s>0 else 0)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
p,q=[0,w],[0,h]
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p[0]=max(p[0],x)
  elif a==2:
    p[1]=min(p[1],x)
  elif a==3:
    q[0]=max(q[0],y)
  else:
    q[1]=min(q[1],y)
s=(p[1]-p[0])*(q[1]-q[0])
print(s if s>0 else 0)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
p,q=[0,w],[0,h]
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p[0]=max(p[0],x)
  elif a==2:
    p[1]=min(p[1],x)
  elif a==3:
    q[1]=max(q[0],y)
  else:
    q[1]=min(q[1],y)
s=(p[1]-p[0])*(q[1]-q[0])
print(s if s>0 else 0)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
p,q=[0,w],[0,h]
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p[0]=max(p[0],x)
  elif a==2:
    p[1]=min(p[1],x)
  elif a==3:
    q[1]=max(q[1],y)
  else:
    q[1]=min(q[1],y)
s=(p[1]-p[0])*(q[1]-q[0])
print(s if s>0 else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Xend = W
Yend = H
Xstart = 0
Ystart = 0
for xya in XYA:
    if xya[2] == 1:
        Xstart = max(Xstart,xya[0])
    elif xya[2] == 2:
        Xend = max(Xend,xya[0])
    elif xya[2] == 3:
        Ystart = max(Ystart,xya[1])
    elif xya[2] == 4:
        Yend = max(Yend,xya[1])
if (Xend - Xstart)>0 and (Yend - Ystart)>0:
    print((Xend - Xstart)*(Yend - Ystart))
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)]

Xend = W
Yend = H
Xstart = 0
Ystart = 0
for xya in XYA:
    if xya[2] == 1:
        Xstart = xya[0]
    elif xya[2] == 2:
        Xend = xya[0]
    elif xya[2] == 3:
        Ystart = xya[1]
    elif xya[2] == 4:
        Yend = xya[1]
if (Xend - Xstart)>0 and (Yend - Ystart)>0:
    print((Xend - Xstart)*(Yend - Ystart))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
x,y,n=list(map(int,input().split()))
xx=x
yy=y
S=[]
a1=0
b1=0
for _ in range(n):
    S.append(list(map(int,input().split())))
for a in S :
    if a[2]==1:
        a1 = max(a1,a[0])
    elif a[2]==2:
        xx = min(xx,a[0])
    elif a[2]==3:
        b1 = max(b1,a[1])
    elif a[2]==4:
        yy = min(yy,a[1])

if(xx-a1)*(yy-b1)<0 or xx< 0 <yy or xx> 0 >yy:
    print(0)
else:
  print((xx-a1)*(yy-b1))

Submission status: Wrong Answer

Solution code:
x,y,n=list(map(int,input().split()))
xx=x
yy=y
S=[]
a1=0
a2=0
b1=0
b2=0
for _ in range(n):
    S.append(list(map(int,input().split())))
for a in S :
    if a[2]==1:
        if a1 < a[0]:
            a1=a[0]
            xx=xx-a[0]
    elif a[2]==2:
        if a2 < x-a[0]:
            a2=x-a[0]
            xx=xx-(x-a[0])
    elif a[2]==3:
        if b1 < a[1]:
            b1=a[1]
            yy=yy-a[1]
    elif a[2]==4:
        if b2 < y-a[1]:
            b2=y-a[1]
            yy=yy-(y-a[1])
if xx*yy<0 and xx<0:
    print(0)
else:
   print(xx*yy)

Submission status: Wrong Answer

Solution code:
x,y,n=list(map(int,input().split()))
xx=x
yy=y
S=[]
a1=0
a2=0
b1=0
b2=0
for _ in range(n):
    S.append(list(map(int,input().split())))
for a in S :
    if a[2]==1:
        if a1 < a[0]:
            a1=a[0]
            xx=xx-a[0]
    elif a[2]==2:
        if a2 < x-a[0]:
            a2=x-a[0]
            xx=xx-(x-a[0])
    elif a[2]==3:
        if b1 < a[1]:
            b1=a[1]
            yy=yy-a[1]
    elif a[2]==4:
        if b2 < y-a[1]:
            b2=y-a[1]
            yy=yy-(y-a[1])
if xx*yy<0:
    print(0)
else:
   print(xx*yy)

Submission status: Wrong Answer

Solution code:
x,y,n=list(map(int,input().split()))
xx=x
yy=y
S=[]
a1=0
a2=0
b1=0
b2=0
for _ in range(n):
    S.append(list(map(int,input().split())))
for a in S :
    if a[2]==1:
        if a1 < a[0]:
            a1=a[0]
            xx=xx-a[0]
    elif a[2]==2:
        if a2 < x-a[0]:
            a2=x-a[0]
            xx=xx-(x-a[0])
    elif a[2]==3:
        if b1 < a[1]:
            b1=a[1]
            yy=yy-a[1]
    elif a[2]==4:
        if b2 < y-a[1]:
            b2=y-a[1]
            yy=yy-(y-a[1])
print(xx*yy)

Submission status: Wrong Answer

Solution code:
"""
author : halo2halo
date : 2, Feb, 2020
"""

import sys
import itertools

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W, H, N = map(int, readline().split())
Xt = W
Xd = 0
Yt = H
Yd = 0
for _ in range(N):
    x, y, a = map(int, readline().split())
    if a == 1:
        Xd = x
    elif a == 2:
        Xt = x
    elif a == 3:
        Yd = y
    else:
        Yt = y

print(0 if Xd > Xt or Yd > Yt else (Xt - Xd) * (Yt - Yd))

Submission status: Wrong Answer

Solution code:
"""
author : halo2halo
date : 2, Feb, 2020
"""

import sys
import itertools

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W, H, N = map(int, readline().split())
X = W
Y = H
for _ in range(N):
    x, y, a = map(int, readline().split())
    if a == 1:
        X -= x
    elif a == 2:
        X -= W - x
    elif a == 3:
        Y -= y
    else:
        Y -= H - y

X=max(0,X)
Y=max(0,Y)

print(X*Y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#x,y,a
#辺をどんどん更新していく
low_x=0
low_y=0
for i in range(n):
    if l[i][-1]==1:
        low_x=l[i][0]
    elif l[i][-1]==2:
        w=l[i][0]
    elif l[i][-1]==3:
        low_y=l[i][1]
    else:
        h=l[i][1]

#print(w,low_x,h,low_y)
print((w-low_x)*(h-low_y) if w>=low_x and h>=low_y else 0)

Submission status: Wrong Answer

Solution code:
import numpy as np
w,h,n=map(int,input().split())
ans=np.zeros((w,h),dtype=np.int)
for _ in range(n):
    x,y,a=map(int,input().split())
    if a == 1:
        ans[:x,:]=1
    elif a == 1:
        ans[:,x-1:]=1
    elif a ==1:
        ans[:y,:]=1
    else:
        ans[:,y-1:]=1
print(np.count_nonzero(ans))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
x_min, x_max = 0, w
y_min, y_max = 0, h
for _ in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = x
    elif a == 2:
        x_max = x
    elif a == 3:
        y_min = y
    else:
        y_max = y
dx = x_max - x_min
dy = y_max - y_min
white_space = max(dx,0) * max(dy,0)
print(white_space)

Submission status: Wrong Answer

Solution code:
#２２０5~

import sys
[a,b,c]=list(map(int,input().split()))# W H N
lst=[]
for i in range(c):
    lst.append(list(map(int,input().split())))
#print(a,b,c,lst)

lstxmax=[0]
lstxmin=[a]
lstymax=[0]
lstymin=[b]
for i in lst:
    if i[2]==1:
        lstxmax.append(i[0])
    if i[2]==2:
        lstxmin.append(i[0])
    if i[2]==3:
        lstymax.append(i[1])
    if i[2]==4:
        lstymin.append(i[1])

xmin=min(lstxmin)
xmax=max(lstxmax)
ymin=min(lstymin)
ymax=max(lstymax)

#print(xmax,xmin,ymax,ymin)
print((xmin-xmax)*(ymin-ymax))

Submission status: Wrong Answer

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

xmin = 0
ymin = 0
xmax = W
ymax = H
for x,y,a in XYA:
  if a == 1:
    xmin = x
  elif a == 2:
    xmax = x
  elif a == 3:
    ymin = y
  else:
    ymax = y
#print(xmax,xmin,ymax,ymin)
print(max(xmax-xmin,0)*max(ymax-ymin,0))

Submission status: Wrong Answer

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

W_right = W
W_left = 0
H_up = H
H_down = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if W_left < x:
            W_left = x
    elif a == 2:
        if W_right > x:
            W_right = x
    elif a == 3:
        if H_down < y:
            H_down = y
    else:
        if H_up > y:
            H_up = y

print(max(0, (W_right - W_left) * (H_up - H_down)))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

w,h,n=LI()
x,X=0,w
y,Y=0,h
for i in ' '*n:
    s,t,a=LI()
    if a==1:
        x=max(x,s)
    elif a==2:
        X=min(X,s)
    elif a==3:
        y=max(y,t)
    elif a==4:
        Y=min(Y,t)

print(abs(X-x)*abs(Y-y))