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

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

max_x = W
min_x = 0
max_y = H
min_y = 0

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        min_x = max(min_x, x)
    elif a == 2:
        max_x = min(max_x, x)
    elif a == 3:
        min_y = max(min_y, y)
    else:
        max_y = min(max_y, y)

if max_x > min_x and max_y > min_y:
    print(max(0, (max_x - min_x) * (max_y - min_y)))
else:
    print(0)

Solution (Python):
nim,mike,kite=map(int,input().split())
x1=0
y1=0
x2=nim
y2=mike
for i in range(kite):
    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)
    elif a==4:
        y2=min(y2,y)
print(max(0,(x2-x1))*max(0,(y2-y1)))

Solution (Python):
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)

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

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

S = W*H
h = list(range(1, H+1))
w = list(range(1, W+1))
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        w = list(filter(lambda num: num > x, w))
    elif a == 2:
        w = list(filter(lambda num: num <= x, w))
    elif a == 3:
        h = list(filter(lambda num: num > y, h))
    else:
        h = list(filter(lambda num: num <= y, h))

print(len(w)*len(h))

Solution (Python):
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 = max(left,grid[i][0])
  elif grid[i][2] == 2:
    right = min(right,grid[i][0])
  elif grid[i][2] == 3:
    down = max(down,grid[i][1])
  elif grid[i][2] == 4:
    up = min(up,grid[i][1])
  
if (right>left)and(up>down):
  print((right-left)*(up-down))
else:
  print(0)

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

Solution (Python):
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 H < h or W < w:
    S = 0
print(S)

Solution (Python):
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
if wmax>wmin and hmax>hmin:
    print((wmax-wmin)*(hmax-hmin) )
else:
    print(0)

Solution (Python):
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)
print(ans if x0 < W and y0 < H else 0)

Solution (Python):
import numpy as np
def I(): return map(int,input().split())

w, h, n = I()
m = np.zeros((h, w), int)

while n:
    x, y, a = I()

    start = y * (a == 4)             
    end = y if (a == 3) else h       

    begin = x * (a == 2)             
    finish = x if (a == 1) else w    

    m[start:end, begin:finish] = 1
    n -= 1
print(h * w - m.sum())

Solution (Python):
x_max, y_max, N = map(int, input().split())
x_min, y_min = 0, 0
l = [[int(i) for i in 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)

Solution (Python):
W, H, n = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(n)]

min_x = 0
max_x = W
min_y = 0
max_y = H
for x, y, a in query:
    if a == 1:
        min_x = max(min_x, x)
    elif a == 2:
        max_x = min(max_x, x)
    elif a == 3:
        min_y = max(min_y, y)
    else:
        max_y = min(max_y, y)

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

Solution (Python):
W, H, N = list(map(int, input().split()))
floor = [[0 for row in range(W)] for col in range(H)]
for i in range(N):
  x, y, a = list(map(int, input().split()))
  if a == 1:
    for row in floor:
      for i in range(len(row[:x])):
        row[i] = 1
  elif a == 2:
    for row in floor:
      for i in range(len(row[x:])+x)[x:]:
        row[i] = 1
  elif a == 3:
    for (h, row) in enumerate(floor):
      if H-y < h+1:
        for i in range(len(row)):
          row[i] = 1
  elif a == 4:
    for (h, row) in enumerate(floor):
      if h < H-y:
        for i in range(len(row)):
          row[i] = 1
res = 0
for row in floor:
  res += row.count(0)
print(res)

Solution (Python):


from sys import stdin

w, h, n = map(int, stdin.readline().rstrip().split())

data = [list(map(int, stdin.readline().rstrip().split())) for i in range(n)]

l, r = 0, w
d, u = 0, h
for di in data:
    if di[2] == 1:
        if l < di[0]:
            l = di[0]
    elif di[2] == 2:
        if r > di[0]:
            r = di[0]
    elif di[2] == 3:
        if d < di[1]:
            d = di[1]
    else:
        if u > di[1]:
            u = di[1]


if (r - l) <= 0 or (u - d) <= 0:
    print(0)
else:
    print((r - l)*(u - d))

Solution (Python):
import numpy as np


w, h, n = map(int, input().split())
v = np.zeros((h, w), dtype=np.int)
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        v[:, :x] = 1
    elif a == 2:
        v[:, x:] = 1
    elif a == 3:
        v[:y, :] = 1
    else:
        v[y:, :] = 1
print(w*h-np.sum(v))

