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 = [int(x) for x in input().split()]
S = [0,w,0,h]

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

    if a == 1:
        S[0] = max(S[0], x)        
    if a == 2:
        S[1] = min(S[1], x)
    if a == 3:
        S[2] = max(S[2], y)        
    if a == 4:
        S[3] = min(S[3], y)

ans = max(0,(S[1] - S[0]) * (S[3] - S[2]))
print(ans)

Submission status: Wrong Answer

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

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

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

for i in range(N):
  if grid[i][2] == 1:
    left = grid[i][0]
  elif grid[i][2] == 2:
    right = grid[i][0]
  elif grid[i][2] == 3:
    down = grid[i][1]
  elif grid[i][2] == 4:
    up = grid[i][1]
  
if (right>left)and(up>down):
  print((right-left)*(up-down))
else:
  print(0)

Submission status: Wrong Answer

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

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

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

for i in range(N):
  if grid[i][2] == 1:
    left = grid[i][0]
  elif grid[i][2] == 2:
    right = grid[i][0]
  elif grid[i][2] == 3:
    down = grid[i][1]
  elif grid[i][2] == 4:
    up = grid[i][1]
  
print((right-left)*(up-down))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
w = 0
h = 0
lx = list()
ly = list()
la = list()
for i in range(1, N+1):
    X, Y, A = map(int, input().split())
    lx.append(X)
    ly.append(Y)
    la.append(A)
    if A == 1 and w < X:
        w = X
    elif A == 2 and X < W:
        W = X
    elif A == 3 and h < Y:
        h = Y
    elif A == 4 and Y < H:
        H = Y
S = (W - w)*(H - h)
if S < 0:
    S = 0
print(S)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
wmax=w
wmin=0
hmax=h
hmin=0

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if wmin<=x:
            wmin=x
    elif a==2:
        if wmax>=x:
            wmax=x
    elif a==3:
        if hmin<=y:
            hmin=y
    else:
        if hmax>=y:
            hmax=y

print((wmax-wmin)*(hmax-hmin))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
x0, y0 = 0, 0
 
for _ in range(N):
    xi, yi, a = map(int, input().split())
    if a == 1:
        x0 = max(xi, x0)
    elif a == 2:
        W = min(xi, W)
    elif a == 3:
        y0 = max(yi, y0)
    elif a == 4:
        H = min(yi, H)

ans = (W-x0)*(H-y0)

Submission status: Wrong Answer

Solution code:
w = 0
h = 0
w2, h2, n = map(int, input().split())
cnt = w2 * h2
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > w:
            w = x
    elif a == 2:
        if x < w2:
            w2 = x
    elif a == 3:
        if y > h:
            h = y
    elif a == 4:
        if y < h2:
            h2 = y

    cnt = (w2-w) * (h2-h)

print(0 if cnt < 0 else cnt)

Submission status: Wrong Answer

Solution code:
x_max, y_max, N = map(int, input().split())
x_min, y_min = 0, 0
l = [input().split() for _ in range(N)]
for i in range(N):
  if l[i][2] == 1:
    x_min = max(x_min, l[i][0])
  elif l[i][2] == 2:
    x_max = min(x_max, l[i][0])
  elif l[i][2] == 3:
    y_min = max(y_min, l[i][1])
  elif l[i][2] == 4:
    y_max = min(y_max, l[i][1])
if x_max-x_min > 0 and y_max-y_min:
  print((x_max-x_min)*(y_max-y_min))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
x_max, y_max, N = map(int, input().split())
x_min, y_min = 0, 0
l = [input().split() for _ in range(N)]
for i in range(N):
  if l[i][2] == 1:
    x_min = max(x_min, l[i][0])
  elif l[i][2] == 2:
    x_max = min(x_max, l[i][0])
  elif l[i][2] == 3:
    y_min = max(y_min, l[i][1])
  elif l[i][2] == 4:
    y_max = min(y_max, l[i][1])
if x_max-x_min > 0 and y_max-y_min:
  print(abs(x_max-x_min)*abs(y_max-y_min))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
