using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc166
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc166E();
			Console.Out.Flush();

        }

        /*
        Obviousely we can solve this using bruteforce for O(n^2) using two loops
        for i and for j and compare the inidces diff and the sum of values, but it will get TLE.
        What is the faster solution? It was hard for me to come up with the solution not formalazing 
        it mathematically. This was my mistake. Always try to mathematically formalize it on a paper.
        Doesn't matter if you cannot mathematically well define the problem. At least, this will be
        more productive to assemble pieces of thoughts on the paper and to figure out dependencies.
        We can see here that there is a dependancy between indices and the sum of the values 
        at these indices. Formally, we can presend an equality like this: |i - j| = Ai + Aj.
        Yes, it may not be strictly correct, but at least it shows sort of the shape of what is happening
        mathematically.
        Let's get rid of the absolute difference for now.
        Then we have i - j = Ai + Aj. Ok if it is an equation then we can move things around there.
        Let's try:
        i = Ai + Aj + j Or
        i - j - Ai = Aj Or even
        i - Ai = Aj + j 
        By suggestions in comments:
        Ok let's take a closer look at the first one
        i = Ai + Aj + j
        Wait, i is really Equal to this statement Ai + Aj + j? Let's call Ai + Aj as sum then
        i = sum + j. Wait, whaat?
        */
        public static void solve_abc166E()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Dictionary<int, long> cnt = new Dictionary<int, long>();
            for (int i = 0; i < n; i++)
            {
                int t = i - a[i];
                if (cnt.ContainsKey(t))
                {
                    cnt[t]++;
                }
                else
                {
                    cnt.Add(t, 1);
                }
            }
            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                int t = i + a[i];
                if (cnt.ContainsKey(t))
                {
                    sum += cnt[t];
                }
            }
            Console.WriteLine(sum);
        }

        public static void solve_abc166D()
        {
            long x = Convert.ToInt64(Console.ReadLine());
            bool ok = false;
            int a = 0;
            int b = 0;
            for (int i = -200; i <= 200; i++)
            {
                for (int j = -200; j <= 200; j++)
                {
                    if ((long)Math.Pow(i, 5) - (long)Math.Pow(j, 5) == x)
                    {
                        a = i;
                        b = j;
                        ok = true;
                        break;
                    }
                }
                if (ok)
                {
                    break;
                }
            }
            Console.WriteLine("{0} {1}", a, b);
        }

        public static void solve_abc166C()
        {
            int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nm[0];
            int m = nm[1];
            int[] h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Dictionary<int, int> g = new Dictionary<int, int>();
            for (int i = 1; i <= n; i++)
            {
                g.Add(i, 0);
            }
            int cnt = 0;
            while (m-- > 0)
            {
                int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                if (h[ab[0] - 1] > h[ab[1] - 1])
                {
                    if (g[ab[0]] >= 0)
                    {
                        g[ab[0]]++;
                    }
                    g[ab[1]] = -1;
                }
                else if (h[ab[1] - 1] > h[ab[0] - 1])
                {
                    if (g[ab[1]] >= 0)
                    {
                        g[ab[1]]++;
                    }
                    g[ab[0]] = -1;
                }
                else
                {
                    g[ab[0]] = -1;
                    g[ab[1]] = -1;
                }
            }
            foreach (var item in g)
            {
                if (item.Value >= 0)
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }

        public static void solve_abc166B()
        {
            int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nk[0];
            int k = nk[1];
            int[] cnt = new int[n];
            while (k-- > 0)
            {
                int d = Convert.ToInt32(Console.ReadLine());
                int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                for (int i = 0; i < d; i++)
                {
                    cnt[a[i] - 1]++; 
                }
            }
            int sum = 0;
            for (int i = 0; i < cnt.Length; i++)
            {
                if (cnt[i] == 0)
                {
                    sum++;
                }
            }
            Console.WriteLine(sum);
        }

        public static void solve_abc166A()
        {
            string s = Console.ReadLine();
            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


Measured memory_bytes: 57256