Problem:
Score: 500 points

Problem Statement

You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.

There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.

According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.

The absolute difference of their attendee numbers is equal to the sum of their heights.

There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?

P.S.: We cannot let you know the secret.

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the number of pairs satisfying the condition.

Sample Input 1

6
2 3 3 1 3 1

Sample Output 1

3

A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.

A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.

A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.

No other pair satisfies the condition, so you should print 3.

Sample Input 2

6
5 2 4 2 8 8

Sample Output 2

0

No pair satisfies the condition, so you should print 0.

Sample Input 3

32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Sample Output 3

22

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

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");
            }
        }
    }
}