CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
import collections

count = 0

count_dict = collections.defaultdict(int)

for idx, a in enumerate(A):
    if idx+a+1 in count_dict:
        count += count_dict[idx+a+1]
        continue
    for i in range(idx+a+1, N):
        if a + A[i] == i - idx:
            count += 1
            count_dict[idx+a+1] += 1

print(count)

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

count = 0

count_dict = collections.defaultdict(int)

for idx, a in enumerate(A):
    count_dict[idx-a] += 1

for idx, a in enumerate(A):
    if idx+a in count_dict:
        count += count_dict[idx+a]
        continue
    # for i in range(idx+a+1, N):
    #     if a + A[i] == i - idx:
    #         count += 1
    #         count_dict[idx+a+1] += 1
# print(count_dict)

print(count)
# Original solution
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	# a_ext = {}
	b_sum_ext = {}
	b_ext = []
	# ai + aj = (j+1) - (i+1)
	# ai + i + 1 = -aj + j + 1

	for i, ai in enumerate(a):
		# a_ext[a[i] + i + 1] = 1
		log.print(a[i]+i+1, -a[i]+i+1)
		b_sum_ext[-a[i]+i+1] = b_sum_ext.get(-a[i]+i+1, 0)+1
	# log.print(b_sum_ext)
	for i in range(n):
		b_sum_ext[-a[i]+i+1] = b_sum_ext.get(-a[i]+i+1, 0)-1
		b_ext.append(dict(b_sum_ext))
	# log.print(b_ext)
	cnt = 0
	log.print(cnt)
	cnt = 0
	for i, ai in enumerate(a):
		if b_ext[i].get(a[i] + i + 1, 0) != 0:
			log.print(i+1, a[i] + i + 1)
			cnt += b_ext[i].get(a[i] + i + 1, 0)
	print(cnt)

	


main()


# Optimized solution
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	# a_ext = {}
	b_sum_ext = {}
	b_ext = []
	# ai + aj = (j+1) - (i+1)
	# ai + i + 1 = -aj + j + 1

	for i, ai in enumerate(a):
		# a_ext[a[i] + i + 1] = 1
		log.print(a[i]+i+1, -a[i]+i+1)
		b_sum_ext[-a[i]+i+1] = b_sum_ext.get(-a[i]+i+1, 0)+1
	cnt = 0
	log.print(cnt)
	cnt = 0
	for i, ai in enumerate(a):
		b_sum_ext[-a[i]+i+1] = b_sum_ext.get(-a[i]+i+1, 0)-1
		if b_sum_ext.get(a[i] + i + 1, 0) != 0:
			log.print(i+1, a[i] + i + 1)
			cnt += b_sum_ext.get(a[i] + i + 1, 0)
	print(cnt)

	


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

add1 = []
sub1 = []
for i in range(n):
    add1.append(a[i] + i)
    sub1.append(i - a[i])

dict1 = {}
dict2 = {}
for i in add1:
    if i in dict1:
        dict1[i] += 1
    else:
        dict1[i] = 1
for i in sub1:
    if i in dict2:
        dict2[i] += 1
    else:
        dict2[i] = 1

sorted1 = sorted(list(dict1.items()), key = lambda x: x[0])
sorted2 = sorted(list(dict2.items()), key = lambda x: x[0])
cnt1 = 0
cnt2 = 0
ans = 0

while cnt1 < len(sorted1) and cnt2 < len(sorted2):
    if sorted1[cnt1][0] == sorted2[cnt2][0]:
        ans += sorted1[cnt1][1] * sorted2[cnt2][1]
        cnt1 += 1
        cnt2 += 1
    elif sorted1[cnt1][0] > sorted2[cnt2][0]:
        cnt2 += 1
    else:
        cnt1 += 1

print(ans)


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

add1 = []
sub1 = []
for i in range(n):
    add1.append(a[i] + i)
    sub1.append(i - a[i])

dict1 = {}
dict2 = {}
for i in add1:
    if i in dict1:
        dict1[i] += 1
    else:
        dict1[i] = 1
for i in sub1:
    if i in dict2:
        dict2[i] += 1
    else:
        dict2[i] = 1

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

print(ans)
# Original solution
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print(('\n'.join(map(str, x))))

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

cnt = 0
for i, a in enu(A):
    if i+a+1<=N-1:
        for j, b in enu(A[i+a+1:]):
            if abs(j+a+1) == a + b:
                cnt += 1
                # print(i, i+a+1+j)
