PROGRAM ATCODER

implicit none
integer :: w,h,n,i,b_w,b_h
integer :: b_l=0, b_r=0, b_u=0, b_d=0 !それぞれ、黒色になる左、右、上、下側の長さ
integer,allocatable :: x(:),y(:),a(:)

read(*,*) w,h,n
allocate(x(n),y(n),a(n))

do i = 1, n
  read(*,*) x(i),y(i),a(i)
  if(a(i) == 1)then
    call chmax(b_l,x(i))
  else if(a(i) == 2)then
    call chmax(b_r,w-x(i))
  else if(a(i) == 3)then
    call chmax(b_u,y(i))
  else if(a(i) == 4)then
    call chmax(b_d,h-y(i))
  end if
end do

b_w = b_l+b_r ; b_h = b_u+b_d

if(b_w >= w .or. b_h >= h)then
  write(*,'(i0)') 0
  stop
end if

write(*,'(i0)') (w-b_w)*(h-b_h)

contains
!!!!!! サブルーチンは↓
subroutine chmax(dp,x)
implicit none
integer :: dp, x

if (dp < x) then
	dp = x
	return
end if

end subroutine
!!!!!!

END PROGRAM ATCODER