CodeEff/ECCO huggingface dataset:
# Original solution
import itertools
N = int(eval(input()))
A = list(map(int,input().split()))
N_comb = list(itertools.combinations([n for n in range(1,N+1)],2))
cnt = 0

for i in range(len(N_comb)):
    x = N_comb[i][0]
    y = N_comb[i][1]
    if abs(x-y)==A[x-1]+A[y-1]:
        cnt = cnt + 1
del N_comb
print(cnt)

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

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

print(cnt)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
i = 0
j = 1
ans = 0
p = 0
nextj = 0
while True:
    if j == n:
        i += 1
        p = 0
        j = min(n-1,min(i+a[i]+1,nextj))

    
    if p == 0 and a[i] + a[j] == j-i:
        ans += 1
        nextj = j
        p = 1
    elif p == 1 and a[i] + a[j] == j-i:
        ans += 1
    j += 1
    
    if i == n-1:
        print(ans)
        exit()
        

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
mae = {}
ans = 0
for i in range(n):
    mae[i+a[i]]=mae.get(i+a[i],0)+1
    ans += mae.get(i-a[i],0)
print(ans)
# Original solution
import sys
input = sys.stdin.readline

N = int(eval(input()))

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


cnt_height_plus_ind = {}
cnt_height_minus_ind = {}
cnt_ind_minus_height = {}
cnt_minus_height_minus_ind = {}

for ind in range(N):
    height = heights[ind]

    if ind - height not in cnt_ind_minus_height:
        cnt_ind_minus_height[ind - height] = 0
    cnt_ind_minus_height[ind - height] += 1

    if ind + height not in cnt_height_plus_ind:
        cnt_height_plus_ind[ind + height] = 0
    cnt_height_plus_ind[ind + height] += 1

    if height - ind not in cnt_height_minus_ind:
        cnt_height_minus_ind[height - ind] = 0
    cnt_height_minus_ind[height - ind] += 1

    if - ind - height not in cnt_minus_height_minus_ind:
        cnt_minus_height_minus_ind[-ind-height] = 0
    cnt_minus_height_minus_ind[-ind-height] += 1
    

ans = 0
for val in cnt_height_minus_ind:
    if val in cnt_minus_height_minus_ind:
        ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]

for val in cnt_height_plus_ind:
    if val in cnt_ind_minus_height:
        ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]

print((ans//2))

# Optimized solution
import sys
input = sys.stdin.readline

N = int(eval(input()))

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


cnt_height_plus_ind = {}
cnt_height_minus_ind = {}
cnt_ind_minus_height = {}
cnt_minus_height_minus_ind = {}

for ind in range(N):
    height = heights[ind]

    if ind - height not in cnt_ind_minus_height:
        cnt_ind_minus_height[ind - height] = 0
    cnt_ind_minus_height[ind - height] += 1

    if ind + height not in cnt_height_plus_ind:
        cnt_height_plus_ind[ind + height] = 0
    cnt_height_plus_ind[ind + height] += 1

    if height - ind not in cnt_height_minus_ind:
        cnt_height_minus_ind[height - ind] = 0
    cnt_height_minus_ind[height - ind] += 1

    if - ind - height not in cnt_minus_height_minus_ind:
        cnt_minus_height_minus_ind[-ind-height] = 0
    cnt_minus_height_minus_ind[-ind-height] += 1
    

ans = 0
#for val in cnt_height_minus_ind:
#    if val in cnt_minus_height_minus_ind:
#        ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]

for val in cnt_height_plus_ind:
    if val in cnt_ind_minus_height:
        ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]

print(ans)
# Original solution
import sys
input = sys.stdin.readline

N = int(eval(input()))

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


cnt_height_plus_ind = {}
cnt_height_minus_ind = {}
cnt_ind_minus_height = {}
cnt_minus_height_minus_ind = {}

for ind in range(N):
    height = heights[ind]

    if ind - height not in cnt_ind_minus_height:
        cnt_ind_minus_height[ind - height] = 0
    cnt_ind_minus_height[ind - height] += 1

    if ind + height not in cnt_height_plus_ind:
        cnt_height_plus_ind[ind + height] = 0
    cnt_height_plus_ind[ind + height] += 1

    if height - ind not in cnt_height_minus_ind:
        cnt_height_minus_ind[height - ind] = 0
    cnt_height_minus_ind[height - ind] += 1

    if - ind - height not in cnt_minus_height_minus_ind:
        cnt_minus_height_minus_ind[-ind-height] = 0
    cnt_minus_height_minus_ind[-ind-height] += 1
    

ans = 0
#for val in cnt_height_minus_ind:
#    if val in cnt_minus_height_minus_ind:
#        ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]

for val in cnt_height_plus_ind:
    if val in cnt_ind_minus_height:
        ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]

