program prob4
    implicit none
    integer::W, H, N, i, j, x, y, a
    integer, allocatable::c(:,:)
    read(*,*) W, H, N
    allocate(c(H,W))
    c = 1
    do i = 1, N
        read(*,*) x, y, a
        if(a == 1) then
            do j = 1, x
                c(:,j) = 0
            end do
        else if(a == 2) then
            do j = x+1, W
                c(:,j) = 0
            end do
        else if(a == 3) then
            do j = 1, y
                c(j,:) = 0
            end do
        else
            do j = y+1, H
                c(j,:) = 0
            end do
        end if
    end do
    write(*,*) sum(c)
    deallocate(c)
    stop
end program