#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll v[300000],r[300000],l[300000];
int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;++i){
    cin>>v[i];
    r[min(200000LL,i+v[i])]++;
    l[max(0LL,i-v[i])]++;
  }
  ll ans=0;
  for(int i=1;i<=n;++i){
    ans+=r[i]*l[i];
  }
  cout<<ans;
}