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-----
6
2 3 3 1 3 1

-----Sample Output-----
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.

Difficulty: interview

Starter code:

Solutions:
from collections import defaultdict

def main():
    d = defaultdict(int)
    d2 = defaultdict(int)

    N = int(input())
    A = list(map(int, input().split()))

    for i in range(N):
        d[i + 1 + A[i]] += 1
        d2[max(0, (i + 1) - A[i])] += 1

    ans = 0

    for k,v in d.items():
        if k == 0:continue
        ans += v * d2[k]

    print(ans)

def __starting_point():
    main()
__starting_point()

def main():
    n = int(input())
    a = list(map(int,input().split()))
    f,s = {},{}
    for i in range(n):
        if i+1-a[i] not in list(f.keys()):
            f[i+1-a[i]] = 1
        else:
            f[i+1-a[i]]+=1
        if i+1+a[i] not in list(s.keys()):
            s[i+1+a[i]] = 1
        else:
            s[i+1+a[i]] += 1
    ans = 0
    for k in list(f.keys()):
        if k in list(s.keys()):
            ans += f[k] * s[k]
    print(ans)

def __starting_point():
    main()

__starting_point()

import collections
n = int(input())
a = list(map(int,input().split()))
ans = 0
cnt = collections.defaultdict(int)
for i in range(n):
  ans += cnt[i-a[i]]
  cnt[i+a[i]]+=1
print(ans)

import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):

    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x
def main():  #startline-------------------------------------------
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    ans = 0
    for i in range(n):
        l = i - a[i]
        ans += d[l]
        d[a[i] + i] += 1
        
    print(ans)
def __starting_point():
    main() #endline===============================================
__starting_point()

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
AP = [0]*N
AM = [0]*N

for i in range(N):
    AP[i]=i+A[i]
    AM[i]=i-A[i]

cnt=0
QC = Counter(AP)
for m in AM:
    cnt += QC[m]

print(cnt)

n=int(input())
y=list(map(int,input().split()))
from collections import Counter
lhs=Counter([j+y[j] for j in range(n)])
rhs=Counter([j-y[j] for j in range(n)])
count=0
for i in lhs:
   if i in rhs:
      count+=lhs[i]*rhs[i]

print(count)


import collections
n = int(input())
a = [0] + list(map(int,input().split()))

a_pos = [a[i]+i for i in range(1,n+1)]
a_neg = [-a[i]+i for i in range(1,n+1)]
#print(a_pos)
#print(a_neg)

c_pos = collections.Counter(a_pos)
c_neg = collections.Counter(a_neg)
#print(c_pos)
#print(c_neg)

ans = 0
for c in c_pos:
    ans += c_pos[c] * c_neg[c]

print(ans)

N = int(input())
A = [(int(x), i+1) for i, x in enumerate(input().split())]

def test(N, A):
    answer = 0
    for a0, i0 in A:
        for a1, i1 in A:
            if a1 + a0 == abs(i1 - i0):
                answer += 1
    return answer // 2

def solve(N, A):
    memo0 = {}
    memo1 = {}
    for a, n in A:
        k = - (a+n)
        if k not in memo0:
            memo0[k] = 0
        memo0[k]+=1
        k = n-a
        if k not in memo1:
            memo1[k] = 0
        memo1[k]+=1
    #print(f"{memo0=}")
    #print(f"{memo1=}")
    answer = 0
    for a, n in A:
        k = a - n
        if k in memo0:
            answer += memo0[k]
        k = a + n
        if k in memo1:
            answer += memo1[k]

    return answer // 2

#print(test(N, A))
print((solve(N, A)))




n = int(input())
a = list(map(int, input().split()))

b = [0 for i in range(n)]

cnt = 0
for i in range(n):
    if i - a[i] >= 0:
        cnt += b[i - a[i]]
    if i + a[i] < n:
        b[i + a[i]] += 1
print(cnt)

import collections
_,A=open(0);P,Q=map(collections.Counter,zip(*[[i-a,i+a]for i,a in enumerate(map(int,A.split()))]));print(sum(P[i]*Q[i]for i in range(6**7)))

from sys import stdin,stdout
# n,e=list(map(int,stdin.readline().split()))
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
d={};ans=0
for i in range(n):
    d[a[i]+i]=d.get(a[i]+i,0)+1
for i in range(n):
    ans+=d.get(i-a[i],0)
print(ans)

