#include <stdio.h>
#include <inttypes.h>

int N;
int A[271828];

int left[271828];
int right[271828];

int main(void) {
	int i;
	int64_t count = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}
	for (i = 1; i <= N; i++) {
		int lidx = i - A[i], ridx = i + A[i];
		if (lidx >= 1) left[lidx]++;
		if (ridx <= N) right[ridx]++;
	}
	for (i = 1; i <= N; i++) {
		count += (int64_t)left[i] * right[i];
	}
	printf("%" PRId64 "\n", count);
	return 0;
}
