#include <stdio.h>
typedef long long ll;
typedef struct hoge{
    ll A;
    ll l;
    ll r;
}height;

int main(){
  ll N;
  ll ans=0;
  scanf("%lld",&N);
  ll L[N];
  ll R[N];
  height H[N];
  for(ll i = 0;i<N;i++){
    scanf("%lld",&H[i].A);
    H[i].l = i-H[i].A;
    H[i].r = i+H[i].A;
    L[i]=0;
    R[i]=0;
  }
  for(ll i = 0;i<N;i++){
    if(H[i].r < N) R[H[i].r]++;
    if(H[i].l>=0) L[H[i].l]++;
  }
  for(ll i = 0;i<N;i++) ans+=R[i]*L[i];
  printf("%lld\n",ans);
  return 0;
}