print(cnt)

# Optimized solution
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print(('\n'.join(map(str, x))))

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

cnt = 0
d = defaultdict(int)
for i, a in enu(A):
    l = (i+1) + a
    r = (i+1) - a
    cnt += d[r]
    d[l] += 1
print(cnt)
# Original solution
from itertools import permutations, combinations,combinations_with_replacement,product

N=int(eval(input()))
a=list(map(int,input().split()))
b=[i for i in range(N)]
A=list(combinations(a,2))
B=list(combinations(b,2))

C=[]
D=[]

for i in A:
    tmp=i[0]+i[1]
    C.append(tmp)

for i in B:
    tmp=abs(i[0]-i[1])
    D.append(tmp)

count=0

for i in range(len(C)):
    if C[i]==D[i]:
        count+=1
    else:
        pass
    
print(count)


# Optimized solution
from itertools import permutations, combinations,combinations_with_replacement,product

N=int(eval(input()))
a=list(map(int,input().split()))
b=[i for i in range(N)]
count=0

C=[i[0]+i[1] for i in combinations(a,2)]
D=[abs(i[0]-i[1]) for i in combinations(b,2)]

for i in range(len(C)):
    if C[i]==D[i]:
        count+=1
    
print(count)
# Original solution
from itertools import permutations, combinations,combinations_with_replacement,product

N=int(eval(input()))
a=list(map(int,input().split()))
b=[i for i in range(N)]
count=0

C=[i[0]+i[1] for i in combinations(a,2)]
D=[abs(i[0]-i[1]) for i in combinations(b,2)]

for i in range(len(C)):
    if C[i]==D[i]:
        count+=1
    
print(count)

# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
result=[]
res=[]
for i in range(N):
    tmp=i+A[i]
    tmp2=i-A[i]
    result.append(tmp)
    res.append(tmp2)

count=0

for i in result:
    for j in res:
        if i==j:
            count+=1
        else:
            pass

print(count)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=[0]*n
for i , j in enumerate(a):
    b[i]=j+i+1
c=[0]*n
q=[]
ans=0
for i , j in enumerate(a):
    c[i]=1+i-j
from collections import Counter
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b
cc=Counter(c)
bb=Counter(b)
for i,j in list(bb.items()):
    for k,l in list(cc.items()):
        if i==k:
            ans+=j*l

print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=[0]*n
for i , j in enumerate(a):
    b[i]=j+i+1
c=[0]*n
q=[]
ans=0
for i , j in enumerate(a):
    c[i]=1+i-j
from collections import Counter
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b
cc=Counter(c)
bb=Counter(b)
f=bb&cc
for i in list(f.keys()):
    ans+=bb[i]*cc[i]

print(ans)
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))

d = [0] * n

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

  


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

lst = [0] * N

ans = 0
for i in range(N):
    if i + 1 + A[i] < N: #iは0から始まるので +1 してあげる
        lst[i + A[i]] += 1
    if i + 1 - A[i] >= 1:
        ans += lst[i - A[i]]

print(ans)
# Original solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
sa = defaultdict(int)
for i,x in enumerate(a):
    sa[(i+1)-x] += 1
res = 0
for i,x in enumerate(a):
    res += sa[i+1+x]
print(res)

# Optimized solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
d = defaultdict(int)
for i,x in enumerate(a):
    d[i+1-x] += 1
res = 0
for i,x in enumerate(a):
    res += d[i+1+x]
print(res)
# Original solution
n = int(eval(input()))
N = [i for i in range(n)]
A = list(map(int,input().split()))
L = [N[i]+A[i] for i in range(n)]
R = [N[j]-A[j] for j in range(n)]
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if L[i] == R[j]:
      ans += 1
print(ans)



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

X = dict()
ans = 0
for i in range(N):
    L = i + A[i]
    if L not in X:
        X[L] = 1
    else:
        X[L] += 1

for i in range(N):
    R = i - A[i]
    if R in X:
        ans += X[R]
        
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

cnt = 0
dist = [a[0]-1] + a[1:]
for i, ai in enumerate(a[1:]):
    cnt += dist[:i+1].count(-ai)
    dist[:i+2] = list([x-1 for x in dist[:i+2]])

print(cnt)


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

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

ans = 0
adds = dict()
for j in range(n):
    sub = j - a[j]
    if sub in list(adds.keys()):
        ans += adds[sub]

    add = j + a[j]
    if add in list(adds.keys()):
        adds[add] += 1
    else:
        adds[add] = 1

