#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <stdio.h>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(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)++)

void marge(int *, int);

int a[200010], p[200010], m[200010];
int main(void)
{

    int i, j, n, pi = 1, mp = 0, mi = 0;
    long long total = 0;
    scanf("%d", &n);
    rep(i, n)
    {
        scanf("%d", a + i);
        p[i] = i + a[i];
        m[i] = i - a[i];
    }
    marge(p, n);
    marge(m, n);
    p[n] = p[n - 1] + 1;
    rep2(i, 1, n + 1)
    {
        if (p[i] == p[i - 1])
        {
            pi++;
            continue;
        }
        rep2(j, mp, n)
        {
            if (p[i - 1] > m[j])
            {
                continue;
            }
            else if (p[i - 1] == m[j])
            {
                total += pi;
            }
            else
            {
                mp = j;
                break;
            }
        }
        pi = 1;
        mi = 0;
    }
    printf("%lld", total);
    return 0;
}

void marge(int *a, int n)
{

    if (n == 1)
        return;

    int *tmp;
    tmp = (int *)malloc((n) * sizeof(int));
    marge(a, n / 2);
    marge(a + n / 2, n - n / 2);

    for (int i = 0; i < n / 2; i++)
        tmp[i] = a[i];
    for (int i = n / 2; i < n; i++)
        tmp[i] = a[n / 2 + n - i - 1];

    int lp = 0, rp = n - 1, p = 0;
    int l3, r3;
    while (p < n)
    {
        l3 = tmp[lp];
        r3 = tmp[rp];
        if (l3 < r3)
        {
            a[p] = l3;
            lp++;
            p++;
        }
        else
        {
            a[p] = r3;
            rp--;
            p++;
        }
    }

    return;
}