Program main
  implicit none
  integer :: N
  integer,allocatable :: A(:)
  integer :: i, j
  integer :: con

  read(*,*) N
  allocate(A(N))
  read(*,*) A(:)

  con = 0
  do i = N, 1, -1
     do j =  i-A(i), 1, -1
        if ( A(i) + A(j)  == i-j ) con = con + 1
     end do
  end do
  write(*,'(i0)') con

  stop
end program main
