from collections import defaultdict





def main():

    _ = 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):

        L[i + height] += 1

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

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

from collections import defaultdict


def main():
    _ = 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):
        L[i + height] += 1
        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()

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

-    _ = int(eval(input())) +    N = int(eval(input())) -        L[i + height] += 1 -        R[i - height] += 1 +        if i + height < N: +            L[i + height] += 1 +        if i - height > 0: +            R[i - height] += 1