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):
import numpy as np

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

arr = np.ones((H,W), dtype=np.bool)

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a==1:
        arr[0:x,:]=False
    elif a==2:
        arr[x:,:]=False
    elif a==3:
        arr[:,0:y]=False
    else:
        arr[:,y:]=False
        
print(np.sum(arr))

Solution (Python):

L = []
Q = []


W, H, N, = map(int,raw_input().split())
for i in range(N):
    L.append(map(int,raw_input().split()))
x1=0
x2=W
y1=0
y2=H


Q = [row[2] for row in L]


for k in range(N):
    if Q[k] == 1:
        x1 = max(x1,L[k][0])
    elif Q[k] == 2:
        x2 = min(x2,L[k][0])
    elif Q[k] == 3:
        y1 = max(y1,L[k][1])
    elif Q[k] == 4:
        y2 = min(y2,L[k][1])

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

Solution (Python):
W, H, N = map(int, input().split())
X = [-1 for i in range(N)]
Y = [-1 for i in range(N)]
A = [-1 for i in range(N)]
for i in range(N):
	X[i], Y[i], A[i] = map(int, input().split())

result = [[0, 0], [W, H]]
for i in range(N):
	if A[i]==1:
		result[0][0] = max(result[0][0], X[i])
	if A[i]==2:
		result[1][0] = min(result[1][0], X[i])
	if A[i]==3:
		result[0][1] = max(result[0][1], Y[i])
	if A[i]==4:
		result[1][1] = min(result[1][1], Y[i])

if result[0][0]>=result[1][0] or result[0][1]>=result[1][1]:
	print(0)
else:
	print((result[1][0]-result[0][0])*(result[1][1]-result[0][1]))

Solution (Python):
w,h,n = map(int,input().split())
x_bit = [1]*w
y_bit = [1]*h

for _ in range(n):
	x,y,a = map(int,input().split())
	if a == 1:
		for i in range(0,x):
			x_bit[i] = 0
	elif a == 2:
		for i in range(x,w):
			x_bit[i] = 0
	elif a == 3:
		for i in range(0,y):
			y_bit[i] = 0
	elif a == 4:
		for i in range(y,h):
			y_bit[i] = 0

print((x_bit.count(1) * (y_bit.count(1))))

Solution (Python):
W, H, N = map(int , input().split())
x = [0] * N
y = [0] * N 
a = [0] * N
for i in range(N):
    x[i], y[i], a[i] = map(int ,input().split())

board = [[1]*(W) for i in range((H))]
for i in range(N):
    l = [(y,x) for x in range(W) for y in range(H)]
    if a[i] == 1:
        l = list(filter(lambda t: t[1] <= x[i]-1, l))
    elif a[i] == 2:
        l = list(filter(lambda t: t[1] > x[i]-1, l))
    elif a[i] == 3:
        l = list(filter(lambda t: t[0] <= y[i]-1, l))
    elif a[i] == 4:
        l = list(filter(lambda t: t[0] > y[i]-1, l))
    for xy in l:
        board[xy[0]][xy[1]] = 0
ans = sum(map(sum, board))
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def S(): return input()


def main():
    w,h,n = LI()
    a = [[1]*w for _ in range(h)]
    for _ in range(n):
        x,y,t = LI()
        if t == 1:
            for _x in range(x):
                for _y in range(h):
                    a[_y][_x] = 0
        elif t == 2:
            for _x in range(x, w):
                for _y in range(h):
                    a[_y][_x] = 0
        elif t == 3:
            for _x in range(w):
                for _y in range(y):
                    a[_y][_x] = 0
        else:
            for _x in range(w):
                for _y in range(y,h):
                    a[_y][_x] = 0
    return sum(sum(_) for _ in a)





print(main())

Solution (Python):
W, H, N = map(int, input().split())
xya = []
l = 0
r = W
u = H
d = 0
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, raw_input().split())
xmax = W
xmin = 0
ymax = H
ymin = 0

