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,raw_input().split())
l=[['.' for i in range(w)] for j in range(h)]
for i in range(n):
    x,y,a=map(int,raw_input().split())
    if a==1:
        for i in range(h):
            for j in range(x):
                l[i][j]='
    elif a==2:
        for i in range(h):
            for j in range(x,w):
                l[i][j]='
    elif a==3:
        for i in range(y):
            l[i]=['
    else:
        for i in range(y,h):
            l[i]=['

ans=chk=0
for i in l:
    ans+=i.count('.')
print ans

Solution (Python):



def main():
    w, h, n = map(int, input().split())
    x_lb = y_lb = 0
    x_ub = w
    y_ub = h
    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            x_lb = max(x_lb, x)
        elif a == 2:
            x_ub = min(x_ub, x)
        elif a == 3:
            y_lb = max(y_lb, y)
        else:
            y_ub = min(y_ub, y)
    print(max(0, (x_ub - x_lb)) * max(0, (y_ub - y_lb)))


if __name__ == '__main__':
    main()

Solution (Python):
W,H,N = map(int , raw_input().split())
white = {"l_bottom":[0,0],"r_top":[W,H]}

areaZero = False

for i in xrange(N):
    x,y,a = map(int,raw_input().split())
    if a == 1:
        if x > white['r_top'][0]:
            areaZero = True 
            continue
        if x > white['l_bottom'][0]:
            white['l_bottom'][0] = x
            continue
    if a == 2:
        if x <  white['l_bottom'][0]:
            areaZero = True 
            continue
        if x < white['r_top'][0]:
            white['r_top'][0] = x
            continue
    if a ==3 :
        if y > white['r_top'][1]:
            areaZero = True 
            continue
        if y > white['l_bottom'][1]:
            white['l_bottom'][1] = y
            continue
    if a == 4 :
        if y < white['l_bottom'][1]:
            areaZero = True 
            continue
        if y < white['r_top'][1]:
            white['r_top'][1] = y
            continue
if areaZero == True:
    print 0
else:
    print (white['r_top'][0]  - white['l_bottom'][0]) * (white['r_top'][1]  - white['l_bottom'][1])

Solution (Python):
W, H, N = map(int, raw_input().split())
b_w = [0, W]
b_h = [0, H]

for i in range(N):
    
    x, y, a = map(int, raw_input().split())
    if a == 1 and x > b_w[0]:
        b_w[0] = x
    elif a == 2 and x < b_w[1]:
        b_w[1] = x
    elif a == 3 and y > b_h[0]:
        b_h[0] = y
    elif a == 4 and y < b_h[1]:
        b_h[1] = y

print max(b_w[1]-b_w[0], 0) * max(b_h[1]-b_h[0], 0)

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

Solution (Python):
w, h, n = input().split()              
w, h, n = int(w), int(h), int(n)       
x = []                                 
y = []                                 
a = []                                 
                                       
for _ in range(n):                     
    x_, y_, a_ = input().split()       
    x.append(int(x_))                  
    y.append(int(y_))                  
    a.append(int(a_))                  
W = w                                  
H = h                                  
w_r = w                                
w_l = 0                                
h_u = h                                
h_l = 0                                
for i in range(n):                     
    if a[i] is 1 and x[i]>w_l:         
        w_l = x[i]                     
    if a[i] is 2 and x[i]<w_r:         
        w_r = x[i]                     
    if a[i] is 3 and y[i]>h_l:         
        h_l = y[i]                     
    if a[i] is 4 and y[i]<h_u:         
        h_u = y[i]                     
                                       
ans = (w_r - w_l)*(h_u - h_l)          
if (w_r - w_l) < 0 or (h_u - h_l) < 0: 
    ans = 0                            
print(ans)

Solution (Python):
def makemap(x,y):
    multilist = [[0 for col in range(y)] for row in range(x)]
    return multilist

def drow(X,Y,x,y,a,multilist):
    if a ==1 :
        for i in range(0,x):
            for j in range(0,Y):
                multilist[i][j]=1
    elif a ==2 :
        for i in range(x,X):
            for j in range(0,Y):
                multilist[i][j]=1
         
    elif a ==3 :
        for i in range(0,X):
            for j in range(0,y):
                multilist[i][j]=1
         
    elif a ==4 :
        for i in range(0,X):
            for j in range(y,Y):
                multilist[i][j]=1
    
    return multilist
    

def main():
    X,Y,N = map(int,input().split())
    mapx=makemap(X,Y)
    count = 0
    for k in range(0,N):
        x,y,a = map(int,input().split())
        mapx = drow(X,Y,x,y,a,mapx)
    for i in range(0,X):
        for j in range(0,Y):
            if mapx[i][j]==0:
                count+=1
    print(count)
    
main()

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

max_x=w
min_x=0
max_y=h
min_y=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        min_x=max(x,min_x)
    if a==2:
        max_x=min(x,max_x)
    if a==3:
        min_y=max(y,min_y)
    if a==4:
        max_y=min(y,max_y)
wid=max_x-min_x if max_x>=min_x else 0
hei=max_y-min_y if max_y>=min_y else 0
print(wid*hei)

Solution (Python):
x1 = 0
y1 = 0
x2, y2, n = list(map(int, input().split()))
for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        if x1 < x:
            x1 = x
    elif a == 2:
        if x < x2:
            x2 = x
    elif a == 3:
        if y1 < y:
            y1 = y
    elif a == 4:
        if y < y2:
            y2 = y

w = x2 - x1
h = y2 - y1
if 0 < w and 0 < h:
    S = (x2 - x1) * (y2 - y1)
else:
    S = 0
if 0 < S:
    print(S)
else:
    print(0)

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

w_min = 0; w_max = W
h_min = 0; h_max = H
curr_area = W * H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > w_min:
        if x >= w_max:
            curr_area = 0
            break
        else:
            w_min = x

    elif a == 2 and x < w_max:
        if x <= w_min:
            curr_area = 0
            break
        else:
            w_max = x
    elif a == 3 and y > h_min:
        if y >= h_max:
            curr_area = 0
            break
        else:
            h_min = y
    elif a == 4 and y < h_max:
        if y <= h_min:
            curr_area = 0
            break
        else:
            h_max = y
    curr_area = (w_max - w_min) * (h_max - h_min)
print(curr_area)

Solution (Python):
def read():
	return [int(i) for i in input().split(' ')]
W, H, N = read()
x = [0] * N
y = [0] * N
a = [0] * N
for i in range(N):
	x[i], y[i], a[i] = read()
new_x = [0] + x + [W]
new_y = [0] + y + [H]
for inx in range(N):
	if(a[inx] == 1):
		new_x = [num for num in new_x if num >= x[inx]] 
	elif(a[inx] == 2):
		new_x = [num for num in new_x if num <= x[inx]] 
	elif(a[inx] == 3):
		new_y = [num for num in new_y if num >= y[inx]] 
	else:
		new_y = [num for num in new_y if num <= y[inx]] 
if(not(new_x) or not(new_y)):
	print(0)
	exit()
area = (max(new_x) - min(new_x)) * (max(new_y) - min(new_y))
print(area)

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

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

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

for s in range(N):
    x = A[s][0]
    y = A[s][1]
    a = A[s][2]
    
    if a==1:
        for t in range(H):
            for u in range(x):
                glid[t][u] = 1
        
    elif a==2:
        for t in range(H):
            for u in range(x,W,1):
                glid[t][u] = 1
    
    elif a==3:
        y_ = H-y
        for t in range(y_,H,1):
            for u in range(W):
                glid[t][u] = 1
    
    else:
        y_ = H-y
        for t in range(0,y_,1):
            for u in range(W):
                glid[t][u] = 1

counter = 0
for i in range(H):
    a = glid[i].count(0)
    counter += a

print(counter)

Solution (Python):
def paint(rect, x, y, a):
    if a == 1:
        indx = x
        for j in range(len(rect)):
            for i in range(indx):
                rect[j][i] = 1
    elif a == 2:
        indx = x
        for j in range(len(rect)):
            for i in range(indx, len(rect[0])):
                rect[j][i] = 1
    elif a == 3:
        indx = y
        for j in range(indx):
            for i in range(len(rect[0])):
                rect[j][i] = 1
    elif a == 4:
        indx = y
        for j in range(indx, len(rect)):
            for i in range(len(rect[0])):
                rect[j][i] = 1

def disp(rect):
    for i in range(len(rect)):
        print(rect[i])

def sum(rect):
    sum = 0
    for i in range(len(rect)):
        for j in range(len(rect[0])):
            sum += rect[i][j]
    return sum

if __name__ == '__main__':
    [W, H, N] = [int(i) for i in raw_input().split(' ')]
    rectangle = [[0 for i in range(W)] for j in range(H)]
    for i in range(N):
        [x, y, a] = [int(n) for n in raw_input().split(' ')]
        paint(rectangle, x, y, a)
    print(H*W - sum(rectangle))

Solution (Python):
if __name__ == '__main__':
    w, h, n = [int(x) for x in input().split()]
    dots = []
    x_start = 0
    y_start = 0
    x_finish = w
    y_finish = h
    zero_flag = False
    for _ in range(n):
        dots.append([int(x) for x in input().split()])
    for dot in dots:
        if dot[2] == 1:
            if dot[0] > x_start:
                x_start = dot[0]
        if dot[2] == 2:
            if dot[0] < x_finish:
                x_finish = dot[0]
        if dot[2] == 3:
            if dot[1] > y_start:
                y_start = dot[1]
        if dot[2] == 4:
            if dot[1] < y_finish:
                y_finish = dot[1]
        if x_finish <= x_start or y_finish <= y_start:
            zero_flag = True
            break

    if zero_flag:
        ans = 0
    else:
        ans = (x_finish - x_start) * (y_finish - y_start)
    print(ans)

Solution (Python):


w,h,n = map(int,raw_input().split())
l = []
for i in range(n):
    row = map(int,raw_input().split())
    l.append(row)

minX =  map(lambda i:i[0], filter(lambda i:i[2]==1,l))
minX.append(0)
minX = max(minX)

maxX =  map(lambda i:i[0], filter(lambda i:i[2]==2,l))
maxX.append(w)
maxX = min(maxX)

minY =  map(lambda i:i[1], filter(lambda i:i[2]==3,l))
minY.append(0)
minY = max(minY)

maxY =  map(lambda i:i[1], filter(lambda i:i[2]==4,l))
maxY.append(w)
maxY = min(maxY)

X = maxX-minX
Y = maxY-minY
if X>0 and Y>0:
    print X*Y
else:
    print 0

Solution (Python):
W, H, N = map(int, input().split())
menseki = W*H
left_x = 0
right_x = W
top_y = H
bottom_y = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > left_x:
            left_x = x
    elif a == 2:
        if x < right_x:
            right_x = x
    elif a == 3:
        if y > bottom_y:
            bottom_y = y
    else:
        if y < top_y:
            top_y = y
ans = (right_x - left_x) * (top_y - bottom_y)
if right_x <= left_x or top_y <= bottom_y:
    ans = 0
print(ans)

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

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

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

ans_W = max(0, (max_x - min_x))
ans_H = max(0, (max_y - min_y))

print(ans_W * ans_H)

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

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

for _ in range(N):
    xi, yi, ai = map(int, input().split())
    if ai == 1:
        left = max(left, xi)
    elif ai == 2:
        right = min(right, xi)
    elif ai == 3:
        top = max(top, yi)
    elif ai == 4:
        bottom = min(bottom, yi)

        
ans = (bottom - top) * (right - left) if bottom > top and right > left else 0
print(ans)

Solution (Python):
w,h,n = map(int,input().split())
xl=0
xh=w
yl=0
yh=h
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:
    print(0)
else:
    print((xh-xl)*(yh-yl))

Solution (Python):
import sys
lines = sys.stdin.readlines()
sizes = lines[0].split(" ")
W=int(sizes[0])
H=int(sizes[1])
N=int(sizes[2])


calW = W
calH = H
maxX = 0
minX = W
maxY = 0
minY = H
for line in lines[1:]:
    inp = []
    for i in line.split(" "):
        inp.append(int(i))
    
    if inp[2]==1 and inp[0]>maxX:
        calW -= inp[0] - maxX
        maxX = inp[0]
    elif inp[2]==2 and inp[0]<minX:
        calW -= W-inp[0] - (W-minX)
        minX = inp[0]
    elif inp[2]==3 and inp[1]>maxY:
        calH -= inp[1] - maxY
        maxY = inp[1]
    elif inp[2]==4 and inp[1]<minY:
        calH -= H-inp[1] - (H-minY)
        minY = inp[1]
    

if calW<0 or calH<0:
    print (0)
else:
    print (calW*calH)

Solution (Python):
sagyou = []
W,H,N = map(int,input().split(' '))
for i in range(0,N):
    sagyou.append(list(map(int,input().split(' '))))
area = [[0,W],[0,H]]
for i in range(0,N):
    if sagyou[i][2] == 1 and area[0][0] <= sagyou[i][0]:
        area[0][0] = sagyou[i][0]
    elif sagyou[i][2] == 2 and area[0][1] >= sagyou[i][0]:
        area[0][1] = sagyou[i][0]
    elif sagyou[i][2] == 3 and area[1][0] <= sagyou[i][1]:
        area[1][0] = sagyou[i][1]
    elif sagyou[i][2] == 4 and area[1][1] >= sagyou[i][1]:
        area[1][1] = sagyou[i][1]
    if (area[0][1]-area[0][0])*(area[1][1]-area[1][0]) <= 0:
        print(0)
        break
    if i == N-1 and (area[0][1]-area[0][0])*(area[1][1]-area[1][0]) >= 0:
        print((area[0][1]-area[0][0])*(area[1][1]-area[1][0]))

Solution (Python):
if __name__ == '__main__':
    whn = list(map(int,input().split()))
    
    a = [0, whn[0], 0, whn[1]]
    for n in range(whn[2]):
        t = list(map(int,input().split()))
        if t[2] == 1:
            a[0] = max(a[0], t[0])
        elif t[2] == 2:
            a[1] = min(a[1], t[0])
        elif t[2] == 3:
            a[2] = max(a[2], t[1])
        elif t[2] == 4:
            a[3] = min(a[3], t[1])
    if a[1] < a[0] or a[3] < a[2]:
        print(0)
    else:
        print((a[1]-a[0])*(a[3]-a[2]))

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

W=int(W)
H=int(H)
N=int(N)

wl=[0,W]
hl=[0,H]

for x in a:
	if x[2]==1:
		wl[0]=max(wl[0],x[0])
	elif x[2]==2:
		wl[1]=min(wl[1],x[0])
	elif x[2]==3:
		hl[0]=max(hl[0],x[1])
	elif x[2]==4:
		hl[1]=min(hl[1],x[1])

high=0
width=0
if wl[1]-wl[0]>0:
	width=wl[1]-wl[0]
if hl[1]-hl[0]>0:
	high=hl[1]-hl[0]
print(high*width)

Solution (Python):
W, H, N =  map(int, raw_input().split())
result = [0, W, 0, H]
for n in range(N):
    x, y, a =  map(int, raw_input().split())
    if a == 1:
        result[0] = max(result[0], x)
    if a == 2:
        result[1] = min(result[1], x)
    if a == 3:
        result[2] = max(result[2], y)
    if a == 4:
        result[3] = min(result[3], y)

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

Solution (Python):

W, H, N = [int(i) for i in input().split()]
xya = [input().split() for i in range(N)]
ld, ru = [0, 0], [W, H]
for i in range(len(xya)):
    id = int(xya[i][2])
    if id == 1 or id == 3:
        ld[id//2] = max(ld[id//2], int(xya[i][id//2]))
    elif id == 2 or id == 4:
        ru[id//3] = min(ru[id//3], int(xya[i][id//3]))
        
if (ru[0]-ld[0]) > 0 and (ru[1]-ld[1])>0:
    print((ru[0]-ld[0])*(ru[1]-ld[1]))
else: print(0)

Solution (Python):
list = input().split()
w = int(list[0])
h = int(list[1])
n = int(list[2])
list2 = []
i = 0
while i < n:
   list2.append(input().split())
   i += 1

i = 0
a = int(0)
b = int(w)
c = int(0)
d = int(h)
while i < n:
    list3 = list2[i]
    if int(list3[2]) == 1:
        a = max(a,int(list3[0]))
    elif int(list3[2]) == 2:
        b = min(b,int(list3[0]))
    elif int(list3[2]) == 3:
        c = max(c,int(list3[1]))
    else:
        d = min(d,int(list3[1]))
    i += 1
if b < a:
    print(0)
elif d < c:
    print(0)
else:
    print((b-a)*(d-c))

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

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

for i in range(n):
    if a[i][2] == 1:
        minx = max(minx, a[i][0])
    elif a[i][2] == 2:
        maxx = min(maxx, a[i][0])
    elif a[i][2] == 3:
        miny = max(miny, a[i][1])
    elif a[i][2] == 4:
        maxy = min(maxy, a[i][1])

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

Solution (Python):
W, H, N = map(int, input().split(' '))
table = [[0 for i in range(W)] for i in range(H)]

for i in range(N):
    x, y, a = map(int, input().split(' '))
    srange = range(W)
    trange = range(H)
    if a==1:
        srange = range(x)
    if a==2:
        srange = range(x, W)
    if a==3:
        trange = range(y)
    if a==4:
        trange = range(y, H)
    for t in trange:
        for s in srange:
            table[t][s] = 1

area = 0
for i in table:
    area += i.count(0)
print(area)

Solution (Python):


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

x1, x2, y3, y4 = 0, W, 0, H

for i in range(N):
	x, y, a = list(map( int, input().split()))
	if a == 1:
		if x > x1:
			x1 = x
	elif a == 2:
		if x < x2:
			x2 = x
	elif a == 3:
		if y > y3:
			y3 = y
	else:
		if y < y4:
			y4 = y

w = x2 - x1
h = y4 - y3

if w > 0 and h > 0:
	print(w * h)
else:
	print(0)

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

Solution (Python):


W, H, N = map(int, raw_input().split())
w = [0, W]
h = [0, H]

for i in xrange(N):
    x, y, a = map(int, raw_input().split())
    if a == 1 and w[0] < x:
        w[0] = x
    elif a == 2 and w[1] > x :
        w[1] = x
    elif a == 3 and h[0] < y:
        h[0] = y
    elif a == 4 and h[1] > y:
        h[1] = y

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

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

data = [[0 for y in range(H)] for x in range(W)]

for a in range(0,N):
  dat = raw_input()
  (x,y,a) = dat.split(" ")
  x = int(x)
  y = int(y)
  a = int(a)
  if a == 1:
    for a in range(0,x):
      for b in range(0,H):
        data[a][b] = 1
  elif a == 2:
    for a in range(x,W):
      for b in range(0,H):
        data[a][b] = 1
  elif a == 3:
    for a in range(0,W):
      for b in range(0,y):
        data[a][b] = 1
  elif a == 4:
    for a in range(0,W):
      for b in range(y,H):
        data[a][b] = 1
ans = 0
for x in data:
  ans += x.count(0)

print ans

Solution (Python):



def main():
    w, h, n = [int(i) for i in raw_input().split()]
    x_min, x_max, y_min, y_max = 0, w, 0, h
    for _ in range(n):
        x, y, a = [int(i) for i in raw_input().split()]
        if a == 1:
            x_min = max(x_min, x)
        if a == 2:
            x_max = min(x_max, x)
        if a == 3:
            y_min = max(y_min, y)
        if a == 4:
            y_max = min(y_max, y)
    if x_min > x_max:
        print 0
    elif y_min > y_max:
        print 0
    else:
        print (x_max-x_min)*(y_max-y_min)

if __name__ == '__main__':
    main()

Solution (Python):
w,h,n = map(int,input().split())
minx = 0
miny = 0
maxx = w
maxy = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        minx = x if x > minx else minx
    elif a == 2:
        maxx = x if maxx > x else maxx
    elif a == 3:
        miny = y if y > miny else miny
    else:
        maxy = y if maxy > y else maxy
width = maxx-minx if maxx > minx else 0
height = maxy-miny if maxy > miny else 0
print(width*height)

Solution (Python):
w, h, n = map(int, raw_input().split())
x = [1 for i in range(w)]
y = [1 for i in range(h)]
for i in range(n):
    x1, y1, a = map(int, raw_input().split())
    if a == 1:
        for t in range(x1):
            x[t] = 0
    if a == 2:
        for t in range(x1, w):
            x[t] = 0
    if a == 3:
        for t in range(y1):
            y[t] = 0
    if a == 4:
        for t in range(y1, h):
            y[t] = 0
print sum(x)*sum(y)

Solution (Python):

w, h, n = list(map(lambda x: int(x), input().split()))

xr = [0]
xl = [w]
yu = [h]
yd = [0]

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

    if a == 1:
        xr.append(x)
    elif a == 2:
        xl.append(x)
    elif a == 3:
        yd.append(y)
    elif a == 4:
        yu.append(y)


x_1 = max(xr) or 0
x_2 = min(xl) or w
y_1 = max(yd) or 0
y_2 = min(yu) or h


ans = (x_2 - x_1) * (y_2 - y_1)

if ans < 0:
    ans = 0

print(ans)

Solution (Python):
w, h, n = map(int, input().split())
minx, maxx, miny, maxy = 0, w, 0, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        minx = max(minx, x)
    if a == 2:
        maxx = min(maxx, x)
    if a == 3:
        miny = max(miny, y)
    if a == 4:
        maxy = min(maxy, y)

print(max(0, maxx - minx) * max(0, maxy - miny))