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):
from sys import stdin
input = stdin.readline
import copy as cp
from collections import deque

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

def Decimal(x):
  print("{0:.10f}".format(x))

class Pair:
  def __init__(self, x=0, y=0):
    self.first = x
    self.second = y

  def __repr__(self):
    return '{0} {1}'.format(self.first, self.second)

  def __lt__(self, pi):
    return self.first < pi.second

def POW(x, n):
  ret = 1
  while n:
    if n&1:
      ret *= x
    x *= x
    n >>= 1
  return ret

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

grid = VVI(H, W)
for _ in range(N):
  x, y, a = map(int, input().rstrip().split())
  if a == 1:
    for xx in range(x):
      for yy in range(H):
        grid[yy][xx] = 1
  elif a == 2:
    for xx in range(x, W):
      for yy in range(H):
        grid[yy][xx] = 1
  elif a == 3:
    for xx in range(W):
      for yy in range(y):
        grid[yy][xx] = 1
  elif a == 4:
    for xx in range(W):
      for yy in range(y, H):
        grid[yy][xx] = 1

ans = 0
for xx in range(W):
  for yy in range(H):
    ans += grid[yy][xx]

ans = H*W-ans

print(ans)

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        l = max(l, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        b = max(b, y)
    else:
        h = min(h, y)

print(max(h - b, 0)*max(w - l, 0))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

W, H, N = MAP()

w, h = np.zeros(W), np.zeros(H)

for _ in range(N):
	x, y, a = MAP()
	if a == 1:
		w[:x] = 1
	elif a == 2:
		w[x:] = 1
	elif a == 3:
		h[:y] = 1
	elif a == 4:
		h[y:] = 1

print(list(w).count(0) * list(h).count(0))

Solution (Python):
import numpy as np

W,H,N=map(int,input().split())
T=[list(map(int,input().split())) for i in range(1,N+1)]

result=np.zeros((H,W))

for i in range(0,N):
    x,y,a=T[i]

    if a==1:
        result[:,:x]=1

    elif a==2:
        result[:,x:]=1

    elif a==3:
        result[:y,:]=1

    elif a==4:
        result[y:,:]=1
    
print(np.count_nonzero(result==0))

Solution (Python):
w, h, n = map(int, input().split())
high = h
low = 0
left = 0
right = w


for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        low = max(low, y)
    else:
        high = min(high, y)

print(max(high - low, 0)*max(right - left, 0))

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

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

for i in range(N):
    if xya[i][2] == 1:
        x_max.append(xya[i][0])
    if xya[i][2] == 2:
        x_min.append(xya[i][0])
    if xya[i][2] == 3:
        y_max.append(xya[i][1])
    if xya[i][2] == 4:
        y_min.append(xya[i][1])

x_1 = max(x_max)
x_2 = min(x_min)
y_3 = max(y_max)
y_4 = min(y_min)

if x_2 - x_1 > 0 and y_4 - y_3 > 0:
    print((x_2 - x_1) * (y_4 - y_3))
else :
    print(0)

Solution (Python):
w,h,n = map(int,input().split())
q = [[0],[w],[0],[h]]
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1 or a == 2:
        q[a-1].append(x)
    else:
        q[a-1].append(y)
if max(q[0]) >= min(q[1]) or max(q[2]) >= min(q[3]):
    print(0)
else:
    print((min(q[1])-max(q[0]))*(min(q[3])-max(q[2])))

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

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

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    left = max(left, x)
  elif a == 2:
    right = min(right, x)
  elif a == 3:
    bottom = max(bottom, y)
  else:
    top = min(top, y)
    
print(max(0, (right-left)) * max(0, (top-bottom)))

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

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

d = l = 0
u = h
r = w

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        l = max(l, x)
    elif a == 2:
        r = min(r, x)
    elif a == 3:
        d = max(d, y)
    else:
        u = min(u, y)

print(max(0, u - d) * max(0, r - l))

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

w0 = 0
h0 = 0

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

for i in c:
    if i[2] == 2:
        if i[0] < w:
            w = i[0]
    elif i[2] == 1:
        if i[0] > w0:
            w0 = i[0]
    elif i[2] == 4:
        if i[1] < h:
            h = i[1]
    elif i[2] == 3:
        if i[1] > h0:
            h0 = i[1]

w = w - w0 
if w < 0:
    w = 0
h = h - h0
if h < 0:
    h = 0
print(w*h)

Solution (Python):
W,H,N = map(int,input().split())
x_r = W
x_l = 0
y_r = H
y_l = 0

for _ in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        x_l = max(x,x_l)
    elif a == 2:
        x_r = min(x,x_r)
    elif a == 3:
        y_l = max(y,y_l)
    else:
        y_r = min(y,y_r)


print(max(0,(x_r-x_l))*max(0,(y_r-y_l)))

Solution (Python):
def ABC_47_B():
    W,H,N = map(int, input().split())
    al=[]
    bl=[]
    cl=[]
    dl=[]

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

        if a == 1:
            al.append(x)
        elif a == 2:
            bl.append(x)
        elif a ==3:
            cl.append(y)
        else:
            dl.append(y)
    
    if len(al) != 0:
        at= max(al)
    else:
        at=0
    if len(bl) != 0:
        bt= min(bl)
    else:
        bt=W
    if len(cl) != 0:
        ct= max(cl)
    else:
        ct=0
    if len(dl) != 0:
        dt= min(dl)
    else:
        dt=H
    

    if (bt-at) >= 0 and (dt-ct) >=0:
        s = (bt-at)*(dt-ct)
    else:
        s = 0


    print(s)

if __name__ == '__main__':

    ABC_47_B()

Solution (Python):
W,H,N = map(int, input().split())
bottom = [0, 0]
top = [W,H]

for _ in range(N):
    x,y,a = map(int, input().split())
    if a==1:
        bottom[0] = max(bottom[0], x)
    elif a==2:
        top[0] = min(top[0], x)
    elif a==3:
        bottom[1] = max(bottom[1], y)
    elif a==4:
        top[1] = min(top[1], y)

print(max(0, top[0]-bottom[0])*max(0,top[1]-bottom[1]))

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

Solution (Python):
import numpy as np
w, h, n = map(int, input().split())

field = np.ones([h, w], dtype=int)

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

print(field.sum())

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

mat=[[True]*H for _ in range(W)]


for _ in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    for i in range(x):
      for j in range(H):
        mat[i][j]=False
  elif a==2:
    for i in range(x,W):
      for j in range(H):
        mat[i][j]=False
  elif a==3:
    for i in range(W):
      for j in range(y):
        mat[i][j]=False
  elif a==4:
    for i in range(W):
      for j in range(y,H):
        mat[i][j]=False


answer=0
for i in range(W):
  for j in range(H):
    if mat[i][j]:
      answer+=1
      
print(answer)

Solution (Python):
w,h,n = list(map(int, input().split()))
data = [list(map(int, input().split())) for _ in range(n)]
x1 = y1 = 0
x2,y2 = w,h
for x,y,a in data:
    if a==1:
        x1=max(x1, x)
    elif a==2:
        x2=min(x2, x)
    elif a==3:
        y1=max(y1, y)
    else:
        y2=min(y2, y)
print(max(x2-x1,0)*max(y2-y1,0))

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

Solution (Python):
W, H, N = map(int, input().split())
grid = [[0] * W for _ in range(H)]
for _ in range(N):
    xi, yi, a = map(int, input().split())
    X = range(W)
    Y = range(H)
    if a in (1, 2):
        X = range(xi) if a == 1 else range(xi, W)
    elif a in (3, 4):
        Y = range(yi) if a == 3 else range(yi, H)
    for x in X:
        for y in Y:
            grid[y][x] |= 1
print(sum(map(lambda x: x.count(0), grid)))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    w, h, n = MI()
    tt = [[1] * w for _ in range(h)]
    for _ in range(n):
        x, y, a = MI()
        if a == 1: i0, i1, j0, j1 = 0, h, 0, x
        if a == 2: i0, i1, j0, j1 = 0, h, x, w
        if a == 3: i0, i1, j0, j1 = 0, y, 0, w
        if a == 4: i0, i1, j0, j1 = y, h, 0, w
        for i in range(i0, i1):
            for j in range(j0, j1):
                tt[i][j] = 0
    ans=sum(sum(row) for row in tt)
    print(ans)

main()

Solution (Python):
from pprint import pprint
width, height, n = map(int, input().split())
rect = [[True for i in range(width)] for j in range(height)]
for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        for y_counter in range(height):
            x_counter = 0
            while x_counter < x:
                rect[y_counter][x_counter] = False
                x_counter += 1
    elif a == 2:
        for y_counter in range(height):
            x_counter = x
            while x_counter < width:
                rect[y_counter][x_counter] = False
                x_counter += 1
    elif a == 3:
        y_counter = 0
        while y_counter < y:
            for x_counter in range(width):
                rect[y_counter][x_counter] = False
            y_counter += 1
            
    elif a == 4:
        y_counter = y
        while y_counter < height:
            for x_counter in range(width):
                rect[y_counter][x_counter] = False
            y_counter += 1
count = 0
for i in rect:
    for j in i:
        if j == True:
            count += 1
print(count)

Solution (Python):
def main():
  n = list(map(int,input().split()))
  x_ans=[0,n[0]]
  y_ans=[0,n[1]] 
  x = [0] * n[2]
  y = [0] * n[2]
  t = [0] * n[2]
  for i in range(n[2]):
    x[i], y[i],t[i] = map(int, input().split())
  for i in range(0,n[2]):
    if t[i]==1 and x_ans[0]<x[i]:
      x_ans[0]=x[i]
    elif t[i]==2 and x[i]<x_ans[1]:
      x_ans[1]=x[i]
    elif t[i]==3 and y_ans[0]<y[i]:
      y_ans[0]=y[i]
    elif t[i]==4 and y[i]<y_ans[1]:
      y_ans[1]=y[i]
  if x_ans[0]>x_ans[1] or y_ans[0]>y_ans[1]:
    print(0)
  else:
    print((x_ans[1]-x_ans[0])*(y_ans[1]-y_ans[0]))
     
main()

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

for x,y,a in xya:
    if a==1:
        for i in range(x):
            for j in range(H):
                b[j][i]=1
    elif a==2:
        for i in range(x,W):
            for j in range(H):
                b[j][i]=1
    elif a==3:
        for i in range(y):
            for j in range(W):
                b[i][j]=1
    else:
        for i in range(y,H):
            for j in range(W):
                b[i][j]=1
res = H*W
for row in b:
    res -= sum(row)
print(res)

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

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

w1 = 0
w2 = w
h1 = 0
h2 = h
for x, y, a in xya:
    if a == 1:
        w1= max(w1, x)
    if a == 2:
        w2 = min(w2, x)
    if a == 3:
        h1 = max(h1, y)
    if a == 4:
        h2 = min(h2, y)
        
print(max(0, (w2-w1))*max(0, (h2-h1)))

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

field = [[1 for _ in range(w)] for _ in range(h)]

for x, y, a in xya:
        for i in range(h):
             for j in range(w):
                    if a == 1 and j < x:
                        field[i][j] = 0
                    if a == 2 and j >= x:
                        field[i][j] = 0
                    if a == 3 and i < y:
                        field[i][j] = 0
                    if a == 4 and i >= y:
                        field[i][j] = 0

ans = 0
for i in field:
    ans += sum(i)
print(ans)

Solution (Python):
import numpy as np
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]