print(ans)

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

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


cnt_height_plus_ind = {}
cnt_ind_minus_height = {}

for ind in range(N):
    height = heights[ind]

    if ind - height not in cnt_ind_minus_height:
        cnt_ind_minus_height[ind - height] = 0
    cnt_ind_minus_height[ind - height] += 1

    if ind + height not in cnt_height_plus_ind:
        cnt_height_plus_ind[ind + height] = 0
    cnt_height_plus_ind[ind + height] += 1

ans = 0
for val in cnt_height_plus_ind:
    if val in cnt_ind_minus_height:
        ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]

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

# Optimized solution
from collections import defaultdict
N = int(eval(input()))
arr = list(map(int, input().split()))
d = defaultdict(int)
ans = 0
for i in range(N):
    if i-arr[i] >= 0:
        ans += d[i-arr[i]]
    d[i+arr[i]] += 1
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(i+1, n):
        if abs(j-i) == a[i]+a[j]:
            ans += 1
print(ans)

# Optimized solution
import sys
# sys.stdin = open('input.txt')

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

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

ans = 0
# key: i + Ai, value: count
d = {}

for j in range(n):
    a1 = j - a[j]
    try:
        ans += d[a1]
    except KeyError:
        d[a1] = 0

    a2 = j + a[j]
    try:
        d[a2] += 1
    except KeyError:
        d[a2] = 1

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(i+1, n):
        if abs(i-j) == 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):
    if i + a[i] in L:
        L[i + a[i]] = L[i + a[i]] + 1
    else:
        L[i + a[i]] = 1

    if i - a[i] in R:
        R[i - a[i]] = R[i - a[i]] + 1
    else:
        R[i - a[i]] = 1

#print(L,R,sep="\n")
ans = 0
for key in list(L.keys()):
    if key in R:
        #print(L[key], R[key])
        ans += L[key] * R[key]
print(ans)

"""
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if abs(i-j) == a[i]+a[j]:
            ans += 1
print(ans)
"""
# Original solution
n = int(eval(input()))
L, R = [0] * n, [0] * n
i = 0
for ipt in input().split():
    L[i] = i + int(ipt)
    R[i] = i - int(ipt)
    i += 1
def make_dic(L):
    L_set = set(L)
    return dict([(i, L.count(i)) for i in L_set])
L_dic, R_dic = make_dic(L), make_dic(R)
cnt = 0
for Lk, Lv in list(L_dic.items()):
    try:
        cnt += R_dic[Lk] * Lv
    except KeyError:
        pass
print(cnt)

# Optimized solution
n = int(eval(input()))
L_dict, R_dict = {}, {}
i = 0
for ipt in input().split():
    try:
        L_dict[i + int(ipt)] += 1
    except KeyError:
        L_dict[i + int(ipt)] = 1
    try:
        R_dict[i - int(ipt)] += 1
    except KeyError:
        R_dict[i - int(ipt)] = 1
    i += 1
cnt = 0
for Lk, Lv in list(L_dict.items()):
    try:
        cnt += R_dict[Lk] * Lv
    except KeyError:
        pass
print(cnt)
# Original solution
#!python3

from collections import defaultdict

iim = lambda: list(map(int, input().rstrip().split()))

def resolve():
    N = int(eval(input()))
    A = list(iim())

    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i, ai in enumerate(A):
        d1[i+ai] += 1
        d2[i-ai] += 1

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

    print(ans)

if __name__ == "__main__":
    resolve()


# Optimized solution
#!python3

from collections import defaultdict

iim = lambda: list(map(int, input().rstrip().split()))