Solution (Python):
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, H):
                for j in range(W):
                    area[i][j] = 1
        elif a == 4:
            for i in range(H - y):
                for j in range(W):
                    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()

Solution (Python):
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, H):
                for j in range(W):
                    area[i][j] = 1
            
            
        elif a == 4:
            for i in range(H - y):
                for j in range(W):
                    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)

def dump(area, H, W):
    for i in range(H):
        for j in range(W):
            print(str(area[i][j]) + " ", end="")
        print()

main()

Solution (Python):
W, H, N = map(int, input().split())
li = []
for i in range(N):
  li.append(list(map(int, input().split())))

a1, a2, a3, a4 = [], [], [], []

for i in range(N):
  if li[i][2] == 1:
    a1.append(li[i])
  elif li[i][2] == 2:
    a2.append(li[i])
  elif li[i][2] == 3:
    a3.append(li[i])
  elif li[i][2] == 4:
    a4.append(li[i])

a1XMAX, a2Xmin, a3YMAX, a4Ymin = 0, W, 0, H
    
if a1 == []:
  pass
else:
  for i in range(len(a1)):
    a1XMAX = max(a1[i][0], a1XMAX)

if a2 == []:
  pass
else:
  for i in range(len(a2)):
    a2Xmin = min(a2[i][0], a2Xmin)
    
if a3 == []:
  pass
else:
  for i in range(len(a3)):
    a3YMAX = max(a3[i][1], a3YMAX)

if a4 == []:
  pass
else:
  for i in range(len(a4)):
    a4Ymin = min(a4[i][1], a4Ymin)

if a1XMAX >= a2Xmin or a3YMAX >= a4Ymin:
  result = 0
  print(result)
  exit()
else:
  result = (a2Xmin - a1XMAX) * (a4Ymin - a3YMAX)
  print(result)

Solution (Python):
w, h, n = map(int, input().split())
rect = [[1 for _ in range(w)] for _ in range(h)]
def drawx(x, y):
    for i in range(x):
        for j in range(y):
            rect[j][i] = 0

def drawy(x, y):
    for i in range(x, w):
        for j in range(y, h):
            rect[j][i] = 0

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        drawx(x, h)
    elif a == 2:
        drawy(x, 0)
    elif a == 3:
        drawx(w, y)
    else:
        drawy(0, y)
print(sum(sum(rect, [])))

Solution (Python):
def solve():
    W, H, N = map(int,input().split())
    area = [[True] * W for i in range(H)]
    for i in range(N):
        x,y,a = map(int,input().split())
        x -= 1
        y -= 1

        if a == 1:
            for h in range(H):
                for w in range(W):
                    if w > x:
                        continue
                    area[h][w] = False
        elif a == 2:
            for h in range(H):
                for w in range(W):
                    if w <= x:
                        continue
                    area[h][w] = False
        elif a == 3:
            for h in range(H):
                if h > y:
                    continue
                for w in range(W):
                    area[h][w] = False
        else:
            for h in range(H):
                if h <= y:
                    continue
                for w in range(W):
                    area[h][w] = False
        

    cnt = 0
    for h in range(H):
        for w in range(W):
            if area[h][w]:
                cnt += 1
    print(cnt)

if __name__ == '__main__':
    solve()

Solution (Python):
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)



print(ans if x0 < W and y0 < H else 0)

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

m = [[0]*(w) for i in range(h)]

for i in range(n):
  x, y, a = map(int, input().split())
  x -= 1
  y -= 1
  if a==1:
    for ii in range(h):
      for jj in range(w):
        if jj<=x:
          m[ii][jj] = 1
  if a==2:
    for ii in range(h):
      for jj in range(w):
        if jj>x:
          m[ii][jj] = 1
  if a==3:
    for ii in range(h):
      for jj in range(w):
        if ii<=y:
          m[ii][jj] = 1
  if a==4:
    for ii in range(h):
      for jj in range(w):
        if ii>y:
          m[ii][jj] = 1
          
cum = sum([sum(m[i]) for i in range(h)])

print(h*w-cum)

Solution (Python):
w,h,n = map(int,input().split())
xika=[0]
xijo=[w]
yika=[0]
yijo=[h]
x = 0
for x in range (n):
    listA = list(map(int,input().split()))
    if listA[2] == 1:
        xika.append(listA[0])
    elif listA[2] == 2:
        xijo.append(listA[0])
    elif listA[2] == 3:
        yika.append(listA[1])
    else:
        yijo.append(listA[1])
    x += 1
