CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

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

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
r = {}
for i in range(n):
    try:
        r[i-a[i]] += 1
    except:
        r[i-a[i]] = 1
cnt = 0
for i in range(n):
    r[i-a[i]] -= 1
    try:
        cnt += r[i+a[i]]
    except:
        pass
print(cnt)
# Original solution
N = int(eval(input()))
List = list(map(int, input().split()))
res = 0
A = [[0 for j in range(N)] for i in range(N)]
B = [[0 for j in range(N)] for i in range(N)]
for i in range(N):
  for j in range(i,N):
    if A[j][i] != 0:
      pass
    else:
      A[i][j] = List[i]+List[j]
      B[i][j] = A[i][j]-abs(j-i)
      if B[i][j] == 0:
        res = res + 1
print(res)

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
m = {}
ans = 0
for i in range(n):
    x = A[i] + i   #i番目と当該数字の和
    if x not in m:
        m[x] = 0   #和の属性値を0とする
    m[x] += 1      #和の属性値に１を足す
    if i - A[i] in m: #i番目と当該数字の差
        ans += m[i - A[i]] #差の位置に当たる属性値を答えに足す
print(ans)
# Original solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys

def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    dic_Lg = {}
    dic_Lw = {}
    for i in range(N):
        x = i - A[i]
        if x in dic_Lg:
            dic_Lg[x]+=1
        else:
            dic_Lg[x]=1
        y = i + A[i]
        if y in dic_Lw:
            dic_Lw[y]+=1
        else:
            dic_Lw[y]=1
        LP = list(dic_Lw.keys()) + list(dic_Lg.keys())
        LP = set(LP)

    ret = 0
    for i in LP:
        if i in dic_Lg and i in dic_Lw:
            ret += dic_Lg[i] * dic_Lw[i]
    print(ret)

if __name__ == '__main__':
    main()

# Optimized solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys

def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    dic_Lg = {}
    dic_Lw = {}
    for i in range(N):
        x = i - A[i]
        if x in dic_Lg:
            dic_Lg[x]+=1
        else:
            dic_Lg[x]=1
        y = i + A[i]
        if y in dic_Lw:
            dic_Lw[y]+=1
        else:
            dic_Lw[y]=1
    LP = list(dic_Lw.keys()) + list(dic_Lg.keys())
    LP = set(LP)
    ret = 0
    for i in LP:
        if i in dic_Lg and i in dic_Lw:
            ret += dic_Lg[i] * dic_Lw[i]
    print(ret)

if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
for i in range(N):
  for j in range(A[i], N):
    if(A[i] + A[j] == j-i):
      ans += 1
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
L = [0] * N
R = list()
for i in range(N):
  R.append(i-A[i])
  if(i+A[i]<=N-1):
    L[i+A[i]] += 1
for r in R:
  if(r > 0):
    ans += L[r]
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
def add(n):
    return n+1
cnt=0
li=[]
for i in range(n):
    cnt += li.count(a[i])
    li=list(map(add,li))
    li.append(1-a[i])
print(cnt)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
d={}
ans=0
for i in range(n):
    if i+a[i] in list(d.keys()):
        d[i+a[i]]+=1
    else:
        d[i+a[i]]=1
    if i-a[i] in list(d.keys()):
        ans+=d[i-a[i]]
print(ans)
# Original solution
import itertools

N = int(eval(input()))

A_list = []
inp_list = list(map(int, input().split(" ")))
for i in range(N):
	A_list.append([i+1, inp_list[i]])
answer = 0
for v in itertools.combinations(A_list, 2):
	if abs(v[0][0] - v[1][0]) == (v[0][1] + v[1][1]):
		answer += 1
print(answer)

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

X1_dict = {}
X2_dict = {}
inp_list = list(map(int, input().split(" ")))
for i, a_i in enumerate(inp_list):
	X1 = i + 1 + a_i
	X2 = i + 1 - a_i
	if X1 in list(X1_dict.keys()):
		X1_dict[X1] += 1
	else:
		X1_dict[X1] = 1
	if X2 in list(X2_dict.keys()):
		X2_dict[X2] += 1
	else:
		X2_dict[X2] = 1

answer = 0
for key, value in list(X1_dict.items()):
	if key in list(X2_dict.keys()):
		answer += value * X2_dict[key]
		