import collections
import bisect
n = int(input())
cnt = collections.defaultdict(list)
dat = list(map(int, input().split()))
buf = []
for i in range(n):
    cnt[i - dat[i]].append(i)
#print(buf)
res = 0
for i in range(n):
    x = i + dat[i]
    if x in cnt:
        res += len(cnt[x]) - bisect.bisect_left(cnt[x], x)
print(res)



# -*- coding: utf-8 -*-


def main():
    from collections import defaultdict
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    ans = 0

    for i in range(n):
        diff = i - a[i]
        ans += d[diff]

        summed = i + a[i]
        d[summed] += 1

    print(ans)


def __starting_point():
    main()

__starting_point()

import collections
N = int(input())
A = list(map(int, input().split()))

#i + Ai
plus = [0] * N
#i - Ai
minus = [0] * N

for i in range(N):
  plus[i] = i + 1 + A[i]
  minus[i] = i + 1 - A[i]
  
#print(plus, minus)  
plus = dict(collections.Counter(plus))
minus = dict(collections.Counter(minus))

#print(plus)
#print(minus)

ans = 0
for i in list(plus.keys()):
  #print(i)
  if i in minus:
    #print(i)
    ans += plus[i] * minus[i]
    #print(ans)

print(ans)


N = int(input())
A = [int(x) for x in input().split()]

counter = {}

for i in range(N):
    counter[i + A[i]] = 0

ans = 0
for i in range(N):
    if i - A[i] in counter:
        ans += counter[i - A[i]]
    counter[i + A[i]] += 1

print(ans)

import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A1 = []; A2 = []
    for i, a in enumerate(A):
        A1.append(i+1+a)
        A2.append(i+1-a)
    A1count = list(collections.Counter(A1).items())
    A2count = collections.Counter(A2)
    ans = 0
    for a, cnt in A1count:
        ans += A2count[a]*cnt
    print(ans)

def __starting_point():
    main()

__starting_point()

from collections import Counter
N = int(input())
A = list(map(int, input().split()))

L = [a+i for a, i in enumerate(A, 1)]
R = [a-i for a, i in enumerate(A, 1)]

ans = 0
R_c = Counter(R)
for l in L:
    ans += R_c[l]

print(ans)

# -*- coding: utf-8 -*-

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

plus_h = {}
minus_h = {}

for i in range(N):
    p = (i+1) + A_list[i]
    m = (i+1) - A_list[i]
    
    plus_h.setdefault(p, 0)
    plus_h[p] += 1
    
    minus_h.setdefault(m, 0)
    minus_h[m] += 1


cnt = 0

for k in plus_h:
    if k in minus_h:
        cnt += (plus_h[k] * minus_h[k])


print(cnt)


from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
L = defaultdict(int)
ans = 0
for i in range(N):
  L[i+1 - A[i]]+=1
for i in range(N):
  ans+=L[i+1+A[i]]
print(ans)



#!/usr/bin/env python3
import collections
import sys

input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))

# 2人の持つ番号の差の絶対値が、2人の身長の和に等しい。
# j - i = Ai + Aj
# j - Aj = Ai + i
l = [j - aj for j, aj in enumerate(a, 1)]
r = [i + ai for i, ai in enumerate(a, 1)]
cnt = collections.Counter(r)
ans = 0
for i in l:
    ans += cnt[i]
print(ans)


from collections import Counter

n=int(input())
a=list(map(int,input().split()))

l1=[i+a[i] for i in range(n)]
l2=[i-a[i] for i in range(n)]

c2=Counter(l2)

ans=0
for i in l1:
  ans+=c2[i]

print(ans)

from collections import Counter

N = int(input())
A = list(map(int, input().split()))

L = [a+i for i, a in enumerate(A)]
R = [j-a for j, a in enumerate(A)]

L, R = Counter(L), Counter(R)

ans = 0

for k in L.keys():
    ans += L[k] * R[k]

print(ans)

from collections import defaultdict

N = int(input())
*A,=map(int,input().split())

'''
方針:
- 各A_i,(i<h)ごとにf(h,j)=A_h+A_j-|h-j|の値がf(i,j)に比べてどれだけ変化するかを計算し、
リストに格納(①)
- 各要素A_k,(j<k)ごとにf(i,k)=A_i+A_k-|i-k|の値がf(i,j)に比べてどれだけ変化するかを
計算し、カウントをとる(②)
- 再度ループを回して①と②を照合し、値が一致する組数をansに加算
'''

