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

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)

-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_minus_ind: +#    if val in cnt_minus_height_minus_ind: +#        ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val] -print((ans // 2)) +print(ans)