print(answer)
# Original solution
import collections

n = int(eval(input()))

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


l = [a[i] +i+1 for i in range(n)]
r = [i+1 -a[i] for i in range(n)]

L = collections.Counter(l)
R = collections.Counter(r)

c = 0

for i in range(max(max(l),max(r))+1):
    c += L.get(i, 0) * R.get(i, 0)

print(c)

# Optimized solution
import collections

n = int(eval(input()))

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


l = [a[i] +i+1 for i in range(n)]
r = [i+1 -a[i] for i in range(n)]

L = collections.Counter(l)
R = collections.Counter(r)

c = 0

for i in list(L.keys()):
    c += L.get(i, 0) * R.get(i, 0)

print(c)
# Original solution
n=int(eval(input()));a=list(map(int,input().split()));b,c,f=[],[],0
for i,q in enumerate(a):b+=i+q,;c+=i-q,
from collections import*
for d,e in list(Counter(b).items()):f+=e*Counter(c)[d]
print(f)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))  
b,c=[],[]
for i,q in enumerate(a):
  b.append(i+q)
  c.append(i-q)
from collections import*
b=list(Counter(b).items())
c=Counter(c)
z=0
for d,e in b:z+=e*c[d]
print(z)
# Original solution
n,*l=list(map(int,open(0).read().split()))
from collections import*
d=defaultdict(int)
a=0
for i in range(n): d[i+l[i]]+=1; a+=d[i-l[i]]*(i>l[i])
print(a)

# Optimized solution
n,*l=list(map(int,open(0).read().split()));d,a={},0
for i in range(n):d[i+l[i]]=d.get(i+l[i],0)+1;a+=d.get(i-l[i],0)
print(a)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

left = []
right = []

for i in range(n):
    left.append(a[i]+i)
    right.append(i-a[i])
    
ans = 0

for i in range(n):
    for j in range(i+1, n):
        #print(i,j)
        if left[i]==right[j]:
            ans += 1

print(ans)

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

mp = [0] * n

ans = 0

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

print(ans)
# Original solution
import collections

N = int(eval(input()))
arr = list(map(int, input().split()))
i_arr =[]
j_arr =[]

ans = 0
for i in range(N):
    i_arr.append(i+arr[i])
    dic = collections.Counter(i_arr)
    j_arr.append(-1*arr[i]+i)
    ans += dic[j_arr[-1]]

print(ans)


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

dic = {}
j_arr =[]

ans = 0
for i in range(N):
    if i+arr[i] not in dic:
        dic[i+arr[i]] = 0
    dic[i+arr[i]] += 1
    j_arr.append(-1*arr[i]+i)
    if -1*arr[i]+i in dic:
        ans += dic[-1*arr[i]+i]

print(ans)
# Original solution
# coding: utf-8
from bisect import bisect_left
from collections import defaultdict


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))

    ret = 0
    X = defaultdict(list)
    for i, a in enumerate(A):
        X[a+i].append(i)

    for j, a in enumerate(A):
        if 0 <= j-a:
            ret += bisect_left(X[j-a], j)

    return str(ret)


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))


# Optimized solution
# coding: utf-8
from collections import defaultdict


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))

    ret = 0
    X = defaultdict(int)
    for i, a in enumerate(A):
        X[a+i] += 1

        if 0 <= i-a:
            ret += X[i-a]

    return str(ret)


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))
# Original solution
N=int(eval(input()))
count=0
a=list(map(int,input().split()))
w=[]
s=[]
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
for i in range(N):
  count+=s.count(w[i])
print(count)

# Optimized solution
N=int(eval(input()))
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*N
maxi=max(a)
for i in range(N):
  s.append(1+i-a[i])
  if 1+i+a[i]<N:
    num[1+i+a[i]]+=1
for i in range(N):
  if s[i]>=0:
    count+=num[s[i]]
print(count)
# Original solution
N=int(eval(input()))
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*N
maxi=max(a)
for i in range(N):
  s.append(1+i-a[i])
  if 1+i+a[i]<N:
    num[1+i+a[i]]+=1
for i in range(N):
  if s[i]>=0:
    count+=num[s[i]]
print(count)

