program sample
    implicit none
  
    integer(8) :: a,b,c,d,i,j,n,h,w,k,m,x(4)
  
    
  
    ! 整数を読み込む
    read(*,*) w,h,n
    x(1)=0
    x(2)=w
    x(3)=0
    x(4)=h
    do i=1,n
        read(*,*)a,b,k
        if(k==1)then
            if(x(1)<a)then
                x(1)=a
            end if
        elseif(k==2)then
            if(x(2)>a)then
                x(2)=a
            end if

        elseif(k==3)then
            if(x(3)<b)then
                x(3)=b
            end if
        else
            if(x(4)>b)then
                x(4)=b
            end if
        end if
    end do
    if(x(2)<=x(1) .or. x(4)<=x(3))then
        write(*,*)0
    else
    	write(*,*)x
        write(*,*)(x(2)-x(1))*(x(4)-x(3))
    end if
                
    
  
    stop
  end program sample
  