program prob4
    implicit none
    integer :: w, h, n
    integer, allocatable :: x(:), y(:), a(:)
    integer :: i, j, k, ans
    logical :: check
    read(*,*) w, h, n
    allocate(x(n), y(n), a(n))
    do k = 1, n
        read(*,*) x(k), y(k), a(k)
    end do
    ans = 0
    do i = 1, W
        do j = 1, H 
            check = .true.
            do k = 1, N
                if(a(k) == 1) then
                    if(i <= x(k)) then
                        check = .false.
                    end if
                else if(a(k) == 2) then
                    if(i-1 >= x(k)) then
                        check = .false.
                    end if
                else if(a(k) == 3) then
                    if(j <= y(k)) then
                        check = .false.
                    end if
                else
                    if(j-1 >= y(k)) then
                        check = .false.
                    end if
                end if
            end do
            if(check .eqv. .true.)then
                ans = ans + 1
            end if
        end do
    end do
    write(*,*) ans

    deallocate(x, y, a)

    stop
contains
end program prob4