# Optimized solution
N=int(eval(input()))
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*N
maxi=max(a)
for i in range(N):
  s.append(i-a[i])
  if i+a[i]<N:
    num[i+a[i]]+=1
for i in range(N):
  if s[i]>=0:
    count+=num[s[i]]
print(count)
# Original solution
n = int(eval(input()))
lst = [int(i) for i in input().split()]

dic = {}
for i in range(n):
  a = lst[i]
  if a >= n - 1:
    continue
  if a not in dic:
    dic[a] = set()
  dic[a].add(i)
#print(dic)
count = 0
for a in list(dic.keys()):
  set_ = dic[a]
  for index in set_:
    b = a + index
    if b > n:
      continue
    for c in list(dic.keys()):
      j = b + c
      if j in dic[c]:
        count += 1
print(count)


# Optimized solution
n = int(eval(input()))
lst = [int(i) for i in input().split()]

dic = {}
count = 0
for i in range(n):
  num = lst[i]
  a = i + num
  if a not in dic:
    dic[a] = 1
  else:
    dic[a] += 1
  b = i - num
  if b in dic:
    count += dic[b]
print(count)
# Original solution
N=int(eval(input()))
a=list(map(int,input().split()))
ans=0
min_a=min(a)
for i in range(N-1,0,-1):
    num=a[i]
    for j in range(max(i-num+1-min_a,0)):
        if a[j]+num==i-j:
            ans+=1
print(ans)


# Optimized solution
N=int(eval(input()))
a=list(map(int,input().split()))
ans=0
L={}
R={}
for i in range(N):
    if a[i]+i in L:
         k=L.get(a[i]+i)
         del L[a[i]+i]
         L[a[i]+i]=k+1
    else:
        L[a[i]+i]=1
    if i-a[i]>0:
        if i-a[i] in R:
             k=R.get(i-a[i])
             del R[i-a[i]]
             R[i-a[i]]=k+1
        else:
            R[i-a[i]]=1
for x in list(L.keys()):
    if x in R:
        ans+=L.get(x)*R.get(x)
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
sorted_a = sorted(a, reverse = True)
max_a = sorted_a[0]
cnt = 0
ans = 0
for i in range(n - 1):
    if a[i] == max_a:
        cnt += 1
        max_a = sorted_a[cnt]
    for j in range(a[i] + i + 1, min(n, a[i] + i + max_a + 1)):
        if a[i] + a[j] == j - i:
            ans += 1
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
dp = [0] * n
ans = 0
for i, j in enumerate(a):
    if i + j < n:
        dp[i + j] += 1
    if 0 < i - j:
        ans += dp[i - j]
print(ans)
# Original solution
from collections import defaultdict
import bisect
def f():
    return []

d=defaultdict(f)
n=int(eval(input()))
a=list(map(int,input().split()))
x=[i+1+a[i] for i in range(n)]
y=[i+1-a[i] for i in range(n)]
for i in range(n):
    d[y[i]].append(i)

ans=0
for i in range(n):
    p=x[i]
    ans+=len(d[p])-bisect.bisect_right(d[p],i)
print(ans)

# Optimized solution
from collections import defaultdict
import bisect
def f():
    return []

d=defaultdict(f)
n=int(eval(input()))
a=list(map(int,input().split()))
x=[i+1+a[i] for i in range(n)]
y=[i+1-a[i] for i in range(n)]
for i in range(n):
    d[y[i]].append(i)

ans=0
for i in range(n):
    ans+=len(d[x[i]])
print(ans)
# Original solution
from collections import defaultdict
n=int(eval(input()))
a=list(map(int,input().split()))
d=defaultdict(int)
for i in range(n):
    d[i+1-a[i]]+=1
print((sum(d[i+1+a[i]] for i in range(n))))

# Optimized solution
from collections import defaultdict
n=int(eval(input()))
a=list(map(int,input().split()))
d=defaultdict(int)
for i in range(n):
    d[i-a[i]]+=1
ans=0
for i in range(n):
    ans+=d[i+a[i]]
print(ans)
# Original solution
N = int(eval(input()))

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

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

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

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

L = {}
R = {}

for i in range(N):
  t = A[i]+i
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  s = i - A[i]
  if s in R:
    R[s] += 1
  else:
    R[s] = 1  
