CodeEff/ECCO huggingface dataset:
# Original solution
import sys
input = sys.stdin.readline

n = int(eval(input()))
seq = [int(x) for x in input().split()]
visited = [False for _ in range(n)]
ans = 0
p = set()
for i, val in enumerate(seq):
    if val > n:
        continue

    for j in range(min(n,i+val-2), n):
        if abs(j-i) == val + seq[j]:
            if not visited[i]:
                visited[i] = True
            if not visited[j]:
                visited[j] = True
            if (i,j) not in p:
                ans += 1
                p.add((i,j))
    for j in range(0, max(i-val, 0)):
        if abs(i - j) == val + seq[j]:
            if not visited[i]:
                visited[i] = True
            if not visited[j]:
                visited[j] = True
            if (j,i) not in p:
                ans += 1
                p.add((j,i))
print(ans)



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

n = int(eval(input()))
seq = [(int(x),i) for i, x in enumerate(input().split())]
seq1 =(i-x for x,i in seq)
seq2 =(i+x for x,i in seq)

d1 = dict()
d2 = dict()
s1 = set()
s2 = set()
for val in seq1:
    try:
        d1[val] += 1
    except:
        d1[val] = 1
for val in seq2:
    try:
        d2[val] += 1
    except:
        d2[val] = 1

ans = 0
for key in d1:
    try:
        ans += d1[key] * d2[key]
    except:
        pass

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

print(ans)


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

d = {}

for i, a in enumerate(A):
    tmp = i + 1 - a
    if tmp in list(d.keys()):
        d[tmp] += 1
    else:
        d[tmp] = 1

# print(d)

for i, a in enumerate(A):
    tmp = a + i + 1
    tmptmp = i + 1 - a
    if tmp in list(d.keys()):
        ans += d[tmp]
    if tmptmp in list(d.keys()):
        d[tmptmp] = max(0, d[tmptmp] - 1)

print(ans)
# Original solution
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
    now = a[i - 1]
    for j in range(i + now, n):
        if a[j] + now == (j+1) - i:
            ans += 1

print(ans)


# Optimized solution
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
R = {}
L = {}
for i in range(n):
    r = i + a[i]
    l = max(i - a[i], 0)
    if r in R:
        R[r] += 1
    else:
        R[r] = 1
    if l in L:
        L[l] += 1
    else:
        L[l] = 1

for k, v in list(R.items()):
    if k in L:
        ans += v * L[k]

print(ans)
# Original solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
import math
N = int(eval(input()))
An = list(map(int,input().split()))
#組み合わせ nC2
numList = list(itertools.combinations(list(range(1,N+1)), 2))
count = 0
for pair in numList:
    #　数字のdiff (絶対値) float型
    numDiff = int(math.fabs(pair[1] - pair[0]))
    # 身長の和
    sumHeight = An[pair[0]-1] + An[pair[1]-1]
    if numDiff == sumHeight:
        count = count + 1
print(count)

# Optimized solution
N = int(eval(input()))
An = list(map(int,input().split()))
resultDict = {}
resultDict['diff'] = []
resultDict['sum'] = []
for num in range(1,N+1):
    resultDict['diff'].append(int(num - An[num-1]))
    resultDict['sum'].append(int(num + An[num-1]))
countN = 0
for i, name in enumerate(resultDict['diff']):        
    countN = countN + resultDict['sum'].count(name)
    if name == resultDict['sum'][i]:
        countN = countN - 1
print(countN)
# Original solution
class Map(dict):
    def __missing__(self, key):
        self[key] = 0
        return 0


def main():
    int(eval(input()))

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print((main()))

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030


# Optimized solution
# class Map(dict):
#     def __missing__(self, key):
#         # この割当てなしのほうが速い。
#         # self[key] = 0
#         return 0


def main():
    int(eval(input()))

    d = {}
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        got = d.get(i + height) or 0
        d[i + height] = got + 1
        ans += d.get(i - height) or 0

    return ans