def main():
    W, H, N = map(int, input().split())
    area = [[0 for w in range(W)] for h in range(H) ]

    for n in range(N):
        x, y, a = map(int, input().split())
        
        if a == 1 :
            for i in range(H):
                for j in range(x):
                    area[i][j] = 1
                    
        elif a == 2:
            for i in range(H):
                for j in range(x, W):
                    area[i][j] = 1

        elif a == 3:
            for i in range(H - y):
                for j in range(W):
                    area[i][j] = 1
            
        elif a == 4:
            for i in range(H - y, H):
                for j in range(x):
                    area[i][j] = 1
    count = 0

    for i in range(H):
        for j in range(W):
            if area[i][j] == 0:
                count += 1
    print(count)
main()

Submission status: Wrong Answer

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

for _ in range(N):
    xi, yi, a = map(int, input().split())
    if a == 1:
        x0 = max(xi, x0)
    elif a == 2:
        W = min(xi, W)
    elif a == 3:
        y0 = max(yi, y0)
    elif a == 4:
        H = min(yi, H)

ans = (W-x0)*(H-y0)
if ans < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

for _ in range(N):
    xi, yi, a = map(int, input().split())
    if a == 1:
        x0 = xi
    elif a == 2:
        W = xi
    elif a == 3:
        y0 = yi
    elif a == 4:
        H = yi

ans = (W-x0)*(H-y0)
if ans < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

whole = W * H

for _ in range(N):
    xi, yi, a = map(int, input().split())
    if a == 1:
        whole -= (xi-x0) * (H-y0)
        x0 = xi
    elif a == 2:
        whole -= (W-xi) * (H-y0)
        W = xi
    elif a == 3:
        whole -= (yi-y0) * (W-x0)
        y0 = yi
    elif a == 4:
        whole -= (H-yi) * (W-x0)
        H = yi

if whole < 0:
    whole = 0
print(whole)

Submission status: Wrong Answer

Solution code:
w,h,n=[int(i) for i in input().split()]
leftdown=[0,0]
righttop=[w,h]


def minimize(leftdown,righttop,x,y,a):
    if a==1:
        leftdown[0]=max(x,leftdown[0])
    elif a==2:
        righttop[0]=min(x,righttop[0])
    elif a==3:
        leftdown[1]=max(y,leftdown[1])
    else:
        righttop[1]=min(y,righttop[1])
    
for i in range(n):
    x,y,a=[int(i) for i in input().split()]
    minimize(leftdown,righttop,x,y,a)
print(max(0,(righttop[0]-leftdown[0])*(righttop[1]-leftdown[1])))

Submission status: Wrong Answer

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

Wmin = 0
Wmax = W
Hmin = 0
Hmax = H

for i in range(N):
    x, y, z = map(int,input().split())
    if z == 1:
        Wmin = min(x, Wmin)
    if z == 2:
        Wmax = max(x, Wmax)
    if z == 3:
        Hmin = min(y, Hmin)
    if z == 4:
        Hmax = max(y, Hmax)
if Wmax < Wmin or  Hmax < Hmin:
    print(0)
else:
    print((Wmax-Wmin)*(Hmax-Hmin))

Submission status: Wrong Answer

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

Wmin = 0
Wmax = W
Hmin = 0
Hmax = H

for i in range(N):
    x, y, z = map(int,input().split())
    if z == 1:
        Wmin = x
    if z == 2:
        Wmax = x
    if z == 3:
        Hmin = y
    if z == 4:
        Hmax = y
if Wmax < Wmin or  Hmax < Hmin:
    print(0)
else:
    print((Wmax-Wmin)*(Hmax-Hmin))

Submission status: Wrong Answer

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

Wmin = 0
Wmax = W
Hmin = 0
Hmax = H

for i in range(N):
    x, y, z = map(int,input().split())
    if z == 1:
        Wmin = x
    if z == 2:
        Wmax = x
    if z == 3:
        Hmin = y
    if z == 4:
        Hmax = y