xika.sort()
xijo.sort()
yika.sort()
yijo.sort()
if xika[-1]>xijo[0] or yika[-1]>yijo[0]:
    print(0)
else:
    print((xijo[0]-xika[-1])*(yijo[0]-yika[-1]))

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

min_x = 0
min_y = 0
max_x = W
max_y = H

width = max_x - min_x
height = max_y - min_y

for n in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        if min_x < x:
            min_x = x
    elif a == 2:
        if max_x > x:
            max_x = x
    elif a == 3 :
        if min_y < y:
            min_y = y
    else :
        if max_y > y:
            max_y = y
    
if min_x >= max_x or min_y >= max_y:
    output = 0
else:
    output = (max_x - min_x) * (max_y - min_y)

print(output)

Solution (Python):
w,h,n = map(int,input().split())
ab = [-1]*2
cd = [10000]*2
for _ in range(n):
    x, y, a = (int(x) for x in input().split())
    if a == 1:
        ab[0] = max(ab[0],x)
    elif a == 3:
        ab[1] = max(ab[1],y)
    elif a == 2:
        cd[0] = min(cd[0],x)
    elif a == 4:
        cd[1] = min(cd[1],y)

if ab[0] != -1 and cd[0] != 10000:
    if cd[0] <= ab[0]:
        yoko = 0
    else:
        yoko = cd[0]-ab[0]
elif ab[0] != -1:
    yoko = w-ab[0]
elif cd[0] != 10000:
    yoko = cd[0]
else:
    yoko = w

if ab[1] != -1 and cd[1] != 10000:
    if cd[1] <= ab[1]:
        tate = 0
    else:
        tate = cd[1]-ab[1]
elif ab[1] != -1:
    tate = h-ab[1]
elif cd[1] != 10000:
    tate = cd[1]
else:
    tate = h

print(yoko*tate)

Solution (Python):
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] = max(d[0],x)
    elif a == 2:
        d[1] = min(d[1],x)
    elif a == 3:
        d[2] = max(d[2],y)
    else:
        d[3] = min(d[3],y)
print(max(0,(d[1]-d[0]))*max(0,(d[3]-d[2])))

Solution (Python):
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]=min(max(x,leftdown[0]),righttop[0])
    elif a==2:
        righttop[0]=max(min(x,righttop[0]),leftdown[0])
    elif a==3:
        leftdown[1]=min(max(y,leftdown[1]),righttop[1])
    else:
        righttop[1]=max(min(y,righttop[1]),leftdown[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])))

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    W, H, N = map(int, input().split())
    xmin, xmax, ymin, ymax = 0, W, 0, H
    for i in range(N):
        x, y, a = map(int, input().split())
        if a == 1:
            xmin = max(xmin, x)
        elif a == 2:
            xmax = min(xmax, x)
        elif a == 3:
            ymin = max(ymin, y)
        elif a == 4:
            ymax = min(ymax, y)

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


if __name__ == "__main__":
    main()

Solution (Python):
W, H, N = map(int, input().split())
left = 0
right = W
down = 0
up = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 2:
        right = min(right, x)
    if a == 1:
        left = max(left, x)
    if a == 3:
        down = max(down, y)
    if a == 4:
        up = min(up, y)

if right >= left and up >= down:
    print((right-left)*(up-down))
else:
    print(0)

Solution (Python):

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

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

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

    if a == 1:
        x_min.append(x)
    elif a == 2:
        x_max.append(x)
    elif a == 3:
        y_min.append(y)
    elif a == 4:
        y_max.append(y)

width = min(x_max) - max(x_min)
height = min(y_max) - max(y_min)
print(width * height if width >= 0 and height >= 0 else 0)

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

l, r, b, t = 0, w, 0, h
for i in range(n):
    if p[i][2] == 1:
        l = max(l, p[i][0])
    if p[i][2] == 2:
        r = min(r, p[i][0])
    if p[i][2] == 3:
        b = max(b, p[i][1])
    if p[i][2] == 4:
        t = min(t, p[i][1])

W = r-l if r > l else 0
H = t-b if t > b else 0
print(W*H)

Solution (Python):
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
area = W * H
X = [0] * W
Y = [0] * H
for x, y, a in xya:
    if a == 1:
        for i in range(x):
            X[i] = 1
    elif a == 2:
        for i in range(x, W):
            X[i] = 1
    elif a == 3:
        for i in range(y):
            Y[i] = 1
    elif a == 4:
        for i in range(y, H):
            Y[i] = 1
print(X.count(0) * Y.count(0))