print(ans)
# Original solution
import itertools
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0

for i in range(N-1):
  wa = i + A[i]
  for j in range(i+1,N):
    sa = j - A[j]
    if wa == sa:
      ans += 1

print(ans)

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

for j in range(N):
  if j-A[j] in D:
    ans += D[j-A[j]]
  if j+A[j] in D:
    D[j+A[j]] += 1
  else:
    D[j+A[j]] = 1
    
print(ans)
# Original solution
N = int(eval(input()))
As = list(map(int, input().split()))

i_plus_Ai = [0 for i in range(N)]
dict = {}
for i in range(N):
    i_plus_Ai[i] = i + As[i]
    tmp = i - As[i]
    if tmp not in dict:
        dict[tmp] = [i]
    else:
        dict[tmp].append(i)
    dict[tmp].sort()

count = 0
for i in range(N):
    if i_plus_Ai[i] in dict:
        kouho = dict[i_plus_Ai[i]]
        for j in range(len(kouho)):
            if kouho[j] > i:
                count += len(kouho) - j
                break

print(count)


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

i_plus_Ai = [0 for i in range(N)]
dict = {}
for i in range(N):
    i_plus_Ai[i] = i + As[i]
    tmp = i - As[i]
    if tmp not in dict:
        dict[tmp] = [i]
    else:
        dict[tmp].append(i)

count = 0
for i in range(N):
    if i_plus_Ai[i] in dict:
        kouho = dict[i_plus_Ai[i]]
        for j in range(len(kouho)):
            if kouho[j] > i:
                count += len(kouho) - j
                break

print(count)
# Original solution
from collections import Counter
import bisect


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors


if __name__ == '__main__':
    N = int(eval(input()))
    A = list(map(int, input().split()))
    negA = []
    idx_negA = []
    for i, a in enumerate(A):
        negA.append(i - a)
        idx_negA.append(i)

    negA = sorted(negA)
    ans = 0
    for i in range(N):
        searched_idx = bisect.bisect_left(negA, i + A[i])

        if searched_idx == N:
            continue
        else:
            if idx_negA[searched_idx] > i:
                while negA[searched_idx] == i + A[i] and searched_idx <= N - 1:
                    ans += 1
                    if searched_idx == N - 1:
                        break
                    searched_idx += 1

    print(ans)


# Optimized solution
from collections import Counter
import bisect


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors


if __name__ == '__main__':
    N = int(eval(input()))
    A = list(map(int, input().split()))
    negA = []
    idx_negA = []
    for i, a in enumerate(A):
        negA.append(i - a)
        idx_negA.append(i)

    cnt_negA = Counter(negA)
    negA_keys = sorted(cnt_negA.keys())
    ans = 0
    for i in range(N):
        if i + A[i] in cnt_negA:
            ans += cnt_negA[i + A[i]]
    print(ans)
# Original solution
from collections import Counter
import bisect


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors


if __name__ == '__main__':
    N = int(eval(input()))
    A = list(map(int, input().split()))
    negA = []
    idx_negA = []
    for i, a in enumerate(A):
        negA.append(i - a)
        idx_negA.append(i)

    cnt_negA = Counter(negA)
    negA_keys = sorted(cnt_negA.keys())
    ans = 0
    for i in range(N):
        if i + A[i] in cnt_negA:
            ans += cnt_negA[i + A[i]]
    print(ans)


# Optimized solution
from collections import Counter
import bisect


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors


if __name__ == '__main__':
    N = int(eval(input()))
    A = list(map(int, input().split()))
    negA = []
    for i, a in enumerate(A):
        negA.append(i - a)

    cnt_negA = Counter(negA)
    negA_keys = sorted(cnt_negA.keys())
    ans = 0
    for i in range(N):
        if i + A[i] in cnt_negA:
            ans += cnt_negA[i + A[i]]
    print(ans)
# Original solution
from collections import defaultdict
n = int(eval(input()))
a = [int(i) for i in input().split()]
d = defaultdict(int)
for i in range(n): d[i+1+a[i]] += 1
ans = 0
for j in range(n): ans += d[j+1-a[j]]
print(ans)

# Optimized solution
from collections import defaultdict
n = int(eval(input()))
a = [int(i) for i in input().split()]
ans = 0
d = defaultdict(int)
for i in range(n):
    ans += d[i+1-a[i]]
    d[i+1+a[i]] += 1