ans=0
diff_list=[] #①照合用の差分リスト
count=defaultdict(int) #②各要素がどれだけはみ出ているかのカウント
#前処理として、最初のループで①と②を作成
for i in range(1,N):
  if i == A[0]+A[i]:
    ans += 1
  d1 = A[i]-A[0]
  d2 = i
  diff_list.append(d1+d2)
  
  count[A[0]+A[i]-i] += 1

for i in range(N-1):
  count[A[0]+A[i+1]-(i+1)] -= 1 #その要素自身を忘れずに引く
  d = diff_list[i]
  ans += count[-d]
  
print(ans)

from collections import Counter
n=int(input())
x=list(map(int,input().split()))
a=[]
b=[]
for i in range(n):
    a.append(x[i]+i+1)
    b.append((i+1)-x[i])
a,b=Counter(a),Counter(b)
ans=0
for i in range(n):
    ans+=a[i]*b[i]
print(ans)

import sys
from bisect import bisect_right, bisect_left
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    A_i, A_j = [], []
    for i in range(n):
        A_i.append(-A[i] - (i + 1))

    for j in range(n):
        A_j.append(A[j] - (j + 1))

    A_j.sort()

    res = 0
    for a in A_i:
        idx_1 = bisect_left(A_j, a)
        idx_2 = bisect_right(A_j, a)
        res += idx_2 - idx_1
    print(res)
    

def __starting_point():
    resolve()

__starting_point()

from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dAl = defaultdict(int)
dAr = defaultdict(int)
for i in range(N):
    L = (i + 1) + A[i]
    R = (i + 1) - A[i]
    dAl[L] += 1
    dAr[R] += 1

# dictの中を見る
ans = 0
for k, v in dAl.items():
    ans += v * dAr[k]
print(ans)

def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    mp = dict()
    ans = 0
    for i in range(N):
        x = i - A[i]
        ans += mp.get(x, 0)
        y = A[i] + i
        mp[y] = mp.get(y, 0) + 1
    print(ans)

def __starting_point():
    resolve()
__starting_point()

N = int(input())
Alist = list(map(int,input().split()))
Aplu = []
Amin = dict()
for i in range(N):
    A = Alist[i]
    Aplu.append(A+(i+1))
    if (i+1)-A not in Amin:
        Amin[(i+1)-A] = 1
    else:
        Amin[(i+1)-A] += 1
Answer = 0
for k in Aplu:
    if k in Amin:
        Answer += Amin[k]
print(Answer)

from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))

d=defaultdict(int)
sm=0
for i in range(n):
  d[i+a[i]]+=1
  sm+=d[i-a[i]]
print(sm)


n = int(input())
a = list(map(int, input().split()))
num = dict()
ans = 0

for i in range(n):
    num[i+a[i]] = 0
    
for i in range(n):
    num[i+a[i]] += 1
    
for i in range(n):
    if i-a[i] in num:
        ans += num[i-a[i]]
        
print(ans)
    


def getInts():
    return [ int(x) for x in input().split() ]

[N] = getInts()
As = getInts()
A = {}
for i in range(1, N+1):
    A[i] = As[i-1]

L = {}
R = {}
for i in range(1, N+1):
    if i - A[i] not in L:
        L[i-A[i]] = 1
    else:
        L[i-A[i]] += 1
    if i + A[i] not in R:
        R[i+A[i]] = 1
    else:
        R[i+A[i]] += 1
count = 0
for k in list(R.keys()):
    if k in L:
        count += R[k]*L[k]
print(count)


from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
constS = defaultdict(int)
constD = defaultdict(int)
for i in range(N):
    Ss = i + A[i]
    Dd = i - A[i]
    constS[Ss] += 1
    constD[Dd] += 1
ans = 0
for key,val in constS.items():
    ans += val * constD[key]
print(ans)

from collections import Counter

N = int(input())
A = list(map(int, input().split()))

p = [i+Ai for i, Ai in zip(range(1, N+1), A)]
q = [j-Aj for j, Aj in zip(range(1, N+1), A)]

pc = Counter(p)
qc = Counter(q)

r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys())

print(r)

N = int(input())
A = list(map(int, input().split()))
A = [0] + A
Sam = []
Dif = []
D2= [0]*200000

for i in range(len(A)):
    Sam.append(i + A[i])
    if i - A[i] > 0:
        Dif.append(i - A[i])

for dif in Dif:
    D2[dif] += 1

count = 0
for sam in Sam:
    if sam < len(D2):
        count += D2[sam]

print(count)

