#include<stdio.h>
#define ll long long


int main(void)
{
  ll n;
  scanf("%lld", &n);
  ll ans = 0;
  ll a[n];
     for(ll i = 0; i < n; i++) {
        scanf("&lld", &a[i]);
    }

       for(ll i = n - 1; i > 2; i--) {
        for(ll j = 1 + a[i]; j <= i; j++) {
            if(j == a[i] + a[i - j])
                ans++;
        }
    }

    printf("%lld", ans);
 
}