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())

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







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

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

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

Solution (Python):
W,H,N=map(int,input().split())
x_max=W
x_min=0
y_max=H
y_min=0
for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    if x>x_min:
      x_min=x
  elif a==2:
    if x<x_max:
      x_max=x
  elif a==3:
    if y>y_min:
      y_min=y
  else:
    if y<y_max:
      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())
S=w*h
bigx,smax,bigy,smay=0,w,0,h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        bigx=max(x,bigx)
    elif a==2:
        smax=min(x,smax)
    elif a==3:
        bigy=max(y,bigy)
    else:
        smay=min(y,smay)
if bigx>=smax or bigy>=smay:
    print(0)
else:
    print((smax-bigx)*(smay-bigy))

Solution (Python):
w_r, h_u, n = map(int, input().split())
xya = []
for i in range(n): xya.append(list(map(int, input().split())))

w_l = 0
h_l = 0
for x in xya:
    if x[2] == 1:
        w_l = max(x[0], w_l)
    elif x[2] == 2:
        w_r = min(x[0], w_r)
    elif x[2] == 3:
        h_l = max(x[1], h_l)
    else:
        h_u = min(x[1], h_u)

print(max((max(w_r-w_l, 0))*max((h_u-h_l), 0), 0))

Solution (Python):
W,H,N=map(int, raw_input().split())
C=[]
for i in range(N):
	x,y,a=map(int, raw_input().split())
	C.append((x,y,a))

R=[[ 0 for i in range(H)] for j in range(W)]


for i in C:
	if i[2]==1:
		for x in range(i[0]):
			for y in range(H):
				R[x][y]=1
	elif i[2]==2:
		for x in range(i[0],W):
			for y in range(H):
				R[x][y]=1
	elif i[2]==3:
		for x in range(W):
			for y in range(i[1]):
				R[x][y]=1
	elif i[2]==4:
		for x in range(W):
			for y in range(i[1],H):
				R[x][y]=1


ans=0
for i in R:
	ans+=len(filter(lambda n:n==0, i) )

print ans

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

    
    f2(W, H, N, xya)


def f1(W, H, N, xya):
    rect = [[1] * W for _ in range(H)]

    for x, y, a in xya:
        x_range = range(W)
        y_range = range(H)
        if a == 1:
            x_range = range(x)
        elif a == 2:
            x_range = range(x, W)
        elif a == 3:
            y_range = range(y)
        elif a == 4:
            y_range = range(y, H)

        for i in y_range:
            for j in x_range:
                rect[i][j] = 0

    ans = sum(map(sum, rect))
    print(ans)


def f2(W, H, N, xya):
    x1, y1 = 0, 0
    x2, y2 = W, H

    for x, y, a in xya:
        if a == 1:
            x1 = max(x, x1)
        elif a == 2:
            x2 = min(x, x2)
        elif a == 3:
            y1 = max(y, y1)
        elif a == 4:
            y2 = min(y, y2)

    if x1 > x2 or y1 > y2:
        ans = 0
    else:
        ans = (x2 - x1) * (y2 - y1)

    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
W,H,N=map(int, input().split())
 
X=[]
Y=[]
A=[]
for i in range(N):
    x,y,a=map(int, input().split())
    X.append(x)
    Y.append(y)
    A.append(a)
 
T=W*H
Ws=0
Hs=0
Wh=W
Hh=H
for i in range(N):
    if A[i]==1:
        if X[i]-Ws>=0:
            T-=(X[i]-Ws)*(Hh-Hs)
            Ws=X[i]
    elif A[i]==2:
        if Wh-X[i]>=0:
            T-=(Wh-X[i])*(Hh-Hs)
            Wh=X[i]
    elif A[i]==3:
        if Y[i]-Hs>=0:
            T-=(Y[i]-Hs)*(Wh-Ws)
            Hs=Y[i]
    elif A[i]==4:
        if Hh-Y[i]>=0:
            T-=(Hh-Y[i])*(Wh-Ws)
            Hh=Y[i]
    if T<=0:
        T=0
        break
 