from collections import Counter
n = int(input())
A = list(map(int, input().split()))

P = [i+a+1 for i,a in enumerate(A)]
Q = [j-a+1 for j,a in enumerate(A)]

cQ = Counter(Q)
ans = 0
for p in P:
    ans += cQ[p]
print(ans)

from collections import Counter

n=int(input())
a=list(map(int,input().split()))

l1=[i+a[i] for i in range(n)]
l2=[i-a[i] for i in range(n)]

c1=Counter(l1)
c2=Counter(l2)

ans=0
for i in c1:
  ans+=c1[i]*c2[i]

print(ans)

import sys,collections
input = sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
B = []
C = []
for i,a in enumerate(A):
    B.append(i+a)
    C.append(i-a)
cnt = 0
Bc = collections.Counter(B)
Cc = collections.Counter(C)

for key,val in list(Bc.items()):
    cnt += val*Cc[key]
print(cnt)


from collections import Counter

n = int(input())
A = list(map(int, input().split()))

A_pos = [A[x]+x for x in range(n)]
A_neg = [-A[x]+x for x in range(n)]

C_pos = Counter(A_pos)
C_neg = Counter(A_neg)

ans = 0

for c in C_pos:
    ans += C_pos[c] * C_neg[c]
print(ans)

from collections import defaultdict

def main():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(lambda: 0)
    ans = 0
    for i, ai in enumerate(a, 1):
        d[str(i+ai)] += 1
        ans += d[str(i-ai)]
    print(ans)
        

def __starting_point():
    main()
__starting_point()

# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr
A.insert(0, 0)
cnt = [0] * (N + 1)
ans = 0
for i in range(1, N + 1):
    if i - A[i] >= 0:
        ans += cnt[i - A[i]]
    if i + A[i] <= N:
        cnt[i + A[i]] += 1
print(ans)

from collections import defaultdict

def main():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(lambda : 0)
    ans = 0
    for i, ai in enumerate(a, 1):
        num = str(ai+i)
        d[num] += 1
        ans += d[str(i-ai)]
    print(ans)
        

def __starting_point():
    main()
__starting_point()

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = Counter(list(i+1+A[i] for i in range(N)))
#print(B,B[3])
C = Counter((i+1-A[i] for i in range(N)))
ans = 0
#print(C)
for j in range(N):
    ans += B[j]*C[j]
print(ans)

from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    L = Counter([i + a for i, a in enumerate(A)])
    R = Counter([i - a for i, a in enumerate(A)])
    ans = 0
    for key in list(R.keys()):
        ans += L[key] * R[key]
    print(ans)

def __starting_point():
    main()

__starting_point()

N = int(input())
A = list(map(int, input().split()))

p = [0] * N
m = [0] * N

for i in range(N):
    p[i] = A[i] + i + 1
    m[i] = i + 1 - A[i]

from collections import Counter

cp = Counter(p)
cm = Counter(m)

ans = 0

for x, y in cp.items():
    ans += cm[x] * y

print(ans)

N = int(input())
L = list(map(int, input().split()))
import copy
U = copy.copy(L)
for i in range (0, N):
	L[i]+=(i+1)
	U[i]= -U[i]+(i+1)


L = sorted(L)
U = sorted(U)

import bisect

count = 0
for i in range (0, N):
	count+= bisect.bisect_right(U, L[i])-bisect.bisect_left(U, L[i])
    
print(count)

n=int(input())
a=[int(x) for x in input().split()]

dic1={}
dic2={}
for i in range(n):
  if i+1+a[i] not in dic1:
    dic1[i+1+a[i]]=1
  else:
    dic1[i+1+a[i]]+=1

for i in range(n):
  if i+1-a[i] not in dic2:
    dic2[i+1-a[i]]=1
  else:
    dic2[i+1-a[i]]+=1

ans=0

for i in dic1:
  if i not in dic2:
    continue

  ans+=dic1[i]*dic2[i]
print(ans)

import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N = i_input()
    A = i_list()

    L = [i+k for i,k in enumerate(A)]
    R = [i-k for i,k in enumerate(A)]

    countR = Counter(R)
    ans = 0
    for l in L:
        ans += countR[l]
    print(ans)

def __starting_point():
    main()


__starting_point()

import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

P = [i + a for i, a in enumerate(A, start=1)]
Q = [j - a for j, a in enumerate(A, start=1)]

res = 0
C = Counter(Q)
for p in P:
    res += C[p]

print(res)


from collections import defaultdict

