from collections import deque

from itertools import product

import sys

import math

import numpy as np

import bisect



sys.setrecursionlimit(200000)

input = sys.stdin.readline





def read():

    N = int(input().strip())

    A = list(map(int, input().strip().split()))

    return N, A





def argsort(seq):

    return sorted(list(range(len(seq))), key=seq.__getitem__)



def solve(N, A):

    # x: i-A[i]の列

    X = np.array([i-A[i] for i in range(N)], dtype=np.int)

    # y: i+A[i]の列

    Y = np.array([i+A[i] for i in range(N)], dtype=np.int)

    keys = np.argsort(X)

    X = X[keys]  # x[i] <= x[i+1]

    Y = Y[keys]

    ans = 0

    for y in Y:

        l = bisect.bisect_left(X, y)

        r = bisect.bisect_left(X, y+1)

        ans += r - l

    return ans





if __name__ == '__main__':

    inputs = read()

    outputs = solve(*inputs)

    print(("{}".format(outputs)))

from collections import defaultdict

from itertools import product

import sys

import math

import bisect



sys.setrecursionlimit(200000)

input = sys.stdin.readline





def read():

    N = int(input().strip())

    A = list(map(int, input().strip().split()))

    return N, A





def solve(N, A):

    # x: i-A[i]の列

    X = [i-A[i] for i in range(N)]

    # y: i+A[i]の列

    Y = [i+A[i] for i in range(N)]

    z = defaultdict(int)

    for y in Y:

        z[y] += 1

    return sum([z[x] for x in X])





if __name__ == '__main__':

    inputs = read()

    outputs = solve(*inputs)

    print(("{}".format(outputs)))

from collections import deque
from itertools import product
import sys
import math
import numpy as np
import bisect

sys.setrecursionlimit(200000)
input = sys.stdin.readline


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def argsort(seq):
    return sorted(list(range(len(seq))), key=seq.__getitem__)


def solve(N, A):
    # x: i-A[i]の列
    X = np.array([i - A[i] for i in range(N)], dtype=np.int)
    # y: i+A[i]の列
    Y = np.array([i + A[i] for i in range(N)], dtype=np.int)
    keys = np.argsort(X)
    X = X[keys]  # x[i] <= x[i+1]
    Y = Y[keys]
    ans = 0
    for y in Y:
        l = bisect.bisect_left(X, y)
        r = bisect.bisect_left(X, y + 1)
        ans += r - l
    return ans


if __name__ == "__main__":
    inputs = read()
    outputs = solve(*inputs)
    print(("{}".format(outputs)))

from collections import defaultdict
from itertools import product
import sys
import math
import bisect

sys.setrecursionlimit(200000)
input = sys.stdin.readline


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    # x: i-A[i]の列
    X = [i - A[i] for i in range(N)]
    # y: i+A[i]の列
    Y = [i + A[i] for i in range(N)]
    z = defaultdict(int)
    for y in Y:
        z[y] += 1
    return sum([z[x] for x in X])


if __name__ == "__main__":
    inputs = read()
    outputs = solve(*inputs)
    print(("{}".format(outputs)))

-from collections import deque +from collections import defaultdict -import numpy as np -def argsort(seq): -    return sorted(list(range(len(seq))), key=seq.__getitem__) - - -    X = np.array([i - A[i] for i in range(N)], dtype=np.int) +    X = [i - A[i] for i in range(N)] -    Y = np.array([i + A[i] for i in range(N)], dtype=np.int) -    keys = np.argsort(X) -    X = X[keys]  # x[i] <= x[i+1] -    Y = Y[keys] -    ans = 0 +    Y = [i + A[i] for i in range(N)] +    z = defaultdict(int) -        l = bisect.bisect_left(X, y) -        r = bisect.bisect_left(X, y + 1) -        ans += r - l -    return ans +        z[y] += 1 +    return sum([z[x] for x in X])