for _ in range(N):
    x, y, a = map(int, raw_input().split())
    if a == 1:
        xmin = max(xmin, x)
    if a == 2:
        xmax = min(xmax, x)
    if a == 3:
        ymin = max(ymin, y)
    if a == 4:
        ymax = min(ymax, y)

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

Solution (Python):




W, H, N = map(int, input().split())
w, h = 0, 0

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

    if a == 1 and w < x:
        w = x
    elif a == 2 and W > x:
        W = x
    elif a == 3 and h < y:
        h = y
    elif a == 4 and H > y:
        H = y
if W-w <= 0 or H-h <= 0:
    print(0)
else:
    S = (W - w) * (H -h)
    print(S)

Solution (Python):

import sys
def blocks(block,w,h):
    x, y, p = map(int, raw_input().split())
    if p == 1:
        for i in range(h):
            for j in range(w):
                if j < x:
                    block[i][j] = False
    if p == 2:
        for i in range(h):
            for j in range(w):
                if j >= x:
                    block[i][j] = False
    if p == 3:
        for i in range(h):
            for j in range(w):
                if i < y:
                    block[i][j] = False
    if p == 4:
        for i in range(h):
            for j in range(w):
                if i >= y:
                    block[i][j] = False
    return block

w, h, n = map(int, raw_input().split())
block = [[True for i in range(w)] for j in range(h)]
for i in range(n):
    block = blocks(block,w,h)
total = 0
for i in range(h):
    for j in range(w):
        if block[i][j] == True:
            total = total + 1
print (total)

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

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

if __name__ == '__main__':
    main()

Solution (Python):
whn=input().split(" ")
W=int(whn[0])
H=int(whn[1])
N=int(whn[2])
a=[]
for i in range(N):
    a.append(input().split(" "))

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

for i in range(N):
    if a[i][2]=="1":
        if left<int(a[i][0]):
            left=int(a[i][0])
    elif a[i][2]=="2":
        if right>int(a[i][0]):
            right=int(a[i][0])
    elif a[i][2]=="3":
        if bottom<int(a[i][1]):
            bottom=int(a[i][1])
    elif a[i][2]=="4":
        if top>int(a[i][1]):
            top=int(a[i][1])


if left>=right:
    print(0)
elif top<=bottom:
    print(0)
else:
    print((top-bottom)*(right-left))

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

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

	if a == 1 and w < x:
		w = x
	elif a == 2 and W > x:
		W = x
	elif a == 3 and h < y:
		h = y
	elif a == 4 and H > y:
		H = y

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

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

w = [0, W]
h = [0, H]

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

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

print max(w[1]-w[0], 0) * max(h[1]-h[0], 0)

Solution (Python):
W, H, N = map(int, raw_input().split())
w, h = 0, 0
 
for i in xrange(N):
    x, y, a = map(int, raw_input().split())

    if a == 1 and w < x:
        w = x
    elif a == 2 and W > x :
        W = x
    elif a == 3 and h < y:
        h = y
    elif a == 4 and H > y:
        H = y
 
print max(W-w, 0) * max(H-h, 0)

Solution (Python):
W, H, N = map(int, raw_input().split())
d = [map(int, raw_input().split()) for _ in range(N)]

r = []
for i in range(H):
    l = []
    for j in range(W):
        l.append(0)
    r.append(l)

for i in d:
    if i[2] == 1:
        for j in range(i[0]):
            for k in range(H):
                r[k][j] = 1
    elif i[2] == 2:
        for j in range(i[0],W):
            for k in range(H):
                r[k][j] = 1
    elif i[2] == 3:
        for j in range(i[1]):
            for k in range(W):
                r[j][k] = 1
    else:
        for j in range(i[1],H):
            for k in range(W):
                r[j][k] = 1

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

Solution (Python):
W, H, N = [int(n) for n in raw_input().split(" ")]
a = [[int(x) for x in raw_input().split(" ")] for n in range(N)]
 
x_min = y_min = 0
x_max, y_max = W, H
 
for s in a:
  if s[2] == 1:
    x_min = max(x_min, s[0])
  elif s[2] == 2:
    x_max = min(x_max, s[0])
  elif s[2] == 3:
    y_min = max(y_min, s[1])
  elif s[2] == 4:
    y_max = min(y_max, s[1])
 
 
