program coloring
  implicit none
  integer :: w, h, n, x, y, a, m(100,100), i
  m = 0
  read(*,*) w, h, n
  do i = 1, n
    read(*,*) x, y, a
    select case(a)
      case(1)
        if (x.gt.0) m(1:x,1:h) = 1
      case(2)
        if (x.lt.w) m(x+1:w,1:h) = 1
      case(3)
        if (y.gt.0) m(1:w,1:y) = 1
      case(4)
        if (y.lt.h) m(1:w,y+1:h) = 1
    end select
  end do
  write(*,'(i0)') w*h-sum(m)
  stop
end program coloring