program abc166e
  use iso_fortran_env
  implicit none
  integer(int64) :: n, i, t
  integer(int64),allocatable :: a(:), x(:), y(:)
  read *, n
  allocate(a(n),x(n),y(n))
  read *, a
  x = 0
  y = 0
  do i = 1,n
     t = i + a(i)
     if (t < n) x(t) = x(t) + 1
     t = i - a(i)
     if (t > 1) y(t) = y(t) + 1
  end do
  print *, sum(x*y)
end program abc166e
