CodeEff/ECCO huggingface dataset:
# Original solution
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip() 
a = list(map(int, l.split()))
count = 0
for i in range(N):
    for j in range(i+1, N):
        if j - i == a[j] + a[i]:
            count += 1

print(count)

# Optimized solution
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip() 
a = list(map(int, l.split()))
count = 0
# j - i = Ai + Aj -> Ai +i = j - Aj
# Li = Ai + i
# Ri = j - Aj
L = []
R = []
for i, one in enumerate(a):
    L.append(one + i+1)
    if (i+1 - one) > 0:
        R.append(i+1-one)
L = sorted(L)
R_count = {}
for one in R:
    if one in R_count:
        R_count[one] += 1
    else:
        R_count[one] = 1
count = 0
for one in L:
    if one in R_count:
        count += R_count[one]

print(count)
# Original solution
from collections import Counter

def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    bigger = [None]*n
    smaller = [None]*n
    for i, ai in enumerate(a):
        bigger[i] = i - ai
        smaller[i] = i + ai
    b = sorted(Counter(bigger).items())
    s = sorted(Counter(smaller).items())
    nb = len(b)
    ns = len(s)
    b.append((10**10, 0))
    s.append((10**11, 0))
    i, j = 0, 0
    ans = 0
    while i < nb or j < ns:
        bi, nbi = b[i]
        si, nsi = s[j]
        if bi == si:
            ans += nbi*nsi
            i += 1
            j += 1
        elif bi > si:
            j += 1
        else:
            i += 1
    print(ans)
        

if __name__ == "__main__":
    main()

# Optimized solution
from collections import defaultdict

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

if __name__ == "__main__":
    main()
# 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+a[i]] += 1
ans = 0
for i in range(n):
  ans += d[i-a[i]]
print(ans)

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

# Optimized solution
def main():
  n = int(eval(input()))
  a = list(map(int, input().split()))
  d = [0]*n
  for i, x in enumerate(a):
    if i+x < n: d[i+x] += 1
  ans = 0
  for i, x in enumerate(a):
    if i-x >= 0: ans += d[i-x]
  print(ans)
main()
# Original solution
n,a=int(eval(input())),list(map(int, input().split()))
d=[0]*n
def main():
 for i,x in enumerate(a):
  if i+x<n:d[i+x]+=1
 print((sum([d[i-x]for i,x in enumerate(a)if i-x>=0])))
main()

# Optimized solution
def main():
 n,a=int(eval(input())),list(map(int, input().split()));d,s=[0]*n,0
 for i,x in enumerate(a):
  if i+x<n:d[i+x]+=1
  if i-x>=0:s+=d[i-x]
 print(s)
main()
# Original solution
from collections import defaultdict


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

    """
    for j>i, j-i = Ai + Aj
    i + Ai = j -Aj
    """

    L = defaultdict(int)
    R = defaultdict(int)

    for i, height in enumerate(heights):
        if i + height < N:
            L[i + height] += 1
        
        if i - height > 0:
            R[i - height] += 1

    total_count = 0
    for x, count_l in list(L.items()):
        if x in R:
            count_r = R[x]
            total_count += count_l * count_r

    print(total_count)


if __name__ == "__main__":
    main()


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

    """
    for j>i, j-i = Ai + Aj
    i + Ai = j -Aj
    """

    L = [0] * N
    R = [0] * N

    count = 0
    for i, height in enumerate(heights):
        right = i + height
        left = i - height

        if right < N:
            R[right] += 1

        if left > 0:
            L[left] += 1
            count += R[left]

    print(count)


if __name__ == "__main__":
    main()
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in list(dr.keys()):
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    for w in y:
      for ww in z:
        if w>ww:
          ans+=1
print(ans)

# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in list(dr.keys()):
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    ans+=len(z)*len(y)
print(ans)
# Original solution
n=int(eval(input()))
A=list(map(int,input().split()))
S=[]
for i in range(n):
    S.append([A[i],i])
S=list(reversed(sorted(S)))
#print(S)
F=[0]*n