Solution (Python):
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 = max(x, Wmin)
    if z == 2:
        Wmax = min(x, Wmax)
    if z == 3:
        Hmin = max(y, Hmin)
    if z == 4:
        Hmax = min(y, Hmax)
if Wmax < Wmin or  Hmax < Hmin:
    print(0)
else:
    print((Wmax-Wmin)*(Hmax-Hmin))

Solution (Python):
w,h,n = map(int,input().split())
a_1 = [0]
a_2 = [0]
a_3 = [0]
a_4 = [0]
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    a_1.append(x)
  if a==2:
    a_2.append(w-x)
  if a==3:
    a_3.append(y)
  if a==4:
    a_4.append(h -y)
if w - (max(a_1) + max(a_2))<=0:
  print(0)
elif h - (max(a_3) + max(a_4))<=0:
  print(0)
else:
  print((w - (max(a_1) + max(a_2))) * (h - (max(a_3) + max(a_4))))

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

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

P=[[1 for i in range(h)] for j in range(w)]

for i in range(n):
  x,y,a=map(int,input().split())
  
  if a==1:
    for k in range(x):
      for l in range(h):
        P[k][l]=0
  
  elif a==2:
    for k in range(x,w):
      for l in range(h):
        P[k][l]=0
  
  elif a==3:
    for k in range(w):
      for l in range(y):
        P[k][l]=0
  
  else:
    for k in range(w):
      for l in range(y,h):
        P[k][l]=0
         
ans=0
for g in range(w):
  for f in range(h):
    ans+=P[g][f]
print(ans)

Solution (Python):
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 = max(i[0], left)
    elif i[2]==2:
        right = min(i[0], right)
    elif i[2]==3:
        down = max(i[1], down)
    else:
        up = min(i[1], up)

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

Solution (Python):
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 = min(W, xya[i][0])
    elif xya[i][2] == 3:
        ys = max(ys, xya[i][1])
    else:
        H = min(H, xya[i][1])
if W - xs <= 0 or H - ys <= 0:
    print(0)
else:
    print((W - xs) * (H - ys))

Solution (Python):



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:
        lx = max(lx, x)
    elif a == 2:
        rx = min(rx, x)
    elif a == 3:
        dy = max(dy, y)
    else:
        uy = min(uy, y)

if rx >= lx and uy >= dy:
    print((uy - dy) * (rx - lx))
else:
    print(0)

Solution (Python):
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)

if tW - minx >= 0 and tH - miny >= 0:
    print((tW - minx) * (tH - miny))
else:
    print(0)

Solution (Python):
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)}
s, t = len(w)-1, len(h)-1
print(0 if s<0 or t<0 else s*t)

Solution (Python):
W,H,N=map(int,input().split())
x1=y1=0
x2,y2=W,H
for i in range(N):
  x,y,a=map(int,input().split())
  if a==1: x1=min(x2,max(x1,x))
  elif a==2: x2=max(x1,min(x2,x))
  elif a==3: y1=min(y2,max(y1,y))
  else: y2=max(y1,min(y2,y))
print((x2-x1)*(y2-y1))

Solution (Python):
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] = max(x,x_axis[0])
    elif a == 2:
        x_axis[1] = min(x, x_axis[1])
    elif a == 3:
        y_axis[0] = max(y,y_axis[0])
    else:
        y_axis[1] = min(y, y_axis[1])
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)

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

left=0
right=W
top=H
bottom=0
for el in xya:
    if el[2]==1:
        if left<el[0]:
            left=el[0]
    if el[2]==2:
        if right>el[0]:
            right=el[0]
    if el[2]==3:
        if bottom<el[1]:
            bottom=el[1]
    if el[2]==4:
        if top>el[1]:
            top=el[1]
    
if left<right and bottom<top:
    print((right-left) * (top-bottom))
else:
    print(0)

Solution (Python):




"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""