print(min((Wmax-Wmin)*(Hmax-Hmin), 0))

Submission status: Wrong Answer

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

Wmin = 0
Wmax = W
Hmin = 0
Hmax = H

for i in range(N):
    x, y, z = map(int,input().split())
    if z == 1:
        Wmin = x
    if z == 2:
        Wmax = x
    if z == 3:
        Hmin = y
    if z == 4:
        Hmax = y

print(W*H-(Wmax-Wmin)*(Hmax-Hmin))

Submission status: Wrong Answer

Solution code:
w,h,n = list(map(int, input().split()))
xya = [list(map(int, input().split())) for _ in range(n)]
left = 0
right = w
down = 0
up = h
for i in xya:
    if i[2]==1:
        left = i[0]
    elif i[2]==2:
        right = i[0]
    elif i[2]==3:
        down = i[1]
    else:
        up = i[1]

print(max(up-down, 0) * max(right-left, 0))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
xs = 0
ys = 0
for i in range(N):
    if W - xs <= 0 or H - ys <= 0:
        print(0)
        quit()
    if xya[i][2] == 1:
        xs = max(xs, xya[i][0])
    elif xya[i][2] == 2:
        W = xya[i][0]
    elif xya[i][2] == 3:
        ys = max(ys, xya[i][1])
    else:
        H = xya[i][1]
if W - xs <= 0 or H - ys <= 0:
        print(0)
else:
    print((W - xs) * (H - ys))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
xs = 0
ys = 0
for i in range(N):
    if W - xs <= 0 or H - ys <= 0:
        print(0)
        quit()
    if xya[i][2] == 1:
        xs = min(xs, xya[i][0])
    elif xya[i][2] == 2:
        W = xya[i][0]
    elif xya[i][2] == 3:
        ys = min(ys, xya[i][1])
    else:
        H = xya[i][1]
if W - xs <= 0 or H - ys <= 0:
        print(0)
else:
    print((W - xs) * (H - ys))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
xs = 0
ys = 0
for i in range(N):
    if W - xs <= 0 or H - ys <= 0:
        print(0)
        quit()
    if xya[i][2] == 1:
        xs = xya[i][0]
    elif xya[i][2] == 2:
        W = xya[i][0]
    elif xya[i][2] == 3:
        ys = xya[i][1]
    else:
        H = xya[i][1]
if W - xs <= 0 or H - ys <= 0:
        print(0)
else:
    print((W - xs) * (H - ys))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
xs = 0
ys = 0
for i in range(N):
    if W - xs < 0 or H - ys < 0:
        print(0)
        quit()
    if xya[i][2] == 1:
        xs = xya[i][0]
    elif xya[i][2] == 2:
        W = xya[i][0]
    elif xya[i][2] == 3:
        ys = xya[i][1]
    else:
        H = xya[i][1]
print((W - xs) * (H - ys))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
xs = 0
ys = 0
for i in range(N):
    if W - xs >= 0 or H - ys < 0:
        print(0)
        quit()
    if xya[i][2] == 1:
        xs = xya[i][0]
    elif xya[i][2] == 2:
        W = xya[i][0]
    elif xya[i][2] == 3:
        ys = xya[i][1]
    else:
        H = xya[i][1]
print((W - xs) * (H - ys))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
xs = 0
ys = 0
for i in range(N):
    if W - xs >= 0 and H - ys < 0:
        print(0)
        quit()
    if xya[i][2] == 1:
        xs = xya[i][0]
    elif xya[i][2] == 2:
        W = xya[i][0]
    elif xya[i][2] == 3:
        ys = xya[i][1]
    else:
        H = xya[i][1]
print((W - xs) * (H - ys))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
xs = 0
ys = 0
for i in range(N):
    if xya[i][2] == 1:
        xs = xya[i][0]
    elif xya[i][2] == 2:
        W = xya[i][0]
    elif xya[i][2] == 3:
        ys = xya[i][1]
    else:
        H = xya[i][1]