if __name__ == '__main__':
    print((main()))

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030
# Original solution
# class Map(dict):
#     def __missing__(self, key):
#         # この割当てなしのほうが速い。
#         # self[key] = 0
#         return 0


def main():
    int(eval(input()))

    d = {}
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        d.setdefault(i + height, 0)
        d[i + height] += 1
        ans += d.setdefault(i - height, 0)

    return ans


if __name__ == '__main__':
    print((main()))

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030


# Optimized solution
# class Map(dict):
#     def __missing__(self, key):
#         # この割当てなしのほうが速い。
#         # self[key] = 0
#         return 0


def main():
    int(eval(input()))

    d = {}
    ans = 0
    d_setdefault = d.setdefault
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        d_setdefault(i + height, 0)
        d[i + height] += 1
        ans += d_setdefault(i - height, 0)

    return ans


if __name__ == '__main__':
    print((main()))

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030
# Original solution
# class Map(dict):
#     def __missing__(self, key):
#         # この割当てなしのほうが速い。
#         # self[key] = 0
#         return 0


def main():
    int(eval(input()))

    d = {}
    ans = 0
    d_setdefault = d.setdefault
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        d_setdefault(i + height, 0)
        d[i + height] += 1
        ans += d_setdefault(i - height, 0)

    return ans


if __name__ == '__main__':
    print((main()))

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030


# Optimized solution
# class Map(dict):
#     def __missing__(self, key):
#         # この割当てなしのほうが速い。
#         # self[key] = 0
#         return 0


def main():
    int(eval(input()))

    d = {}
    ans = 0
    d_setdefault = d.setdefault
    d_get = d.get
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        got = d_get(i + height) or 0
        d[i + height] = got + 1
        ans += d_setdefault(i - height, 0)

    return ans


if __name__ == '__main__':
    print((main()))

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030
# Original solution
# class Map(dict):
#     def __missing__(self, key):
#         # この割当てなしのほうが速い。
#         # self[key] = 0
#         return 0


def main():
    int(eval(input()))

    d = {}
    ans = 0
    d_setdefault = d.setdefault
    d_get = d.get
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        got = d_get(i + height) or 0
        d[i + height] = got + 1
        ans += d_setdefault(i - height, 0)

    return ans


if __name__ == '__main__':
    print((main()))

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030


# Optimized solution
def main():
    int(eval(input()))

    d = {}
    ans = 0
    d_get = d.get
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        got = d_get(i + height) or 0
        d[i + height] = got + 1
        ans += d_get(i - height) or 0

    return ans


if __name__ == '__main__':
    print((main()))

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030
# Original solution
#!/usr/bin/env python3

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    max_A = max(A)
    num = tuple(range(1, N + 1))
    cand = 0
    for a in range(N):
        a_height = A[a]
        for b in range(min(a + 1 + a_height, N), N):
            diff_num = b - a
            sum_height = A[a] + A[b]
            if diff_num == sum_height:
                cand += 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print((' '.join(list(map(str, data)))))


if __name__ == '__main__':
    main()


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

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    num = tuple(range(1, N + 1))
    cand = 0
    log = {}
    for i in range(0, N):
        if i + 1 - A[i] in log:
            cand += log[i + 1 - A[i]]
        if i + 1 + A[i] in log:
            log[i + 1 + A[i]] += 1
        else:
            log[i + 1 + A[i]] = 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print((' '.join(list(map(str, data)))))


if __name__ == '__main__':
    main()
# Original solution
n = int(input().strip())
a = list(map(int, input().split()))
left = {}
for i in range(len(a)):
    if left.get(a[i] + i):
        left[a[i] + i].append(i)
    else:
        left[a[i] + i] = [i]
ans = 0
for i in range(len(a)):
    if left.get(i - a[i]):
        ans += len(list([x for x in left[i - a[i]] if x < i]))
print(ans)


