def main():

    n = int(eval(input()))

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

    Ilis = {}

    Jlis = {}

    for i in range(n):

        k = a[i]+i+1

        l = i-a[i]+1

        if k not in list(Ilis.keys()):

            Ilis[k] = 1

        else:

            Ilis[k]+=1

        if l not in list(Jlis.keys()):

            Jlis[l]=1

        else:

            Jlis[l]+=1

    ans = 0

    for i in list(Ilis.keys()):

        if i in list(Jlis.keys()):

            ans += Ilis[i]*Jlis[i]

    print(ans)



if __name__ == "__main__":

    main()

def main():

    n = int(eval(input()))

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

    sa,wa = {},{}

    for i in range(n):

        if a[i]+i+1 not in list(wa.keys()):

            wa[a[i]+i+1]=1

        else:

            wa[a[i]+i+1]+=1

        if i-a[i] >0:

            if i+1-a[i] not in list(sa.keys()):

                sa[i+1-a[i]]=1

            else:

                sa[i+1-a[i]]+=1

    ans = 0

    for k in list(sa.keys()):

        if k in list(wa.keys()):

            ans += sa[k]*wa[k]

    print(ans)





if __name__ == "__main__":

    main()

def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    Ilis = {}
    Jlis = {}
    for i in range(n):
        k = a[i] + i + 1
        l = i - a[i] + 1
        if k not in list(Ilis.keys()):
            Ilis[k] = 1
        else:
            Ilis[k] += 1
        if l not in list(Jlis.keys()):
            Jlis[l] = 1
        else:
            Jlis[l] += 1
    ans = 0
    for i in list(Ilis.keys()):
        if i in list(Jlis.keys()):
            ans += Ilis[i] * Jlis[i]
    print(ans)


if __name__ == "__main__":
    main()

def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    sa, wa = {}, {}
    for i in range(n):
        if a[i] + i + 1 not in list(wa.keys()):
            wa[a[i] + i + 1] = 1
        else:
            wa[a[i] + i + 1] += 1
        if i - a[i] > 0:
            if i + 1 - a[i] not in list(sa.keys()):
                sa[i + 1 - a[i]] = 1
            else:
                sa[i + 1 - a[i]] += 1
    ans = 0
    for k in list(sa.keys()):
        if k in list(wa.keys()):
            ans += sa[k] * wa[k]
    print(ans)


if __name__ == "__main__":
    main()

-    Ilis = {} -    Jlis = {} +    sa, wa = {}, {} -        k = a[i] + i + 1 -        l = i - a[i] + 1 -        if k not in list(Ilis.keys()): -            Ilis[k] = 1 +        if a[i] + i + 1 not in list(wa.keys()): +            wa[a[i] + i + 1] = 1 -            Ilis[k] += 1 -        if l not in list(Jlis.keys()): -            Jlis[l] = 1 -        else: -            Jlis[l] += 1 +            wa[a[i] + i + 1] += 1 +        if i - a[i] > 0: +            if i + 1 - a[i] not in list(sa.keys()): +                sa[i + 1 - a[i]] = 1 +            else: +                sa[i + 1 - a[i]] += 1 -    for i in list(Ilis.keys()): -        if i in list(Jlis.keys()): -            ans += Ilis[i] * Jlis[i] +    for k in list(sa.keys()): +        if k in list(wa.keys()): +            ans += sa[k] * wa[k]