module yukicoder1031 implicit none integer :: n integer, allocatable :: p(:) contains subroutine read_input read *, n allocate(p(n)) read *, p end subroutine read_input end module yukicoder1031 program main use yukicoder1031 implicit none integer :: r = 0 integer :: i, j integer :: max_index, min_index call read_input do i = 1, n do j = i+1, n max_index = maxloc(p(i:j), 1) min_index = minloc(p(i:j), 1) r = r + merge(1, 0, abs(max_index - min_index) == j - i) end do end do print '(I0)', r end program main