program ordinary_number
    implicit none
    integer(4):: n, i, count=0
    integer(4),allocatable:: p(:)

    read*, n
    allocate(p(n))
    read*, p(:)

    do i=1, n-2
        if (is_ordinary(p(i:i+2))) count=count+1
    end do

    print*, count

contains
logical function is_ordinary(ar)
    integer(4):: ar(3)

    if (ar(2) < max(ar(1),ar(3)) .and. ar(2) > min(ar(1),ar(3))) then
        is_ordinary = .true.
    else
        is_ordinary = .false.
    end if
end function
end program ordinary_number