field = [[1 for _ in range(w)] for _ in range(h)]

for x, y, a in xya:
        for i in range(h):
             for j in range(w):
                    if a == 1 and j < x:
                        field[i][j] = 0
                    if a == 2 and j >= x:
                        field[i][j] = 0
                    if a == 3 and i < y:
                        field[i][j] = 0
                    if a == 4 and i >= y:
                        field[i][j] = 0

print(sum(sum(np.array(field))))

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





W,H,N = IL()

l = [[1]*W for i in range(H)]

for _ in range(N):
  x,y,t = IL()
  
  if t==1:
    for i in range(H):
      for j in range(x):
        l[i][j] = 0
  if t==2:
    for i in range(H):
      for j in range(W-x):
        l[i][W-1-j] = 0
  if t==4:
    for i in range(y,H):
      l[i] = [0]*W
  if t==3:
    for i in range(y):
      l[i] = [0]*W

P(sum(sum(l[i]) for i in range(H)))

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

d = [[0], [W], [0], [H]]

for x, y, a in xya:
    if a == 1 or a == 2:
        d[a-1] += [x]
    else:
        d[a-1] += [y]

if min(d[1]) - max(d[0]) > 0 and min(d[3]) - max(d[2]) > 0:
    ret = (min(d[1]) - max(d[0])) * ( min(d[3]) - max(d[2]))
    print(max(ret, 0))
