CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
for i in range(n):
    for j in range(i + a[i],n):
        if a[i] + a[j] == j - i:
            count += 1
print(count)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = [0] * n
count = 0
for i in range(n):
    if i + a[i] < n:
        b[i + a[i]] += 1
    if i - a[i] >= 0:
        count += b[i-a[i]]
print(count)
# Original solution
import collections


n = int(input())
hs = list(map(int, input().split(' ')))
def f(hs):
	#print sorted([(e,i) for i,e in enumerate(hs)])
	count =0
	for i in range(len(hs)):
		for j in range(i+1, len(hs)):
			if hs[i] + hs[j] == j-i:
				count+=1
	return count
print(f(hs))

# Optimized solution
import collections
n = int(input())
hs = list(map(int, input().split(' ')))
def f(nums):
	cc,count = collections.Counter(), 0

	#j - i = aj + ai  =>  ai + i = j - aj
	for i in range(len(nums)-1, -1, -1):
		count += cc[nums[i] + i]
		cc[i - nums[i]]+=1
	return count
		


print(f(hs))
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
pair=0
X2=[]

for i in range(N):
    a=A[i]
    x1=i+1-a
    x2=i+1+a
    pair+=X2.count(x1)
    X2.append(x2)
print(pair)

# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
pair=0
As={}

for i in range(N):
    a=A[i]
    x1=i+1-a
    x2=i+1+a
    if x1 in As:
        pair+=As[x1]
    if x2 in As:
        As[x2]+=1
    else:
      As[x2]=1
print(pair)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

x = []
y = []

for i, elem in enumerate(a):
    x.append(i+a[i])
    y.append(i-a[i])

ans = 0

for i in x:
    ans += y.count(i)

print(ans)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

x = []
y = {}

for i, elem in enumerate(a):
    x.append(i+a[i])
    y[i-a[i]] = y.get(i-a[i], 0) + 1

ans = 0

for i in x:
    ans += y.get(i, 0)

print(ans)
# Original solution
import itertools

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

# total = N * (N-1) // 2

combi = list(itertools.combinations(list(range(N)), 2))

count = 0
for i, j in combi:
    if A[i] + A[j] == abs(i-j):
        count += 1
print(count)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

count = 0

for i in range(N):
    for j in range(i+A[i], N):
        if A[i] + A[j] == abs(i-j):
            count += 1

print(count)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

count = 0

for diff in range(1, N):
    for i in range(N-diff):
#        print(diff, i, i+diff)
        if i+diff < N and A[i] + A[i+diff] == diff:
            count += 1

print(count)


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
L = {}

count = 0

for i in range(N):
    l = i + A[i]
    r = i - A[i]
    if r in list(L.keys()):
        count += L[r]
    if l in list(L.keys()):
        L[l] += 1
    else:
        L[l] = 1
print(count)
# Original solution
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    a = na()

    larger = [(i + 1) - a[i] for i in range(n)]
    larger_cnt = collections.Counter(larger)

    ans = 0
    for j in range(n):
        smaller = a[j] + (j + 1)
        larger_cnt[(j + 1) - a[j]] -= 1
        if smaller in list(larger_cnt.keys()):
            if larger_cnt[smaller] != 0:
                ans += larger_cnt[smaller]

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    a = na()

    larger = [i - a[i] for i in range(n)]
    larger_cnt = collections.Counter(larger)

    ans = 0
    for j in range(n):
        smaller = a[j] + j
        larger_cnt[j - a[j]] -= 1
        if smaller in list(larger_cnt.keys()):
            if larger_cnt[smaller] != 0:
                ans += larger_cnt[smaller]

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
heights = list(map(int, input().split()))

diffMax = 2 * max(heights)
diffMin = 2 * min(heights)

cnt = 0

for i in range(diffMin, max([diffMax, n]) + 1):
    for j in range(n - i):
        if (heights[j] + heights[j + i]) == i:
            cnt += 1
print(cnt)

# Optimized solution
n = int(eval(input()))
heights = list(map(int, input().split()))

diffMax = 2 * max(heights)
diffMin = 2 * min(heights)

cnt = 0

arrSize = min([max([i + heights[i] for i in range(len(heights))]),max([i - heights[i] for i in range(len(heights))])]) + 1

seppenPlus = [0] * arrSize
seppenMinus = [0] * arrSize


for i in range(len(heights)):
    seppenPlusNum = i + heights[i]
    seppenMinusNum = i - heights[i]

    if seppenPlusNum < arrSize:
    	seppenPlus[seppenPlusNum] += 1

    if seppenMinusNum >= 0:
        seppenMinus[seppenMinusNum] += 1

