#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int height[n];
    int max = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &height[i]);
        if (max < height[i])
            max = height[i];
    }
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + height[i]; j < (n < i + height[i] + 2 * max ? n : i + height[i] + 2 * max); j++)
            if (j - i == height[j] + height[i])
                ans++;
    }
    printf("%lld\n", ans);
    return 0;
}