N = int(input())
A = [int(_) for _ in input().split()]

F = defaultdict(int)
B = defaultdict(int)

for i, v in enumerate(A):
    F[i+v] += 1
    B[i-v] += 1

ans = 0
for i in F:
    ans += F[i] * B[i]
print(ans)


from collections import Counter
n = int(input())
A = list(map(int, input().split()))
ma = max(A) + n -1 
P = [i+a+1 for i,a in enumerate(A) if i+a+1 <= ma]
Q = [j-a+1 for j,a in enumerate(A) if j-a+1 > 0]
 
cQ = Counter(Q)
cP = Counter(P)
ans = 0
for p in cP.keys():
    ans += cQ[p]*cP[p]
print(ans)

from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

n = int(input())
a = list(map(int, input().split()))

p = [i-a[i] for i in range(n)]
q = [a[i]+i for i in range(n)]

pp = Counter(p)
qq = Counter(q)

ans = 0
for d in list(pp.items()):
    ans += d[1] * qq[d[0]]

print(ans)








from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
dic = defaultdict(int)

ans = 0
#j-i = Ai+A　⇄　j-A[j] = A[i]+i
for i in range(n):
    Sum = A[i] + i
    dic[Sum] += 1
    Dif = i - A[i]
    ans += dic[Dif]
print(ans)


from collections import defaultdict
b = defaultdict(int)
c = defaultdict(int)
n = int(input())
a = map(int, input().split())

for idx,i in enumerate(a, start=1):
  b[i - idx] += 1
  c[i + idx] += 1
ans = 0
for k,v in b.items():
  ans += (v * c[-1 * k])
print(ans)

#import numpy as np
#import math
#from decimal import *
#from numba import njit
from collections import Counter

#@njit
def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = 0
    r = []
    l = []
    for i in range(N):
        r += i - A[i],
        l += i + A[i],

    c = Counter(l)
    for i in r:
        count += c[i]

    print(count)
main()


n = int(input())
a = list(map(int,input().split()))
ans = 0
d = {}
for i in range(n):
  if d.get(i+a[i],0)==0:
    d[i+a[i]] = [0,0]
  if d.get(i-a[i],0)==0:
    d[i-a[i]] = [0,0]
  d[i+a[i]][0] += 1
  d[i-a[i]][1] += 1
for v in d.values():
  ans += v[0]*v[1]
print(ans)

# -*- coding: utf-8 -*-


def main():
    from collections import defaultdict
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    ans = 0

    # KeyInsight:
    # j - i = Ai + Aj (j > i)、条件つきで絶対値の記号を外す
    # ▲: 計算量を落とす: 片方を固定して、考えられないか?
    # 左辺・右辺を独立として考えられないか?
    # See:
    # https://www.youtube.com/watch?v=OCRLlMa7kL0&feature=youtu.be
    for i in range(n):
        # jまでにiがどれだけ条件を満たすかを判定している
        # Ai + i = j - Aj
        # jの計算に相当
        diff = i - a[i]
        ans += d[diff]

        # iの計算に相当
        summed = i + a[i]
        d[summed] += 1

    print(ans)


def __starting_point():
    main()

__starting_point()

n = int(input())
a = list(map(int, input().split()))
num = dict()
ans = 0

for i in range(n):
    num[i+a[i]] = 0

for i in range(n):
    if i-a[i] in num:
        ans += num[i-a[i]]
    num[i+a[i]] += 1
print(ans)
    


import collections
N=int(input())
A=list(map(int,input().split()))

s=0
d=collections.defaultdict(int)
for i in range(N):
  d[i+A[i]]+=1
for i in range(N):
  s+=d[i-A[i]]
print(s)

N = int(input())
A = list(map(int, input().split()))
ans = 0
B = []
C = []
maA = max(A) + N -1
for k in range(N):
  if A[k] + k <= maA:
    B.append(A[k]+k)
  if -A[k] + k >0:
    C.append(-A[k]+k)
B.sort()
C.sort()

c = 0
b = 0
while b < len(B) and c < len(C):
  if B[b] == C[c]:
    s = 0
    t = 0
    j = float('inf')
    k = float('inf')
    for j in range(b, len(B)):
      if B[b] == B[j]:
        s += 1
      else:
        break
    for k in range(c, len(C)):
      if C[c] == C[k]:
        t +=1
      else:
        break
    ans += s*t
    b = j
    c = k
    continue
  elif B[b] > C[c]:
    c += 1
  else:
    b += 1