for i in range(len(seppenPlus)):
    cnt += seppenPlus[i] * seppenMinus[i]

print(cnt)
# Original solution
from collections import Counter

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

li1 = [i + e for i, e in enumerate(a, 1)]
li2 = [i - e for i, e in enumerate(a, 1)]

c1 = Counter(li1)
c2 = Counter(li2)

ans = 0
for k, v in list(c1.items()):
    v2 = c2[k]
    ans += v * v2

print(ans)


# Optimized solution
from collections import defaultdict

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

d = defaultdict(int)
ans = 0
for i, ai in enumerate(a, 1):
    ans += d[i - ai]
    d[i + ai] += 1

print(ans)
# Original solution
from itertools import combinations
from collections import Counter
n = int(eval(input()))
A = list(map(int,input().split()))
c = Counter(A)
hs = []
for k,v in list(c.items()):
  if v == 1:
    hs.append(k)
  elif v >= 2:
    hs.append(k)
    hs.append(k)
    
    
ts = []    
for cmb in combinations(hs,2):
  ts.append(sum(cmb))
  
ts = list(set(ts))

ans = 0
for h in ts:
  for i in range(n-h):    
    if abs(A[i]+A[i+h]) == h:
      ans += 1
      
print(ans)

# Optimized solution
n = int(eval(input()))
A = list(map(int,input().split()))

X = {}
ans = 0
for i in range(n):
  L = i+A[i]
  R = i-A[i]
  
  if L not in X:
    X[L] = 0
    
  X[L]+=1
  
  if R in X:
    ans += X[R]
    
print(ans)
# Original solution
from bisect import bisect_left, bisect, insort

