#include <bits/stdc++.h>
using namespace std;
//#include <stdlib.h>

int main()
{
    vector <unsigned int> height;
   unsigned int n, i,j, number = 0,min=0,max=0;
   scanf("%u", &n);

    for(i = 0; i < n; i++)
    {
        scanf("%u", &number);
        if(number>max)max=number;
        if(number<min||i==0)min=number;
        height.push_back(number);

    }
   // printf("%u\n",min);
   number=0;

    for(i = 0; i < n-1; i++)
    {
        j=(2*min>height[i])?i+2*min:i+height[i];

        for( ; j < n&&(j - i)<=2*max; j++)
        {
            if((j - i) == height[i] + height[j])
            {
                number++;
            }
        }
    }

    printf("%u\n", number);
    return 0;
}
