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

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

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

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

-from collections import defaultdict - - -    L = defaultdict(int) -    R = defaultdict(int) +    L = [0] * N +    R = [0] * N +    count = 0 -        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) +        right = i + height +        left = i - height +        if right < N: +            R[right] += 1 +        if left > 0: +            L[left] += 1 +            count += R[left] +    print(count)