print(T)

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

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

T=W*H
Ws=0
Hs=0
Wh=W
Hh=H
for i in range(N):
    if A[i]==1:
        if X[i]-Ws>=0:
            T-=(X[i]-Ws)*(Hh-Hs)
            Ws=X[i]
    elif A[i]==2:
        if Wh-X[i]>=0:
            T-=(Wh-X[i])*(Hh-Hs)
            Wh=X[i]
    elif A[i]==3:
        if Y[i]-Hs>=0:
            T-=(Y[i]-Hs)*(Wh-Ws)
            Hs=Y[i]
    elif A[i]==4:
        if Hh-Y[i]>=0:
            T-=(Hh-Y[i])*(Wh-Ws)
            Hh=Y[i]
    if T<=0:
        T=0
        break

print(T)

Solution (Python):
W,H,N = [int(i) for i in input().split()]
rect = [[0]*W for _ in range(H)]
for _ in range(N):
  x,y,a = [int(i) for i in input().split()]
  if a==1:
    for w in range(x):
      for h in range(H):
        rect[h][w]=1
  elif a==2:
    for w in range(x,W):
      for h in range(H):
        rect[h][w]=1
  elif a==3:
    for w in range(W):
      for h in range(y):
        rect[h][w]=1    
  elif a==4:
    for w in range(W):
      for h in range(y,H):
        rect[h][w]=1
ans = 0
for w in range(W):
  for h in range(H):
    if rect[h][w]==0:
      ans+=1
print(ans)

Solution (Python):
w,h,n = map(int,input().split())
table = [[1]*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):
                table[i][j] = 0
    if a == 2:
        for i in range(x,w):
            for j in range(h):
                table[i][j] = 0
    if a == 3:
        for i in range(w):
            for j in range(y):
                table[i][j] = 0
    if a == 4:
        for i in range(w):
            for j in range(y,h):
                table[i][j] = 0
print(sum(map(sum,table)))

Solution (Python):
W, H, N = map(int,input().split())
points = [list(map(int,input().split())) for _ in range(N)]
width = list(range(1, W + 2))
height = list(range(1, H + 2))

a = len(width)
b = len(height)

for i in range(N):
    if points[i][2] == 1:
        for j in range(a):
            if width[j] < points[i][0] + 1:
                width[j] = 0
    if points[i][2] == 2:
        for j in range(a):
            if width[j] > points[i][0] + 1:
                width[j] = 0
    if points[i][2] == 3:
        for j in range(b):
            if height[j] < points[i][1] + 1:
                height[j] = 0
    if points[i][2] == 4:
        for j in range(b):
            if height[j] > points[i][1] + 1:
                height[j] = 0

c = width.count(0)
d = height.count(0)

for i in range(c):
    width.remove(0)
for i in range(d):
    height.remove(0)
if width != []:
    s = max(width)
    t = min(width)
else:
    s, t = 0, 0
if height != []:
    x = max(height)
    y = min(height)
else:
    x, y = 0, 0
ans = (s-t) * (x-y)
print(ans)

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

xmin, ymin = 0, 0
xmax, ymax = w, 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)

xmax = max(xmin, xmax)
ymax = max(ymin, ymax)

print((xmax-xmin)*(ymax-ymin))

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

Solution (Python):
import numpy as np

W, H, N = map(int, input().split())
XYA = [tuple(map(int, input().split())) for i in range(N)]
Field = [[1]*W for i in range(H)]
Field = np.array(Field)

for x, y, a in XYA:
    if a == 1:
        Field[:, :x] = 0
    if a == 2:
        Field[:, x:] = 0
    if a == 3:
        Field[:y, :] = 0
    if a == 4:
        Field[y:, :] = 0

ans = Field.sum()
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)
    elif a == 4:
        y2 = min(y2, y)

x2 = max(x1, x2)
y2 = max(y1, y2)

print((y2 - y1) * (x2 - x1))

