        #include <stdio.h>
        #define N 200001
        int r[2 * N] = {0};
         
        int main() {
            int n, a[N], t;
            long long int u, s = 0;
            scanf("%d", &n);
            for (int i = 1; i <= n; i++) {
                scanf("%lld", &u);
                if (u < N) {
                    t = i - u;
                    if (0 <= t && t < 2 * N) r[t]++;
                    a[i] = (int) u;
                } else a[i] = 0;
            }
            for (int i = 1; i < n; i++) {
                u = a[i] + i;
                t = i - a[i];
                if (0 <= t && t < 2 * N) r[t]--;
                if (a[i] && u < 2 * N) s += r[u];
            }
            printf("%lld", s);
            return 0;
        }