ans=0
C=[0]*n
for i in range(n):
    s=S.pop(0)
    d=s[0] #距離
    x=s[1] #座標
    F[x]=1
    L1=max(x-2*d,0)
    L2=max(x-d,-1)
    R1=min(x+d,n)
    R2=min(x+2*d,n-1)
    if L1<=L2:
        for j in range(L1,L2+1):
            if F[j]==1:
                continue
            if x-j==d+A[j]:
                ans+=1
                #print(s,j)
    if R1<=R2:
        for j in range(R1,R2+1):
            if F[j]==1:
                continue
            if j-x==d+A[j]:
                ans+=1
                #print(s,j)
print(ans)

# Optimized solution
n=int(eval(input()))
A=list(map(int,input().split()))
C=[]
for i in range(n):
    C.append([i+A[i],0])
    C.append([i-A[i],1])
C.sort()
now=C[0][0]
c0=0
c1=0
ans=0
for c in C:
    if now==c[0]:
        if c[1]==0:
            c0+=1
        else:
            c1+=1
    else:
        ans+=c0*c1
        c0=0
        c1=0
        if c[1]==0:
            c0+=1
        else:
            c1+=1
        now=c[0]
ans+=c0*c1
print(ans)
# Original solution
from collections import Counter
from itertools import combinations
inputs = open(0).readlines()
n = int(inputs[0])
*A, = (list(map(int, inputs[1].split())))
B = [a+i for i, a in enumerate(A, 1)]
C = [i-a for i, a in enumerate(A, 1)]
ans = 0
for k1, v1 in list(Counter(B).items()):
    for k2, v2 in list(Counter(C).items()):
        if k1 == k2:
            ans += v1*v2
print(ans)

# Optimized solution
from collections import Counter
inputs = open(0).readlines()
n = int(inputs[0])
*A, = (list(map(int, inputs[1].split())))
B = Counter([a+i for i, a in enumerate(A, 1)])
C = Counter([i-a for i, a in enumerate(A, 1)])
ans = 0
for k, v in list(B.items()):
    if k in C:
        ans += C[k]*v
print(ans)
# Original solution
from collections import Counter
inputs = open(0).readlines()
n = int(inputs[0])
*A, = (list(map(int, inputs[1].split())))
B = Counter([a+i for i, a in enumerate(A, 1)])
C = Counter([i-a for i, a in enumerate(A, 1)])
ans = 0
for k, v in list(B.items()):
    if k in C:
        ans += C[k]*v
print(ans)

# Optimized solution
n, *A = list(map(int, open(0).read().split()))
ans, d = 0, {}
for i, a in enumerate(A, 1):
    x, y = i+a, i-a
    d[x] = d.get(x, 0)+1
    ans += d.get(y, 0)
print(ans)
# Original solution
n=int(eval(input()))
heights=list(map(int,input().split(" ")))
res=0
for i in range(n):
    for j in range(n):
        if abs(j-i)==heights[i]+heights[j]:
            res+=1
print((int(res/2)))

# Optimized solution
n=int(eval(input()))
heights=list(map(int,input().split(" ")))
dic={}
res=0
for i in range(n):
    if heights[i]-i not in dic:
        dic[heights[i]-i]=1
    else:
        dic[heights[i]-i]+=1
for j in range(n):
    if -heights[j]-j in dic:
        res+=dic[-heights[j]-j]
print(res)
# Original solution
# なんか身長順でソートすればいいんじゃない？
# 身長差でありえるのは1〜Nなので，身長差が1になるエージェントの組み合わせをだして，それぞれの身長差について調べる
# でも結局全探索になるか？やっぱり配列を作ると同時に答えが独立してうまく求まるようなのがいいよね
# j-i = Aj+Ai となるのが求めるもの，これを変換してiとjの式のみに分離すると，うまく配列を作るだけでうまくいくようになる
# j-Aj = Ai+i となる．こうすると独立しているので,X=i-Ai,Y=Ai+iを作り，setもしくはdictで探索すればすぐです！
# i==jのときはi-i == Ai+Ai が絶対に成立しないので問題ない

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)]
#Y=set(Y) # set使うと同じ要素が減るのでだめ！！！
dicY=dict()
for y in Y:
    if not y in dicY:
        dicY[y]=1
    else:
        dicY[y]+=1
count=0
for x in X:
    if x in Y:
        count+=dicY[x]
print(count)