print(ans)
# Original solution
n = int(eval(input()))
import itertools
a_list = list(map(int,input().split()))
cand_list = list(itertools.combinations([i for i in range(n)],2))
count = 0
for cand in cand_list:
  if abs(cand[1] - cand[0]) == a_list[cand[0]] + a_list[cand[1]]:
    count += 1
    
print(count)


# Optimized solution
n = int(eval(input()))
a_list = list(map(int,input().split()))
c_list = a_list.copy()
for i in range(n):
  a_list[i] -= i + 1
count = 0
for i in range(n-1):
  target = a_list[i+1:]
  count += target.count(-(c_list[i] + i + 1))
  
print(count)
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
ans=0
AA=[]
M=0
for i in range(N):
    if A[i]<N:
        M=max(A[i],M)

m=min(A)
cnt=0
for i in range(N):
    LM=min(i+M+A[i]+1,N)
    lm=max(i+m+A[i],i+1)
    for j in range(lm,LM):
        cnt+=1
        if j-i==abs(A[i]+A[j]):
            ans+=1
print(ans)

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

L={}
R={}
ans=0
for i in range(N):
    if i+A[i] in L:
        L[i+A[i]]+=1
    else:
        L[i+A[i]]=1
    if A[i]<=i:
        if i-A[i] in R:
            R[i-A[i]]+=1
        else:
            R[i-A[i]]=1
for r in R:
    if r in L:
        ans+=L[r]*R[r]
print(ans)
# Original solution
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float("inf")

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

min_diff = 1
max_diff = N - 1

count = 0
for diff in range(min_diff, max_diff + 1):
    pairs = []
    i = 1
    while True:
        j = i + diff
        if j <= N:
            pairs.append([i, j])
        else:
            break
        i += 1
    # pprint(pairs)
    for i, j in pairs:
        if abs(i - j) == A[i-1] + A[j-1]:
            count += 1

print(count)


# Optimized solution
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import math
import itertools
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float("inf")

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

min_diff = 1
max_diff = N - 1

dl = defaultdict(list)
dr = defaultdict(list)
for i in range(1, N + 1):
    key = i + A[i-1]
    dl[key].append(i)
    key = i - A[i-1]
    if key > 0:
        dr[key].append(i)
# pprint(dict(dl))
# pprint(dict(dr))

count = 0
for diff in range(min_diff, max_diff + 1):
    count += len(dl[diff]) * len(dr[diff])
print(count)
# Original solution
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

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

B = []
for i,a in enumerate(A):
    if a <= N-1:
        B.append([a,i])
if len(B)==0:
    print((0))
    exit()
B.sort()
cnt = 0
for i in range(len(B)):
    for j in range(i+1,len(B)):
        if B[i][0]+B[j][0]==abs(B[i][1]-B[j][1]):
            cnt +=1
        if B[i][0]+B[j][0]>=N:
            break
print(cnt)



# Optimized solution
import sys,collections
input = sys.stdin.readline
N=int(eval(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)
# Original solution
n=int(eval(input()))
a_=list(map(int,input().split()))
from collections import defaultdict
a=[[i,ai] for i,ai in enumerate(a_)]
sa=defaultdict(lambda:0)
# sa[(i,j)]:i番目の人までで自分の番号-身長がjの人
d=defaultdict(lambda:0)
# 自分の番号-身長の累計
mt=0
for i,ai in a:
  d[i-ai]+=1
  for k,v in list(d.items()):
    sa[(i+1,k)]=v
ans=0
for i,ai in a:
  c=sa[(n,i+ai)]-sa[(i+1,i+ai)]
  ans+=c
print(ans)


# Optimized solution
def main(n,a_):
  from collections import defaultdict
  lr=[[i+ai,i-ai] for i,ai in enumerate(a_)]
  rs=defaultdict(lambda:0)
  ls=defaultdict(lambda:0)
  ans=0
  for l,r in lr:
    rs[r]+=1
    ls[l]+=1
  for k in list(rs.keys()):
    ans+=rs[k]*ls[k]
  print(ans)
if __name__=='__main__':
  n=int(eval(input()))
  a_=list(map(int,input().split()))
  #n=200000
  #a_=[3 for _ in range(n)]
  main(n,a_)
# Original solution
# N人の参加者, 参加者iの身長はAi, 背番号の差の絶対値が身長の和に等しい組
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
memo = defaultdict(int)
ans = 0
for i, x in enumerate(A, 1):
    ans += memo[i-A[i-1]]
    memo[i+A[i-1]] += 1
print(ans)


# Optimized solution
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
count = defaultdict(int)
ans = 0
for i in range(N):
    ans += count[i-A[i]]
    count[A[i]+i] += 1
print(ans)
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int,input().split()))