def resolve():
    N = int(eval(input()))
    A = list(iim())

    ans = 0
    dp = [0]*N
    for i, ai in enumerate(A):
        x = i + ai
        if x < N:
            dp[x] += 1
        x = i - ai
        if x >= 0:
            ans += dp[x]

    print(ans)

if __name__ == "__main__":
    resolve()
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
p = [i + A[i] for i in range(N)]
m = [j - A[j] for j in range(N)]
a = min(p)
b = max(m)
for i in range(a,b+1):
    if i in p and i in m:
        ans += p.count(i) * m.count(i)
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
p = {}
m = {}
for i in range(N):
    if p.get(i+A[i]) is None:
        p[i+A[i]] = 1
    else:
        p[i+A[i]] += 1
for i in range(N):
    if m.get(i-A[i]) is None:
        m[i-A[i]] = 1
    else:
        m[i-A[i]] += 1
for x in range(min(p),max(m)+1):
    if x in p and x in m:
        ans += p[x] * m[x]
print(ans)
# Original solution
N = int(eval(input())) + 1
A = [0] + [int(i) for i in input().split()]

MAX_I = 10 ** 9
cnt = 0

for i in range(1, N):
    if MAX_I >= i + A[i]:
        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 = [int(i) for i in input().split()]
i_Ai = {}
cnt = 0

for i, h in enumerate(A):
	imh = i - h
	if imh in i_Ai:
		cnt += i_Ai[imh]
	iph = i + h
	if iph in i_Ai:
		i_Ai[iph] += 1
	else:
		i_Ai[iph] = 1
print(cnt)
# Original solution
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))

maxVal = N + max(A)
ans = 0

L = defaultdict(int)
R = defaultdict(int)
for x in range(1, maxVal+1):
    for i in range(1, N+1):
        if i + A[i-1] == x:
            L[i+A[i-1]] += 1

    for j in range(1, N+1):
        if j - A[j-1] == x:
            R[j-A[j-1]] += 1


for x in range(1, maxVal+1):
    ans += L[x] * R[x]

print(ans)


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

maxVal = N + max(A)
ans = 0

candidatesL = defaultdict(int)
for i in range(1, N+1):
    candidatesL[i+A[i-1]] += 1

candidatesR = defaultdict(int)
for j in range(1, N+1):
    candidatesR[j-A[j-1]] += 1

ans = 0
for x in list(candidatesL.keys()):
    ans += candidatesL[x] * candidatesR[x]

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

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
# a+i と i-aのとりうる値の個数をカウントするが
# 一致するとしても[0, n)の範囲だけなのでDの大きさはnで十分
D = [0]*n
for i, a in enumerate(A):
    if 1+i+a < n:
        D[i+a] += 1
ans = 0
# i-aに対応するD[i-a]を加えるだけで答えが求まる
for i, a in enumerate(A):
    if 1+i-a >= 0:
        ans += D[i-a]
print(ans)
# Original solution
N = int(eval(input()))
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

count = 0
for k in range(0, max(AI)):
    ci = AI.count(k)
    cj = AJ.count(k)
    count += ci * cj
print(count)

# Optimized solution
N = int(eval(input()))
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

cai = {}
caj = {}
vali = set()
valj = set()
for ai, aj in zip(AI, AJ):
    if not ai in cai:
        cai[ai] = 0
    if not aj in caj:
        caj[aj] = 0

    cai[ai] += 1
    vali.add(ai)

    caj[aj] += 1
    valj.add(aj)

count = 0
for val in vali & valj:
    count += cai[val] * caj[val]

print(count)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))
D1 = {}
D2 = {}
def count(D, s):
    if s in D:
        D[s] += 1
    else:
        D[s] = 1
for i, a in enumerate(A):
        count(D1, a+i)
        count(D2, i-a)
ans = 0
for d, num in list(D1.items()):
    if d in D2:
        ans += num * D2[d]
print(ans)

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
# a+i と i-aのとりうる値の個数をカウントするが
# 一致するとしても[0, n)の範囲だけなのでDの大きさはnで十分
D = [0]*n
for i, a in enumerate(A):
    if i+a < n:
        D[i+a] += 1
