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:
x0, y0 = 0, 0
w, h, n = map(int, input().split())

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x0 < x:
        x0 = x
    elif a == 2 and x < w:
        w = x
    elif a == 3 and y0 < y:
        y0 = y
    elif a == 4 and y < h:
        h = y

ans = (w - x0) * (h - y0)
if ans < 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

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

ans = (w - x0) * (h - y0)
if ans < 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
x_max=W
x_min=0
y_max=H
y_min=0
for i in range(N):
  li=list(map(int,input().split()))
  if li[2]==1 and li[0]>x_min:
    x_min=li[0]
  elif li[2]==2 and li[0]<x_max:
    x_max=li[0]
  elif li[2]==3 and li[1]>y_min:
    y_min=li[1]
  elif li[2]==4 and li[1]<y_max:
    y_max=li[1]
    
#print(x_max,x_min,y_max,y_min)
s=(x_max-x_min)*(y_max-y_min)
if s>0:
  print(s)
else:
  print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
a_r = w
a_l = 0
a_u = h
a_d = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        a_l = max(a_l, x)
    elif a == 2:
        a_r = min(a_r, x)
    elif a == 3:
        a_d = max(a_d, y)
    else:
        a_u = min(a_u, y)

print(a_l, a_r, a_d, a_u)
print(max(0, a_r - a_l) * max(0, a_u - a_d))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
a_r = w
a_l = 0
a_u = h
a_d = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        a_l = max(a_l, x)
    elif a == 2:
        a_r = min(a_r, x)
    elif a == 3:
        a_d = max(a_d, y)
    else:
        a_u = max(a_u, y)

print(max(0, a_r - a_l) * max(0, a_u - a_d))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
a_r = w
a_l = 0
a_u = h
a_d = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        a_l = x
    elif a == 2:
        a_r = x
    elif a == 3:
        a_d = y
    else:
        a_u = y

print(max(0, a_r - a_l) * max(0, a_u - a_d))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
A = []
B = []
C = []
D = []

for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    A.append(x)
  elif a == 2:
    x = W-x
    B.append(x)
  elif a == 3:
    C.append(y)
  else:
    y = H-y
    D.append(y)
if len(A)>0:
    a = max(A)
else:
    a=0

if len(B)>0:
    b = max(B)
else:
    b = 0

if len(C)>0:
    c = max(C)
else:
    c = 0
if len(D)>0:
    d = max(D)
else:
    d = 0

w = W - (a+b)
h = H - (c+d)
if w*h<=0:
    print(0)
else:
    print(w*h)

Submission status: Wrong Answer

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

if len(B)>0:
    b = max(B)
else:
    b = 0

if len(C)>0:
    c = max(C)
else:
    c = 0
if len(D)>0:
    d = max(D)
else:
    d = 0

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    x0, x1 = 0, W
    y0, y1 = 0, H
    for i in range(N):
        if a[i] == 1:
            x0 = max(x0, x[i])
        if a[i] == 2:
            x1 = min(x1, x[i])
        if a[i] == 3:
            y0 = max(y0, y[i])
        if a[i] == 4:
            y1 = min(y1, y[i])
    ret = max(0, (x1 - x0) * (y1 - y0))
    print(ret)
    return


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

print(area)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int,input().split())
xmin,xmax,ymin,ymax = 0,W,0,H
for _ in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if x > xmin:
            xmin = x
    elif a == 2:
        if x < xmax:
            xmax = x
    elif a == 3:
        if y > ymin:
            ymin = y
    else:
        if y < ymax:
            ymax = y

ans = max(0,(xmax-xmin)*(ymax-ymin))
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

#C
def C():
    return

#D
def D():
    return

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

Submission status: Wrong Answer

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

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

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

#C
def C():
    return

#D
def D():
    return

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

Submission status: Wrong Answer

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

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

#B
def B():
    W, H, n = LI()
    wh = [[0, 0], [W, H]]
    for _ in range(n):
        x, y, a = LI()
        if a == 1:
            wh[0][0] = x
        if a == 2:
            wh[1][0] = x
        if a == 3:
            wh[0][1] = y
        if a == 4:
            wh[1][1] = y
        if wh[1][0] <= wh[0][0]:
            print(0)
            return
        if wh[1][1] <= wh[0][1]:
            print(0)
            return
    print((wh[1][0] - wh[0][0]) * (wh[1][1] - wh[0][1]))
    return

#C
def C():
    return

#D
def D():
    return

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

Submission status: Wrong Answer

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

#A
def A():
    a = LI()
    print(len(list(set(a))))
    return

#B
def B():
    W, H, n = LI()
    wh = [[0, 0], [W, H]]
    for _ in range(n):
        x, y, a = LI()
        if a == 1:
            wh[0][0] = x
        if a == 2:
            wh[0][1] = x
        if a == 3:
            wh[1][0] = y
        if a == 4:
            wh[1][1] = y
        if wh[0][1] <= wh[0][0]:
            print(0)
            return
        if wh[1][1] <= wh[1][0]:
            print(0)
            return
    print((wh[1][0] - wh[0][0]) * (wh[1][1] - wh[0][1]))
    return

#C
def C():
    return

#D
def D():
    return


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

Submission status: Wrong Answer

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

#A
def A():
    a = LI()
    print(len(list(set(a))))
    return

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

#C
def C():
    return

#D
def D():
    return


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

Submission status: Wrong Answer

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

#A
def A():
    a = LI()
    print(len(list(set(a))))
    return

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