minus = []
plus = []
for i in range(len(A)):
    minus.append(A[i]-(i+1))
    plus.append(-A[i]-(i+1))

d = {}
for m in minus:
    d[m] = d.get(m,0) + 1

ans = 0
for p in plus:
    ans += d.get(p,0)
print (ans)

# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int,input().split()))

minus = []
plus = []
for i in range(len(A)):
    minus.append(A[i]-(i+1))
    plus.append(A[i]+(i+1))

d = {}
for m in minus:
    d[m] = d.get(m,0) + 1

ans = 0
for p in plus:
    ans += d.get(-p,0)
print (ans)
# Original solution
def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    A.insert(0, 0)

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

if __name__ == "__main__":
    resolve()

# Optimized solution
def resolve():
    N = int(eval(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)

if __name__ == "__main__":
    resolve()
# Original solution
from collections import defaultdict
d_i = defaultdict(list)
d_j = defaultdict(list)

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

for i in range(N):
    d_i[i-A[i]].append(i)
    d_j[i+A[i]].append(i)

cnt = 0
for key in list(d_j.keys()):
    arr_i = d_i[key]
    arr_j = d_j[key]
    for i in arr_i:
        for j in arr_j:
            if i > j:
                cnt += 1
print(cnt)


# Optimized solution
from collections import defaultdict
d_i = defaultdict(list)
d_j = defaultdict(list)

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

for i in range(N):
    d_i[i-A[i]].append(i)
    d_j[i+A[i]].append(i)

cnt = 0
for key in list(d_j.keys()):
    arr_i = d_i[key]
    arr_j = d_j[key]
    cnt += len(arr_j) * len(arr_i)
print(cnt)
# Original solution
from collections import Counter


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

R = [None] * (N + 1)
R[N] = Counter()
L = [None] * (N + 1)
L[0] = Counter()

# n < i
# for i in range(N):
#     c = Counter()
#     c[A[i] + i] = 1
#     L[i + 1] = L[i] | c

# n >= i
c = Counter()
for n in range(N - 1, -1, -1):
    R[n] = R[n + 1] | c
    R[n][(n + 1) - A[n]] += 1

ans = 0
for i, Ai in enumerate(A):
    # n < a
    # c0 = i - a
    # l = L[i][c0]

    # n >= a
    c1 = Ai + (i + 1)
    r = R[i + 1][c1]

    ans += r

print(ans)


# Optimized solution
from collections import Counter


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

# R = [None] * (N + 1)
# R[N] = Counter()

R = Counter()
cnt = 0
for n in range(N - 1, 0, -1):
    R[(n + 1) - A[n]] += 1
    c = A[n - 1] + ((n - 1) + 1)
    cnt += R[c]

# ans = 0
# for i, Ai in enumerate(A):
#     # n < a
#     # c0 = i - a
#     # l = L[i][c0]

#     # n >= a
#     c1 = Ai + (i + 1)
#     r = R[i + 1][c1]

#     ans += r

print(cnt)
# Original solution
from collections import Counter

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

A1 = [0]*N
A2 = [0]*N

for i in range(N):
    A1[i] = A[i] + i
    A2[i] = i - A[i]

cnt = 0
for i in range(N):
    c = Counter(A2[i+1:])
    cnt += c[A1[i]]

print(cnt)

# Optimized solution
from collections import Counter
# import sys

# input = sys.stdin.readline

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

A1 = [0]*N
A2 = [0]*N

for i in range(N):
    A1[i] = A[i] + i
    A2[i] = i - A[i]

c = Counter(A2)

cnt = 0
for i in range(N):
    cnt += c[A1[i]]

print(cnt)
# Original solution
from collections import*
n,*a=list(map(int,open(0).read().split()))
s=0
d=defaultdict(int)
for i,a in enumerate(a):
  s+=d[i-a]
  d[i+a]+=1
print(s)

# Optimized solution
n,*a=list(map(int,open(0).read().split()))
i=s=0
d=[0]*n
for a in a:
  if i>=a:s+=d[i-a]
  if i+a<n:d[i+a]+=1
  i+=1
print(s)