#include <stdio.h>


int main(){
  int n;  scanf("%d", &n);
  static int a[100003];
  static int conne[100003][2];


  for(int i=1; i<=n; i++){
    conne[i][0] = conne[i][1] = 0;
  }
  
  for(int i=1; i<=n; i++){
    scanf("%d", &a[i]);
    if(i+a[i] <= n){
      conne[i+a[i]][0]++;
    }
    if(i-a[i] > 1){
      conne[i-a[i]][1]++;
    }
  }
  
  long long int count = 0;
  for(int i=2; i<n; i++){
    count = count + conne[i][0] * conne[i][1];
  }
  printf("%lld\n", count);
  return 0;
}
    
