#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <stdio.h>
#include <stdlib.h>

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) ((a) > 0 ? (a) : (-1 * (a)))
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define rep2(i, s, e) for ((i) = (s); (i) < (e); (i)++)

int main(void)
{
    int i, j, n, cnt = 0;
    int *a, *b;

    scanf("%d", &n);

    a = (int *)malloc(n * sizeof(int));
    b = (int *)malloc(n * sizeof(int));

    rep(i, n)
        scanf("%d", a + i);
    b[n - 1] = a[n - 1];
    rep(i, n - 1)
    {
        if (b[n - 1 - i] > a[n - 2 - i])
            b[n - 2 - 1] = a[n - 2 - i];
    }
    rep(i, n)
    {
        rep2(j, i + a[i] + b[min(i + a[i] + b[min(n - 1, i + a[i])], n - 1)], n)
        {
            if (a[i] + a[j] == j - i)
                cnt++;
        }
    }
    printf("%d", cnt);
    return 0;
}