# Optimized solution
n = int(input().strip())
a = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(len(a)):
    if dic.get(i - a[i]):
        ans += dic[i - a[i]]
    if dic.get(a[i] + i):
        dic[a[i] + i] += 1
    else:
        dic[a[i] + i] = 1
print(ans)
# Original solution
from collections import Counter

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

l = []
r = []
for i, ai in enumerate(a):
   l.append(i+ai)
   r.append(i-ai)

ans = 0
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()))

l = []
r = []
for i, ai in enumerate(a):
   l.append(i+ai)
   r.append(i-ai)

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

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

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
ans = 0
d = {}
for i in range(n):
  if d.get(i+a[i],0)==0:
    d[i+a[i]] = [0,0]
  if d.get(i-a[i],0)==0:
    d[i-a[i]] = [0,0]
  d[i+a[i]][0] += 1
  d[i-a[i]][1] += 1
for v in list(d.values()):
  ans += v[0]*v[1]
print(ans)
# Original solution
n = int(eval(input()))
a_list = list(map(int, input().split()))

agents = {}
n_pair = 0

for i, a in enumerate(a_list):
  x = i - a
  if x not in agents:
    agents[x] = []
  agents[x].append(i)

for i, a in enumerate(a_list):
  x = i + a
  if x in agents:
    for j in agents[x]:
      if i != j:
        n_pair += 1
print(n_pair)

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

agents = {}
n_pair = 0

for i, a in enumerate(a_list):
  x = i - a
  if x not in agents:
    agents[x] = 0
  agents[x] += 1

for i, a in enumerate(a_list):
  x = i + a
  if x in agents:
    n_pair += agents[x]
print(n_pair)
# Original solution
from collections import defaultdict
import bisect
N = int(eval(input()))
A = list(map(int,input().split()))
plus = [A[i]+(i+1) for i in range(N)]
diff = [-A[i]+(i+1) for i in range(N)]

plusc = defaultdict(list)
for i in range(N):
    plusc[plus[i]].append(i)
ans = 0
for i in range(1,N):
    ans += bisect.bisect_left(plusc[diff[i]],i)
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
count = 0
dicta = {}
for i in range(N):
    if i - A[i] in dicta:
        count += dicta[i-A[i]]
    if i + A[i] in dicta:
        dicta[i+A[i]] += 1
    else:
        dicta[i+A[i]] = 1
print(count)
# Original solution
#!/usr/bin/env python3
from collections import defaultdict

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main(A, N):
    d1 = defaultdict(int)
    d2 = defaultdict(int)

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

    mn_x = min(min(d1.keys()), min(d2.keys()))
    mx_x = max(max(d1.keys()), max(d2.keys()))

    cnt = 0
    for x in range(mn_x, mx_x+1):
        cnt += d1[x]* d2[x]

    print(cnt)
    pass

if __name__ == '__main__':
    N = int(eval(input()))
    A = list(map(int, input().split()))
    main(A, N)