else:
    print(0)

Solution (Python):
W,H,N = map(int, input().split())
l = 0
r = W
row = 0
up = H
for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        if x > l:
            l = x
    elif a == 2:
        if x < r:
            r = x
    elif a == 3:
        if y > row:
            row = y
    elif a == 4:
        if y < up:
            up = y
print(max(max((r-l),0)*max((up-row),0),0))

Solution (Python):
w,h,n = [int(x) for x in input().split()]
xy = []
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    xy.append(tmp)

r = w
u = h
l = 0
b = 0

for z in xy:
    if z[2] == 1:
        l = max(l, z[0])
    elif z[2] == 2:
        r = min(r, z[0])
    elif z[2] == 3:
        b = max(b, z[1])
    elif z[2] == 4:
        u = min(u, z[1])

if (r-l) < 0 and (u-b) < 0:
    print(0)
else:
    print(max((r-l)*(u-b), 0))

Solution (Python):
w,h,n=map(int, input().split())
xl=0
xr=w
yd=0
yu=h
for _ in range(n):
    x,y,a=map(int, input().split( ))
    if a==1:
        xl=max(xl,x)
    elif a==2:
        xr=min(xr,x)
    elif a==3:
        yd=max(yd,y)
    else:
        yu=min(yu,y)
ans=max(xr-xl,0)*max(yu-yd,0)
print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    W,H,N=map(int,input().split())
    c=[[1]*W for _ in range(H)]
    for _ in range(N):
        x,y,a=map(int,input().split())
        if a==1:
            for i in range(x):
                for j in range(H):
                    c[j][i]=0
        if a==2:
            for i in range(x,W):
                for j in range(H):
                    c[j][i]=0
        if a==3:
            for i in range(W):
                for j in range(y):
                    c[j][i]=0
        if a==4:
            for i in range(W):
                for j in range(y,H):
                    c[j][i]=0
    print(sum(sum(c,[])))

