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

def main():

    N = int(eval(input()))

    heights = list(map(int, input().split()))



    """

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

    -> i + Ai = j -Aj

    """



    x = [0] * N  # x represents i + Ai



    count = 0

    for i, height in enumerate(heights):

        right = i + height

        left = i - height



        if right < N:

            x[right] += 1



        if left > 0:

            count += x[left]



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

def main():
    N = int(eval(input()))
    heights = list(map(int, input().split()))
    """
    for j>i, j-i = Ai + Aj
    -> i + Ai = j -Aj
    """
    x = [0] * N  # x represents i + Ai
    count = 0
    for i, height in enumerate(heights):
        right = i + height
        left = i - height
        if right < N:
            x[right] += 1
        if left > 0:
            count += x[left]
    print(count)


if __name__ == "__main__":
    main()

-    i + Ai = j -Aj +    -> i + Ai = j -Aj -    L = [0] * N -    R = [0] * N +    x = [0] * N  # x represents i + Ai -            R[right] += 1 +            x[right] += 1 -            L[left] += 1 -            count += R[left] +            count += x[left]