def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    h_plus_i = [ai+i for i, ai in enumerate(a, 1)]
    h_minus_i = [ai-i for i, ai in enumerate(a, 1)]
    s_h_plus_i = list(sorted(h_plus_i))
    s_h_minus_i = list(sorted(h_minus_i))
    ans = 0
    for hpi, hmi in zip(h_plus_i, h_minus_i):
        i1 = bisect_left(s_h_minus_i, -hpi)
        i2 = bisect_left(s_h_plus_i, -hmi)
        if (i1 < n and s_h_minus_i[i1] == -hpi):
            ans += bisect_left(s_h_minus_i, -hpi+1)-i1
        if (i2 < n and s_h_plus_i[i2] == -hmi):
            ans += bisect_left(s_h_plus_i, -hmi+1)-i2
            
    print((ans//2))

if __name__ == "__main__":
    main()


# Optimized solution
def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    plus = [None]*n
    minus = [None]*n
    for i, ai in enumerate(a, 1):
        plus[i-1] = i+ai
        minus[i-1] = i-ai
    plus.sort()
    minus.sort()
    ans = 0
    j = 0
    i = 0
    while i < n:
        pi = plus[i]
        p_num = 1
        m_num = 1
        while j < n-1 and minus[j] < pi:
            j += 1
        mi = minus[j]
        if mi == pi:
            while j < n-1 and mi == minus[j+1]:
                m_num += 1
                j += 1
            while i < n-1 and pi == plus[i+1]:
                p_num += 1
                i += 1
            ans += p_num*m_num
        i += 1
        
    print(ans)
    

if __name__ == "__main__":
    main()
# Original solution
import itertools 
n = int(eval(input()))
a = list(map(int, input().split()))
a_list = [[j, i] for i, j in enumerate(a)]
#a_list.sort(reverse=True)
pairs = list(itertools.combinations(a_list, 2))
#print(pairs)
ans = 0
for pair in pairs:
    if pair[0][0] + pair[1][0] >= n:
        continue
    elif pair[0][1] == pair[1][1]:
        continue
    elif abs(pair[0][1]-pair[1][1]) == (pair[0][0]+pair[1][0]):
        ans += 1

"""
pairs = list(itertools.combinations(range(n), 2))
print(pairs)
ans = 0
for pair in pairs:
    if abs(pair[0]-pair[1]) == (a[pair[0]]+a[pair[1]]):
        ans += 1
"""

print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
add_dic = {}
sub_dic = {}

for i in range(n):
    add_tmp = i + a[i]
    sub_tmp = i - a[i]
    if not add_tmp in list(add_dic.keys()):
        add_dic[add_tmp] = 1
    else:
        add_dic[add_tmp] += 1
    if not sub_tmp in list(sub_dic.keys()):
        sub_dic[sub_tmp] = 1
    else:
        sub_dic[sub_tmp] += 1

ans = 0
for k, v in list(add_dic.items()):
    if k in list(sub_dic.keys()):
        ans += v * sub_dic[k]
print(ans)
# Original solution
def n0():return int(eval(input()))
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(eval(input())) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

from collections import defaultdict
n=n0()
a=[0]
a.extend(n1())

m1=[i+a[i] for i in range(n+1)]
m2=[j-a[j] for j in range(n+1)]

d1=defaultdict(list)
d2=defaultdict(list)
for i in range(1,n+1):
    d1[m1[i]].append(i)
    d2[m2[i]].append(i)

ans=0
for i in d1:
    if len(d2[i])>0:
        for k in d1[i]:
            ans+=len([h for h in d2[i] if h>k])
print(ans)

# Optimized solution
def n0():return int(eval(input()))
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(eval(input())) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

from collections import defaultdict
n=n0()
a=[0]
a.extend(n1())

m1=[i+a[i] for i in range(n+1)]
m2=[j-a[j] for j in range(n+1)]

d1=defaultdict(list)
d2=defaultdict(list)
for i in range(1,n+1):
    d1[m1[i]].append(i)
    d2[m2[i]].append(i)

ans=0
for i in d1:
    ans+=len(d1[i])*len(d2[i])
            
print(ans)
# Original solution
#j-i=Ai+Aj(j>i)
#j-Aj=Ai+i

#Lj=Ri=X
from bisect import bisect_left

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

    L={}
    R={}
    for i in range(N):
        l=(i+1)-A[i]
        r=A[i]+i+1
        if (l in list(L.keys())):
            L[l].append(i+1)
        else:
            L[l]=[i+1]
        if (r in list(R.keys())):
            R[r].append(i+1)
        else:
            R[r]=[i+1]
    
    L_zip=list(zip(list(L.keys()),list(L.values())))
    R_zip=list(zip(list(R.keys()),list(R.values())))

    L_zip=sorted(L_zip)
    R_zip=sorted(R_zip)

    R_key,R_value=list(zip(*R_zip))

    res=0


    for l,l_index in L_zip:
        if l>0:
            ind=bisect_left(R_key ,l)
            if R_key[ind]==l:
                for l in l_index:
                    for r in R_value[ind]:
                        if l>r:
                            res+=1
            if ind>=1:
                R_key=R_key[ind-1:]
                R_value=R_value[ind-1:]

    print(res)

if __name__=="__main__":
    main()





# Optimized solution
#j-i=Ai+Aj(j>i)
#j-Aj=Ai+i

#Lj=Ri=X
from bisect import bisect_left

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

    L={}
    R={}

    res=0

    for i in range(N):
        l=(i+1)-A[i]
        r=A[i]+i+1
        if (l in list(R.keys())):
            res+=len(R[l])
        if (r in list(R.keys())):
            R[r].append(i+1)
        else:
            R[r]=[i+1]


    print(res)

if __name__=="__main__":
    main()
# Original solution
#j-i=Ai+Aj(j>i)
#j-Aj=Ai+i

#Lj=Ri=X
from bisect import bisect_left

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

    L={}
    R={}

    res=0

    for i in range(N):
        l=(i+1)-A[i]
        r=A[i]+i+1
        if (l in list(R.keys())):
            res+=len(R[l])
        if (r in list(R.keys())):
            R[r].append(i+1)
        else:
            R[r]=[i+1]


    print(res)

if __name__=="__main__":
    main()





# Optimized solution
def main():
    N=int(eval(input()))
    A=list(map(int,input().split()))

    L={}
    R={}

    for i in range(N):
        l=(i+1)+A[i]
        r=(i+1)-A[i]
        if (l in list(L.keys())):
            L[l]+=1
        else:
            L[l]=1
        if r in list(R.keys()):
            R[r]+=1
        else:
            R[r]=1

    res=0
    for key in list(L.keys()):
        if key in list(R.keys()):
            res+=R[key]*L[key]

    print(res)
if __name__=="__main__":
    main()
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
later_max = [0]*(n+1)
a.insert(0, 0)
for i in range(1, n):
    later_max[i] = i + a[i] + max(a[i+1:])
    if later_max[i] > n:
        later_max[i] = n

# print(a)
# print(later_max)
count = 0
for i in range(1, n):
    j = i + a[i] + 1
    # print(f"start:{i} {j}")
    while j <= later_max[i]:
        if a[i] + a[j] == j - i:
            # print(i, j)
            count += 1
        j += 1

print(count)


# Optimized solution
n = int(eval(input()))
a_array = list(map(int, input().split()))
a_array.insert(0, 0)
x_sum = {}
x_dis = {}

for i in range(1, n+1):
    a_sum = i + a_array[i]
    if a_sum in x_sum:
        x_sum[a_sum].append(i)
    else:
        x_sum[a_sum] = [i]
    if not(a_sum in x_dis):
        x_dis[a_sum] = []

    a_dis = i - a_array[i]
    if a_dis > 0:
        if a_dis in x_dis:
            x_dis[a_dis].append(i)
        else:
            x_dis[a_dis] = [i]
        if not(a_dis in x_sum):
            x_sum[a_dis] = []

# print(x_sum)
# print(x_dis)
count = 0
for k in list(x_sum.keys()):
    count += len(x_sum[k]) * len(x_dis[k])

print(count)
# Original solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n=I()
  l=LI()

  # j-i=Ai+Aj
  # Ai+i=j-Aj

  a=[]
  b=[]
  for i in range(n):
    x=l[i]
    a.append(x+(i+1))
    b.append((i+1)-x)

  ans=0
  for i,x in enumerate(a[i:]):
    ans+=b.count(x)

  for i,x in enumerate(b[i:]):
    ans+=a.count(x)

  return ans

# main()
print((main()))


# Optimized solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n=I()
  l=LI()

  # j-i=Ai+Aj
  # Ai+i=j-Aj

  a=[]
  b={}
  for i in range(n):
    x=l[i]
    a.append(x+i)
    y=i-x
    if y in b:
      b[y]+=1
    else:
      b[y]=1

  ans=0
  for x in a:
    if x in b:
      ans+=b[x]

  return ans

# main()
print((main()))
# Original solution
N = int(eval(input()))
A = input().split()

pear = 0

for i in range(N-1, 0, -1):
  for j in range(i):
    if int(A[i]) >= (i - j):
      break
    if (i - j) == (int(A[i]) + int(A[j])):
      pear += 1
      
print(pear)

# Optimized solution
N = int(eval(input()))
A = input().split()

pear = 0

i_result = {}
j_result = {}

for i in range(N):
  result = str(i + int(A[i]))
  if result in i_result:
    i_result[result] += 1
  else:
    i_result[result] = 1

for j in range(N):
  result = str(j - int(A[j]))
  if result in j_result:
    j_result[result] += 1
  else:
    j_result[result] = 1

for k in list(i_result.keys()):
  if k in j_result:
    pear += (i_result[k] * j_result[k])
      
      
print(pear)
# Original solution
N =int(eval(input()))
A = list(map(int,input().split()))
x=0
y=0
ans =0
while x <N:
    y =x+A[x]
    while y <N:
        t = A[x]+A[y]
        if t == y-x:
            ans +=1
        y+=1
    x+=1
print(ans)

# Optimized solution
N =int(eval(input()))
A = list(map(int,input().split()))
d ={}
r ={}
ans =0
for x in range(N):
    d[x] =0
    r[x] =0
for x in range(N):
    dt = A[x]+x
    rt = x-A[x]
    if dt<N:
        d[dt] +=1
    if rt >-1:
        r[rt] +=1
for x in range(N):
    if d[x] !=0 and r[x]!=0:
        ans = ans + d[x]*r[x]
print(ans)
# Original solution
N=int(eval(input()))

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

NA=[]

for i in range(N):
    NA.append(A[i]-i)

from collections import Counter

d=Counter(NA)

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

print(cnt)



# Optimized solution
N=int(eval(input()))

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

NA=[]

cnt=0
d={}
for i in range(N):
    if A[i]-i in d:
        cnt+=d[A[i]-i]
    if not -A[i]-i in d:
        d[-A[i]-i]=1
    else:
        d[-A[i]-i]+=1

print(cnt)
# Original solution
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

from collections import defaultdict
ar = defaultdict(list)
al = defaultdict(list)

for i in range(n):
    al[i+a[i]].append(i)
    ar[i-a[i]].append(i)

mi = 0-max(a)
ma = n+max(a)

ans = 0
for i in range(mi,ma):
    ans += len(ar[i]) * len(al[i])

print(ans)



# Optimized solution
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

from collections import defaultdict
ar = defaultdict(list)
al = defaultdict(list)

for i in range(n):
    al[i+a[i]].append(i)
    ar[i-a[i]].append(i)

x = list(al.keys())

ans = 0
for i in x:
    ans += len(ar[i]) * len(al[i])

print(ans)
# Original solution
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

ans=0
for i in range(n):
  for j in range(i,n):
    if abs(j-i) == a[i]+a[j]:
      ans+=1

print(ans)

# Optimized solution
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

ans=0

nums = dict()

for i in range(n):
  num_i = i+a[i]
  if num_i not in nums:
    nums[num_i]=0
  nums[num_i]+=1

for j in range(n):
  num_j = j-a[j]
  if num_j in nums:
    ans+=nums[num_j]

print(ans)
# Original solution
# 32:35
n = int(eval(input()))

heights = list(map(int, input().split()))

values = dict()

for ii, h in enumerate(heights):
    c1 = ii - h
    if (c1) in values:
        values[c1].append((ii, h))
    else:
        values[c1] = [(ii, h)]

count = dict()
for j, h in enumerate(heights):
    if (j + h) in values:
        for i, ai in values[j + h]:
            if i > 0 and i > j and not (j, i) in count:
                count[(j, i)] = True


print((len(count)))

# Optimized solution
# 32:35
n = int(eval(input()))

heights = list(map(int, input().split()))

values = dict()

for ii, h in enumerate(heights):
    c1 = ii - h
    if (c1) in values:
        values[c1].append((ii, h))
    else:
        values[c1] = [(ii, h)]

count = 0
for j, h in enumerate(heights):
    if (j + h) in values:
        count += len(values[j + h])
        # for i, ai in values[j + h]:
        #     if i > 0 and i > j and not (j, i) in count:
        #         count[(j, i)] = True


print(count)
# Original solution
import sys
input=lambda :sys.stdin.readline().rstrip()
from collections import defaultdict

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

d = defaultdict(int)
ans = 0
for j in range(n):
    Dif = j - A[j]
    ans += d[Dif]
    Sum = A[j] + j
    d[Sum] += 1
print(ans)

# Optimized solution
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()
  from collections import defaultdict

  #f_inf=float("inf")
  #MOD=10**9+7
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    n = 6
    A = [2, 3, 3, 1, 3, 1]

  else:
    ##INPUT 
    n = int(eval(input()))
    A = list(map(int, input().split()))

  ## SUBMITION CODES HERE
  d = defaultdict(int)
  ans = 0
  for j in range(n):
    Dif = j - A[j]
    ans += d[Dif]
    Sum = A[j] + j
    d[Sum] += 1
  print(ans)
  
main()
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
from collections import Counter
ai,aj=[],[]
for i in range(n):
  aj.append(i-a[i])
  ai.append(i+a[i])
c1=Counter(ai)
c2=Counter(aj)
ans=0
for k in list(c1.keys()):
  ans+=c1[k]*c2[k]
print(ans)




# Optimized solution
n = int(eval(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)
# Original solution
import collections

n = int(eval(input()))
participant = list(map(int, input().split()))
hashSet = collections.defaultdict(lambda:set())
for i,v in enumerate(participant):
  hashSet[v].add(i)
  
ans = 0
for i,v in enumerate(participant):
  for key, s in list(hashSet.items()):
    if i+v+key in s:
      ans += 1

print(ans)

# Optimized solution
import collections
 
eval(input())
p = list(map(int, input().split()))
map1 = collections.defaultdict(lambda:0)
map2 = collections.defaultdict(lambda:0)
 
for i, v in enumerate(p):
  map1[i+v] += 1
  map2[i-v] += 1

ans = 0
for i in map1:
  if i in map2:
    ans += map1[i] * map2[i]

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
i_list = [a + i + 1 for i, a in enumerate(A)]

ans = 0
for j in range(N):
    ans += i_list[:j+1].count(j+1-A[j])
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
#i_list = [a + i + 1 for i, a in enumerate(A)]

ans = 0
mp = {}
for i in range(N):
    i_kou = i + 1 + A[i]
    if i_kou in mp:
        mp[i_kou] += 1
    else:
        mp[i_kou] = 1
    j_kou = i + 1 - A[i]
    if j_kou in mp:
        ans += mp[j_kou]
print(ans)
# Original solution
from sys import stdin
from sys import setrecursionlimit
from itertools import accumulate

setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
point = 0

for i in range(2,n):
    for j in range(n-i):
        if a[j]+a[j+i] == i:
            point += 1

print(point)

# Optimized solution
from sys import stdin
from sys import setrecursionlimit

setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))

dic = {}
point = 0

for i,j in enumerate(a):
    if i+j in dic:
        dic[i+j] += 1
    else:
        dic[i+j] = 1

for i,j in enumerate(a):
    if i-j in dic:
        point += dic[i-j]

print(point)