if (x_max > x_min) 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())
w, h = 0, 0

for _ in range(N):
	x, y, a = map(int, input().split())
	if a == 1:
		if w < x:
			w = x
	elif a == 2:
		if W > x:
			W = x
	elif a == 3:
		if h < y:
			h = y
	elif a == 4:
		if H > y:
			H = y

if W-w < 0 or H-h < 0:
	print(0)
else:
	print((W-w)*(H-h))

Solution (Python):
W, H, N = [int(x) for x in input().strip().split()]
x_min = 0
y_min = 0

for i in range(N):
    x, y, a = [int(x) for x in input().strip().split()]
    if a == 1 and x_min < x:
        x_min = x
    elif a == 2 and W > x:
        W = x
    elif a == 3 and y_min < y:
        y_min = y
    elif a == 4 and H > y:
        H = y
    
if x_min > W or y_min > H:
    print('0')
else:
    print((W - x_min)*(H - y_min))

Solution (Python):

"""Snuke's Coloring 2 (ABC Edit)
 
@author: hijiri.n
@modified: 11-19-2016
 
"""
 
def data(): return list(map(int, input().split()))
 
 
def solve(init, point):
    w, h, N = init
    rect = [0, w, 0, h]
 
    for p in point:
        x, y, a = p
 
        rect[a - 1] = [min, max][a % 2](rect[a - 1], [x, y][a > 2])
 
        if rect[1] <= rect[0] or rect[3] <= rect[2]:
            return 0
        
    return (rect[1] - rect[0]) * (rect[3] - rect[2])
 

i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print(solve(i_in, p_in))

Solution (Python):
import sys

W, H, N = map(int, sys.stdin.readline().split())
top = H
left = 0
right = W
down = 0
for _ in xrange(N):
    x, y, a = map(int, sys.stdin.readline().split())
    if a == 1:
        left = max(left,x)
    elif a == 2:
        right = min(right,x)
    elif a == 3:
        down = max(down,y)
    elif a == 4:
        top = min(top,y)
    else:
        pass

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

Solution (Python):

"""Snuke's Coloring 2 (ABC Edit)

@author: hijiri.n
@modified: 11-19-2016

"""

def data(): return list(map(int, input().split()))


def solve(init, point):
    w, h, N = init
    rect = [0, w, 0, h]

    for p in point:
        x, y, a = p

        if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
            rect[a - 1] = [x, y][a > 2]

        if (rect[1] <= rect[0]) if a <= 2 else (rect[3] <= rect[2]):
            return 0
        
    return (rect[1] - rect[0]) * (rect[3] - rect[2])


i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print(solve(i_in, p_in))

Solution (Python):

"""Snuke's Coloring 2 (ABC Edit)

@author: hijiri.n
@modified: 11-19-2016

"""

def data(): return list(map(int, input().split()))


def solve(init, point):
    w, h, N = init
    rect = [0, w, 0, h]

    for p in point:
        x, y, a = p

        if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
            rect[a - 1] = [x, y][a > 2]

        if (rect[1] <= rect[0]) if a <= 2 else (rect[3] <= rect[2]):
            return 0
        
    return (rect[1] - rect[0]) * (rect[3] - rect[2])


i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print(solve(i_in, p_in))

Solution (Python):

"""Snuke's Coloring 2 (ABC Edit)

@author: hijiri.n
@modified: 11-19-2016

"""

def data(): return list(map(int, input().split()))


def solve(init, point):
    w, h, N = init
    rect = [0, w, 0, h]

    for p in point:
        x, y, a = p

        if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
            rect[a - 1] = [x, y][a > 2]

        if rect[1] <= rect[0] or rect[3] <= rect[2]:
            return 0
        
    return (rect[1] - rect[0]) * (rect[3] - rect[2])


i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print(solve(i_in, p_in))

Solution (Python):

"""Snuke's Coloring 2 (ABC Edit)

@author: hijiri.n
@modified: 11-19-2016

"""