ans = 0
# i-aに対応するD[i-a]を加えるだけで答えが求まる
for i, a in enumerate(A):
    if i-a >= 0:
        ans += D[i-a]
print(ans)
# Original solution
#!/usr/bin/env python

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

    cnt = 0

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

if __name__ == '__main__':
    main()


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

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

    lst1 = [0] * n
    lst2 = [0] * n

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

        if 0 <= p < n:
            lst1[p] += 1
        if 0 <= q < n:
            lst2[q] += 1

    for i in range(n):
        cnt += lst1[i] * lst2[i]

    print(cnt)

if __name__ == '__main__':
    main()
# Original solution
# -*- coding: utf-8 -*-
# モジュールのインポート
import collections

# 標準入力の取得
N = int(eval(input()))
A = list(map(int, input().split()))

# 求解処理
# A_i + i = -A_j + j (i < j)
left = [A[i] + i for i in range(N)]
right = collections.Counter([-A[j] + j for j in range(N)])
result = 0
for l in left:
    result += right[l]

# 結果出力
print(result)


# Optimized solution
# -*- coding: utf-8 -*-
# モジュールのインポート
import collections

# 標準入力の取得
N = int(eval(input()))
A = list(map(int, input().split()))

# 求解処理
left = {}
result = 0
for j in range(N):
    r = -A[j] + j
    result += left.get(r, 0)
    l = A[j] + j
    left[l] = left.get(l, 0) + 1

# 結果出力
print(result)
# Original solution
# -*- coding: utf-8 -*-
# モジュールのインポート
import collections

# 標準入力の取得
N = int(eval(input()))
A = list(map(int, input().split()))

# 求解処理
left = {}
result = 0
for j in range(N):
    r = -A[j] + j
    result += left.get(r, 0)
    l = A[j] + j
    left[l] = left.get(l, 0) + 1

# 結果出力
print(result)


# Optimized solution
# -*- coding: utf-8 -*-
# 標準入力の取得
N = int(eval(input()))
A = list(map(int, input().split()))


def main() -> None:
    """Entry point
    """
    # 求解処理
    """
    1 <= i < j <= Nとすると、
    j - i = A_i + A_j ⇒ -A_j + j = A_i +i
    となる。
    したがって、各jについて、左辺の値を計算し、等式が成立するようなi(< j)の個数を求めればよい。
    """
    right = {}
    result = 0
    for j in range(N):
        l = -A[j] + j
        result += right.get(l, 0)
        r = A[j] + j
        right[r] = right.get(r, 0) + 1

    # 結果出力
    print(result)


if __name__ == "__main__":
    main()
# Original solution
from sys import stdin

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

l = {}
r = {}

for i in range(n):
    x = i + an[i]
    if x not in l:
        l[x] = [i]
    else:
        l[x].append(i)

    x = i - an[i]
    if x not in r:
        r[x] = [i]
    else:
        r[x].append(i)

sum = 0
for k in l:
    if k in r:
        for i in range(len(l[k])):
            for j in range(len(r[k])):
                if l[k][i] != r[k][j]:
                    sum += 1
print(sum)


# Optimized solution
from sys import stdin

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

l = {}
r = {}

for i in range(n):
    x = i + an[i]
    if x not in l:
        l[x] = [i]
    else:
        l[x].append(i)

    x = i - an[i]
    if x not in r:
        r[x] = [i]
    else:
        r[x].append(i)

sum = 0
for k in l:
    if k in r:
        sum += len(l[k])*len(r[k])

print(sum)
# Original solution
from collections import Counter

n=int(eval(input()))
a=list(map(int,input().split()))
ans=0
l=[]
r=[]
for i,j in enumerate(a):
    l.append(i+j)
    r.append(i-j)

#ref = dict(Counter(r))
#ans = 0
#for i in l:
#    ans += ref.get(i, 0)
#print(ans)

for i in l:
    ans+=r.count(i)
    
print(ans)

# Optimized solution
from collections import Counter

n=int(eval(input()))
a=list(map(int,input().split()))
ans=0
l=[]
r=[]
for i,j in enumerate(a):
    l.append(i+j)
    r.append(i-j)