def main():
  w,h,n = map(int,input().split())
  rec = [[0] * w for _ in range(h)] 
  
  
  
  
  
  for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
      for i in range(h):
        for j in range(0,x):
          
          rec[i][j] = 1 
    elif a == 2:
       for i in range(h):
        for j in range(x,w):
          
          rec[i][j] = 1 
    elif a == 3:
       for i in range(0,y):
        for j in range(w):
          
          rec[i][j] = 1 
    if a == 4:
      
      for i in range(y,h):
        for j in range(w):
          
          rec[i][j] = 1 
      
      
      
  
  """for i in range(h):
    
    print('{}'.format(rec[i]))"""
  
  
  sx,sy,gx,gy = -1,-1,-1,-1 
  flag = False
  for j in range(w): 
    for i in range(h): 
      if (not flag) and rec[i][j] == 0:
        flag = True
        sx,sy = j,i
      
      
      
      if flag:
        if rec[i][j] == 0:
          gx,gy = j,i
        """if j+1<w:
          if rec[i][j+1] == 1:
            if i+1<h:
              if rec[i+1][j] != 0:
                print(j+1,i)
                gx,gy = j+1,i
                continue
              else:
                pass
            else:
              gx,gy = j+1,i
              break
        else:
          if i+1<h:
            if rec[i+1][j] == 1:
              gx,gy = j,i+1
              continue"""
          
  
  if gx==sx==-1 and sy==gy==-1:
    print(0)
    exit()
  print((gx-sx+1)*(gy-sy+1))
  
if __name__ == '__main__':
  main()

Solution (Python):
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])*max(0,p[3]-p[2]))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Solution (Python):
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


if __name__ == '__main__':
    w, h,n = map(int, input().split())
    ans = []

    for i in range(h):
        s = [1]*w
        ans.append(s)
    for i in range(n):
        a, b, c = map(int, input().split())
        if c == 1:
           for j in range(0,h):
               for k in range(0,a):
                   ans[j][k] =0
        if c == 2:
           for j in range(0,h):
               for k in range(a,w):
                   ans[j][k] =0
        if c == 3:
           for j in range(0,b):
               for k in range(0,w):
                   ans[j][k] =0
        if c == 4:
           for j in range(b,h):
               for k in range(0,w):
                   ans[j][k] =0

    s = 0
    for  i in ans:
        for j in i:
            s += j

    print(s)

Solution (Python):
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])*max(0,p[3]-p[2]))

Solution (Python):
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)

Solution (Python):
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]))

Solution (Python):

from collections import Counter
def inputlist(): return [int(j) for j in input().split()]

W,H,N = inputlist()
flag = [[True]*(H+1) for _ in range(W+1)]
def search(x,y,a):
    if a == 3:
        for i in range(W+1):
            for j in range(y+1):
                flag[i][j] = False
    if a == 4:
        for i in range(W+1):
            for j in range(y+1,H+1):
                flag[i][j] = False
    if a == 2:
        for i in range(x+1,W+1):
            for j in range(H+1):
                flag[i][j] = False
    if a == 1:
        for i in range(x+1):
            for j in range(H+1):
                flag[i][j] = False
for i in range(N):
    x,y,a = inputlist()
    search(x,y,a)
ans = 0
for i in range(1,W+1):
    for j in range(1,H+1):
        if flag[i][j]:
            ans +=1
print(ans)

Solution (Python):
W, H ,N = [int(i) for i in input().split()]
X = [0, W]
Y = [0, H]
for _ in range(N):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        X = [max(X[0], x), X[1]]
        if X[0] >= X[1]:
            break
    elif a == 2:
        X = [X[0], min(X[1], x)]
        if X[0] >= X[1]:
            break
    elif a == 3:
        Y = [max(Y[0], y), Y[1]]
        if Y[0] >= Y[1]:
            break
    else:
        Y = [Y[0], min(Y[1], y)]
        if Y[0] >= Y[1]:
            break
print(max(0, X[1] - X[0]) * max(0, Y[1] - Y[0]))

Solution (Python):
W,H,N = map(int, input().split())
x_M,x_m = 0,W
y_M,y_m = 0,H
for i in range(N):
    x,y,a  = map(int, input().split())
    
    if a == 1:
        x_M = max(x_M, x)
    elif a == 2:
        x_m = min(x_m, x)
    elif a == 3:
        y_M = max(y_M, y)
    else:
        y_m = min(y_m, y)

ans = max(0,x_m-x_M)*max(0,y_m-y_M)
print(ans)

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

array =[[0] * w for i in range(h)]

for i in range(n):
  x,y,a = map(int, input().split())
  
  if a==1:
    for j in range(h):
      for k in range(x):
        array[j][k] = 1
  elif a==2:
    for j in range(h):
      for k in range(w-x):
        array[j][w-1-k] = 1
  elif a==3:
    for j in range(y):
      array[j] = [1]*w
  elif a==4:
    for j in range(h-y):
      array[h-1-j] = [1]*w

cnt = 0
for i in range(h):
  for j in range(w):
    if array[i][j] == 0:
      cnt += 1
      
print(cnt)