#include<stdio.h>
#define ll long long
int main(){
    int n;
    scanf("%d",&n);
    ll a[n + 1];
    ll max = n;
    for(int i = 1; i <= n; i++){
        scanf("%lld",&a[i]);
        if(a[i] > n - 1)
            a[i] = 0;
    }
    ll ans = 0;
    ll b[n + 1], c[n + 1];
    for(int i = 1; i <= n; i++){
        b[i] = i - a[i];
        c[i] = i + a[i];
        if(a[i] == 0){
            b[i] = -1;
            c[i] = -1;
        }
    }
    int d[2 * n + 1];
    for(int i = 0; i < 2 * n; i++)
        d[i] = 0;
    for(int i = 1; i <= n; i++){
        if(c[i] >= 0)
            d[c[i]] ++;
    }
    for(int i = 1; i <= n; i++){
        if(b[i] >= 0){
            ans += d[b[i]];
        }
    }
    printf("%lld\n",ans);
    return 0;
}