#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    vector<ll> Fo, Se;
    ll N;
    cin>>N;
    ll A;
    rep(i, N){
        cin>>A;
        Fo.push_back(i+1+A);
        Se.push_back(i+1-A);
    }
    Fo.push_back(1000000); Se.push_back(10000000);
    ll count=0; ll fcount=0; ll scount=0; ll thisval=Fo[0];
    ll f=0, s=0;
    sort(all(Fo));
    sort(all(Se));
    while(true){
        while(Fo[f]>Se[s] && s<N) s++;
        while(Fo[f]<Se[s] && f<N) f++;
        if(f>=N || s>=N) break;
        if(Fo[f]==Se[s]){
            fcount=0; scount=0; thisval=Fo[f];
            while(Fo[f]==thisval && f<N) f++, fcount++;
            while(Se[s]==thisval && s<N) s++, scount++;
            count+=fcount*scount;
        }
    }
    cout<<count<<endl;
    return 0;
}