#print(B)
#print(C)
print(ans)

from collections import Counter

def main():
    n=int(input())
    lst=list(map(int,input().split()))
    lst1=Counter([i+x for i,x in enumerate(lst)])
    lst2=Counter([i-x for i,x in enumerate(lst)])
    sm=0
    for x in lst1:
        if x in lst2:
            sm+=lst1[x]*lst2[x]
    print(sm)

main()

import numpy as np
from collections import Counter
n = int(input())
a = np.array(list(map(int, input().split())))
ni = np.array([i for i in range(n)])

ap = a + ni
an = (a - ni) * -1

cp = Counter(ap)
cn = Counter(an)

ans = 0
for i in cp.keys():
  ans += cp[i] * cn[i] 

print(ans)

from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
for i, a in enumerate(A):
    d[i + a] += 1
ans = 0
for j, a in enumerate(A):
    ans += d[j - a]
print(ans)

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
ans=0
for i,j in enumerate(a):
    b.append(i+j)
    c.append(i-j)
d=Counter(c)
for i in b:
    ans+=d.get(i,0)

print(ans)

from collections import defaultdict
import numpy as np
import collections

N = int(input())
As = list(map(int, input().split()))

B = defaultdict(int)

ans = 0

for index, A in enumerate(As):
    ans += B[index-A]
    
    B[index+A] += 1
#    print(B)
#    print(list(B[:20]))

print(ans)


n = int(input())
a = list(map(int, input().split()))
l = [i+a[i] for i in range(n)]
r = [i-a[i] for i in range(n)]
lc = {}
rc = {}
for i in range(n):
    lc[l[i]] = 0
    lc[r[i]] = 0
    rc[r[i]] = 0
    rc[l[i]] = 0
for i in range(n):
    lc[l[i]] += 1
    rc[r[i]] += 1
ans = 0
for i in set(lc.keys()):
    ans += rc[i]*lc[i]
print(ans)

n = int(input())
a = list(map(int, input().split()))

ipa = {}
ima = {}
for i in range(n):
    p = i + a[i]
    if p in ipa:
        ipa[p] += 1
    else:
        ipa[p] = 1
    m = i - a[i]
    if m in ima:
        ima[m] += 1
    else:
        ima[m] = 1

ans = 0
for k in ipa:
    if k in ima:
        ans += ipa[k] * ima[k]
print(ans)

# 参考 : https://atcoder.jp/contests/abc166/submissions/16829140
n = int(input())
a = list(map(int,input().split()))
# 参加者 i,j が取引する場合、 j - i = A_i + A_j が成り立つ。
# 変形すると -i - A_i = -j + A_j, i + A_i = j - A_j になる。
# l = i + A_i, r = j - A_j
l = [i + a[i] for i in range(n)]
r = [i - a[i] for i in range(n)]
# 連想配列(辞書)を使う。
x = {}
y = {}
# 辞書にキーを追加する。
for i in range(n):
    x[l[i]] = 0
    y[l[i]] = 0
    y[r[i]] = 0
# キーの値を人数分増やす。
for i in range(n):
    x[l[i]] += 1
    y[r[i]] += 1
ans = 0
# x のキーで取引する人数を調べる。
for i in set(x.keys()):
    ans += x[i] * y[i]
print(ans)

from collections import Counter
n = int(input())
x = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(i+1+x[i])
    b.append(i+1-x[i])
ans = 0
a, b = Counter(a), Counter(b)
for i in range(min(a), max(b)+1):
    ans += a[i]*b[i]
print(ans)

n = int(input())
a = list(map(int,input().split()))

dic = dict()
for i, j in enumerate(a, start=1):
    if dic.get(i-j):
        dic[i-j] += 1
    else:
        dic[i-j] = 1

ans = 0
for i, j in enumerate(a, start=1):
    if dic.get(i+j):
        ans += dic[i+j]

print(ans)

import collections

N = int(input())
A = list(map(int, input().split()))

# ap+aq == p-q (p>q)
# p-ap = q+aq

mp = {}
ans = 0
for p in range(N):
    if p-A[p]+1 in mp:
        ans += mp[p-A[p]+1]
    if p+A[p]+1 in mp:
        mp[p+A[p]+1] += 1
    else:
        mp[p + A[p] + 1] = 1

print(ans)




from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = [a+i for i, a in enumerate(A)]
C = [j-a for j, a in enumerate(A)]
B, C = Counter(B), Counter(C)
ans = 0
for k in B.keys():
    ans += B[k]*C[k]