#print(L,R)
ans = 0
for i in range(N):
  t = A[i]+i
  #ans += R[t]
  if t in list(R.keys()):
    ans += R[t]
    #print(t,R[t])
print(ans)
# Original solution
import bisect
n=int(eval(input()))
A=list(map(int,input().split()))

X=[A[i]-(i+1) for i in range(n)]
Y=[-A[i]-(i+1) for i in range(n)]
ans=0
X.sort()

for y in Y:
    i=bisect.bisect_left(X,y)
    for j in range(i,n):
        if X[j]==y:
            ans+=1
        else:
            break
print(ans)

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

X=[A[i]-(i+1) for i in range(n)]
Y=[-A[i]-(i+1) for i in range(n)]
ans=0

P=defaultdict(int)
Q=defaultdict(int)

for x in X:
    P[x]+=1
for y in Y:
    Q[y]+=1

p=set(P.keys())
q=set(Q.keys())

r=p&q

for key in r:
    ans+=P[key]*Q[key]
print(ans)
# Original solution
N = int(eval(input()))
A = [int(v) for v in input().split()]
count = 0
for i in range(len(A)-1):
  for j in range(i+1,len(A)):
    a1,a2 = A[i],A[j]
    diff = j-i
    if diff == a1+a2:
      count += 1
print(count)

# Optimized solution
N = int(eval(input()))
A = [int(v) for v in input().split()]
L, R = {}, {}
for i,a in enumerate(A):
  l,r = i+a,i-a
  if l not in L: L[l]=0
  if r not in R: R[r]=0
  L[l]+=1
  R[r]+=1

count = 0
for X in L:
  if X not in R: continue
  count += L[X]*R[X]
print(count)
# Original solution
from collections import Counter
import sys
input = sys.stdin.readline

n = int(eval(input()))
a = list(map(int, input().split()))
minus = Counter([i-a[i] for i in range(n)])
plus = Counter([i+a[i] for i in range(n)])

cnt = 0
for i in minus:
    if i in plus:
        cnt += minus[i] * plus[i]
print(cnt)


# Optimized solution
from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
minus = Counter([i - a[i] for i in range(n)])
plus = Counter([i + a[i] for i in range(n)])

cnt = 0
for i in minus:
    if i in plus:
        cnt += minus[i] * plus[i]
print(cnt)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
plus = []
minus = []
for i in range(n):
  plus.append(a[i]+i+1)
  minus.append(i+1-a[i])
c = 0
for i in range(n-1):
  for j in range(i,n):
    if plus[i] == minus[j]:
      c += 1
print(c)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
plus = dict()
minus = dict()
for i in range(n):
  num = i+1
  p = a[i] + num
  m = num - a[i]
  if p in plus:
    plus[p] += 1
  else:
    plus[p] = 1
  if (m) in minus:
    minus[m] += 1
  else:
    minus[m] = 1
c = 0
for v in list(plus.keys()):
  if v in minus:
    c += plus[v] * minus[v]
print(c)
# Original solution
def solve(n, xs):

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

    return ans
if __name__ == "__main__":
    n = int(eval(input()))
    xs = [int(i) for i in input().split()]
    print((solve(n, xs)))


# Optimized solution
def solve(n, xs):

    ans = 0
    tmp = {}
    for i in range(n-1, -1, -1):
        l = i+1 + xs[i]
        r = i+1 - xs[i]

        if l in tmp:
            ans += tmp[l]

        if r in tmp:
            tmp[r] += 1
        else:
            tmp[r] = 1

    return ans
if __name__ == "__main__":
    n = int(eval(input()))
    xs = [int(i) for i in input().split()]
    print((solve(n, xs)))
# Original solution
import itertools
 
N = int(eval(input()))
A = list(map(int,input().split()))
 
comb = itertools.combinations(list(range(N)), 2)
ans = 0
 
for c in comb:
  if A[c[0]]+A[c[1]] == abs(c[0]-c[1]):
    ans += 1
 
print(ans)

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

L={}
R={}
for i in range(1,len(A)+1):
  L[str(i+A[i-1])] = L.get(str(i+A[i-1]),0)+1
  R[str(i-A[i-1])] = R.get(str(i-A[i-1]),0)+1

