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# (Mono-mcs 6.8.0.105) (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC166
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_E();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var s = Ex.Read;

            var str = s == "ABC" ? "ARC" : "ABC";
            str.Cw();
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            var l = Ex.ReadIntArray();
            // N 人のすぬけ君  K 種類のお菓子
            var n = (int)l[0];
            var k = (int)l[1];

            // お菓子を1つも持っていない
            bool[] ans = new bool[n];

            for (int i = 0; i < k; i++)
            {
                var ii = Ex.ReadInt;
                var l2 = Ex.ReadIntArray();
                foreach (var v in l2) ans[v - 1] = true;
            }
            ans.Where(v => !v).Count().Cw();
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
            var l = Ex.ReadLongArray();
            // N 個の展望台があり、展望台 i の標高は H i です。  M 本の道
            // 道jは展望台Ajと展望台Bjを結んでいます
            var n = l[0];
            var m = l[1];

            var h = Ex.ReadLongArray();

            //展望台 i から一本の道を使って辿り着ける どの展望台よりも展望台 i の方が標高が高い
            //展望台 i から一本の道を使って辿り着ける 展望台が存在しない場合
            bool[] ans = new bool[n];

            for (int i = 0; i < m; i++)
            {
                var lm = Ex.ReadLongArray();
                var a = lm[0] - 1;
                var b = lm[1] - 1;
                if (h[a] <= h[b]) ans[a] = true;
                if (h[a] >= h[b]) ans[b] = true;
            }
            ans.Where(v => !v).Count().Cw();
        }
    }
    public class ABC_D
    {
        long x;
        public ABC_D()
        {
            x = Ex.ReadLong;
            if (0 == x)
            {
                $"0 0".Cw();
                return;
            }

            long[] arr = new long[90];

            //for (long i = 0; true; i++)
            //{
            //    if (i * i * i * i * i > 2 * 1000000000)
            //    {
            //        i.Cw();
            //        break;
            //    }
            //}
            for (long i = 0; i < 90; i++)
            {
                arr[i] = i * i * i * i * i;
                if (arr[i] == x)
                {
                    $"0 -{i}".Cw();
                    return;
                }
            }
            for (long j = 0; j < 90; j++)
            {
                for (long k = j; (arr[j] + arr[k]) <= x && k < 88; k++)
                {
                    //$"{j} -{k}".Cw();
                    if (arr[j] + arr[k] == x)
                    {
                        $"{j} -{k}".Cw();
                        return;
                    }
                }
                for (long k = j; k > 0 && (arr[j] - arr[k]) <= x; k--)
                {
                    // $"{j} {k}".Cw();
                    if (arr[j] - arr[k] == x)
                    {
                        $"{j} {k}".Cw();
                        return;
                    }
                }
            }
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
            long n = Ex.ReadLong;
            var l = Ex.ReadLongArray();
            long ans = 0;
            long[] arr = new long[n];
            for (long i = 0; i < n; i++)
            {
                if (i - l[i] >= 0)
                    arr[i - l[i]]++;
            }
            for (long i = 0; i < n; i++)
            {
                if (i + l[i] < n) ans += arr[i + l[i]];
            }
            ans.Cw();
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static string yesno(this bool b) { return b ? "yes" : "no"; }
        public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        public static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}