      PROGRAM piyo
      IMPLICIT NONE
      integer :: w,h,n
      integer,allocatable :: x(:),y(:),a(:)
      integer :: i
      logical,allocatable :: rect(:,:)
      
      read*,w,h,n
      allocate( x(n),y(n),a(n) )
      do i = 1,n
        read*,x(i),y(i),a(i)
      end do
      
      allocate( rect(1:w,1:h) )
      rect = .true.
      
      do i = 1,n
        select case( a(i) )
          case( 1 )
            rect(1:x(i),:) = .false.
          case( 2 )
            rect(x(i)+1:w,:) = .false.
          case( 3 )
            rect(:,1:y(i)) = .false.
          case( 4 )
            rect(:,y(i)+1:h) = .false.
        end select
      end do
      
      
      print*,count( rect )
      
      
      
      
      
      
      END PROGRAM