#include <bits/stdc++.h>

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define vct vector
#define stk stack
#define qu queue
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define br break
#define con continue
#define re return
#define tc(t) int t; cin>>t; while(t--)
#define q(q) int q; cin>>q; while(q--)
#define subs substr
#define er erase

const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

int fact(int n,int M)
{
    int r=1;
    loop(i,0,n)
    {
        r=(r*(i+1))%M;
    }
    re r;
}

int cons_freq(int a[],int n,int p,int q)
{
    int c=0;
    for(int i=p;i<n;i++)
    {
        if(a[i]==q) c++;
        else br;
    }
    re c;
}

int binary_search(int a[],int low,int high,int key)
{
    while(low<=high)
    {
        int mid=low+(high-low)/2;
        if(a[mid]<key) low=mid+1;
        else if(a[mid]>key) high=mid-1;
        else re mid;
    }
    re -1;
}

bool check_perfect_square(int n)
{
    re (sqrt(n)-floor(sqrt(n))==0);
}

bool check_prime(int n)
{
    if(n<2) re false;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0) re false;
    }

    re true;
}

bool check_pali(string s)
{
    string str=s;
    reverse(str.begin(),str.end());

    re str==s;
}

void dfs(vct <int> adj[],bool vis[],int s)
{
    vis[s]=true;
    for(int i=0;i<adj[s].size();i++)
    {
        if(!vis[adj[s][i]])
            dfs(adj,vis,adj[s][i]);
    }
}

void bfs(vct <int> adj[],bool vis[],int s)
{
    qu <int> q;
    q.push(s);
    vis[s]=true;
    while(!q.empty())
    {
        int v=q.front();
        q.pop();
        for(int i=0;i<adj[v].size();i++)
        {
            if(!vis[adj[v][i]])
            {


                vis[adj[v][i]]=true;
                q.push(adj[v][i]);
            }
        }
    }
}

void dijkstra(vct <pair<int,int> > adj[],int src,bool vis[],int dist[],int n)
{
    //First is distance from source vertex, second is index of the vertex
    ms <pair <int,int> > s;
    s.insert(make_pair(0,src));
    while(!s.empty())
    {
        pair <int,int> p=*s.begin();
        s.erase(s.begin());
        int d=p.fi,v=p.se;
        if(vis[v]) continue;
        vis[v]=true;
        for(int i=0;i<adj[v].size();i++)
        {
            if(dist[v]+adj[v][i].se<dist[adj[v][i].fi])
            {
                dist[adj[v][i].fi]=dist[v]+adj[v][i].se;
                s.insert(mp(dist[adj[v][i].fi],adj[v][i].fi));
            }
        }
    }

}

int Kadane(int a[],int n)
{
    int dp[n];
    dp[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
        dp[i]=max(dp[i+1]+a[i],a[i]);
    }
    re *_max(dp,dp+n);
}

int digits(int n)
{
    int c=0;
    while(n)
    {
        c++;
        n/=10;
    }
    re c;
}

int setbits(int n)
{
    re __builtin_popcount(n);
}

int lcm(int a,int b)
{
    re (a*b)/__gcd(a,b);
}

int minSwaps(int arr[], int n)
{
    // Create an array of pairs where first
    // element is array element and second element
    // is position of first element
    pair<int, int> arrPos[n];
    for (int i = 0; i < n; i++)
    {
        arrPos[i].first = arr[i];
        arrPos[i].second = i;
    }

    // Sort the array by array element values to
    // get right position of every element as second
    // element of pair.
    sort(arrPos, arrPos + n);

    // To keep track of visited elements. Initialize
    // all elements as not visited or false.
    vector<bool> vis(n, false);

    // Initialize result
    int ans = 0;

    // Traverse array elements
    for (int i = 0; i < n; i++)
    {
        // already swapped and corrected or
        // already present at correct pos
        if (vis[i] || arrPos[i].second == i)
            continue;

        // find out the number of  node in
        // this cycle and add in ans
        int cycle_size = 0;
        int j = i;
        while (!vis[j])
        {
            vis[j] = 1;

            // move to next node
            j = arrPos[j].second;
            cycle_size++;
        }

        // Update answer by adding current cycle.
        if (cycle_size > 0)
        {
            ans += (cycle_size - 1);
        }
    }

    // Return result
    return ans;
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;
    int a[n];
    map <int,int> m1,m2;
    loop(i,0,n)
    {
        cin>>a[i];
        m1[i+a[i]]++;
        m2[i-a[i]]++;
    }
    int c=0;
    for(auto p:m1)
    {
        c+=(p.se*m2[p.fi]);
    }
    cout<<c;
    re 0;
}


Measured memory_bytes: 39516