# Optimized solution
# なんか身長順でソートすればいいんじゃない？
# 身長差でありえるのは1〜Nなので，身長差が1になるエージェントの組み合わせをだして，それぞれの身長差について調べる
# でも結局全探索になるか？やっぱり配列を作ると同時に答えが独立してうまく求まるようなのがいいよね
# j-i = Aj+Ai となるのが求めるもの，これを変換してiとjの式のみに分離すると，うまく配列を作るだけでうまくいくようになる
# j-Aj = Ai+i となる．こうすると独立しているので,X=i-Ai,Y=Ai+iを作り，setもしくはdictで探索すればすぐです！
# i==jのときはi-i == Ai+Ai が絶対に成立しないので問題ない

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)]
#Y=set(Y) # set使うと同じ要素が減るのでだめ！！！
dicY=dict()
for y in Y:
    if not y in dicY:
        dicY[y]=1
    else:
        dicY[y]+=1
count=0
for x in X:
    if x in dicY:
        count+=dicY[x]
print(count)
# Original solution
from collections import defaultdict
from bisect import bisect_right

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

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

cnt = defaultdict(list)
for i in range(n):
	cnt[b[i]].append(i)

ans = 0
for i in range(n):
	k = bisect_right(cnt[c[i]], i)
	ans += len(cnt[c[i]][k:])

print(ans)


# Optimized solution
from collections import defaultdict

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

ans = 0
cnt = defaultdict(int)
for i in range(n):
	ans += cnt[i - a[i]]
	cnt[i + a[i]] += 1

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

out = 0

for i in range(n):
    w = i-a[i]
    for j in range(i):
        if(w == a[j] + j):
            out += 1
print(out)


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

ml = [0] * n
pl = [0] * n

out = 0

for i in range(0, n):
    if(i+a[i]<n):
        pl[i+a[i]] += 1
    if(i-a[i]>=0):
        ml[i-a[i]] += 1

for i in range(0, n):
    out += pl[i] * ml[i]

print(out)
# Original solution
from collections import Counter


def main():
    N = int(eval(input()))
    A = tuple(int(c) for c in input().split(' '))

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

    #はじめL_t = defaultdict(list)としてiの候補を追加していったが、iとjは重複しないのでチェックが不要
    '''
    L_t = defaultdict(int)
    for i, l in enumerate(L):
        L_t[l] += 1
    R_t = defaultdict(int)
    for j, r in enumerate(R):
        R_t[r] += 1
    '''
    L_t = Counter(L)
    R_t = Counter(R)
    x_max = max(L)
    x_min = min(R)
    cnt = 0
    for x in range(x_min, x_max+1):
        l_candidate = L_t[x]
        r_candidate = R_t[x]

        cnt += l_candidate * r_candidate

    print(cnt)


if __name__ == "__main__":
    main()

# Optimized solution
#解説を見て実装
from collections import Counter

def main():
    N = int(eval(input()))
    A = tuple(int(c) for c in input().split(' '))
    L = [i+a for i, a in enumerate(A)]
    R = [i-a for i, a in enumerate(A)]
    #print(L)
    #print(R)

    #はじめL_t = defaultdict(list)としてiの候補を追加していったが、iとjは重複しないのでチェックが不要
    L_t = Counter(L)
    R_t = Counter(R)
    cnt = 0
    x_candidate = set(L) & set(R)
    for x in x_candidate:
        l_candidate = L_t[x]
        r_candidate = R_t[x]
        cnt += l_candidate * r_candidate

    print(cnt)

if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

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

print(ans)


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

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

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

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


# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
x = {}
ans = 0
for i in range(n):
    R = i + a[i]
    if not R in x:
        x[R]=1
    else: x[R]+=1
    
for i in range(n):
    L = i - a[i]
    if L in x:
        ans+=x[L]
print(ans)
# Original solution
from collections import defaultdict

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

ans = 0

R = defaultdict(int) 
#R= defaultdict(lambda:0) 

for i ,Ai in enumerate(A,1):
  R[i+Ai]+=1

L = defaultdict(int) 
for j ,Aj in enumerate(A,1):
  L[j-Aj]+=1

for i in R:
  ans+=R.get(i,0)*L.get(i,0)

print(ans)

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

ia = {}
pair = 0
for j, a in enumerate(la):
  ia[j + a] = ia.get(j + a, 0) + 1