#C
def C():
    return

#D
def D():
    return


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

Submission status: Wrong Answer

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

#A
def A():
    a = LI()
    print(len(list(set(a))))
    return

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

#C
def C():
    return

#D
def D():
    return


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

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x0, x1, y0, y1 = 0, w, 0, h
for i in range(n):
	x, y, a = map(int, input().split())
	if a == 1:
		x0 = max(x0, x)
	elif a == 2:
		x1 = min(x1, x)
	elif a == 3:
		y0 = max(y0, y)
	else:
		y1 = min(y1, y)
		
m = x1 - x0
n = y1 - y0
if m >= 0 or n >= 0:
	print(0)
else:
	print(m * n)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x0, x1, y0, y1 = 0, w, 0, h
for i in range(n):
	x, y, a = map(int, input().split())
	if a == 1:
		x0 = max(x0, x)
	elif a == 2:
		x1 = min(x1, x)
	elif a == 3:
		y0 = max(y1, y)
	else:
		y1 = min(y1, y)
		
m = x1 - x0
n = y1 - y0
if m >= 0 or n >= 0:
	print(0)
else:
	print(m * n)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x0, x1, y0, y1 = 0, w, 0, h
f = False
for i in range(n):
	x, y, a = map(int, input().split())
	if a == 1:
		x0 = max(x0, x)
	elif a == 2:
		x1 = min(x1, x)
	elif a == 3:
		y0 = max(y1, y)
	else:
		y1 = min(y1, y)
	
	if x0 >= x1 or y0 >= y1:
		f = True
		
m = x1 - x0
n = y1 - y0
if f:
	print(0)
else:
	print(m * n)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x0, x1, y0, y1 = 0, w, 0, h
f = False
for i in range(n):
	x, y, a = map(int, input().split())
	if a == 1:
		x0 = x
	elif a == 2:
		x1 = x
	elif a == 3:
		y0 = y
	else:
		y1 = y
	
	if x0 >= x1 or y0 >= y1:
		f = True
		
m = x1 - x0
n = y1 - y0
if f:
	print(0)
else:
	print(m * n)

Submission status: Wrong Answer

Solution code:
x_li = []
y_li = []
a_li = []
while True:
	try:
		x, y, a = map(int, input().split())
	except:
		break
	x_li.append(x)
	y_li.append(y)
	a_li.append(a)
x = max(x_li)
y = max(y_li)
x0 = 0
y0 = 0
f = False
for i in range(len(a_li)):
	if a_li[i] == 1:
		x0 = x_li[i]
	elif a_li[i] == 2:
		x = x_li[i]
	elif a_li[i] == 3:
		y0 = y_li[i]
	else:
		y = y_li[i]

	if x0 >= x or y0 >= y:
		f = True
		break
m = x - x0
n = y - y0
if f:
	print(0)
else:
	print(m * n)

Submission status: Wrong Answer

Solution code:
x_li = []
y_li = []
a_li = []
while True:
	try:
		x, y, a = map(int, input().split())
	except:
		break
	x_li.append(x)
	y_li.append(y)
	a_li.append(a)
x = max(x_li)
y = max(y_li)
x0 = 0
y0 = 0
for i in range(len(a_li)):
	if a_li[i] == 1:
		x0 = x_li[i]
	elif a_li[i] == 2:
		x = x_li[i]
	elif a_li[i] == 3:
		y0 = y_li[i]
	else:
		y = y_li[i]

m = x - x0
n = y - y0
if m <= 0 or n <= 0:
	print(0)
else:
	print(m * n)

Submission status: Wrong Answer

Solution code:
x_li = []
y_li = []
a_li = []
while True:
	try:
		x, y, a = map(int, input().split())
	except:
		break
	x_li.append(x)
	y_li.append(y)
	a_li.append(a)
x = max(x_li)
y = max(y_li)
x0 = 0
y0 = 0
for i in range(len(a_li)):
	if a_li[i] == 1:
		x0 = x_li[i]
	elif a_li[i] == 2:
		x = x_li[i]
	elif a_li[i] == 3:
		y0 = y_li[i]
	else:
		y = y_li[i]
print((x - x0) * (y - y0))

Submission status: Wrong Answer

Solution code:
maxX, maxY, a = map(int, input().split())
minX = 0
minY = 0
for i in range(a):
    x, y, b = map(int, input().split())
    if b == 1:
        minX = max(x, minX)
    elif b == 2:
        maxX = min(x, maxX)
    elif b == 3:
        minY = max(y, minY)
    elif b == 4:
        maxY = min(y, minY)
if maxX > minX and maxY > minY:
    print(((maxX - minX)*(maxY - minY)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
maxX, maxY, a = map(int, input().split())
minX = minY = 0
for i in range(a):
    x, y, b = map(int, input().split())
    if b == 1:
        minX = max(x, minX)
    elif b == 2:
        maxX = min(x, maxX)
    elif b == 3:
        minY = max(y, minY)
    elif b == 4:
        maxY = min(y, minY)
if maxX > minX and maxY > minY:
    print(((maxX - minX)*(maxY - minY)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
maxX, maxY, a = map(int, input().split())
minX = minY = 0
for i in range(a):
    x, y, b = map(int, input().split())
    if b == 1:
        minX = x
    elif b == 2:
        maxX = x
    elif b == 3:
        minY = y
    elif b == 4:
        maxY = y
if maxX >= minX and maxY >= minY:
    print(((maxX - minX)*(maxY - minY)))
else:
    print(0)