def data(): return list(map(int, input().split()))


def solve():
    w, h, N = data()
    rect = [0, w, 0, h]

    for i in range(N):
        x, y, a = data()
        if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
            rect[a - 1] = [x, y][a > 2]

        if rect[1] <= rect[0] or rect[3] <= rect[2]:
            return 0
        
    return (rect[1] - rect[0]) * (rect[3] - rect[2])

print(solve())

Solution (Python):

"""Snuke's Coloring 2 (ABC Edit)

@author: hijiri.n
@modified: 11-19-2016

"""

def data(): return list(map(int, input().split()))


def solve():
    w, h, N = data()
    rect = [0, w, 0, h]

    for i in range(N):
        x, y, a = data()
        if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
            rect[a - 1] = [x, y][a > 2]
        
        if (rect[1] - rect[0]) <= 0 & (rect[3] - rect[2]) <= 0:
            return 0

    return (rect[1] - rect[0]) * (rect[3] - rect[2])

print(solve())

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

field = [[0 for x in range(w)] for y in range(h)]

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

def a1(line):
    for l in field:
        for x in range(line[0]):
            l[x] = 1

def a2(line):
    for l in field:
        for x in range(line[0], w):
            l[x] = 1

def a3(line):
    for y in range(line[1]):
        field[h - y - 1] = [1 for x in range(w)]

def a4(line):
    for y in range(line[1], h):
        field[h - y - 1] = [1 for x in range(w)]

for line in a:
    globals()["a" + str(line[2])](line[:2])

print(list(itertools.chain(*field)).count(0))

Solution (Python):



W, H, N = list(map(int, input().split()))
minX = 0
maxX = W
minY = 0
maxY = H

def calc():
    if maxX < minX or maxY < minY:
        return 0
    return (maxX - minX) * (maxY - minY)

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a is 1:
        if minX < x:
            minX = x
    elif a is 2:
        if maxX > x:
            maxX = x
    elif a is 3:
        if minY < y:
            minY = y
    elif a is 4:
        if maxY > y:
            maxY = y

print(calc())

Solution (Python):
W,H,N = [int(x) for x in raw_input().split(" ")]
x = []
y = []
a = []

for n in range(N):
	i,j,k = [int(w) for w in raw_input().split(" ")]
	x.append(i)
	y.append(j)
	a.append(k)

X = 0
Y = 0

for i in range(N):
	if a[i] == 1:
		X = max(X,x[i])

	elif a[i] == 2:
		W = min(W,x[i])

	elif a[i] == 3:
		Y = max(Y,y[i])

	elif a[i] == 4:
		H = min(H,y[i])

if X >= W:
	print 0
elif Y >= H:
	print 0
else:
	print (H-Y)*(W-X)

Solution (Python):

W,H,N = map(int,raw_input().split())
arr = []
for i in xrange(N):
    arr.append(map(int,raw_input().split()))

minx=0
miny=0
maxx=W
maxy=H

for r in arr:
    (x,y,a) = r
    if a==1 and x > minx:
        minx = x
    elif a==2 and x < maxx:
        maxx = x
    elif a==3 and y > miny:
        miny = y
    elif a==4 and y < maxy:
        maxy = y
xx = maxx-minx
yy = maxy-miny

r = 0 if xx < 0 or yy < 0 else (xx * yy)
print(r)

Solution (Python):

 
w, h, N = list(map(int, input().split()))
 
rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
        rect[a - 1] = [x, y][a > 2]

w, h = rect[1] - rect[0], rect[3] - rect[2]
if w > 0 and h > 0:
    print(w * h)
else:
    print(0)

Solution (Python):

 
w, h, N = list(map(int, input().split()))
 
rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
        rect[a - 1] = [x, y][a > 2]

w, h = rect[1] - rect[0], rect[3] - rect[2]
print([0, w * h][w > 0 and h > 0])

Solution (Python):

 
w, h, N = list(map(int, input().split()))
 
rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
        rect[a - 1] = [x, y][a > 2]
 
length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))