if W - xs >= 0 and H - ys >= 0:
    print((W - xs) * (H - ys))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#in1 = '10 10 5'
#in2 = ['1 6 1','4 1 3','6 9 4','9 4 2','3 1 3']

rx, uy, n = map(int, input().split())
#rx, uy, n = map(int, in1.split())

dy = 0
lx = 0

for idx1 in range(n):
    x, y, a = map(int, input().split())
    #x, y, a = map(int, in2[idx1].split())
    if a == 1:
        lx = max(lx, x)
    elif a == 2:
        rx = min(rx, x)
    elif a == 3:
        dy = max(dy, y)
    else:
        uy = min(uy, y)

mul = (uy - dy) * (rx - lx)
if mul < 0:
    print(0)
else:
    print(mul)

Submission status: Wrong Answer

Solution code:
rx, uy, n = map(int, input().split())

dy = 0
lx = 0

for idx1 in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if lx < x:
            lx = x
    elif a == 2:
        if rx > x:
            rx = x
    elif a == 3:
        if dy < y:
            dy = y
    else:
        if uy > y:
            uy = y

mul = (uy - dy) * (rx - lx)
if mul < 0:
    print(0)
else:
    print(mul)

Submission status: Wrong Answer

Solution code:
import sys

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

tW = W
tH = H

minx = 0
miny = 0

if W == 1 and H == 1:
    print(1)
    sys.exit()

