#include<stdio.h>

int main(){

    long long int N;
    scanf("%lld", &N);
    
    long long int i,j, ans;
    long long int A[200000+1] = {0};
    long long int X[200000+1] = {0};
    long long int Y[200000+1] = {0};

    for( i = 1; i <= N; i++ ){
        scanf("%lld", &A[i]);

        if( i + A[i] <= N ){
            X[ i+A[i] ] += 1;
            ans += Y[ i+A[i] ];
        }
        if( i - A[i] >= 0 ){
            Y[ i-A[i] ] += 1;
            ans += X[ i-A[i] ];
        }
    }
    


    printf("%lld\n", ans);

    return 0;
}