Solution (Python):


w,h,N=list(map(int,input().split()))

rect=[0,w,0,h]
for i in range(N):
    x,y,a=list(map(int, input().split()))
    rect[a-1]=(lambda c,r,p:[r,c][p*(c-r)<0])([x,y][a>2],rect[a-1],[1,-1][a%2])

length=lambda x:[x,0][x<0]
print(length(rect[1]-rect[0])*length(rect[3]-rect[2]))

Solution (Python):


w, h, N = list(map(int, input().split()))

rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])([x, y][a > 2], rect[a - 1], [1, -1][a % 2])

length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))

Solution (Python):


w, h, N = list(map(int, input().split()))

rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])([x, y][a > 2], rect[a - 1], int(not a % 2) - int(a % 2))

length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))

Solution (Python):


w, h, N = list(map(int, input().split()))

rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    rect[a - 1] = (lambda c, r, p: [r, c][[c < r, c > r][p]])([x, y][a > 2], rect[a - 1], a % 2)

length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))

Solution (Python):

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

for i in range(n):
    x,y,a=map(int, input().split())
    if a==1: wo=max(wo, x)
    if a==2: w=min(w, x)
    if a==3: ho=max(ho, y)
    if a==4: h=min(h, y)

ans=(w-wo)*(h-ho)

if wo>=w or ho>=h: print(0)
else: print(ans)

Solution (Python):

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

for i in range(n):
    x,y,a=map(int, input().split())
    if a==1:
        if x>wo: wo=x
    if a==2:
        if x<w: w=x
    if a==3:
        if y>ho: ho=y
    if a==4:
        if y<h: h=y

ans=(w-wo)*(h-ho)

if wo>=w or ho>=h: print(0)
else: print(ans)

Solution (Python):
w,h,n=map(int,input().split())
xmax=w
xmin=ymin=0
ymax=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)
    else:
        ymax=min(ymax,y)

width=max(0,xmax-xmin)
height=max(0,ymax-ymin)

print(width*height)

Solution (Python):
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())
        if a == 1:
            for x1 in range(0, x):
                for y1 in range(H):
                    field[y1][x1] = 0
        elif a == 2:
            for x1 in range(x, W):
                for y1 in range(H):
                    field[y1][x1] = 0
        elif a == 3:
            for y1 in range(H - y, H):
                for x1 in range(W):
                    field[y1][x1] = 0
        elif a == 4:
            for y1 in range(H - y):
                for x1 in range(W):
                    field[y1][x1] = 0

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


if __name__ == '__main__':
    main()

Solution (Python):
w, h, n = map(int, input().split())
l, r, d, u = 0, w, 0, 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 > d:
            d = y
    elif a == 4:
        if y < u:
            u = y
    if l >= r or d >= u:
        print(0)
        break
else:
    print(w * h - l * h - (w - r) * h - (r - l) * d - (r - l) * (h - u))

Solution (Python):
w, h, n = map(int, input().split())
p = [0, 0]
q = [w, h]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if p[0] < x:
            p[0] = x
    if a == 2:
        if x < q[0]:
            q[0] = x
    if a == 3:
        if p[1] < y:
            p[1] = y
    if a == 4:
        if y < q[1]:
            q[1] = y

    if p[0] > q[0]:
        q[0] = p[0]
    if p[1] > q[1]:
        q[1] = p[1]

        
s = (q[0] - p[0])*(q[1] - p[1])

print(s)

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

max_x_1 = 0
min_x_2 = w
max_y_3 = 0
min_y_4 = h
for i in range(n):
    ai = xya[i][2]
    if ai == 1:
        if xya[i][0] > max_x_1:
            max_x_1 = xya[i][0]
    if ai == 2:
        if xya[i][0] < min_x_2:
            min_x_2 = xya[i][0]
    if ai == 3:
        if xya[i][1] > max_y_3:
            max_y_3 = xya[i][1]
    if ai == 4:
        if xya[i][1] < min_y_4:
            min_y_4 = xya[i][1]

x = min_x_2 - max_x_1
if x <= 0:
    print("0")