if __name__ == '__main__':
    main()

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

Solution (Python):
W, H, N = map(int, input().strip().split(" "))
paint = [0] * 4
paint[0] = -1
paint[1] = W
paint[2] = -1
paint[3] = H

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

s = 0
for x in range(W):
    for y in range(H):
        if x >= paint[0] and x < paint[1] and y >= paint[2] and y < paint[3]:
            s += 1

print(s)

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    w, h, n = mi()
    xmin, xmax, ymin, ymax = 0, w, 0, h

    for _ in range(n):
        x, y, a = mi()
        if a == 1:
            xmin = max(xmin, x)
        elif a == 2:
            xmax = min(xmax, x)
        elif a == 3:
            ymin = max(ymin, y)
        else:
            ymax = min(ymax, y)
        
    if xmin >= xmax or ymin >= ymax:
        print(0)
    else:
        print((xmax - xmin) * (ymax - ymin))


if __name__ == "__main__":
    main()

Solution (Python):
h,w,n = map(int,input().split())
d = {1:0,2:h,3:0,4:w}
for _ in range(n):
  x,y,a = map(int,input().split())
  if a %2:
    d[a] = max(d[a],[x,y][a//2]) 
  else:
    d[a] = min(d[a],[x,y][a//2-1])

if d[1] > d[2] or d[3] > d[4]:
  print(0)
else:
  ans = (d[2]-d[1]) * (d[4]-d[3])
  print(ans)

Solution (Python):
w, h, n = map(int, input().split())
min_x, min_y, max_x, max_y = 0, 0, w, h
for _ in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    min_x = max(x, min_x)
  elif a == 2:
    max_x = min(x, max_x)
  elif a == 3:
    min_y = max(y, min_y)
  else:
    max_y = min(y, max_y)
s = (max_x - min_x if max_x >= min_x else 0) * (max_y - min_y if max_y >= min_y else 0)
print(s)

Solution (Python):
W,H,N=list(map(int,input().split()))
l=[[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(x):
         for k in range(H):
            l[k][j] = 1
   elif a == 2:
      for j in range(x,W):
         for k in range(H):
            l[k][j] = 1
   elif a == 3:
      for j in range(0,y):
         l[j] = [1]*W
   elif a == 4:
      for j in range(y,H):
         l[j] = [1]*W
ans=W*H
for i in range(H):
   ans-=l[i].count(1)
print(ans)

Solution (Python):
import numpy as np
W, H, N = map(int, input().split())

grid = np.array([[1] * W for _ in range(H)])

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

    if a == 1:
        grid[:, :x] = 0
    elif a == 2:
        grid[:, x:] = 0
    elif a == 3:
        grid[:y, :] = 0
    else:
        grid[y:, :] = 0

print(np.count_nonzero(grid.ravel()))

Solution (Python):
w,h,n = map(int, input().split())
min_x, max_x, min_y, max_y = 0, w, 0, h
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)
print((max_x-min_x if max_x>=min_x else 0)*(max_y-min_y if max_y>=min_y else 0))

Solution (Python):
w,h,n = map(int,input().split())
x_li = [0]*n
y_li = [0]*n
a_li = [0]*n
for i in range(n):
    x_li[i],y_li[i],a_li[i] = map(int,input().split())

sx,sy = 0,0
gx,gy = w,h
for i in range(n):
    a,x,y = a_li[i],x_li[i],y_li[i]
    if a==1:
        sx=max(sx,x)
    if a==2:
        gx=min(gx,x)
    if a==3:
        sy=max(sy,y)
    if a==4:
        gy=min(gy,y)
x = max(0,gx-sx)
y = max(0,gy-sy)
print(x*y)

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

Solution (Python):
w,h,n = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(n)]
 
xmin,xmax,ymin,ymax = 0,w,0,h
 
for a in A:
  if a[2] == 1:
    xmin = max(xmin, a[0])
  if a[2] == 2:
    xmax = min(xmax, a[0])
  if a[2] == 3:
    ymin = max(ymin, a[1])
  if a[2] == 4:
    ymax = min(ymax, a[1])
    
S = (xmax-xmin) * (ymax-ymin)
if S < 0 or xmin > xmax or ymin > ymax:
  S = 0
print(S)

Solution (Python):

W, H, N = map(int, input().split())
area = [[1] * H for i in range(W)]

def fill(x0, y0, x1, y1):
    for j in range(x1 - x0):
        for k in range(y1 - y0):
            area[x0+j][y0+k] = 0
  
for i in range(N):
    x, y, a = map(int, input().split())
    x0 = x if a == 2 else 0
    y0 = y if a == 4 else 0
    x1 = x if a == 1 else W
    y1 = y if a == 3 else H
    fill(x0, y0, x1, y1)

print(sum(map(sum, area)))

Solution (Python):
a,b,c=map(int,input().split())
x1=0
x2=a
y1=0
y2=b
for i in range(c):
    e,f,g=map(int,input().split())
    if g==1:
        if x1<e:
            x1=e
    elif g==2:
        if x2>e:
            x2=e
    elif g==3:
        if y1<f:
            y1=f
    else:
        if y2>f:
            y2=f
if (0>(x2-x1))or(0>(y2-y1)):
    print(0)
else:
    print((x2-x1)*(y2-y1))

Solution (Python):
w, h, n = map(int, input().split())
lis = []
for i in range(n):
  lis.append(list(map(int, input().split())))
x=0
y=0

for i in lis:
  if i[2] == 1:
    if x < i[0]:
      x=i[0]
  elif i[2] == 2:
    if i[0] < w:
      w=i[0]
  elif i[2] == 3:
    if y < i[1]:
      y=i[1]
  else:
    if i[1] < h:
      h=i[1]
x_a = w-x
y_a= h-y
if x_a < 0 or y_a < 0:
  print(0)
  exit()
print(x_a*y_a)

Solution (Python):
W, H, N = map(int, input().split())
lis = []
xi = 0
yi = 0
xj = W
yj = H
for i in range(N):
    
    x, y, a = map(int, input().split())
    if (a==1) and (x>xi):
        xi = x
    elif (a==2) and (x<xj):
        xj = x
    elif (a==3) and (y>yi):
        yi = y
    elif (a==4) and (y<yj):
        yj = y

x = W-xi-(W-xj)
if x<0:
    x = 0
y = H-(H-yj)-yi
if y<0:
    y = 0

print(x*y)

Solution (Python):
w, h, n = map(int, input().split())
S = [[1 for k in range(w)] for k in range(h)]
for k in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(h):
            for l in range(x):
                S[j][l] = 0
    if a == 2:
        for j in range(h):
            for l in range(x, w):
                S[j][l] = 0
    if a == 3:
        for j in range(y):
            for l in range(w):
                S[j][l] = 0
    if a == 4:
        for j in range(y, h):
            for l in range(w):
                S[j][l] = 0
ans = 0
for k in range(h):
    for j in range(w):
        ans += S[k][j]
print(ans)

Solution (Python):
W, H, N = map(int, input().split())
x1, x2, y1, y2 = 0, W, 0, H

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    else:
        y2 = min(y2, y)

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

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

Solution (Python):
W,H,N=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
x1=0
x2=W
y1=0
y2=H
for i in range(N):
    if X[i][2]==1:
        x1=max(x1,X[i][0])
    elif X[i][2]==2:
        x2=min(x2,X[i][0])
    elif X[i][2]==3:
        y1=max(y1,X[i][1])
    else:
        y2=min(y2,X[i][1])
print((y2-y1)*(x2-x1) if (y2-y1)>0 and (x2-x1)>0 else 0)

Solution (Python):
W, H, N = map(int, input().split())
a1, a2, a3, a4 = 0, W, 0, H
for _ 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)
        
if a1 <= a2 and a3 <= a4:
    print((a2-a1) * (a4-a3))
else:
    print(0)

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

limit = [0, w, 0, h]

for i in range(n):
  x, y, a = map(int, input().split())
  a -= 1
  if a == 0:
    limit[a] = max(limit[a], x)
  if a == 1:
    limit[a] = min(limit[a], x)
  if a == 2:
    limit[a] = max(limit[a], y)
  if a == 3:
    limit[a] = min(limit[a], y)
    
dx = max(0, limit[1] - limit[0])
dy = max(0, limit[3] - limit[2])
print(dx * dy)