program main
  implicit none
  integer w,h,n,x,y,a,i
  integer,allocatable::m(:,:)
  read*,w,h,n
  allocate(m(w,h))
  m=1;
  do i=1,n
     read*,x,y,a
     if(a==1) then
        m(1:x,:)=0
     elseif(a==2)then
	m(x+1:w,:)=0
     elseif(a==3)then
	m(:,1:y)=0
     else
        m(:,y+1:h)=0
     end if

  end do
  print*,sum(m)
end program main
