#include<stdio.h>
int main()
{
int n,i;
  scanf("%d",&n);
long long int sw1[n],sw2[n],a[n],ans;
  ans=0;
  for(i=0;i<n;++i)
  {
  sw1[i]=0;
  sw2[i]=0;
  scanf("%lld",&a[i]);
  }
  
  for(i=0;i<n;++i)
  {
  if(i-a[i]>=0) sw1[i-a[i]]++;
  if(i+a[i]<n) sw2[i+a[i]]++;
  }
  
  for(i=0;i<n;++i)
  {
  ans=ans+sw1[i]*sw2[i];
  }
  
  printf("%lld",ans);

return 0;}