Solution (Python):
w, h, n = input().split()
lx ,ly ,hx ,hy = 0, 0, int(w), int(h)
for i in range(int(n)):
    S = list(map(int, input().split()))
    if S[2]==1 and lx<S[0]:
        lx = S[0]
    elif S[2]==2 and hx>S[0]:
        hx = S[0]
    elif S[2]==3 and ly<S[1]:
        ly = S[1]
    elif S[2]==4 and hy>S[1]:
        hy = S[1]
ans = int(hx-lx)*int(hy-ly) 
if hx-lx<=0 or hy-ly<=0:
    print(0)
else: print(ans)

Solution (Python):
def LI(): return [int(x) for x in input().split(" ")]
def LS(): return [str(x) for x in input().split(" ")]
def ItoS(L): return [str(x) for x in L]
def StoI(L): return [int(c) for c in L]


def solve():
    w, h, n = LI()
    X, Y, A = [], [], []
    for _ in range(n):
        tmp1, tmp2, tmp3 = LI()
        X.append(tmp1)
        Y.append(tmp2)
        A.append(tmp3)

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

    for i, a in enumerate(A):
        if a == 1:
            for j in range(X[i]):
                for k in range(h):
                    field[k][j] = 0
        elif a == 2:
            for j in range(X[i], w):
                for k in range(h):
                    field[k][j] = 0
        elif a == 3:
            for j in range(Y[i]):
                for k in range(w):
                    field[j][k] = 0
        elif a == 4:
            for j in range(Y[i], h):
                for k in range(w):
                    field[j][k] = 0
        else:
            pass
        
    ans = 0
    for ele in field:
        ans += ele.count(1)

    print(ans)


solve()

Solution (Python):
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for _ in [0]*n]
minx = max([x for x,y,a in xya if a==1]+[0])
maxx = min([x for x,y,a in xya if a==2]+[w])
miny = max([y for x,y,a in xya if a==3]+[0])
maxy = min([y for x,y,a in xya if a==4]+[h])
print(max(0,maxx-minx)*max(0,maxy-miny))

Solution (Python):
w, h, n = input().split()
lx ,ly ,hx ,hy = 0, 0, int(w), int(h)
for i in range(int(n)):
    S = list(map(int, input().split()))
    if S[2]==1 and lx<S[0]:
        lx = S[0]
    elif S[2]==2 and hx>S[0]:
        hx = S[0]
    elif S[2]==3 and ly<S[1]:
        ly = S[1]
    elif S[2]==4 and hy>S[1]:
        hy = S[1]
ans = int(hx-lx)*int(hy-ly) 
if hx-lx<=0 or hy-ly<=0:
    print(0)
else: print(ans)