else:
    y = min_y_4 - max_y_3
    if y <= 0:
        print("0")
    else:
        print(x * y)

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

for i in range(n):
    li.append([int(i) for i in input().split()])

flag = [[0 for i in range(w)] for j in range(h)]
count = 0

for i in range(n):
    if(li[i][2] == 1):
        for x in range(li[i][0]):
            for y in range(h):
                flag[y][x] = 1
    elif(li[i][2] == 2):
        for x in range(li[i][0], w):
            for y in range(h):
                flag[y][x] = 1
    elif(li[i][2] == 3):
        for x in range(w):
            for y in range(li[i][1]):
                flag[y][x] = 1
    elif(li[i][2] == 4):
        for x in range(w):
            for y in range(li[i][1], h):
                flag[y][x] = 1

for x in range(w):
    for y in range(h):
        if(flag[y][x] == 0):
            count+=1

print(count)

Solution (Python):
W,H,N=map(int,input().split())
xl=0
xh=W
yl=0
yh=H
allblack=False
for _ in range(N):
    x,y,a = map(int,input().split())
    if a==1:
        xl=max(xl,x)
    elif a==2:
        xh=min(xh,x)
    elif a==3:
        yl=max(yl,y)
    else:
        yh=min(yh,y)
    if xl>=xh or yl>=yh:
        allblack=True
        break
print(0 if allblack else (xh-xl)*(yh-yl))

Solution (Python):


w,h,n=map(int,raw_input().split())
xmax=ymax=0
xmin=w
ymin=h
for i in range(n):
 x,y,a=map(int,raw_input().split())
 if a==1:
  xmax=max(xmax,x)
 elif a==2:
  xmin=min(xmin,x)
 elif a==3:
  ymax=max(ymax,y)
 elif a==4:
  ymin=min(ymin,y)

if xmin<=xmax:
 res=0
elif ymin<=ymax:
 res=0
else:
 res=(xmin-xmax)*(ymin-ymax)
print res

Solution (Python):
W,H,N = (int(i) for i in input().split())
fill_map = [[ 0 for i in range(H)] for j in range(W)]
def count(fill_map):
    counter = 0
    for i in range(W):
        for j in range(H):
            if fill_map[i][j] == 0:
                counter += 1
    return counter

def _fill(l1,l2,fill_map):
    for i in range(l1[0],l2[0]+1):
        for j in range(l1[1],l2[1]+1):
            fill_map[i][j] = 1
            
def fill(axis,direction,fill_map):
    if axis == 0:
        if direction == 0:
            
            _fill([0,0],[x-1,H-1],fill_map)
        else:
            
            _fill([x,0],[W-1,H-1],fill_map)
    else:
        if direction == 0:
            
            _fill([0,0],[W-1,y-1],fill_map)
        else:
            
            _fill([0,y],[W-1,H-1],fill_map)



for i in range(N):
    x,y,a = (int(i) for i in input().split())
    if a == 1:
        fill(0,0,fill_map)
    elif a == 2:
        fill(0,1,fill_map)
    elif a == 3:
        fill(1,0,fill_map)
    elif a == 4:
        fill(1,1,fill_map)

result = count(fill_map)
print(result)

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

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

x_min,y_min,x_max,y_max = 0,0,w,h

for i in range(n):
    x,y,a = map(int,raw_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)
    elif a == 4:
        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):
a,b,c=list(map(int,input().split()))

X=[[0 for i in range(a)] for j in range(b)]

d=[input().split() for i in range(c)]

for i in range(c):
    if d[i][2]=="1":
        for j in range(b):
            for k in range(int(d[i][0])):
                X[j][k]=1
    elif d[i][2]=="2":
        for j in range(b):
            for k in range(a-1,int(d[i][0])-1,-1):
                X[j][k]=1
    elif d[i][2]=="3":
        for j in range(int(d[i][1])):
            for k in range(a):
                X[j][k]=1
    else:
        for j in range(b-1,int(d[i][1])-1,-1):
            for k in range(a):
                X[j][k]=1


