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:
# coding: utf-8


def main():

    x_end, y_end, n = map(int, input().split(' '))
    x_start, y_start = 0, 0
    inputs = []
    for _ in range(n):
        inputs.append(list(map(int, input().split(' '))))

    for input_ in inputs:
        if input_[2] == 1:
            x_start = input_[0]
        elif input_[2] == 2:
            x_end = input_[0]
        elif input_[2] == 3:
            y_start = input_[1]
        elif input_[2] == 4:
            y_end = input_[1]
    area = (x_end - x_start) * (y_end - y_start)
    if area < 0:
        area = 0

    print(area)

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

X, Y = [0, w], [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        X[0] = max(X[0], x)
    if a == 2:
        X[1] = min(X[1], x)
    if a == 3:
        Y[0] = max(Y[0], y)
    if a == 4:
        Y[1] = min(Y[1], y)

print(max(0, (X[1] - X[0]) * (Y[1] - Y[0])))

Submission status: Wrong Answer

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

X, Y = [0, w], [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        X[0] = x
    if a == 2:
        X[1] = x
    if a == 3:
        Y[0] = y
    if a == 4:
        Y[1] = y

print(max(0, (X[1] - X[0]) * (Y[1] - Y[0])))

Submission status: Wrong Answer

Solution code:
W, H ,N = map(int,input().split())
#白い部分の長方形の左右上下を設定
r = W
l = 0
m = H
n = 0
#左右上下を入力の度に更新
for _ in range(N):
    x, y , a = map(int,input().split())
    if a == 1:
        l = x
    if a == 2:
        r = x
    if a == 3:
        n = y
    if a == 4:
        m = y
#長方形ができないときは面積０だよ
if l >= r or n >= m:
    print(0)
else:
    print((r-l)*(m-n))

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline

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

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

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:
        B = max(B,y)
    elif a == 4:
        T = min(T,y)

res = (R-L) * (T-B)

res = max(res,0)

print(res)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline

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

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

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

res = (R-L) * (T-B)

print(res)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline

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

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

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

res = (R-L) * (T-B)

res = max(res,0)

print(res)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
p, q, r, s = 0, 0, w, h
for i in range(n):
   x, y, a = map(int, input().split())

   if (a == 1):
      p = x
   elif (a == 2):
      r = x
   elif (a == 3):
      q = y
   else:
      s = y

if (r - p < 0):
   r = p
if (s - q < 0):
   s = q
print(r - p, s - q)

Submission status: Wrong Answer

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

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

x1,y1 = [0,0]
x2,y2 = [W,H]

for x,y,a in points:
    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 <= 0 or y-y1 <=0:
    print("0")
else:
    print((x2-x1)*(y2-y1))

Submission status: Wrong Answer

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

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

x1,y1 = [0,0]
x2,y2 = [W,H]

for x,y,a in points:
    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 <= 0 or y-y1 <=0:
    print("0")
else:
    res = (x2-x1) * (y2 - y1)
    print(res)

Submission status: Wrong Answer

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

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

x1,y1 = [0,0]
x2,y2 = [W,H]

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


res = max((x2-x1) * (y2 - y1),0)

print(res)

Submission status: Wrong Answer

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

a1 = 0
a2 = w
a3 = 0
a4 = h
for _ in range(n):
   x,y,a = map(int,input().split())
   if a == 1:
      a1 = max(a1, x)
   if a == 2:
      a2 = min(a2, x)
   if a == 3:
      a3 = max(a3, y)
   if a == 4:
      a4 = min(a4, y)
a5 = max(a2 - a1, 0)
a6 = max(a4 -a3, 0)
print(max((a2-a1)*(a4-a3), 0))

Submission status: Wrong Answer

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

a1 = 0
a2 = w
a3 = 0
a4 = h
for _ in range(n):
   x,y,a = map(int,input().split())
   if a == 1:
      a1 = max(a1, x)
   if a == 2:
      a2 = min(a2, x)
   if a == 3:
      a3 = max(a3, y)
   if a == 4:
      a4 = min(a4, y)
print(max((a2-a1)*(a4-a3), 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)]
maxw=0
minw=w
maxh=0
minh=h
for i in range(n):
  if a[i][-1]==1:    
    maxw=max(a[i][0],maxw)
  elif a[i][-1]==2:
    minw=min(a[i][0],minw)
  elif a[i][-1]==3:    
    maxh=max(a[i][1],maxw)
  else:
    minh=min(a[i][1],minw)
    
haba=max(0,minw-maxw)
takasa=max(0,minh-maxh)

print(haba*takasa)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

points = [list(map(int, input().split())) for _ in range(N)]
# res = [[0 for _ in range(W)] for _ in range(H)]
res = 0

minx, maxx, miny, maxy = [0,W,0,H]
x = 0
y = 0

for x,y,a in points:
    if a == 1:
        minx = x
    if a == 2:
        maxx = x
    if a == 3:
        miny = y
    if a == 4:
        maxy = y


if maxx - minx <= 0 or maxy - miny <=0:
    res = 0
else:
    res = (maxx-minx) * (maxy - miny)

print(res)

Submission status: Wrong Answer

Solution code:
import sys
w,h,n = map(int, sys.stdin.readline().split())

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

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = min(y, y_max)

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

Submission status: Wrong Answer

Solution code:
import sys
w,h,n = map(int, sys.stdin.readline().split())

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

for i 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

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
info=[]
for i in range(n):
    x,y,a=map(int,input().split())
    info.append([x,y,a])
top,down,left,right=h,0,0,w
def calc(x,y,a):
    global top,down,left,right
    if a==1:
        if x<left:
            left=x
    elif a==2:
        if right<x:
            right=x
    elif a==3:
        if down<y:
            down=y
    else:
        if y<top:
            top=y
for i in range(n):
    calc(info[i][0],info[i][1],info[i][2])
    if top<=down:
        top,down=0,0
        break
    if right<=left:
        right,left=0,0
        break
    #print(right)
    #print(left)
print((top-down)*(right-left))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
info=[]
for i in range(n):
    x,y,a=map(int,input().split())
    info.append([x,y,a])
top,down,left,right=h,0,0,w
def calc(x,y,a):
    global top,down,left,right
    if a==1:
        left=x
    elif a==2:
        right=x
    elif a==3:
        down=y
    else:
        top=y
for i in range(n):
    calc(info[i][0],info[i][1],info[i][2])
    if top<=down:
        top,down=0,0
        break
    if right<=left:
        right,left=0,0
        break
    #print(right)
    #print(left)
print((top-down)*(right-left))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
w_2 = 0
h_2 = 0
order = []

for i in range(n):
    array = list(map(int, input().split()))
    order.append(array)

for i, j, a in order:
    if a == 1:
        w_2 = max(0, i)
    elif a == 2:
        w = min(w, i)
    elif a == 3:
        h_2 = max(0, j)
    else:
        h = min(h, j)

tate = h - h_2
yoko = w - w_2
if tate < 0 or yoko < 0:
    print(0)
    exit()
print(max(tate*yoko, 0))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
w_2 = 0
h_2 = 0
order = []

for i in range(n):
    array = list(map(int, input().split()))
    order.append(array)

for i, j, a in order:
    if a == 1:
        w_2 = max(0, i)
    elif a == 2:
        w = min(w, i)
    elif a == 3:
        h_2 = max(0, j)
    else:
        h = min(h, j)

tate = h - h_2
yoko = w - w_2
print(max(tate*yoko, 0))

Submission status: Wrong Answer

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

mw = 0
mh = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        mw = max(mw, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        mh = max(mh, y)
    elif a == 4:
        h = min(h, y)

print((w-mw)*(h-mh) if mw <= w or mh <= h else 0)

Submission status: Wrong Answer

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

mw = 0
mh = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        mw = max(mw, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        mh = max(mh, y)
    elif a == 4:
        h = min(h, y)

s = (w-mw)*(h-mh)
print(s if s > 0 else 0)

Submission status: Wrong Answer

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

mw = 0
mh = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        mw = x
    elif a == 2:
        w = x
    elif a == 3:
        mh = y
    elif a == 4:
        h = y

s = (w-mw)*(h-mh)
print(s if s > 0 else 0)

Submission status: Wrong Answer

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

minx = 0
maxx = w
miny = 0
maxy = h

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

	if a == 1:
		maxx = min(maxx, x)
	elif a == 2:
		minx = max(minx, x)
	elif a == 3:
		maxy = min(maxy, y)
	else:
		miny = max(miny, y)

ans = (maxx - minx) * (maxy - miny)

if minx < maxx and miny < maxy:
	print(ans)
else:
	print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

for i in range(N):
  x, y, a = [int(j) for j in input().split()]
  
  if a == 1:
    x_min = x
  elif a == 2:
    x_max = x
  elif a == 3:
    y_min = y
  else:
    y_max = y

width = x_max - x_min
height = y_max - y_min

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    cnt = 0
    for y_ in range(H):
        for x_ in range(W):
            for i in range(N):
                if a[i] == 1 and x_ < x[i] or a[i] == 2 and x_ >= x[i] or a[i] == 3 and y_ < y[i] or a[i] == 4 and y_ >= y[i]:
                    break
            else:
                cnt += 1
    return cnt

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    a = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    cnt = 0
    for y_ in range(H + 1):
        for x_ in range(W + 1):
            for i in range(N):
                if a[i] == 1 and x_ < x[i] or a[i] == 2 and x_ > x[i] or a[i] == 3 and y_ < y[i] or a[i] == 4 and y_ > y[i]:
                    break
            else:
                cnt += 1
    return cnt

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    a = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:



def main()->None:
    W, H, N = map(int, input().split())
    range_N = range(N)
    xl, xr, yd, yu = 0, W, 0, H
    for i in range_N:
        x, y, a = map(int, input().split())
        if a == 1:
            xl = max(x, xl)
        if a == 2:
            xr = min(x, xr)
        if a == 3:
            yd = max(y, yd)
        else:
            yu = min(y, yu)
    if xl >= xr or yd >= yu:
        print(0)
    else:
        print((xr - xl) * (yu - yd))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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

for i in list_state:
    if i[2] == 1 and min_x < i[0]:
        min_x = i[0]
    if i[2] == 2 and max_x > i[0]:
        max_x = i[0]
    if i[2] == 3 and min_y < i[1]:
        min_y = i[1]
    if i[2] == 4 and max_y > i[1]:
        max_y = i[1]

x = max_x - min_x
y = max_y - min_y

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

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
x1 = y1 = 0
x2 = W
y2 = H
for _ 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)

print(max(0, (x2 - x1) * (y2 - y1)))

Submission status: Wrong Answer

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

x1 = 0
y1 = 0
x2 = W
y2 = H

for i in range(N):
    a = xya[i][2]

    if a == 1:
        x1 = max(x1, xya[i][0])
    elif a == 2:
        x2 = min(x2, xya[i][0])
    elif a == 3:
        y1 = max(y1, xya[i][1])
    else:
        y2 = min(y2, xya[i][1])

print(max(0,(x2-x1) * (y2-y1)))

Submission status: Wrong Answer

Solution code:

w, h, n = (int(x) for x in input().split())

squre_1 = 0
squre_2 = w
squre_3 = 0
squre_4 = h

for i in range(n):
    x, y, a = (int(x) for x in input().split())
    if a == 1 and squre_1 <= x:
        squre_1 = x
    elif a == 2 and squre_2 >= x:
        squre_2 = x
    elif a == 3 and squre_3 <= y:
        squre_3 = y
    elif a == 4 and squre_4 >= y:
        squre_4 = y

ans = (squre_2 - squre_1) * (squre_4 - squre_3)
print(ans)

Submission status: Wrong Answer

Solution code:
w, h, n = (int(x) for x in input().split())

squre_1 = 0
squre_2 = w
squre_3 = 0
squre_4 = h

for i in range(n):
    x, y, a = (int(x) for x in input().split())
    if a == 1 and squre_1 < x:
        squre_1 = x
    elif a == 2 and squre_2 > x:
        squre_2 = x
    elif a == 3 and squre_3 < y:
        squre_3 = y
    elif a == 4 and squre_4 > y:
        squre_4 = y

ans = (squre_2 - squre_1) * (squre_4 - squre_3)
print(ans)

Submission status: Wrong Answer

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

x_ = 0
y_ = 0

W_ = W
H_ = H

y__ = 0
x__ = 0


for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if x__ < x:
            W -= x
            x_ = x
            x__ = x

    elif a == 2:
        if x_ == 0:
            W -= (W-x)
            x_ = x
        elif x_ > x:
            W = 0
        else:
            W -= (W_-x)
            x_ = x 

    elif a == 3:
        if y__ < y:
            H -= y
            y_ = y
            y__ = y



    elif a == 4:
        if y_ == 0:
            H -= (H-y)
            y_ = y
        elif y_ > y:
            H = 0
        else:
            H -= (H_-y)
            y_ = y

else:
    print(W * H)

Submission status: Wrong Answer

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

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

l = [0,0]
r = [w,h]

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

    if a==1:
        l[0] = x
    elif a==2:
        r[0] = x
    
    elif a==3:
        l[1] = y
    elif a==4:
        r[1] = y

if (r[0]-l[0]) <= 0 or (r[1]-l[1])<=0:
    print(0)
else:
    print((r[0]-l[0])*(r[1]-l[1]))

Submission status: Wrong Answer

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

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

l = [0,0]
r = [w,h]

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

    if a==1:
        l[0] = x
    elif a==2:
        r[0] = x
    
    elif a==3:
        l[1] = y
    elif a==4:
        r[1] = y

print((r[0]-l[0])*(r[1]-l[1]))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
W0 = 0
H0 = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        W0 = x
    elif a == 2:
        W = x
    elif a == 3:
        H0 = y
    elif a == 4:
        H = y
if W-W0 < 0 or H-H0 <0:
    print(0)
print((W-W0)*(H-H0))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
W0 = 0
H0 = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        W0 = x
    elif a == 2:
        W = x
    elif a == 3:
        H0 = y
    elif a == 4:
        H = y
area = (W-W0)*(H-H0)
if area < 0:
    print(0)
else:
    print(area)

Submission status: Wrong Answer

Solution code:
w,h,n = [int(i) for i in input().split()]
lst = []
for _ in range(n):
  lst.append([int(i) for i in input().split()])
a,b = 0,0
for i in lst:
  if i[2] == 1:
    a = max(a,i[0])
  elif i[2] == 2:
    w = min(w, i[0])
  elif i[2] == 3:
    b = max(b, i[1])
  elif i[2] == 4:
    h = min(h, i[1])
m = (w-a)*(h-b)
print(m * (m > 0))

Submission status: Wrong Answer

Solution code:
w,h,n = [int(i) for i in input().split()]
lst = []
for _ in range(n):
  lst.append([int(i) for i in input().split()])
a,b = 0,0
for i in lst:
  if i[2] == 1:
    a = max(a,i[0])
  elif i[2] == 2:
    w = min(w, i[0])
  elif i[2] == 3:
    b = max(b, i[1])
  else:
    h = min(h, i[1])
m = (w-a)*(h-b)
print(m * (m > 0))

Submission status: Wrong Answer

Solution code:

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


d = []
for _ in range(n):
  a = [int(i) for i in input().split()]
  d.append(a)
  
#print(w, h)
  
x1 = [0]
x2 = [w]
y1 = [0]
y2 = [h]

for i in range(n):
  if d[i][2] == 1:
    x1.append(d[i][0])
  if d[i][2] == 2:
    x2.append(d[i][0])
  if d[i][2] == 3:
    y1.append(d[i][1])
  if d[i][2] == 4:
    y2.append(d[i][1])
#print(x1, x2, y1, y2)
x1 = sorted(x1, reverse = True)[0]
x2 = sorted(x2)[0]
y1 = sorted(y1, reverse = True)[0]
y2 = sorted(y2)[0]

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

Submission status: Wrong Answer

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

bottom_left = [0, 0]
top_right = [W, H]

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and bottom_left[0] < x:
        bottom_left[0] = x
    elif a == 2 and top_right[0] > x:
        top_right[0] = x
    elif a == 3 and bottom_left[1] <  y:
        bottom_left[1] = y
    elif a == 4 and top_right[1] > y:
        top_right[1] = y

area = max((top_right[0] - bottom_left[0]) * (top_right[1] - bottom_left[1]), 0)

print(area)

Submission status: Wrong Answer

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

xl1 =[0]
xl2 =[w]
yl3 =[0]
yl4 =[h]
for i in range(n):
    if xya[i][2]==1:
        xl1.append(xya[i][0])
    elif xya[i][2]==2:
        xl2.append(xya[i][0])
    elif xya[i][2]==3:
        yl3.append(xya[i][1])
    elif xya[i][2]==4:
        yl4.append(xya[i][1])

s = (min(xl2)-max(xl1))*(min(yl4)-max(yl3))
if s>0:
    print(s)
else:
    print(0)

Submission status: Wrong Answer

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

xl1 =[0]#max
xl2 =[w]#min
yl3 =[0]#max
yl4 =[h]#min
for i in range(n):
    if xya[i][2]==1:
        xl1.append(xya[i][0])
    elif xya[i][2]==2:
        xl2.append(xya[i][0])
    elif xya[i][2]==3:
        yl3.append(xya[i][1])
    elif xya[i][2]==4:
        yl4.append(xya[i][1])

s = (max(xl1)-min(xl2))*(max(yl3)-min(yl4))
if s>0:
    print(s)
else:
    print(0)

Submission status: Wrong Answer

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

xl1 =[0]#max
xl2 =[w]#min
yl3 =[0]#max
yl4 =[h]#min
for i in range(n):
    if xya[i][2]==1:
        xl1.append(xya[i][0])
    elif xya[i][2]==2:
        xl2.append(xya[i][0])
    elif xya[i][2]==3:
        yl3.append(xya[i][1])
    elif xya[i][2]==4:
        yl4.append(xya[i][1])

s = (max(xl1)-min(xl2))*(max(yl3)-min(yl4))
if s>=0:
    print(s)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W,H,N = map(int,input().split())
zero = [0,0]
X = [W,H]
ans = True
for i in range(N):
    x,y,a = map(int,input().split())
    if(a == 1):
        if zero[0] < x < X[0]:
            zero[0] = x
        elif X[0] < x:
            ans = False
            break
    elif(a == 2):
        if zero[0] < x < X[0]:
            X[0] = x
        elif zero[0] > x:
            ans = False
            break
    elif(a == 3):
        if zero[1] < y < X[1]:
            zero[1] = y
        elif X[1] < y:
            ans = False
            break
    elif(a == 4):
        if zero[1] < y < X[1]:
            X[1] = y
        elif zero[0] > y:
            ans = False
            break
if(ans):
    S = (X[1] - zero[1]) * (X[0] - zero[0])
    print(S)
else:
    print(0)

Submission status: Wrong Answer

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

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

for i in range(N):
    xi, yi, ai = map(int, input().split())

    if ai == 1:
        xl = max(xi, xl)
    elif ai == 2:
        xr = min(xi, xr)
    elif ai == 3:
        yl = max(yi, yl)
    else:
        yh = min(yi, yh)

ans = (xr - xl) * (yh - yl)
if ans > 0:
    print(ans)
else:
    print('0')

Submission status: Wrong Answer

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

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

for i in range(N):
    xi, yi, ai = map(int, input().split())

    if ai == '1':
        xl = max(xi, xl)
    elif ai == '2':
        xr = min(xi, xr)
    elif ai == '3':
        yl = max(yi, yl)
    else:
        yh = min(yi, yh)

ans = (xr - xl) * (yh - yl)
if ans > 0:
    print(ans)
else:
    print('0')

Submission status: Wrong Answer

Solution code:
W,H,N = map(int, input().split())
data = [0,W,0,H]
for i in range(0,N):
    xi,yi,ai = map(int, input().split())
    if ai == 1:
        data[0] = max([data[0],xi])
    elif ai == 2:
        data[1] = min([data[1],xi])
    elif ai == 3:
        data[2] = max([data[2],yi])
    else:
        data[3] = min([data[3],yi])

ans = (data[1]-data[0])*(data[3]-data[2])
if ans < 0: ans = 0
print(ans)

Submission status: Wrong Answer

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

print(max(0,(xr-xl)*(yr-yl)))

Submission status: Wrong Answer

Solution code:
w,h,n=[int(j) for j in input().split()]
xl,xr=0,w
yl,yr=0,h
for i in range(n):
    x,y,a=[int(j) for j in input().split()]
    if a==1:
        xl=x
    elif a==2:
        xr=x
    elif a==3:
        yl=y
    else:
        yr=y
print(max(0,(xr-xl)*(yr-yl)))

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    W,H,N = MI()
    bottom = 0
    top = H
    left = 0
    right = W
    for i in range(N):
        a,b,c = MI()
        if c==1:
            left = max(left,a)
        if c==2:
            right = min(right,a)
        if c==3:
            bottom = max(bottom, b)
        if c==4:
            top = min(top, b)
    print(max(0,(right-left)*(top-bottom)))
if __name__ == '__main__':
    main()