ans = 0
for i in range(1,N+1):
  if str(i) in L and str(i) in R:
    ans += L[str(i)] * R[str(i)]

print(ans)
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]

j_Aj = [0]

for j, aj in enumerate(a):
    j_Aj.append(j + 1 - aj)
i_Ai = [0] * (max(j_Aj)+1)
ans = 0
for j, j_aj in enumerate(j_Aj):
    if j == 0:
        continue
    if j_aj >= 2:
        ans += i_Ai[j_aj]
    if j + a[j - 1]<=max(j_Aj):
        i_Ai[j + a[j - 1]] += 1
print(ans)

# Optimized solution
n = int(eval(input()))
a = [int(i) for i in input().split()]

j_Aj = [0]

for j, aj in enumerate(a):
    j_Aj.append(j + 1 - aj)
maxj=max(j_Aj)
i_Ai = [0] * (maxj+1)
ans = 0
for j, j_aj in enumerate(j_Aj):
    if j == 0:
        continue
    if j_aj >= 2:
        ans += i_Ai[j_aj]
    if j + a[j - 1]<=maxj:
        i_Ai[j + a[j - 1]] += 1
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    for j in range(i+2, n):
        if a[i] >= abs(i-j) or a[j] >= abs(i-j):
          if a[i] > abs(i-(n-1)): break
          else: continue 
        if abs(i-j) == a[i]+a[j]: ans += 1
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = []
c = {}

ans = 0
for i in range(n):
    b.append(a[i]+i+1)
    x = -a[i]+i+1
    if x in c:
        c[x] += 1
    else:
        c[x] = 1
for i in range(n):
    if b[i] in c:
        ans += c[b[i]]
print(ans)
# Original solution
import itertools

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

del_n = [abs(x - y) for x, y in itertools.combinations(list(range(1, n+1)), 2)]
sum_a = [x + y for x, y in itertools.combinations(a, 2)]
# print(del_n)
# print(sum_a)
cnt = 0

for d, s in zip(del_n, sum_a):
    if d == s:
        cnt += 1
print(cnt)


# Optimized solution
import itertools

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

for i in range(1, n+1):
    if n > a[i-1]:
        for j in range(max(a[i-1], i+1), n+1):
            if abs(i - j) == a[i-1] + a[j-1]:
                cnt += 1

print(cnt)
# Original solution
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(eval(input())) for _ in range(n)]
inp = lambda :int(eval(input()))
ip = lambda :[int(w) for w in input().split()]
mp = lambda :list(map(int,input().split()))

n = inp()
x = ip()
ctr = 0
for i in range(n-1):
    for j in range(i+1,n):
        if (j-i) == x[i]+x[j]:
            ctr += 1
print(ctr)

# Optimized solution
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(eval(input())) for _ in range(n)]
inp = lambda :int(eval(input()))
ip = lambda :[int(w) for w in input().split()]
mp = lambda :list(map(int,input().split()))

n = inp()
x = ip()
ctr = 0
a = [i+x[i] for i in range(n)]
b = [i-x[i] for i in range(n)]

dt1 = {} 
for i in a: dt1[i] = dt1.get(i,0)+1
dt2 = {} 
for i in b: dt2[i] = dt2.get(i,0)+1

for i in dt1:
    if i in dt2:
        ctr += dt1[i]*dt2[i]