#ref = dict(Counter(r))
#ans = 0
#for i in l:
#    ans += ref.get(i, 0)
#print(ans)
b=Counter(r)
for i in l:
    ans+=b.get(i,0)

print(ans)
# Original solution
from collections import defaultdict
N = int(eval(input()))
A = [int(i) for i in input().split()]
P = []
H = defaultdict(list)
for i, v in enumerate(A):
    H[i+v].append(i)
    P.append((i, i-v))
ans = 0

for i, v in P:
    for j in H[v]:
        if i > j:
            ans += 1
print(ans)

# Optimized solution
from collections import defaultdict
N = int(eval(input()))
A = [int(i) for i in input().split()]
H = defaultdict(int)
ans = 0
for i, v in enumerate(A):
    ans += H[i-v]
    H[i+v] += 1
print(ans)
# Original solution
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = int(sys.stdin.readline())
a = inpl()
count = 0
maxx = max(a)
minn = min(a)
for i in range(n):
    for j in range(i+1, n):
        if a[i] + maxx < j-i:
            break
        elif a[i] + minn > j-i:
            continue
        if a[i] + a[j] == j - i:
            count += 1
print(count)

# Optimized solution
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = int(sys.stdin.readline())
a = inpl()
dic ={}
res = 0
for i in range(n):
    res += dic.get(i - a[i], 0)
    dic[i + a[i]] = dic.get(i + a[i], 0) + 1

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

total = 0
for i in range(n):
  for j in range(i+1, n):
    total += int(abs(j-i) == a[i]+a[j])
print(total)

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

dict_diffs1 = dict()
dict_diffs2 = dict()
for i in range(1, n+1):
  dict_diffs1[i+a[i-1]] = dict_diffs1.get(i+a[i-1], 0) + 1
  dict_diffs2[i-a[i-1]] = dict_diffs2.get(i-a[i-1], 0) + 1
total = 0
for j in range(1, n+1):
  total += dict_diffs1.get(j-a[j-1], 0)
  total += dict_diffs2.get(j+a[j-1], 0)
total = total//2
print(total)
# Original solution
from collections import deque

N = int(eval(input()))

A = [
  int(j) - i  for i, j in enumerate(input().split())
]


ans = 0
d = deque(A)
for i in range(N):
  a = d.popleft()
  c = d.count(-a - 2 * i)
  ans += c
print(ans)

# Optimized solution
from collections import deque, Counter

N = int(eval(input()))

A = [
  int(j) - i  for i, j in enumerate(input().split())
]
cnt_A = Counter(A)

ans = 0
d = deque(A)
for i in range(N):
  a = d.popleft()
  #c = d.count(-a - 2 * i)
  c = cnt_A[-a - 2 * i]
  ans += c
print(ans)
# Original solution
if __name__ == '__main__':
    n = int(eval(input()))
    a = [int(i) for i in input().split()]
    d = dict()
    count = 0
    for no in a:
        d[no] = set()
    for i in range(n):
        no = a[i]
        pos = i+1
        # print(d)
        # print("> pos: "+str(pos))
        if no < pos:
            for j in range(no+1,pos,1):
                # print(">> j: "+str(j))
                if d.get(j-no) is not None and len(d.get(j-no)) > 0:
                    if pos - j in d.get(j-no):
                        count += 1
        d[no].add(pos)
    # print(d)
    print(count)






# Optimized solution
if __name__ == '__main__':
    n = int(eval(input()))
    a = [int(i) for i in input().split()]
    d = dict()
    count = 0
    ar = [(a[i]+i+1) for i in range(n)]
    br = [(i+1-a[i]) for i in range(n)]
    for i in range(n):
        if d.get(ar[i]) is not None:
            d[ar[i]] += 1
        else:
            d[ar[i]] = 1
    c = dict()
    for i in range(n):
        if c.get(br[i]) is not None:
            c[br[i]] += 1
        else:
            c[br[i]] = 1
    count = 0
    for no in list(c.keys()):
        if d.get(no) is not None:
            count += (c[no]*d[no])
    
    print(count)
# Original solution
N=int(eval(input()))
Agents=list(map(int,input().split()))

from itertools import combinations

comb = list(combinations([i for i in range(N)],2))