c=0
for i in range(b):
    for j in range(a):
        if X[i][j]==0:
            c+=1

print(c)

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

Solution (Python):
W, H, N = map(int, raw_input().split())
x = []
y = []
a = []
for i in xrange(N):
    mem = map(int, raw_input().split())
    x.append(mem[0])
    y.append(mem[1])
    a.append(mem[2])

t, b, r, l = H, 0, W, 0

for (xi, yi, ai) in zip(x, y, a):
    if ai == 1:
        l = (l < xi) and xi or l
    elif ai == 2:
        r = (xi < r) and xi or r
    elif ai == 3:
        b = (b < yi) and yi or b
    elif ai == 4:
        t = (yi < t) and yi or t
        
h = (r > l) and r - l or 0
v = (t > b) and t - b or 0
print h * v

Solution (Python):
import numpy as np

if __name__ == "__main__":
	w,h,n = map(int, raw_input().split())
	fi = np.zeros([h,w])

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


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

Solution (Python):
w,h,n = map(int,raw_input().split(" "))
lines = map(lambda x : map(int,x.split(" ")),[raw_input() for var in range(n)])

x_min,x_max,y_min,y_max = 0,w,0,h
for var in lines:
    x,y,a = var
    if a == 1:
        x_min = x_min if x_min > x else x
    elif a == 2:
        x_max = x_max if x_max < x else x
    elif a == 3:
        y_min = y_min if y_min > y else y
    elif a == 4:
        y_max = y_max if y_max < y else y

print (lambda x: x if x > 0 else 0  )(x_max-x_min)*(y_max - y_min)

Solution (Python):
def readints(): return map(int,input().split())

W, H, N = readints()
d = [[1 for w in range(W)] for h in range(H)]

for _ in range(N):
    x, y, a = readints()
    if a == 1:
        for h in range(H):
            for w in range(x):
                d[h][w] = 0
                
    elif a == 2:
        for h in range(H):
            for w in range(x,W):
                d[h][w] = 0

    elif a == 3:
        for h in range(y):
            for w in range(W):
                d[h][w] = 0

    else:
        for h in range(y,H):
            for w in range(W):
                d[h][w] = 0

res = 0
for h in range(H):
    res += sum(d[h])

print(res)

Solution (Python):
def Main():
    w,h ,n = map(int,input().split())
    mnx = 0
    mny = 0
    mxx = w
    mxy = h

    for i in range(n):
        x,y ,a = map(int ,input().split())
        if a == 1:
            mnx = max(mnx, x)
        elif a == 2:
            mxx = min(mxx, x)
        elif a == 3:
            mny = max(mny, y)
        elif a == 4:
            mxy = min(mxy, y)

    if mxy <= mny or mxx <= mnx:
        print(0)
    else:
        print((mxy - mny)*(mxx - mnx))


if __name__ == '__main__':
    Main()

Solution (Python):
w, h, n = list(map(int, input().split()))
ma1 = ma2 = ma3 = ma4 = 0
flag = flag1 = True
while(n):
	x, y, a = list(map(int, input().split()))
	if a == 1:
		if x > ma1:
			ma1 = x
	elif a == 2:
		if flag:
			ma2 = x
			flag = False
		if x < ma2:
			ma2 = x
	elif a == 3:
		if y > ma3:
			ma3 = y
	elif a == 4:
		if flag1:
			ma4 = y
			flag1 = False
		if y < ma4:
			ma4 = y
	n -= 1
 
if ma1 and ma2:
	if ma1 >= ma2:
		width = 0
	else:
		width = abs(ma1-ma2)
else:
	if ma1 == 0 and ma2 == 0:
		width = w
	elif ma1 == 0:
		width = ma2
	elif ma2 == 0:
		width = w - ma1
if ma3 and ma4:
	if ma3 >= ma4:
		height = 0
	else:
		height = abs(ma3-ma4)
else:
	if ma3 == 0 and ma4 == 0:
		height = h
	elif ma3 == 0:
		height = ma4
	elif ma4 == 0:
		height = h - ma3
 
print(width*height)