program main
      implicit none
      integer(4) :: n, i
      integer(8), allocatable :: a(:)
      integer(8), allocatable :: tmpi(:), tmpj(:)
      integer(8) :: cnt

      read *, n
      allocate( a(n) )
      read *, a

      allocate(tmpi(n))
      allocate(tmpj(n))
      tmpi(:) = 0
      tmpj(:) = 0

      do i = 1, n
        if ( i + a(i) < n+1 ) then
          tmpi(i+a(i)) = tmpi(i+a(i)) + 1
        end if
        if ( i - a(i) > 0 ) then
          tmpj(i-a(i)) = tmpj(i-a(i)) + 1
        end if
      end do


      cnt = 0
      do i = 1, n
        cnt = cnt + tmpi(i) * tmpj(i)
      end do

      print *, cnt
      
end program main