for x, y, a in xya:
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        tW = min(tW, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        tH = min(tH, y)

ans = (tW - minx) * (tH - miny)
if ans <= 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

tW = W
tH = H

minx = 0
miny = 0

for x, y, a in xya:
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        tW = min(tW, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        tH = min(tH, y)

ans = (tW - minx) * (tH - miny)
if ans <= 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

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

for i in range(N):
    if a[i]==1:
        w = w - {_ for _ in range(x[i])}
    elif a[i]==2:
        w = w - {_ for _ in range(x[i]+1,W+1)}
    elif a[i]==3:
        h = h - {_ for _ in range(y[i])}
    else:
        h = h - {_ for _ in range(y[i]+1, H+1)}
ans = (len(w)-1)*(len(h)-1)
print(0 if ans<0 else ans)

Submission status: Wrong Answer

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

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

for i in range(N):
    if a[i]==1:
        w = w - {_ for _ in range(x[i])}
    elif a[i]==2:
        w = w - {_ for _ in range(x[i]+1,W+1)}
    elif a[i]==3:
        h = h - {_ for _ in range(y[i])}
    else:
        h = h - {_ for _ in range(y[i]+1, H+1)}

print((len(w)-1)*(len(h)-1))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split(' '))
x_axis = [0, w]
y_axis = [0, h]
for i in range(n):
    x, y, a = map(int, input().split(' '))
    if a == 1:
        x_axis[0] = x
    elif a == 2:
        x_axis[1] = x
    elif a == 3:
        y_axis[0] = y
    else:
        y_axis[1] = y

if x_axis[1]-x_axis[0] > 0 and y_axis[1]-y_axis[0] > 0:
    ans = (x_axis[1]-x_axis[0])*(y_axis[1]-y_axis[0])
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x_l = 0
x_r = w
y_l = 0
y_h = h

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
      if x > x_l:
        x_l = x
    elif a == 2:
        if x < x_r:
          x_r == x
    elif a == 3:
        if y > y_l:
          y_l = y
    else:
        if y < y_h:
          y_h = y

menseki = 0
if x_l <= x_r and y_l <= y_h:
  menseki = (y_h - y_l)*(x_r - x_l)

print(menseki)

Submission status: Wrong Answer

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

x_l = 0
x_r = w
y_l = 0
y_h = h

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
      if x > x_l:
        x_l = x
    elif a == 2:
        if x < x_r:
          x_r == x
    elif a == 3:
        if y > y_l:
          y_l = y
    else:
        if y < y_h:
          y_h = y

menseki = 0
if x_l <= x_r and y_l <= y_h:
  menseki = (y_h - y_l)*(x_l - x_r)

print(menseki)

Submission status: Wrong Answer

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

x_l = 0
x_r = w
y_l = 0
y_h = h

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
      if x > x_l:
        x_l = x
    elif a == 2:
        if x < x_r:
          x_r == x
    elif a == 3:
        if y > y_l:
          y_l = y
    else:
        if y < y_h:
          y_h = y

menseki = 0
if x_r <= x_l and y_l <= y_h:
  menseki = (y_h - y_l)*(x_l - x_r)

print(menseki)

Submission status: Wrong Answer

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

hani = [0,w,0,h]

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

        hani[0] = max(hani[0],x)
    elif a == 2:
        hani[1] = min(hani[1],x)
    elif a == 3:
        hani[2] = max(hani[2],y)
    else:
        hani[3] = min(hani[3],y)

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

Submission status: Wrong Answer

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

hani = [0,w,0,h]

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

        hani[0] = max(hani[0],x)
    elif a == 2:
        hani[1] = min(hani[1],x)
    elif a == 3:
        hani[2] = max(hani[2],y)
    else:
        hani[3] = min(hani[3],y)

    print(max(0,hani[1]-hani[0]) * max(0,hani[3]-hani[2]))
else:
    print(0)

Submission status: Wrong Answer

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

hani = [0,w,0,h]

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        hani[0] = max(hani[0],x)
    elif a == 2:
        hani[1] = min(hani[1],x)
    elif a == 3:
        hani[2] = max(hani[2],y)
    else:
        hani[3] = min(hani[3],y)

if (hani[1]-hani[0]) * (hani[3]-hani[2]) >= 0:
    print((hani[1]-hani[0]) * (hani[3]-hani[2]))
else:
    print(0)

Submission status: Wrong Answer

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

hani = [0,w,0,h]

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        hani[0] = max(hani[0],x)
    elif a == 2:
        hani[1] = min(hani[1],x)
    elif a == 3:
        hani[2] = max(hani[2],y)
    else:
        hani[3] = min(hani[3],y)

if (hani[1]-hani[0]) * (hani[3]-hani[2]) > 0:
    print((hani[1]-hani[0]) * (hani[3]-hani[2]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
inp = list(map(int,input().split()))
left_max=0
right_min=inp[0]
upper_min=inp[1]
lower_max=0

for i in range(inp[2]):
    inin = list(map(int,input().split()))
    if inin[2] == 1 and inin[0]>left_max:
        left_max=inin[0]
    if inin[2] == 2 and inin[0]<right_min:
        right_min=inin[0]
    if inin[2] == 4 and inin[1]<upper_min:
        upper_min=inin[1]
    if inin[2] == 3 and inin[1]>lower_max:
        lower_max=inin[1]
left_max=min(left_max,right_min)
upper_min=min(upper_min,lower_max)
print((right_min-left_max)*(upper_min-lower_max))

Submission status: Wrong Answer

Solution code:
inp = list(map(int,input().split()))
left_max=0
right_min=inp[0]
upper_min=inp[1]
lower_max=0

for i in range(inp[2]):
    inin = list(map(int,input().split()))
    if inin[2] == 1 and inin[0]>left_max:
        left_max=inin[0]
    if inin[2] == 2 and inin[0]<right_min:
        right_min=inin[0]
    if inin[2] == 4 and inin[1]<upper_min:
        upper_min=inin[1]
    if inin[2] == 3 and inin[1]>lower_max:
        lower_max=inin[1]

print((right_min-left_max)*(upper_min-lower_max))

Submission status: Wrong Answer

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

x = [int(i) for i in range(w+1)]
y = [int(i) for i in range(h+1)]

for i in range(n):
    x_i, y_i, a = map(int,input().split())
    if a == 1:
        x = [int(j) for j in x if j >= int(x_i)]
    elif a == 2:
        x = [int(j) for j in x if j <= int(x_i)]
    elif a == 3:
        y = [int(j) for j in y if j >= int(y_i)]
    elif a == 4:
        y = [int(j) for j in y if j <= int(y_i)]

print((len(x)) * len(y))

Submission status: Wrong Answer

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

x = [int(i) for i in range(w+1)]
y = [int(i) for i in range(h+1)]

for i in range(n):
    x_i, y_i, a = map(int,input().split())
    if a == 1:
        x = [int(j) for j in x if j >= int(x_i)]
    elif a == 2:
        x = [int(j) for j in x if j < int(x_i)]
    elif a == 3:
        y = [int(j) for j in y if j >= int(y_i)]
    elif a == 4:
        y = [int(j) for j in y if j < int(y_i)]

print((len(x)) * len(y))

Submission status: Wrong Answer

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

x = [int(i) for i in range(w+1)]
y = [int(i) for i in range(h+1)]

for i in range(n):
    x_i, y_i, a = map(int,input().split())
    if a == 1:
        x = [int(j) for j in x if j > int(x_i)]
    elif a == 2:
        x = [int(j) for j in x if j < int(x_i)]
    elif a == 3:
        y = [int(j) for j in y if j > int(y_i)]
    elif a == 4:
        y = [int(j) for j in y if j < int(y_i)]

print(len(x) * len(y))

Submission status: Wrong Answer

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

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

for i in range(n):
    if p[i][2]==1:
        minx=max(minx,p[i][0])
    if p[i][2]==2:
        maxx=min(maxx,p[i][0])
    if p[i][2]==3:
        miny=max(miny,p[i][1])
    if p[i][2]==4:
        maxy=min(maxy,p[i][1])
s=(maxx-minx)*(maxy-miny)
print(s if s>0 else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

w,h,n=list(map(int,input().split()))
x=[]
y=[]
a=[]

for i in range(n):
    x1,y1,a1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    a.append(a1)

loop=0
x_max=[0]
x_min=[w]
y_max=[0]
y_min=[h]

for aa in a:
    loop+=1
    if aa== 1:
        x_max.append(x[loop-1])

    elif aa==2:
        x_min.append(x[loop-1])

    elif aa==3:
        y_max.append(y[loop-1])

    elif aa==4:
        y_min.append(y[loop-1])

x=max(x_max)-min(x_min)
y=max(y_max)-min(y_min)

ans=x*y
if ans<=0:
    ans=0

print(ans)

Submission status: Wrong Answer

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

x_left = 0
x_right = w
y_top = h
y_bottom = 0

for i in range(n):
    a, b, c = map(int, input().split())
    if c == 1:
        x_left = a
    elif c == 2:
        x_right = a
    elif c == 3:
        y_bottom = b
    else:
        y_top = b

if x_left < x_right and y_bottom < y_top:
    print(abs(x_right - x_left) * abs(y_top - y_bottom))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
leftW,leftH=0,0
rightW,rightH=W,H

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1 and leftW<x:
        leftW=x
    elif a==2 and x<rightW:
        rightW=x
    elif a==3 and leftH<y:
        leftH=y
    elif a==4 and y<rightH:
        rightH=y
ans=(rightH-leftH)*(rightW-leftW)
if ans<1: print(0)
else: print(ans)

Submission status: Wrong Answer

Solution code:
W, H , N = list(map(int, input().split()))
W0 = 0
H0 = 0
X = []
Y = []
A = []
for i in range(N):
    x,y,a=[int(i) for i in input().split()]
    X.append(x)
    Y.append(y)
    A.append(a)
for j in range (N):
    if A[j] == 1:
        if X[j] >=  W0:
            W0 = X[j]
    elif A[j] == 2:
        if X[j] <= W:
            W = X[j]
    elif A[j] == 3:
        if Y[j] >= H0:
            H0 = Y[j]
    elif A[j] == 4:
        if Y[j] <= H:
            H = Y[j]
h = H - H0
w = W - W0
if h*w >= 0:
    print(h*w)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W, H , N = list(map(int, input().split()))
W0 = 0
H0 = 0
X = []
Y = []
A = []
for i in range(N):
    x,y,a=[int(i) for i in input().split()]
    X.append(x)
    Y.append(y)
    A.append(a)
for j in range (N):
    if A[j] == 1:
        if X[j]>W0:
            W0 = X[j]
    elif A[j] == 2:
        if X[j]<W:
            W = X[j]
    elif A[j] == 3:
        if Y[j]>H0:
            H0 = Y[j]
    elif A[j] == 4:
        if Y[j]<H:
            H = Y[j]
h = H - H0
w = W - W0
if h*w >= 0:
    print(h*w)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
x=[0]*N
y=[0]*N
a=[0]*N
H_min=0
H_max=H
W_min=0
W_max=W

for i in range(N):
  x[i],y[i],a[i] = map(int,input().split())
  if a[i]==1:
    W_min=x[i]
  elif a[i]==2:
    W_max=x[i]
  elif a[i]==3:
    H_min=y[i]
  else:
    H_max=y[i]

height = max(0,H_max-H_min)
width = max(0,W_max-W_min)
print(height*width)

Submission status: Wrong Answer

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

xl, xr, yb, yt = 0, w, 0, h

for i in range(n):
    if xya[i][2] == 1:
        xl = xya[i][0]
    elif xya[i][2] == 2:
        xr = xya[i][0]
    elif xya[i][2] == 3:
        yb = xya[i][1]
    else:
        yt = xya[i][1]

if xr - xl <= 0 or yt - yb <= 0:
    print(0)
else:
    print((xr - xl)*(yt - yb))

Submission status: Wrong Answer

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

xl, xr, yb, yt = 0, w, 0, w

for i in range(n):
    if xya[i][2] == 1:
        xl = xya[i][0]
    elif xya[i][2] == 2:
        xr = xya[i][0]
    elif xya[i][2] == 3:
        yb = xya[i][1]
    else:
        yt = xya[i][1]

if xr - xl <= 0 or yt - yb <= 0:
    print(0)
else:
    print(abs(xr - xl)*abs(yb - yt))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
area = h*w
a1=0
a2=w
a3=0
a4=h
for i in range(n):
  x,y,a = map(int,input().split())
  if a ==1:
    a1 = max(a1,x)
  elif a ==2:
    a2 = min(a2,x)
  elif a ==3:
    a3 = max(a3,y)
  elif a==4:
    a4 = min(a4,y)
#print(a1,a2,a3,a4)
area -= a1*h + (w-a2)*h + a3*w + (h-a4)*w 
if area<=0:
  print(0)
else:
  print(area-(a1*(a3+(h-a4))+(10-a2)*(a3+(h-a4))))

Submission status: Wrong Answer

Solution code:
W,H,N = list(map(int, input().split()))
p = [0] * 3
s = [0] * 2
e = [W, H]
for i in range(N):
    p = list(map(int, input().split()))
    if p[2] == 1:
        s[0] = p[0]
    elif p[2] == 2:
        e[0] = p[0]
    elif p[2] == 3:
        s[1] = p[1]
    elif p[2] == 4:
        e[1] = p[1]

if e[0] >= s[0] and e[1] >= s[1]:
    print((e[0] - s[0]) * (e[1] - s[1]))
else:
    print(0)

Submission status: Wrong Answer

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

x_left = 0
x_right = w
y_top = h
y_bottom = 0

for i in range(n):
    a, b, c = map(int, input().split())
    if c == 1:
        x_left = a
    elif c == 2:
        x_right = a
    elif c == 3:
        y_bottom = b
    else:
        y_top = b

if x_left < x_right and y_bottom < y_top:
    print((x_right - x_left) * (y_top - y_bottom))
else:
    print(0)

Submission status: Wrong Answer

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

My=h
Mx=w
my=0
mx=0
for x,y,a in xya:
    if a==1:mx=x
    if a==2:Mx=x
    if a==3:my=y
    if a==4:My=y

if Mx-mx<=0 or My-my<=0:print(0)
else:print((Mx-mx)*(My-my))

Submission status: Wrong Answer

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