# coding: utf-8

from bisect import bisect_left

from collections import defaultdict





def solve(*args: str) -> str:

    n = int(args[0])

    A = list(map(int, args[1].split()))



    ret = 0

    X = defaultdict(list)

    for i, a in enumerate(A):

        X[a+i].append(i)



    for j, a in enumerate(A):

        if 0 <= j-a:

            ret += bisect_left(X[j-a], j)



    return str(ret)





if __name__ == "__main__":

    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8

from collections import defaultdict





def solve(*args: str) -> str:

    n = int(args[0])

    A = list(map(int, args[1].split()))



    ret = 0

    X = defaultdict(int)

    for i, a in enumerate(A):

        X[a+i] += 1



        if 0 <= i-a:

            ret += X[i-a]



    return str(ret)





if __name__ == "__main__":

    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8
from bisect import bisect_left
from collections import defaultdict


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    ret = 0
    X = defaultdict(list)
    for i, a in enumerate(A):
        X[a + i].append(i)
    for j, a in enumerate(A):
        if 0 <= j - a:
            ret += bisect_left(X[j - a], j)
    return str(ret)


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8
from collections import defaultdict


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    ret = 0
    X = defaultdict(int)
    for i, a in enumerate(A):
        X[a + i] += 1
        if 0 <= i - a:
            ret += X[i - a]
    return str(ret)


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))

-from bisect import bisect_left -    X = defaultdict(list) +    X = defaultdict(int) -        X[a + i].append(i) -    for j, a in enumerate(A): -        if 0 <= j - a: -            ret += bisect_left(X[j - a], j) +        X[a + i] += 1 +        if 0 <= i - a: +            ret += X[i - a]