print(ans)

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)

for i, a in enumerate(A):
    d[i+a] += 1

ans = 0
for j, a in enumerate(A):
    ans += d[j-a]

print(ans)


n=int(input())
a=list(map(int,input().split()))
b=[]
c=0
for i in range(n*2):
    b.append(0)
for i in range(n):
    if(i+a[i]<=n):
        b[i+a[i]]+=1
    if(i>=a[i]):
        c+=b[i-a[i]]

print(c)

from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
counter = defaultdict(int)

ans = 0
for i, v in enumerate(a):
    ans += counter[i - v]
    counter[i + v] += 1

print(ans)

N = int(input())
A = list(map(int, input().split()))
# i<jとして、条件は j-i = A_i + A_j
# i + A_i = j - A_j

dict1 = {}
for i in range(1, N + 1):
    tmp = i + A[i - 1]
    if tmp not in dict1:
        dict1[tmp] = 1
    else:
        dict1[tmp] += 1

dict2 = {}
for i in range(1, N + 1):
    tmp = i - A[i - 1]
    if tmp not in dict2:
        dict2[tmp] = 1
    else:
        dict2[tmp] += 1

# print(dict1, dict2)
ans = 0
for k, v in list(dict1.items()):
    if k in dict2:
        ans += v * dict2[k]
print(ans)


N = int(input())
L = [0] * (404040)
A = list(map(int, input().split()))
ans = 0
for i, a in enumerate(A):
    ia = i - a
    if ia >= 0:
        ans += L[ia]
    ai = a + i
    if ai < 404040:
        L[ai] += 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
L = {}
R = {}
ans = 0
for i in range(N):
  t = i + 1 + A[i]
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  t = i + 1 - A[i]
  if t > 0:
    if t in R:
      R[t] += 1
    else:
      R[t] = 1
for i in R:
  if i in L:
    ans += R[i] * L[i]
print(ans)

n = int(input())
h_list = list(map(int,input().split()))

a_dict = dict()
b_dict = dict()

for i in range(n):
    a = h_list[i]+i
    b = i-h_list[i]
    if not a in a_dict:
        a_dict[a] = 1
    else:
        a_dict[a] += 1
    if not b in b_dict:
        b_dict[b] = 1
    else:
        b_dict[b] += 1

count = 0
for a in a_dict:
    if a in b_dict:
        count += a_dict[a]*b_dict[a]
print(count)


N=int(input())
A=list(map(int,input().split()))

d={}

for i in range(len(A)):
  d.setdefault(i-A[i],0)
  d[i-A[i]]+=1
ans=0
for i in range(len(A)):
  if d.get(i+A[i]):
    ans+=d.get(i+A[i])
print(ans)

n = int(input())
a = list(map(int,input().split()))

x = [ aa + i  for i,aa in enumerate(a,start = 1)]
y = [ i - aa  for i,aa in enumerate(a,start = 1)]

from collections import Counter
c = Counter(y)
ans = 0
for xx in x:
    ans += c[xx]
print(ans)





N = int(input())
A = list(map(int, input().split()))
start = [0]*N
ans = 0
for i in range(N):
    if i+A[i]+1 < N:
        start[i+A[i]+1] += 1

for i in range(N):
    if i-A[i]+1 < 0:
        continue
    if i-A[i]+1 >= N:
        continue
    ans += start[i-A[i]+1]

print(ans)


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n = int(input())
    a = list(map(int, input().split()))

    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i, ae in enumerate(a):
        d1[i + ae +1] += 1
        d2[i - ae +1] += 1
    r = 0
    for d1e in d1.keys():
        rt = d1[d1e] * d2[d1e]
        r += rt
    print(r)

def __starting_point():
    main()
__starting_point()

n=int(input())
a=list(map(int,input().split()))
num1=[0]*(2*(10**5)+10)
num2=[0]*(2*(10**5)+10)
for i in range(n):
    if a[i]+i+1<2*(10**5)+5:
        num1[a[i]+i+1]+=1
    if a[i]+1<i+1:
        num2[-a[i]+i+1]+=1
ans=0
for i in range(len(num1)):
    ans+=num1[i]*num2[i]
print(ans)


n = int(input())
arr = list(map(int,input().split()))
addarr = [i+1+arr[i] for i in range(n)]
diffarr = [i+1-arr[i] for i in range(n)]

from collections import Counter
cnt = Counter([addarr[0]])
ans = 0