for j, a in enumerate(la): 
  pair += ia.get(j - a, 0)

print(pair)
# Original solution
from collections import deque

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

[N] = getInts()
As = getInts()

maxV = max(As)
minV = min(As)

count = 0
for i in range(N):
    r2 = min(i+As[i]+minV, N-1)
    for j in range(r2, N):
        if As[j]+As[i] == abs(i-j):
            count += 1
print(count)

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

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

L = {}
R = {}
for i in range(1, N+1):
    if i - A[i] not in L:
        L[i-A[i]] = 1
    else:
        L[i-A[i]] += 1
    if i + A[i] not in R:
        R[i+A[i]] = 1
    else:
        R[i+A[i]] += 1
count = 0
for k in list(R.keys()):
    if k in L:
        count += R[k]*L[k]
print(count)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
counter = 0
for j in range(1, N):
    for i in range(j + 1, N + 1):
        if j + A[j-1] == i - A[i-1]:
            counter += 1
print(counter)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
dic = {}
dic[1 + A[0]] = 1
for i in range(2, N+1):
    if i - A[i-1] in dic:
        ans += dic[i - A[i-1]]
    if i + A[i-1] in dic:
        dic[i + A[i-1]] = dic[i + A[i-1]] + 1
    else:
        dic[i + A[i-1]] = 1
print(ans)
# Original solution
from itertools import combinations

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

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

print(ans)



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

ans = 0
mp = {}

for i in range(n):
    sa = i - a[i]
    if sa in mp:
        ans += mp[sa]
    wa = i + a[i]
    if wa in mp:
        mp[wa] += 1
    else:
        mp[wa] = 1

print(ans)
# Original solution
def getN():
    return int(eval(input()))
def getNM():
    return list(map(int, input().split()))
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, Counter
from sys import exit
import math


def main():
    n = getN()
    nums = getList()
    den = [num - i for i, num in enumerate(nums)]
    cnt = Counter(den)
    ans = 0
    for i in range(n-1):
        k1, k2 = nums[i], nums[i+1]
        su = k1 + k2
        tgt = den[i+1] - su + 1
        if tgt in list(cnt.keys()):
            ans += cnt[tgt]
    print(ans)
if __name__ == "__main__":
    main()

# Optimized solution
import sys
from collections import defaultdict, deque
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7

def divide(k):
    return pow(k, MOD-2, MOD)


def make_nck(n):
    ret = [1]
    for i in range(1, n+1):
        ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)

    # print(ret)
    return ret

def make_nigojyo(n):
    ret = [1]

    for i in range(1, n+1):
        ret.append((ret[-1] * 25) % MOD)

    # print(ret)
    return ret


def solve():
    n = getN()
    nums = getList()

    agentss = [num - i for i, num in enumerate(nums)]
    agents = [-num - i for i, num in enumerate(nums)]
    agents.sort()
    agentss.sort()
    ans = 0
    for ag in agentss:
        ans += bisect_right(agents, ag) - bisect_left(agents,ag)
        # print(ag, ans)
        # bisect_left()
    print(ans)
    # print(agents)
    # print(agentss)


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()
# Original solution
N=int(eval(input()))
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
setL=set(L)  
setR=set(R)
for i in range(N):
  if i in setL and i in setR:
    ans+=L.count(i)*R.count(i)
print(ans)    

# Optimized solution
N=int(eval(input()))
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)
# Original solution
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# import numpy as np
# from itertools import *
# from collections import *
from collections import Counter

# S = input().split()
# N = int(input().split())
# N, K = [int(x) for x in input().split()]

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

number = list(range(1, N+1))
numhei = [0] * N
for n in range(N):
    numhei[n] = number[n] + A[n]

count = 0
for n in number:
    count += Counter(numhei)[n - A[n-1]]

print(count)


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

# import numpy as np
# from itertools import *
# from collections import *
from collections import Counter

# S = input().split()
# N = int(input().split())
# N, K = [int(x) for x in input().split()]

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

number = list(range(1, N+1))
numhei = [0] * N
for n in range(N):
    numhei[n] = number[n] + A[n]

c = Counter(numhei)
count = 0
for n in number:
    count += c[n - A[n-1]]

print(count)
# Original solution
def diff(a,b):
    if a>b:
        return(a-b)
    else:
        return(b-a)
