#include<stdio.h>
int main()
{
int n,i,j,ans;
  ans=0;
 scanf("%d",&n);
  long int a[n];
  for(i=0;i<n;++i)
  {
  scanf("%ld",&a[i]);
  }
  
  for(i=0;i<n-2;++i)
  {if(i+a[i]+1<n )
     {for(j=i+a[i]+1;j<n;++j)
         {
          if(j-i == a[i]+a[j]) ans++;
          }
      }
  }
  printf("%d",ans);
  
return 0;
}