for i in range(1,n):
    tmp = diffarr[i]
    ans += cnt[tmp]
    cnt.update([addarr[i]])

print(ans)

from collections import Counter
N = int(input())
A = list(map(int, input().split()))

s = [i+a for i, a in enumerate(A)]
t = [j-a for j, a in enumerate(A)]

d = Counter(s)
ans = 0

for i in t:
    ans += d[i]
print(ans)

n=int(input())
a=list(map(int,input().split()))
ans=0

l=[]
r=[]

for i in range(n):
  nu=i+1
  x=a[i]
  l.append(x+nu)
  r.append(nu-x)
  
di1={}
di2={}

for i in range(0,n):
  if i==n-1:
    continue
  else:
    if l[i] not in di1:
      di1[l[i]]=0
    di1[l[i]]+=1
    if r[i+1] not in di2:
      di2[r[i+1]]=0
    di2[r[i+1]]+=1
    if r[i+1] in di1:
      ans+=di1[r[i+1]]
      
print(ans)

from collections import Counter as C
n=int(input())
a=list(map(int,input().split()))
l=C([i+a[i]for i in range(n)])
r=C([i-a[i]for i in range(n)])
b=0
for i in l.keys():
    b+=l[i]*r[i]
print(b)

n = int(input())
a = list(map(int, input().split()))
count = {}
for i in range(len(a)):#番号と身長を引く
    minus = (i+1) - a[i]
    if minus in count:
        count[minus] += 1
    else:
        count[minus] = 1
total = 0
for i in range(len(a)):
    plus = a[i] + (i+1)
    if plus in count:
        total += count[plus]
print(total)


n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
ans=0
for i in range(n):
  b.append(i+1-a[i])
  c.append(a[i]+i+1)
x=max(b)
if x<=0:
  print(0)
  return
else:
  ans=0
  b_=[0]*(x+1)
  for i in range(n):
    if 0<=b[i]<=x:
      b_[b[i]]+=1
  for i in range(n):
    if 0<=c[i]<=x:
      ans+=b_[c[i]]
  print(ans)      

n = int(input())
a = list(map(int, input().split()))
b1,b2,dic,ans = [],[],{},0
for i, j in enumerate(a):
    b1.append(j-i)
    b2.append(-j-i)
for i, j in zip(b1, b2):
    if i in dic:
        ans += dic[i]
    if j in dic:
        dic[j] += 1
    else:
        dic[j] = 1
print(ans)

# 雰囲気で書いたら通ってしまったがなんで通ったかわからん
# i<jという前提を無視しているのではと感じる

N = int(input())
A = list(map(int, input().split()))
# i<jとして、条件は j-i = A_i + A_j
# i + A_i = j - A_j

dict1 = {}
for i in range(1, N + 1):
    tmp = i + A[i - 1]
    if tmp not in dict1:
        dict1[tmp] = 1
    else:
        dict1[tmp] += 1

dict2 = {}
for i in range(1, N + 1):
    tmp = i - A[i - 1]
    if tmp not in dict2:
        dict2[tmp] = 1
    else:
        dict2[tmp] += 1

# print(dict1, dict2)
ans = 0
for k, v in list(dict1.items()):
    if k in dict2:
        ans += v * dict2[k]
print(ans)


from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

#i - j == a[i] + a[j]
#=> i - a[i] == j + a[j]
#j - i == a[i] + a[j]
#=> i + a[i] == j - a[j]
n = INT()
a = LIST()
c = [0]*(2*n+1)
for i in range(n):
    if i - a[i] >= 0:
        c[i-a[i]] += 1
ans = 0
for i in range(n):
    if i + a[i] <= 2*n:
        ans += c[i+a[i]]
print(ans)

n = int(input())
a = list(map(int,input().split()))

dic = {}

ans = 0
for i in range(n):
    if i+1-a[i] in dic:
        ans += dic[i+1-a[i]]
    
    if a[i]+(i+1) in dic:
        dic[(i+1)+a[i]] = dic[(i+1)+a[i]] + 1
    else:
        dic[(i+1)+a[i]] = 1
        
print(ans)

import collections
N = int(input())
A = [0]
A += list(map(int, input().split()))
cnt = 0
L = [- 10 ** 6]
R = [- 10 ** 6]

for i in range(1, N + 1):
    L.append(i + A[i])
    R.append(i - A[i])
c = collections.Counter(L)

for j in range(1, N + 1):
    cnt += c.get(R[j], 0)
print(cnt)