n=int(eval(input()))
l=list(map(int,input().split()))
new=[]
count=0
for i in range(0,len(l)):
    new.append((l[i],i+1))
new.sort()
for i in range(0,len(new)):
    for j in range(i+1,len(new)):
        if new[i][0]+new[j][0]>2*10**5:
            break
        if new[i][0]+new[j][0]==diff(new[i][1],new[j][1]):
            count+=1
print(count)




        



# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
count=0
new=[]
s=set()
d={}
for i in range(0,len(l)):
    new.append(i+1-l[i])
    s.add(i+1+l[i])
    if i+1+l[i] in list(d.keys()):
        d[i+1+l[i]]+=1
    else:
        d[i+1+l[i]]=1
for i in range(0,len(new)):
    if new[i] in s:
        count+=d[new[i]]
print(count)
# Original solution
import collections

def solve(K, r):
    dic = collections.defaultdict(set)
    for i, n in enumerate(r):
        dic[n].add(i)
    ans = 0
    for i, n in enumerate(r):
        for k in range(i,K):
            target_sum = abs(k-i)-n
            if k in dic[target_sum]:
                ans+=1
    return ans
k = int(eval(input()))
r = list(map(int, input().split()))
print((solve(k, r)))

# Optimized solution
import collections

def solve(k, r):
    count = {}
    ans = 0
    for i, n in enumerate(r):
        target = i-n
        ans += count.get(target, 0)
        count[i+n] = count.get(i+n, 0)+1
    return ans
k = int(eval(input()))
r = list(map(int, input().split()))
print((solve(k, r)))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0

for i in range(N-2):
    j = i + 1
    while j <= N-1:
        if A[j] + A[i] == j - i:
            ans += 1
        else:
        	pass
        j += 1
print(ans)

# Optimized solution
N = int(eval(input()))
dic = {}
ans = 0
A = list(map(int, input().split()))
for i in range(N):
    dic[i] = 0

for i in range(N):
    b = A[i]+N-i-1
    if A[i] < N-i:
        a = N-i-A[i]-1
        dic[a] += 1
    if b < N:
        ans += dic[b]
print(ans)
# Original solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    d = defaultdict(int)
    res = 0
    n = int(eval(input()))
    a = list(map(int, input().split()))
    for i in range(n-1, -1, -1):
        res += d[i+a[i]]
        d[i-a[i]] += 1
    print(res)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    d = {}
    res = 0
    n = int(eval(input()))
    a = list(map(int, input().split()))
    for i in range(n-1, -1, -1):
        if i+a[i] in d:
            res += d[i+a[i]]
        if i-a[i] not in d:
            d[i-a[i]] = 1
        else:
            d[i-a[i]] += 1
    print(res)

if __name__ == '__main__':
    main()
# Original solution
def main():
    _ = eval(input())
    lst_a = [int(a) for a in input().strip().split(' ')]

    # build hash table
    hash_tbl = {}
    for i, a_i in enumerate(lst_a):
        n_i = i + 1
        tmp = int(n_i - a_i)
        if tmp > 0:
            if tmp in list(hash_tbl.keys()):
                hash_tbl[tmp].append(n_i)
            else:
                hash_tbl[tmp] = [n_i]

    ans = 0
    for j, a_j in enumerate(lst_a):
        n_j = j + 1
        tmp = int(n_j + a_j)
        if tmp in list(hash_tbl.keys()):
            ans += len([idx for idx in hash_tbl[tmp] if idx > j])
    print((int(ans)))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    _ = eval(input())
    lst_a = [int(a) for a in input().strip().split(' ')]

    # build hash table
    hash_tbl = {}
    for i, a_i in enumerate(lst_a):
        n_i = i + 1
        tmp = int(n_i - a_i)
        if tmp > 0:
            if tmp in list(hash_tbl.keys()):
                hash_tbl[tmp].append(n_i)
            else:
                hash_tbl[tmp] = [n_i]

    ans = 0
    for j, a_j in enumerate(lst_a):
        n_j = j + 1
        tmp = int(n_j + a_j)
        if tmp in list(hash_tbl.keys()):
            # ans += len([idx for idx in hash_tbl[tmp] if idx > j])
            ans += len(hash_tbl[tmp])
    print((int(ans)))


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

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