Solution (Python):
def main():
    w, h, n = map(int, input().split())
    f = [[1 for i in range(w)] for i 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(x):
                    if f[i][j] == 1:
                    	f[i][j] = 0
        if a == 2:
            for i in range(h):
                for j in range(x, w):
                	if f[i][j] == 1:
                		f[i][j] = 0
        if a == 3:
            for i in range(h - y, h):
                for j in range(w):
                    if f[i][j] == 1:
                    	f[i][j] = 0
        if a == 4:
            for i in range(h - y):
                for j in range(w):
                    if f[i][j] == 1:
                    	f[i][j] = 0
    

    ans = 0
    for l in f:
        ans += sum(l)
    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
w, h, n = map(int, input().split())
li = []
ans = 0
for i in range(h):
  li.append([0]*w)

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

  if a == 1:
    for i in li:
      for j in range(x):
        i[j] = 1
  elif a == 2:
    for i in li:
      for j in range(x, w):
        i[j] = 1
  elif a == 3:
    for i in range(h - y,h):
      for j in range(w):
        li[i][j] = 1
  elif a == 4:
    for i in range(h - y):
      for j in range(w):
        li[i][j] = 1

for i in li:
  ans += i.count(0)

print(ans)

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

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(x, x1)
    elif a == 2:
        x2 = min(x, x2)
    elif a == 3:
        y1 = max(y, y1)
    else:
        y2 = min(y, y2)
print(max((x2-x1), 0) * max((y2-y1), 0))

Solution (Python):
l = list(map(int, input().split()))

w = l[0]
h = l[1]
n = l[2]

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

for i in range(n):
    l = list(map(int, input().split()))
    x = l[0]
    y = l[1]
    a = l[2]
    if a == 1:
        if minx < x:
            minx = x
    elif a == 2:
        if maxx > x:
            maxx = x
    elif a == 3:
        if miny < y:
            miny = y
    elif a == 4:
        if maxy > y:
            maxy = y
    if maxx - minx <= 0 or maxy - miny <= 0:
        maxx = 0
        minx = 0
        maxy = 0
        miny = 0

cnt = w * h

ans = (maxx-minx) * (maxy-miny)
if ans < 0:
    ans = 0
print(ans)

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

sx = 0
ex = W
sy = 0
ey = H

for n in range(N):
  x, y, a = [int(w) for w in input().split()]
  if a == 1:
    sx = max(sx, x)
  elif a == 2:
    ex = min(ex, x)
  elif a == 3:
    sy = max(sy, y)
  else:
    ey = min(ey, y)

print(max(0,ex-sx)*max(0,ey-sy))

Solution (Python):
W, H, N = [int(i) for i in input().split()]
w, h = 0, 0
for i in range(N):
    x, y, a = [int(i) for i in input().split()]
    if a is 1:
        w = max(w, x)
    elif a is 2:
        W = min(W, x)
    elif a is 3:
        h = max(h, y)
    elif a is 4:
        H = min(H, y)

print(max(0, max(0, W - w) * max(0, H - h)))

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

z = [[0 for i in range(w)] for i in range(h)]  
ans = 0

for i in range(n):
    if xya[i][2] == 1:
        for j in range(h):
            z[j][:xya[i][0]] = [1]*xya[i][0]
    elif xya[i][2] == 2:
        for j in range(h):
            z[j][xya[i][0]:] = [1]*(w-xya[i][0])
    elif xya[i][2] == 3:
        z[:xya[i][1]] = [[1]*w]*xya[i][1]
    elif xya[i][2] == 4:
        z[xya[i][1]:] = [[1]*w]*(h-xya[i][1])

for i in range(len(z)):
    ans += z[i].count(0)

print(ans)

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

Solution (Python):
W, H, N = list(map(int, input().split()))
left = 0
right = W
bottom = 0
top = H
for i in range(N):
    x, y, a = list(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)
    elif a == 4:
        top = min(top, y)
print(max(0, right-left)*max(0, top-bottom))

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

X=[]
Y=[]
A=[]


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

yoko1=0
yoko2=W
tate1=0
tate2=H

for j in range(N):
    if A[j]==1:
        if yoko1<X[j]:
            yoko1=X[j]
    
    elif A[j]==2:
        if yoko2>X[j]:
            yoko2=X[j]
        
    elif A[j]==3:
        if tate1<Y[j]:
            tate1=Y[j]

    elif A[j]==4:
        if tate2>Y[j]:
             tate2=Y[j]

ans=(tate2-tate1)*(yoko2-yoko1)

if (tate2-tate1)<0 or (yoko2-yoko1)<0:
    print(0)
else:
    print(ans)

Solution (Python):
w,h,n = map(int,input().split())
arr = []
base_x = 0
base_y = 0
for i in range(n):
    arr.append(list(map(int,input().split())))
    x = arr[i][0]
    y = arr[i][1]
    num = arr[i][2]
    if num == 1:
        base_x = max(base_x,x)
    elif num == 2:
        w = min(w,x)
    elif num == 3:
        base_y = max(base_y,y)
    elif num == 4:
        h = min(h,y)
w2 = w - base_x
h2 = h - base_y
if base_x >= w or base_y >= h:
    print("0")
else:
    print(w2 * h2)

Solution (Python):
W,H,N=map(int,input().split())
n=H
e=0
w=W
s=0
for i in range(N):
  X,Y,A=map(int,input().split())
  if A==1: e=max(e,X)
  elif A==2: w=min(w,X)
  elif A==3: s=max(s,Y)
  else: n=min(n,Y)
if e>=w or s>=n: print(0)
else: print((w-e)*(n-s))

Solution (Python):
from collections import defaultdict


def main():
    W, H, N = map(int, input().split())
    field = [[1] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        y_s, y_e = 0, H
        x_s, x_e = 0, W
        if a == 1:
            x_s, x_e = 0, x
        elif a == 2:
            x_s, x_e = x, W
        elif a == 3:
            y_s, y_e = H - y, H
        elif a == 4:
            y_s, y_e = 0, H - y

        for y in range(y_s, y_e):
            for x in range(x_s, x_e):
                field[y][x] = 0

    print(sum([sum(line) for line in field]))

if __name__ == '__main__':
    main()

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

d = 0
u = h
r = w
l = 0

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if l <= x:
            l = x
    elif a == 2:
        if r >= x:
            r = x
    elif a == 3:
        if d <= y:
            d = y
    elif a == 4:
        if u >= y:
            u = y
    if u-d <= 0 or r-l <= 0:
        break
ans = (r-l) * (u-d)
if ans <= 0:
    print(0)
else:
    print(ans)

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

rect = [0, 0, W, H]

ans = -1

XY_a = []

for i in range(N):
    XY_a.append(list(map(int, input().split())))
    
for i in range(N):
    if XY_a[i][2] == 1:
        rect[0] = max(XY_a[i][0], rect[0])
    elif XY_a[i][2] == 2:
        rect[2] = min(XY_a[i][0], rect[2])
        
    elif XY_a[i][2] == 3:
        rect[1] = max(XY_a[i][1], rect[1])
    elif XY_a[i][2] == 4:
        rect[3] = min(XY_a[i][1], rect[3])
        
    if rect[0] >= rect[2] or rect[1] >= rect[3]:
        ans = 0
        break
        
if ans == 0:
    print(ans)
else :
    ans = (rect[2] - rect[0])*(rect[3] - rect[1])
    print(ans)

Solution (Python):
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

w,h,n = rli()
xl = 0
xh = w
yl = 0
yh = h
for i in range(n):
    x,y,a = rli()
    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)
if(xh < xl or yh < yl):
    print(0)
else:
    print((xh-xl)*(yh-yl))

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

    x = [0, W]
    y = [0, H]
    for p in P:
        if p[2] == 1 and x[0] < p[0]:
            x[0] = p[0]
        elif p[2] == 2 and x[1] > p[0]:
            x[1] = p[0]
        elif p[2] == 3 and y[0] < p[1]:
            y[0] = p[1]
        elif p[2] == 4 and y[1] > p[1]:
            y[1] = p[1]

    region = [x[1] - x[0], y[1] - y[0]]
    if region[0] <= 0 or region[1] <= 0:
        area = 0
    else:
        area = region[0] * region[1]

    print(area)

main()

Solution (Python):
w, h, n = map(int, input().split())
l = []
for i in range(n):
    x = input().split()
    x[0], x[1], x[2]= map(int, x)
    l.append(x)
originalh = []
originalw = []
for i in range(h):
    originalh.append(1)
for i in range(w):
    originalw.append(1)
for i in l:
    if i[2] == 1:
        for i in range(i[0]):
            originalw[i] = 0
    elif i[2] == 2:
        for i in range(1, w-i[0]+1):
            originalw[-i] = 0
    elif i[2] == 3:
        for i in range(i[1]):
            originalh[i] = 0
    else:
        for i in range(1, h-i[1]+1):
            originalh[-i] = 0
    
r = sum(originalw) * sum(originalh)
print(r)

Solution (Python):
W,H,N = map(int, raw_input().split())
l = 0
r = W
d = 0
u = H
for i in range(N):
    x,y,a = map(int, raw_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)
if l >= r or d >= u:
    print 0
else:
    print (r-l) * (u-d)

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

p1 = [W,H]
p2 = [0,H]
p3 = [0,0]
p4 = [W,0]

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


for i,j,k in g:
    if(k == 1):
        if(i > p2[0]):
            p2[0] = i
            p3[0] = i
        else:
            continue
    elif(k == 2):
        if(i < p1[0]):
            p1[0] = i
            p4[0] = i
        else:
            continue
    elif(k == 3):
        if(j > p3[1]):
            p3[1] = j
            p4[1] = j
        else:
            continue
    else:
        if(j < p2[1]):
            p1[1] = j
            p2[1] = j
        else:
            continue

w = p1[0] - p2[0]
h = p1[1] - p4[1]

if(w<=0 or h<=0):
    print(0)
else:
    print(w*h)

Solution (Python):
import numpy as np
W, H, N = map(int, raw_input().split())
A = np.ones((W, H), dtype=np.int)
for i in range(N):
    x, y, a = map(int, raw_input().split())
    if a == 1:
        A[:x,:] = 0
    elif a == 2:
        A[x:,:] = 0
    elif a == 3:
        A[:,:y] = 0
    elif a == 4:
        A[:,y:] = 0
print np.sum(A)

Solution (Python):
maxw, maxh, N = list(map(int, input().split(' ')))
minw, minh = 0, 0

for n in range(N):
    x, y, a = list(map(int, input().split(' ')))
    if a == 1:
        minw = max(minw, x)
    elif a == 2:
        maxw = min(maxw, x)
    elif a == 3:
        minh = max(minh, y)
    elif a == 4:
        maxh = min(maxh, y)

if maxw-minw < 0 or maxh-minh < 0:
    res = 0
else:
    res = (maxw-minw)*(maxh-minh)
print(res)

Solution (Python):
w,h,n = map(int, raw_input().split())
mat = [[False for _ in range(w)] for _ in range(h)]
for _ in range(n):
    x,y,a = map(int, raw_input().split())
    if a == 1:
        for i in range(h):
            for j in range(x):
                mat[i][j] = True
    elif a == 2:
        for i in range(h):
            for j in range(x,w):
                mat[i][j] = True
    elif a == 3:
        for i in range(y):
            for j in range(w):
                mat[i][j] = True
    elif a == 4:
        for i in range(y,h):
            for j in range(w):
                mat[i][j] = True
print sum([i.count(False) for i in mat])

Solution (Python):
W,H,N = map(int,input().split())
act = [[0 for j in range(3)] for i in range(N)]
xl = 0 
xr = W 
yd = 0 
yu = H 
for i in range(N):
	act[i] = [int(j) for j in input().split()]
for obj in act:
	if(obj[2]==1):
		xl = max(obj[0],xl)
	elif(obj[2]==2):
		xr = min(obj[0],xr)
	elif(obj[2]==3):
		yd = max(obj[1],yd)
	elif(obj[2]==4):
		yu = min(obj[1],yu)
ans = (xr-xl)*(yu-yd)

if(xr < xl or yu < yd):
	print(0)
else:
	print(ans)

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

Solution (Python):
def paint(b, type, x, y):
    if type == 1:
        b[:, :x] = 0
    elif type == 2:
        b[:, x:] = 0
    elif type == 3:
        b[:y, :] = 0
    else:
        b[y:, :] = 0
    return b

import numpy as np
W, H, N = list(map(int, input().split()))
w = []
for i in range(0, W):
    w.append(1)
b = [w for i in range(0, H)]
board = np.array(b)

for i in range(0, N):
    x, y, type = list(map(int, input().split()))
    board = paint(board, type, x, y)

print(str(np.sum(board)))

Solution (Python):
W,H,N=map(int,input().split())
L,R = 0,W
D,T = 0,H
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if R <= x:
            L,R = 0,0
        elif L <= x:
            L = x
    elif a == 2:
        if x <= L:
            L,R = 0,0
        elif x <= R:
            R = x
    elif a == 3:
        if T <= y:
            D,T = 0,0
        elif D <= y:
            D = y
    else:
        if y <= D:
            D,T = 0,0
        elif y <= T:
            T = y
print( ( R - L ) * ( T - D ) )

Solution (Python):
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    W, H, N = map(int, input().split())
    xl, xr, yb, yt = 0, W, 0, H

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

        if a == 1:
            xl = max(xl, x)
            pass
        elif a == 2:
            xr = min(xr, x)
            pass
        elif a == 3:
            yb = max(yb, y)
            pass
        else:
            yt = min(yt, y)
            pass

    if xr > xl and yt > yb:
        ans = (xr - xl) * (yt - yb)
    else:
        ans = 0

    print(ans)

if __name__ == '__main__':
    solve()

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

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






for x, y, a in xya:
    if a == 1:
        for i in range(h):
            can[i][0:x] = [0] * x
    if a == 2:
        for i in range(h):
            can[i][x:] = [0] * (h - x)
    if a == 3:
        for i in range(h - y, h):
            can[i] = [0] * w
    if a == 4:
        for i in range(h - y):
            can[i] = [0] * w




ans = sum([sum(cw) for cw in can])
print(ans)

Solution (Python):
w,h,n=map(int,input().split())
lx,ly,ux,uy=0,0,w,h
for i in range(n):
    x,y,a=map(int,input().split())
    if a == 1:
        lx=max(lx,x)
    elif a == 2:
        ux=min(ux,x)
    elif a == 3:
        ly=max(ly,y)
    else:
        uy=min(uy,y)
if ux < lx or uy < ly: print(0)
else: print((ux-lx)*(uy-ly))

Solution (Python):

import sys
W, H, N = map(int,input().split())
xya = []
W1, W2, H3, H4 = (0, W, 0, H)

for tmp in range(0, N):
    xya.append(list(map(int,input().split())))

for y in range(0, N):

    if xya[y][2] == 1:
        W1 = max(W1, xya[y][0])
    elif xya[y][2] == 2:
        W2 = min(W2, xya[y][0])
    elif xya[y][2] == 3:
        H3 = max(H3, xya[y][1])
    else:
        H4 = min(H4, xya[y][1])

    if W1 >= W2 or H3 >= H4:
        print(0)
        sys.exit()

print((W2 - W1)*(H4 - H3))

Solution (Python):

import sys
W, H, N = map(int,input().split())
xya = []
W1 = 0
W2 = W
H3 = 0
H4 = H
for tmp in range(0, N):
    xya.append(list(map(int,input().split())))

for y in range(0, N):
    if xya[y][2] == 1:
        W1 = max(W1, xya[y][0])
    elif xya[y][2] == 2:
        W2 = min(W2, xya[y][0])
    elif xya[y][2] == 3:
        H3 = max(H3, xya[y][1])
    else:
        H4 = min(H4, xya[y][1])

    if W1 >= W2 or H3 >= H4:
        print(0)
        sys.exit()

    W_ans = W2 - W1
    H_ans = H4 - H3

print(W_ans*H_ans)

Solution (Python):
W, H, N = map(int,input().split())
x = []
y = []
a = []
x1 = 0
x2 = W
y1 = 0
y2 = H
for i in range(N):
    temp = list(map(int,input().split()))
    x.append(temp[0])
    y.append(temp[1])
    a.append(temp[2])

for i in range(N):
    if a[i] == 1:
        x1 = max(x1,x[i])
    if a[i] == 2:
        x2 = min(x2,x[i])
    if a[i] == 3:
        y1 = max(y1,y[i])
    if a[i] == 4:
        y2 = min(y2,y[i])
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())

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)
    elif a == 4:
        y2 = min(y2, y)
ans = max(0,x2-x1) * max(0,y2-y1)
print(ans)

Solution (Python):
w, h, n = map(int, input().split())
sx, sy, ex, ey = 0, 0, w, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = max(sx, x)
    if a == 2:
        ex = min(ex, x)
    if a == 3:
        sy = max(sy, y)
    if a == 4:
        ey = min(ey, y)
ans = (ex - sx) * (ey - sy)
if ex - sx < 0 or ey - sy < 0:
    print(0)
else:
    print(ans)