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()
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()
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()

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()

-    for i in range(n): -        if i + a[i] < n: -            d[i + a[i]] += 1 +    for i, x in enumerate(a): +        if i + x < n: +            d[i + x] += 1 -    for i in range(n): -        if i - a[i] >= 0: -            ans += d[i - a[i]] +    for i, x in enumerate(a): +        if i - x >= 0: +            ans += d[i - x]