print(ctr)
# Original solution
from collections import Counter
N = int(eval(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_min = min(B)
b_max = max(B)
B, C = Counter(B), Counter(C)
ans = 0
for k in range(b_min, b_max):
    ans += B[k]*C[k]
print(ans)

# Optimized solution
from collections import Counter
N = int(eval(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 list(B.keys()):
    ans += B[k]*C[k]
print(ans)
# Original solution
import itertools
import sys
input = sys.stdin.readline

def main():
    N = int(eval(input()))
    h_list = list(map(int, input().split()))
    c_list = list(itertools.combinations(list(range(N)),2))
    ans = 0

    for c in c_list:
            if abs(c[0] - c[1]) == h_list[c[0]] + h_list[c[1]]:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
eval(input())
A = [int(h) for h in input().split()]
iph_dic = {}
pair_of_spies = 0

for i, h in enumerate(A):
    if i - h in iph_dic:
        pair_of_spies += iph_dic[i - h]
    if i + h in iph_dic:
        iph_dic[i + h] += 1
    else:
        iph_dic[i + h] = 1

print(pair_of_spies)
# Original solution
import itertools
import math

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

def agent(a,i,j):
  return abs(i-j)==abs(a[i-1]+a[j-1])

count=0
X=list(range(1,N+1))
for c in itertools.combinations(X,2):
   if agent(A,*c):
      count+=1
      
print(count)
      

# Optimized solution
 
N=int(eval(input()))
*A,=list(map(int,input().split()))
ref,count={},0

for i,a in enumerate(A):
  if i-a in ref:
     count += ref[i-a]
  if i+a in ref:
     ref[i+a]+=1
  else:
     ref[i+a]=1

print(count)
# Original solution
n=int(eval(input()))
a=[0]*n
a=list(map(int,input().split()))
L=[]
R=[]
ans=0
for i in range(n):
    L.append(i-a[i])
    R.append(i+a[i])
    ans+=L.count(R[i])+R.count(L[i])

print(ans)

# Optimized solution
n=int(eval(input()))
a=[0]*n
a=list(map(int,input().split()))
L={}
R={}
ans=0
for i in range(n):
    L.setdefault(i-a[i],0)
    R.setdefault(i+a[i],0)
    L[i-a[i]]+=1
    R[i+a[i]]+=1
    
    if (i-a[i] in R):
        ans+=R[i-a[i]]
        #print(ans,L[i-a[i]])
    if (i+a[i] in L):
        ans+=L[i+a[i]]

print(ans)
#print(L)
#print(R)
# Original solution
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
L = defaultdict(list)
R = defaultdict(list)
for i in range(N):
    L[i + A[i]].append(i)
    R[i - A[i]].append(i)

# print(L)
# print(R)
ans = 0
for k in list(L.keys()):
    l = L[k]
    r = R[k]
    cnt = 0
    for i in l:
        for j in r:
            if i < j:
                ans += 1
print(ans)

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

ans = 0
for k, v in list(L.items()):
    ans += v * R[k]
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
vals = []
ans = 0
for i in range(1, n+1):
    vals.append(i-a[i-1])
for i in range(n):
    for v in range(n):
        if(i+1+a[i] == vals[v] or i+1+a[i] == vals[v]):
            ans+=1
print(ans)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
vals = []
mappy = {}
ans = 0
for i in range(n):
    if(i+1-a[i] > 0):
        if(i+1-a[i] in mappy):
            mappy[i+1-a[i]]+=1
        else:
            mappy[i+1-a[i]] =1
for i in range(n):
    if(i+1+a[i]in mappy):
        ans+=mappy[i+1+a[i]]
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

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

print(ans)                

# Optimized solution
# 二分探索モジュール bisect
# 添字はiとjの分で相殺(本当の添字は+1が必要だが[(i+1)-(j+1)]なのでいらない(以下は式変形))
import bisect
N = int(eval(input()))
A = list(map(int, input().split()))
X = [A[i]+i for i in range(N)]
Y = [j - A[j] for j in range(N)]
ans = 0
Y.sort()
for i in range(N):
    ans += bisect.bisect_right(Y,X[i]) - bisect.bisect_left(Y,X[i])
print(ans)


'''
bisect 二分探索モジュール
A = [1,1,3,3,3,4,5,6]
B = 3
bisect.bisect_left(A, b) 配列Aにbが左から何番目に入るかを返す #2
bisect.bisect_right(A,b) 配列Aにbが右から何晩目に入るかを返す #5
'''
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
m = A[0]
c = 0

for i in range(1, N):
    if i <  m+A[i]:
        m = min(m, A[i])
    else:
        for j in range(0, i):
            if A[i] + A[j] == i - j:
                c += 1
        m = min(m, A[i])

print(c)

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

L = [ i+1+A[i] for i in range(N) ]
R = [j+1-A[j] for j in range(N) ]

Ld = {}
Rd = {}

for i in range(N):
    if R[i] in list(Rd.keys()):
        Rd[R[i]] += 1
    else:
        Rd[R[i]] = 1

ans = 0
for i in range(N):
    if L[i] in list(Rd.keys()):
        ans += Rd[L[i]]
    if L[i] == R[i]:
        ans -= 1
        
print(ans)