# Optimized solution
#!/usr/bin/env python3
from collections import defaultdict

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main(A, N):
    d1 = defaultdict(int)
    d2 = defaultdict(int)

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

    cnt = 0
    for x in list(d1.keys())+list(d2.keys()):
        cnt += d1[x]* d2[x]

    print((cnt//2))
    pass

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

N = int(eval(input()))
A = list(map(int, input().split()))
ans, d = 0, dict()

for i in range(N):
    diff = A[i] + A[0] - i 
    if d.get(diff) == None:
        d[diff] = [i]
    else:
        d[diff].append(i)

diff = 0
if d.get(0) != None:
    ans += len(d[0])

for i in range(1, N):
    diff -= A[i] - A[i-1] + 1
    dl = d.get(diff) 
    if dl != None:
        index = bisect.bisect_right(dl, i)        
        d[diff] = d[diff][index:]
        ans += len(d[diff])

print(ans)

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

for i in range(N):
    key = A[i] + i
    if d.get(key) == None:
        d[key] = 1
    else:
        d[key] += 1
    
    key = i - A[i]
    if d.get(key) != None:
        ans += d[key]

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

AI = sorted([(a, i) for i, a in enumerate(A)])

dic = list()
tmp = 0
for i, (a, pos) in enumerate(AI):
    if a > 2 * 10**5:
        break
    if tmp != a:
        tmp = a
        dic.append((a, i))

nums = [a for (a, i) in dic]
inds = [i for (a, i) in dic]
inds.append(N)
L = len(dic)


def check(p1, p2):
    # print(p1, p2)
    sumsum = nums[p1] + nums[p2]
    ret = 0
    for i in range(inds[p1], inds[p1+1]):
        for j in range(inds[p2], inds[p2+1]):
            if sumsum == abs(AI[i][1] - AI[j][1]):
                ret += 1
    # print("return ", ret)
    return ret // 2 if p1 == p2 else ret


# print(dic)
# print(nums)
# print(inds)

ans = 0
for i in range(L):
    for j in range(i, L):
        if nums[i] + nums[j] > 2 * 10**5:
            continue
        ans += check(i, j)

print(ans)


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

L = {}
R = {}
for i, a in enumerate(A):
    x = i + 1 + a
    L[x] = L[x] + 1 if x in L else 1

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

# print(L, R)

ans = 0
for x in list(L.keys()):
    ans += L[x] * (R[x] if x in R else 0)

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,n):
        if a[i]+a[j]==(j+1)-(i+1):
            ans+=1
print(ans)

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

print(ans)
# Original solution
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(eval(input()))

def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print((k.join(list(map(str, lst)))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product


def solve():
    n = II()
    A = LI()

    memo = {}
    ans = 0
    for i in range(n):
        mae = (i+1) + A[i]
        ima = (i+1) - A[i]
        ans += memo.get(ima, 0)
        memo[mae] = memo.get(mae, 0) + 1
    # print(memo)
    print(ans)


if __name__ == '__main__':
    solve()


# Optimized solution
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(eval(input()))
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()

    memo = {}
    ans = 0
    for i, a in enumerate(A):
        i = i + 1
        # print(i, a - i, i - a)
        ans = ans + memo.get(i - a, 0)
        memo[a + i] = memo.get(a + i, 0) + 1
    print(ans)


if __name__ == '__main__':
    solve()
# Original solution
n = int(eval(input()))
a_list = list(map(int, input().split()))
count = 0
Jlist = []
for j in range(2, n+1):
    if j > a_list[j-1]:
        for i in range(1, j):
            if j -a_list[j-1] == a_list[i-1] + i:
                count += 1

print(count)

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

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

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

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

Aii=[0]*(N)
Ajj=[0]*(N)

for i in range(N):
    x=A[i]+i+1
    y=i+1-A[i]
    if 1<x<N: Aii[x]+=1
    if 1<y<N: Ajj[y]+=1

ans=0
for i in range(N):
    ans+=Aii[i]*Ajj[i]

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

c = [0]*n
d = [0]*n
for i, j in enumerate(a):
    c[i] = j-i

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

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

c = [0]*n
d = [0]*n

for i, j in enumerate(a):
    c[i] = i + j

for i, j in enumerate(a):
    d[i] = i - j

x = {}
for i, j in enumerate(c):
    if j not in x:
        x[j]=[i]
    else:
        x[j].append(i)
ans = 0
for i in d:
    if i not in x:
        continue
    else:
        ans += len(x[i])
print(ans)
# Original solution
import math
from collections import Counter
n=int(eval(input()))
l=[int(x) for x in input().split()]
f1=[]
f2=[]
for i in range(1,len(l)+1):
	f1.append(i-l[i-1])
	f2.append(l[i-1]+i)

c=0
for i in range(len(l)):
	c+=f1.count(f2[i])
print(c)




# Optimized solution
n=int(eval(input()))
l=[int(x) for x in input().split()]
f1={}
f2={}
for i in range(1,len(l)+1):
	if i-l[i-1] in f1:
		f1[i-l[i-1]]+=1
	else:
		f1[i-l[i-1]]=1
	if l[i-1]+i in f2:
		f2[l[i-1]+i]+=1
	else:
		f2[l[i-1]+i]=1

c=0
#print(f1)
#print(f2)
for u,v in list(f1.items()):
	c+=f2.get(u,0)*v
print(c)
# Original solution
n = int(eval(input()))
t = list(map(int, input().split()))
r = []
ans = 0
for i in range(len(t)):
  r.append(i+1 + t[i])
for i in range(len(t)):
  if((i+1 - t[i]) >= 1):
    ans += r.count(i+1-t[i])
print(ans)

# Optimized solution
n = int(eval(input()))
t = list(map(int, input().split()))
r = {}
ans = 0
for i in range(len(t)):
  try:
    r[i+1 + t[i]] += 1
  except KeyError:
    r[i+1 + t[i]] = 1
for i in range(len(t)):
  if((i+1 - t[i]) >= 1):
    try:
      ans += r[i+1-t[i]]
    except KeyError:
      continue
print(ans)
# Original solution
import math

n=int(eval(input()))
A=list(map(int, input().split()))
L=['null']*n
R=['null']*n
c=0

for i,a in enumerate(A):
  L[i]=i+a
  R[i]=i-a
  c+=L.count(R[i])
print(c)


# Optimized solution
n=int(eval(input()))
A=list(map(int, input().split()))
d={}
c=0

for i,a in enumerate(A):
  if i+a not in d:
    d[i+a]=1
  else:
    d[i+a]+=1
  if i-a in d:
    c+=d[i-a]

print(c)
# Original solution
n = int(eval(input()))
height = [int(x) for x in input().split()]
cnt =0

for i_index, i in enumerate(height[:-1]):
    if i+i_index >= n:
        continue

    for j_index, j in enumerate(height[i_index+i+1:]):
        if j+i == j_index+i+1:
            cnt += 1
            # print(i,j,j_index)
            
print(cnt)

# Optimized solution
# n = int(input())
# height = [int(x) for x in input().split()]
# cnt =0

# for i_index, i in enumerate(height[:-1]):
#     if i+i_index >= n:
#         continue

#     for j_index, j in enumerate(height[i_index+i+1:]):
#         if j+i == j_index+i+1:
#             cnt += 1
#             # print(i,j,j_index)
            
# print(cnt)
def count(dic,x):
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
 
N=int(eval(input()))
A=list(map(int,input().split()))
dic1={}
dic2={}
s=0
for i in range(N):
    count(dic1,i-A[i])
    count(dic2,i+A[i])
for x in dic1:
    if x in dic2:
        s+=dic1[x]*dic2[x]
print(s)
# Original solution
from itertools import combinations

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

idx = list(range(0, N))
idx_comb = list(combinations(idx, 2))
count = 0
for i, j in idx_comb:
    if abs(i-j) == (A[i] + A[j]):
        count += 1

print(count)

# Optimized solution
from itertools import combinations

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

idx = tuple(range(0, N))
idx_comb = tuple(combinations(idx, 2))
count = 0
for i, j in idx_comb:
    if abs(i-j) == (A[i] + A[j]):
        count += 1

print(count)
# Original solution
# -*- coding: utf-8 -*-
# 整数の入力
n = int(eval(input()))
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0

for i in range(n):
    a_height = h_list[i]
    n_aa = i + a_height + 1000000000 + 1
    if n_aa > n:
        n_aa = n
    for k in range(i + 1 + a_height, n_aa):
        b_height = h_list[k]
        if k - i == a_height + b_height:
            count += 1

print(count)


# Optimized solution
# -*- coding: utf-8 -*-
# 整数の入力
n = int(eval(input()))
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0
result_dict = {}

for i in range(n):
    key = (i+1) + h_list[i]
    value = result_dict.get(key, 0)
    result_dict[key] = value + 1

for j in range(n):
    key = (j+1) - h_list[j]
    count += result_dict.get(key, 0)

print(count)