#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <stdlib.h>
#include <math.h>

void merge_sort(long int array[], long int right, long int left);

long int a[200000];

int main(void)
{
	long int i, j, k;
	long int n;
	long int siraberuhito[200000];
	long int ninzu = 0;
	long int work;
	long int flg = 0;
	long int ans = 0;
	
	scanf("%ld", &n);
	
	for(i = 0; i < n; i++) {
		scanf("%ld", &a[i]);
		if(a[i] < n) {
			siraberuhito[ninzu] = i;
			ninzu++;
		}
	}
	
	merge_sort(siraberuhito, 0, n - 1);
	/*
	for(i = 0; i < ninzu; i++) {
		printf("%ld %ld\n", siraberuhito[i], a[siraberuhito[i]]);
	}
	*/
	for(i = 0; i < ninzu; i++) {
		if(2 * a[i] > n) {
			break;
		}
		for(j = i + 1; j < ninzu; j++) {
			if(labs(siraberuhito[i] - siraberuhito[j]) == a[siraberuhito[i]] + a[siraberuhito[j]]) {
				ans++;
			}
		}
	}
	
	printf("%ld\n", ans);
	
	return 0;
}

void merge_sort(long int array[], long int left, long int right)
{
	long int i, j, k, mid;
	long int work[200000];
	if(left < right) {
		mid = (left + right) / 2;
		merge_sort(array, left, mid);
		merge_sort(array, mid + 1, right);
		for(i = mid; i >= left; i--) {
			work[i] = array[i];
		}
		for(j = mid + 1; j <= right; j++) {
			work[right - (j - (mid + 1) )] = array[j];
		}
		i = left;
		j = right;
		for(k = left; k <= right; k++) {
			if(a[work[i]] < a[work[j]]) {
				array[k] = work[i++];
			} else {
				array[k] = work[j--];
			}
		}
	}
}