cnt=0
for i in comb:
    if Agents[i[0]] + Agents[i[1]] == abs(i[0] - i[1]):
        cnt+=1

print(cnt)



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

# from itertools import combinations

# comb = list(combinations([i for i in range(N)],2))

# cnt=0
# for i in comb:
#     if Agents[i[0]] + Agents[i[1]] == abs(i[0] - i[1]):
#         print(i[0],i[1])
#         cnt+=1

# print(cnt)
cnt=0

for i in range(0,N):
    k=Agents[i]-(i+1)
    if k<i:
        k=i+1
    for j in range(k,N):
        if Agents[i]+Agents[j]==abs(i-j):
            # print(i,j,Agents[i],Agents[j])
            cnt+=1

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


##Miss 1
# from itertools import combinations

# comb = list(combinations([i for i in range(N)],2))

# cnt=0
# for i in comb:
#     if Agents[i[0]] + Agents[i[1]] == abs(i[0] - i[1]):
#         print(i[0],i[1])
#         cnt+=1

# print(cnt)

# Miss 2
# for i in range(0,N):
#     k=Agents[i]-(i+1)
#     if k<i:
#         k=i+1
#     for j in range(k,N):
#         if Agents[i]+Agents[j]==abs(i-j):
#             # print(i,j,Agents[i],Agents[j])
#             cnt+=1


L={}
for i in range(N):
    L['{}'.format(i+1)]=i+1 + Agents[i]
R={}
for j in range(N):
    R['{}'.format(j+1)]=j+1 - Agents[j]
cnt=0

for key,value in list(L.items()):
    for key2,value2 in list(R.items()):
        if int(key) < int(key2) and value == value2:
            cnt+=1


print(cnt)


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


##Miss 1
# from itertools import combinations

# comb = list(combinations([i for i in range(N)],2))

# cnt=0
# for i in comb:
#     if Agents[i[0]] + Agents[i[1]] == abs(i[0] - i[1]):
#         print(i[0],i[1])
#         cnt+=1

# print(cnt)

# Miss 2
# for i in range(0,N):
#     k=Agents[i]-(i+1)
#     if k<i:
#         k=i+1
#     for j in range(k,N):
#         if Agents[i]+Agents[j]==abs(i-j):
#             # print(i,j,Agents[i],Agents[j])
#             cnt+=1


L={}
for i in range(N):
    s = i+1 + Agents[i] 
    if s in L:
        L[s]+=1
    else:
        L[s]=1

R={}
for j in range(N):
    s= j+1 - Agents[j]
    if s in R:
        R[s]+=1
    else:
        R[s]=1
cnt=0

for key,value in list(L.items()):
    cnt += R.get(key,0) * value
# for key,value in L.items():
#     for key2,value2 in R.items():
#         if int(key) < int(key2) and value == value2:
#             cnt+=1


print(cnt)
# Original solution
import itertools

N = int(eval(input()))
A = list(map(int, input().split()))
array = list(itertools.combinations(list(range(N)), 2))
count = 0

for x in array:
    if (A[x[1]] + A[x[0]]) == (x[1] - x[0]):
        count += 1
print(count)


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
count = 0
l_array = []
r_array = []
for i, X in enumerate(A):
    l_array.append(i + X)
    r_array.append(i - X)

for x in l_array:
    count += r_array.count(x)
print(count)
# Original solution
import collections

N = int(eval(input()))
A = list(map(int, input().split()))
B = collections.defaultdict(int)
C = collections.defaultdict(int)

for i in range(N):
    B[i-A[i]] += 1 
    C[i+A[i]] += 1
#print(B)
#print(C)
ans = 0
for i in B:
    #print(i) i=Key
    ans += B[i]*C[i]
print(ans)

# Optimized solution
import collections

N = int(eval(input()))
A = list(map(int, input().split()))
B = {}
C = {}

for i in range(N):
    if i-A[i] in B:
        B[i-A[i]] += 1
    else:
        B[i-A[i]] = 1
    if i+A[i] in C:
        C[i+A[i]] += 1
    else:
        C[i+A[i]] = 1
#print(B)
#print(C)
ans = 0
for i in B:
    #print(i) i=Key
    if i in C:
        ans += B[i]*C[i]
print(ans)