You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.
There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.
According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.
 - The absolute difference of their attendee numbers is equal to the sum of their heights.
There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?
P.S.: We cannot let you know the secret.

-----Constraints-----
 - All values in input are integers.
 - 2 \leq N \leq 2 \times 10^5
 - 1 \leq A_i \leq 10^9\ (1 \leq i \leq N)

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 A_2 \dots A_N

-----Output-----
Print the number of pairs satisfying the condition.

-----Sample Input-----
6
2 3 3 1 3 1

-----Sample Output-----
3

 - A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.
 - A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.
 - A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.
No other pair satisfies the condition, so you should print 3.

Difficulty: MEDIUM

Solutions:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
	d[i - a[i]] += 1
ans = 0
for i in range(n):
	ans += d[i + a[i]]
print(ans)


N = int(input())
A = list(map(int, input().split()))
t = [0] * (N + 1)
ans = 0
for i in range(N):
	sa = i - A[i]
	if sa >= 0:
		ans += t[sa]
	wa = i + A[i]
	if wa < N:
		t[wa] += 1
print(ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = []
c = []
ans = 0
for (i, j) in enumerate(a):
	b.append(i + j)
	c.append(i - j)
d = Counter(c)
for i in b:
	ans += d.get(i, 0)
print(ans)


n = int(input())
A = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(n):
	x = i - A[i]
	y = i + A[i]
	if x in dic:
		ans += dic[x]
	if y in dic:
		dic[y] += 1
	else:
		dic[y] = 1
print(ans)


import bisect as bi
import collections as cc
I = lambda : list(map(int, input().split()))
d = cc.defaultdict(int)
(n,) = I()
l = I()
ans = 0
for i in range(n):
	d[l[i] + i] += 1
	ans += d[i - l[i]]
print(ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l1 = [i + a[i] for i in range(n)]
l2 = [i - a[i] for i in range(n)]
c1 = Counter(l1)
c2 = Counter(l2)
ans = 0
for i in c1:
	ans += c1[i] * c2[i]
print(ans)


from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
dic = defaultdict(int)
ans = 0
for i in range(n):
	Sum = A[i] + i
	dic[Sum] += 1
	Dif = i - A[i]
	ans += dic[Dif]
print(ans)


from collections import Counter
n = int(input().strip())
L = list(map(int, input().strip().split()))
seen = Counter()
ans = 0
for j in range(n):
	ans += seen[j - L[j]]
	seen[L[j] + j] += 1
print(ans)


import collections
n = int(input())
arr = list(map(int, input().split()))
ans = 0
cnt = collections.defaultdict(int)
for i in range(1, n + 1):
	ans += cnt[i - arr[i - 1]]
	cnt[i + arr[i - 1]] += 1
print(ans)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
p = [i + Ai for (i, Ai) in zip(range(1, N + 1), A)]
q = [j - Aj for (j, Aj) in zip(range(1, N + 1), A)]
pc = Counter(p)
qc = Counter(q)
r = sum((pc[k] * qc[k] for k in pc.keys() & qc.keys()))
print(r)


N = int(input())
A = list(map(int, input().split()))
p = [0] * N
m = [0] * N
for i in range(N):
	p[i] = A[i] + i + 1
	m[i] = i + 1 - A[i]
from collections import Counter
cp = Counter(p)
cm = Counter(m)
ans = 0
for (x, y) in cp.items():
	ans += cm[x] * y
print(ans)


n = int(input())
h_list = list(map(int, input().split()))
a_dict = dict()
b_dict = dict()
for i in range(n):
	a = h_list[i] + i
	b = i - h_list[i]
	if not a in a_dict:
		a_dict[a] = 1
	else:
		a_dict[a] += 1
	if not b in b_dict:
		b_dict[b] = 1
	else:
		b_dict[b] += 1
count = 0
for a in a_dict:
	if a in b_dict:
		count += a_dict[a] * b_dict[a]
print(count)


from collections import Counter
n = int(input())
x = list(map(int, input().split()))
a = []
b = []
for i in range(n):
	a.append(x[i] + i + 1)
	b.append(i + 1 - x[i])
(a, b) = (Counter(a), Counter(b))
ans = 0
for i in range(n):
	ans += a[i] * b[i]
print(ans)


n = int(input())
A = list(map(int, input().split()))
d = {}
res = 0
for (_i, a) in enumerate(A):
	i = _i + 1
	if i - a in d:
		res += d[i - a]
	d[a + i] = 1 if a + i not in d else d[a + i] + 1
print(res)


import collections
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
l = [j - aj for (j, aj) in enumerate(a, 1)]
r = [i + ai for (i, ai) in enumerate(a, 1)]
cnt = collections.Counter(r)
ans = 0
for i in l:
	ans += cnt[i]
print(ans)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
d = dict(Counter([i + A[i - 1] for i in range(1, N + 1)]))
ans = sum([d.get(i - A[i - 1], 0) for i in range(1, N + 1)])
print(ans)


n = int(input())
l = list(map(int, input().split()))
from collections import *
c = Counter()
a = 0
for i in range(n):
	c[i + l[i]] += 1
	if i > l[i]:
		a += c[i - l[i]]
print(a)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
cnt = 0
c = defaultdict(int)
for i in range(n):
	c[i + 1 - a[i]] += 1
for i in range(n):
	cnt += c[a[i] + i + 1]
print(cnt)


n = int(input())
A = list(map(int, input().split()))
m = {}
ans = 0
for i in range(n):
	x = A[i] + i
	if x not in m:
		m[x] = 0
	m[x] += 1
	if i - A[i] in m:
		ans += m[i - A[i]]
print(ans)


N = int(input())
A = list(map(int, input().split()))
L = {}
R = {}
ans = 0
for i in range(N):
	t = i + 1 + A[i]
	if t in L:
		L[t] += 1
	else:
		L[t] = 1
	t = i + 1 - A[i]
	if t > 0:
		if t in R:
			R[t] += 1
		else:
			R[t] = 1
for i in R:
	if i in L:
		ans += R[i] * L[i]
print(ans)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
s = [i + a for (i, a) in enumerate(A)]
t = [j - a for (j, a) in enumerate(A)]
d = Counter(s)
ans = 0
for i in t:
	ans += d[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
ans = 0
for i in range(n):
	b.append(i + 1 - a[i])
	c.append(a[i] + i + 1)
x = max(b)
if x <= 0:
	print(0)
	return
else:
	ans = 0
	b_ = [0] * (x + 1)
	for i in range(n):
		if 0 <= b[i] <= x:
			b_[b[i]] += 1
	for i in range(n):
		if 0 <= c[i] <= x:
			ans += b_[c[i]]
	print(ans)


from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque, Counter
from operator import mul
import copy
import heapq
n = int(input())
a = list(map(int, input().split()))
p = [i - a[i] for i in range(n)]
q = [a[i] + i for i in range(n)]
pp = Counter(p)
qq = Counter(q)
ans = 0
for d in list(pp.items()):
	ans += d[1] * qq[d[0]]
print(ans)


N = int(input())
A = list(map(int, input().split()))
ans = 0
D = {}
for j in range(N):
	if j - A[j] in D:
		ans += D[j - A[j]]
	if j + A[j] in D:
		D[j + A[j]] += 1
	else:
		D[j + A[j]] = 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
dic1 = {}
dic2 = {}
for i in range(n):
	if i + 1 + a[i] not in dic1:
		dic1[i + 1 + a[i]] = 1
	else:
		dic1[i + 1 + a[i]] += 1
for i in range(n):
	if i + 1 - a[i] not in dic2:
		dic2[i + 1 - a[i]] = 1
	else:
		dic2[i + 1 - a[i]] += 1
ans = 0
for i in dic1:
	if i not in dic2:
		continue
	ans += dic1[i] * dic2[i]
print(ans)


from collections import Counter

def main():
	n = int(input())
	A = list(map(int, input().split()))
	L = Counter([i + a for (i, a) in enumerate(A)])
	R = Counter([i - a for (i, a) in enumerate(A)])
	ans = 0
	for key in list(R.keys()):
		ans += L[key] * R[key]
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
ans = 0
B = []
C = []
maA = max(A) + N - 1
for k in range(N):
	if A[k] + k <= maA:
		B.append(A[k] + k)
	if -A[k] + k > 0:
		C.append(-A[k] + k)
B.sort()
C.sort()
c = 0
b = 0
while b < len(B) and c < len(C):
	if B[b] == C[c]:
		s = 0
		t = 0
		j = float('inf')
		k = float('inf')
		for j in range(b, len(B)):
			if B[b] == B[j]:
				s += 1
			else:
				break
		for k in range(c, len(C)):
			if C[c] == C[k]:
				t += 1
			else:
				break
		ans += s * t
		b = j
		c = k
		continue
	elif B[b] > C[c]:
		c += 1
	else:
		b += 1
print(ans)


from math import ceil, floor, factorial, gcd, sqrt, log2, cos, sin, tan, acos, asin, atan, degrees, radians, pi, inf
from itertools import accumulate, groupby, permutations, combinations, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(MAP())
n = INT()
a = LIST()
c = [0] * (2 * n + 1)
for i in range(n):
	if i - a[i] >= 0:
		c[i - a[i]] += 1
ans = 0
for i in range(n):
	if i + a[i] <= 2 * n:
		ans += c[i + a[i]]
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
cnt = 0
for i in range(n):
	if i - a[i] >= 0:
		cnt += b[i - a[i]]
	if i + a[i] < n:
		b[i + a[i]] += 1
print(cnt)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
ans = 0
di = defaultdict(int)
for (i, a) in enumerate(A):
	ans += di[i + 1 - a]
	di[i + 1 + a] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
d = [0] * n
for i in range(n):
	if i + a[i] < n:
		d[i + a[i]] += 1
ans = 0
for i in range(n):
	if i - a[i] >= 0:
		ans += d[i - a[i]]
print(ans)


import collections
cnt = collections.defaultdict(int)
N = int(input())
ans = 0
height = list(map(int, input().split()))
for n in range(1, N + 1):
	ans += cnt[n - height[n - 1]]
	cnt[n + height[n - 1]] += 1
print(ans)


import collections
(n, *a) = map(int, open(0).read().split())
l = [i + 1 + a[i] for i in range(n)]
r = [i + 1 - a[i] for i in range(n)]
L = collections.Counter(l)
R = collections.Counter(r)
print(sum((L[i] * R[i] for i in L.keys())))


n = int(input())
a = list(map(int, input().split()))
x = [aa + i for (i, aa) in enumerate(a, start=1)]
y = [i - aa for (i, aa) in enumerate(a, start=1)]
from collections import Counter
c = Counter(y)
ans = 0
for xx in x:
	ans += c[xx]
print(ans)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = [a + i for (a, i) in enumerate(A, 1)]
R = [a - i for (a, i) in enumerate(A, 1)]
ans = 0
R_c = Counter(R)
for l in L:
	ans += R_c[l]
print(ans)


def main():
	from collections import defaultdict
	import sys
	input = sys.stdin.readline
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	ans = 0
	for i in range(n):
		diff = i - a[i]
		ans += d[diff]
		summed = i + a[i]
		d[summed] += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
res = 0
for (idx, a) in enumerate(A):
	if idx > 0:
		res += d[idx - a]
	d[a + idx] += 1
print(res)


from collections import Counter
n = int(input())
A = list(map(int, input().split()))
ma = max(A) + n - 1
P = [i + a + 1 for (i, a) in enumerate(A) if i + a + 1 <= ma]
Q = [j - a + 1 for (j, a) in enumerate(A) if j - a + 1 > 0]
cQ = Counter(Q)
cP = Counter(P)
ans = 0
for p in cP.keys():
	ans += cQ[p] * cP[p]
print(ans)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
s = 0
for i in range(N):
	s += d[i - A[i]]
	d[A[i] + i] += 1
print(s)


N = int(input())
A = list(map(int, input().split()))
ans = 0
start_idx = [0] * N
for (i, a) in enumerate(A):
	if i + a < N:
		start_idx[i + a] += 1
	if i - a >= 0:
		ans += start_idx[i - a]
print(ans)


n = int(input())
l = list(map(int, input().split()))
d = [0] * n
cnt = 0
for i in range(len(l)):
	if i + l[i] + 1 < n:
		d[i + l[i]] += 1
	if i - l[i] + 1 > 0:
		cnt += d[i - l[i]]
print(cnt)


import collections
n = int(input())
l = list(map(int, input().split()))
k = []
for i in range(n):
	k.append(i + 1 + l[i])
c = collections.Counter(k)
cnt = 0
for i in range(n):
	cnt += c[i + 1 - l[i]]
print(cnt)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
cnt = defaultdict(int)
ans = 0
for (i, v) in enumerate(a):
	ans += cnt[i - v]
	cnt[i + v] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
il = [i + a[i] for i in range(n)]
jl = [j - a[j] for j in range(n)]
from collections import Counter as c
d = c(jl)
x = 0
for i in il:
	x += d[i]
print(x)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = [A[i] + i for i in range(N)]
R = [i - A[i] for i in range(N)]
c = Counter(R)
ans = 0
for l in L:
	ans += c[l]
print(ans)


from collections import defaultdict as dfd
n = int(input())
a = [int(i) for i in input().split()]
d = dfd(int)
ans = 0
for (i, a_i) in enumerate(a, 1):
	ans += d[i - a_i]
	d[i + a_i] += 1
print(ans)


n = int(input())
f = {}
h = list(map(int, input().split()))
ans = 0
for i in range(n):
	if i - h[i] in f:
		ans += f[i - h[i]]
	if i + h[i] in f:
		f[i + h[i]] += 1
	else:
		f[i + h[i]] = 1
print(ans)


(n, *a) = map(int, open(0).read().split())
(s, *d) = [0] * -~n
for (i, a) in enumerate(a):
	if i >= a:
		s += d[i - a]
	if i + a < n:
		d[i + a] += 1
print(s)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(list((i + 1 + A[i] for i in range(N))))
C = Counter((i + 1 - A[i] for i in range(N)))
ans = 0
for j in range(N):
	ans += B[j] * C[j]
print(ans)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dAl = defaultdict(int)
dAr = defaultdict(int)
for i in range(N):
	L = i + 1 + A[i]
	R = i + 1 - A[i]
	dAl[L] += 1
	dAr[R] += 1
ans = 0
for (k, v) in dAl.items():
	ans += v * dAr[k]
print(ans)


import itertools
from collections import deque, defaultdict, Counter
from itertools import accumulate
import bisect
from heapq import heappop, heappush, heapify
import math
from copy import deepcopy
import queue
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, 10 ** 5 + 1):
	fact.append(fact[-1] * i % Mod)
	inv.append(-inv[Mod % i] * (Mod // i) % Mod)
	factinv.append(factinv[-1] * inv[-1] % Mod)

def cmb(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p

def sieve_of_eratosthenes(n):
	if not isinstance(n, int):
		raise TypeError('n is not int')
	if n < 2:
		raise ValueError('n is not effective')
	prime = [1] * (n + 1)
	for i in range(2, int(math.sqrt(n)) + 1):
		if prime[i] == 1:
			for j in range(2 * i, n + 1):
				if j % i == 0:
					prime[j] = 0
	res = []
	for i in range(2, n + 1):
		if prime[i] == 1:
			res.append(i)
	return res

class UnionFind:

	def __init__(self, n):
		self.parent = [i for i in range(n + 1)]
		self.rank = [0 for i in range(n + 1)]

	def findroot(self, x):
		if x == self.parent[x]:
			return x
		else:
			y = self.parent[x]
			y = self.findroot(self.parent[x])
			return y

	def union(self, x, y):
		px = self.findroot(x)
		py = self.findroot(y)
		if px < py:
			self.parent[y] = px
		else:
			self.parent[px] = py

	def same_group_or_no(self, x, y):
		return self.findroot(x) == self.findroot(y)

def pow_k(x, n):
	if n == 0:
		return 1
	K = 1
	while n > 1:
		if n % 2 != 0:
			K *= x
		x *= x
		n //= 2
	return K * x

def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	ans = 0
	for i in range(n):
		l = i - a[i]
		ans += d[l]
		d[a[i] + i] += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
(S, D) = ([0] * N, [0] * N)
for i in range(N):
	if A[i] + i < N:
		S[A[i] + i] += 1
	if i - A[i] > 0:
		D[i - A[i]] += 1
ans = 0
for l in range(N):
	ans += S[l] * D[l]
print(ans)


n = int(input())
a = list(map(int, input().split()))
from collections import Counter
cc = Counter()
ans = 0
for (i, val) in enumerate(a, 1):
	if i - val > 0:
		ans += cc[i - val]
	cc[i + val] += 1
print(ans)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
constS = defaultdict(int)
constD = defaultdict(int)
for i in range(N):
	Ss = i + A[i]
	Dd = i - A[i]
	constS[Ss] += 1
	constD[Dd] += 1
ans = 0
for (key, val) in constS.items():
	ans += val * constD[key]
print(ans)


from collections import Counter
N = input().split()
A = list(map(int, input().split()))
C = Counter()
res = 0
for (i, a) in enumerate(A):
	res += C[-(a - i)]
	C[a + i] += 1
print(res)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
AP = [0] * N
AM = [0] * N
for i in range(N):
	AP[i] = i + A[i]
	AM[i] = i - A[i]
cnt = 0
QC = Counter(AP)
for m in AM:
	cnt += QC[m]
print(cnt)


from collections import *
(n, *a) = map(int, open(0).read().split())
(b, c, z) = ([], [], 0)
for (i, q) in enumerate(a):
	b += (i + q,)
	c += (i - q,)
c = Counter(c)
for (j, p) in Counter(b).items():
	z += p * c[j]
print(z)


from collections import Counter
(N, *A) = map(int, open(0).read().split())
L = Counter((l + a for (l, a) in enumerate(A)))
R = Counter((r - a for (r, a) in enumerate(A)))
print(sum((R[k] * v for (k, v) in L.items())))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = [0] * n
	for (i, x) in enumerate(a):
		if i + x < n:
			d[i + x] += 1
	print(sum([d[i - x] for (i, x) in enumerate(a) if i - x >= 0]))
main()


N = int(input())
(*A,) = map(int, input().split())
(ref, count) = ({}, 0)
for (i, a) in enumerate(A):
	if i - a in ref:
		count += ref[i - a]
	if i + a in ref:
		ref[i + a] += 1
	else:
		ref[i + a] = 1
print(count)


from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
c = Counter()
ans = 0
for (i, x) in enumerate((int(x) for x in input().split())):
	ans += c[i - x]
	c[i + x] += 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
D = {}
ans = 0
for i in range(N):
	s = i - A[i]
	if s in D:
		ans += D[s]
	t = i + A[i]
	if t not in D:
		D[t] = 0
	D[t] += 1
print(ans)


from collections import defaultdict
n = int(input())
a = [0]
a.extend(map(int, input().split()))
mp = defaultdict(int)
ans = 0
for i in range(1, n + 1):
	ans += mp[i - a[i]]
	mp[i + a[i]] += 1
print(ans)


from collections import defaultdict

def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	ans = 0
	for (i, ai) in enumerate(a, 1):
		d[str(i + ai)] += 1
		ans += d[str(i - ai)]
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = [int(x) for x in input().split()]
dp = [0] * n
ans = 0
for (i, j) in enumerate(a):
	if i + j < n:
		dp[i + j] += 1
	if 0 < i - j:
		ans += dp[i - j]
print(ans)


n = int(input())
A = [int(x) for x in input().split()]
res = 0
counter = {}
for i in reversed(range(n)):
	x = A[i]
	res += counter.get(x + i, 0)
	counter[i - x] = counter.get(i - x, 0) + 1
print(res)


from collections import *
N = int(input())
A = list(map(int, input().split()))
ans = 0
c = Counter()
for i in range(1, N + 1):
	ans += c[i - A[i - 1]]
	c[i + A[i - 1]] += 1
print(ans)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
ans = 0
for (i, x) in enumerate(A, 1):
	ans += D[i - x]
	D[x + i] += 1
print(ans)


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict

def main():
	n = int(input())
	a = list(map(int, input().split()))
	d1 = defaultdict(int)
	d2 = defaultdict(int)
	for (i, ae) in enumerate(a):
		d1[i + ae + 1] += 1
		d2[i - ae + 1] += 1
	r = 0
	for d1e in d1.keys():
		rt = d1[d1e] * d2[d1e]
		r += rt
	print(r)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
import collections
B = []
C = []
for (i, a) in enumerate(A):
	B.append(a - i)
	C.append(-a - i)
C = collections.Counter(C)
ans = 0
for b in B:
	ans += C[b]
print(ans)


from collections import defaultdict
N = int(input())
p = list(map(int, input().split()))
d = defaultdict(int)
ans = 0
for i in range(N):
	ans += d[i + 1 - p[i]]
	d[i + 1 + p[i]] += 1
print(ans)


N = int(input())
A = [(int(x), i + 1) for (i, x) in enumerate(input().split())]

def test(N, A):
	answer = 0
	for (a0, i0) in A:
		for (a1, i1) in A:
			if a1 + a0 == abs(i1 - i0):
				answer += 1
	return answer // 2

def solve(N, A):
	memo0 = {}
	memo1 = {}
	for (a, n) in A:
		k = -(a + n)
		if k not in memo0:
			memo0[k] = 0
		memo0[k] += 1
		k = n - a
		if k not in memo1:
			memo1[k] = 0
		memo1[k] += 1
	answer = 0
	for (a, n) in A:
		k = a - n
		if k in memo0:
			answer += memo0[k]
		k = a + n
		if k in memo1:
			answer += memo1[k]
	return answer // 2
print(solve(N, A))


def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	mp = dict()
	ans = 0
	for i in range(N):
		x = i - A[i]
		ans += mp.get(x, 0)
		y = A[i] + i
		mp[y] = mp.get(y, 0) + 1
	print(ans)

def __starting_point():
	resolve()
__starting_point()


N = int(input())
D = {}
A = [int(a) for a in input().split()]
ans = 0
for (i, a) in enumerate(A):
	if i - a in D:
		ans += D[i - a]
	if i + a in D:
		D[i + a] += 1
	else:
		D[i + a] = 1
print(ans)


from collections import Counter
N = int(input())
(*A,) = map(int, input().split())
counter = Counter()
ans = 0
for (i, a) in enumerate(A, 1):
	temp = a - i
	ans += counter[temp]
	counter[-a - i] += 1
print(ans)


from collections import defaultdict
N = map(int, input().split())
A = list(map(int, input().split()))
res = 0
d = defaultdict(int)
for (i, num) in enumerate(A):
	res += d[i - num]
	d[i + num] += 1
print(res)


N = int(input())
A = list(map(int, input().split()))
ans = 0
t = dict()
for i in range(N):
	if A[i] - i in t:
		ans += t[A[i] - i]
	t.setdefault(-A[i] - i, 0)
	t[-A[i] - i] += 1
print(ans)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
L = defaultdict(int)
ans = 0
for i in range(N):
	L[i + 1 - A[i]] += 1
for i in range(N):
	ans += L[i + 1 + A[i]]
print(ans)


import collections
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append(a[i] - i)
c = collections.Counter(b)
m = 0
for i in range(n):
	m += c[-(i + a[i])]
	c[a[i] - i] -= 1
print(m)


n = int(input())
la = [int(i) for i in input().split()]
ia = {}
pair = 0
for (j, a) in enumerate(la):
	ia[j + a] = ia.get(j + a, 0) + 1
for (j, a) in enumerate(la):
	pair += ia.get(j - a, 0)
print(pair)


N = int(input())
A = list(map(int, input().split()))
check = {}
ans = 0
for i in range(N):
	x = i - A[i]
	y = A[i] + i
	ans += check.get(x, 0)
	check.setdefault(y, 0)
	check[y] += 1
print(ans)


n = int(input())
from collections import defaultdict
a = list(map(int, input().split()))
ans = 0
dp = defaultdict(int)
for (e, i) in enumerate(a, 1):
	if e - i >= 0:
		ans += dp[e - i]
	dp[i + e] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
l1 = [0] * n
l2 = [0] * n
k = 0
ans = 0
for i in a:
	if k + i < n:
		l1[k + i] += 1
	if k - i >= 0:
		l2[k - i] += 1
	k += 1
for i in range(n):
	ans += l1[i] * l2[i]
print(ans)


N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
cnt = [0] * (N + 1)
ans = 0
for i in range(1, N + 1):
	if i - A[i] >= 0:
		ans += cnt[i - A[i]]
	if i + A[i] <= N:
		cnt[i + A[i]] += 1
print(ans)


from collections import Counter

def main():
	N = int(input())
	A = list(map(int, input().split()))
	count = 0
	r = []
	l = []
	for i in range(N):
		r += (i - A[i],)
		l += (i + A[i],)
	c = Counter(l)
	for i in r:
		count += c[i]
	print(count)
main()


from collections import defaultdict
(n, *A) = map(int, open(0).read().split())
(ans, d) = (0, defaultdict(int))
for (i, a) in enumerate(A, 1):
	(x, y) = (i + a, i - a)
	d[x] += 1
	ans += d[y]
print(ans)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ans = 0
c = Counter()
for (idx, a) in enumerate(A):
	idx += 1
	ans += c[idx - a]
	c[idx + a] += 1
print(ans)


import collections
N = int(input())
A = [0]
A += list(map(int, input().split()))
cnt = 0
L = [-10 ** 6]
R = [-10 ** 6]
for i in range(1, N + 1):
	L.append(i + A[i])
	R.append(i - A[i])
c = collections.Counter(L)
for j in range(1, N + 1):
	cnt += c.get(R[j], 0)
print(cnt)


(_, *l) = map(int, open(0).read().split())
(d, a, i) = ({}, 0, 0)
for h in l:
	d[i + h] = d.get(i + h, 0) + 1
	a += d.get(i - h, 0)
	i += 1
print(a)


from collections import *
(n, *a) = map(int, open(0).read().split())
o = []
t = []
for (i, x) in enumerate(a):
	o += (i + x,)
	t += (i - x,)
f = lambda l: sum((x * (x - 1) // 2 for x in Counter(l).values()))
print(f(o + t) - f(o) - f(t))


import collections
n = int(input())
a = [int(_) for _ in input().split()]
l = [a[i] + i for i in range(n)]
r = [i - a[i] for i in range(n)]
c = collections.Counter(r)
ans = 0
for i in range(n):
	ans += c[l[i]]
print(ans)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = [A[k] + k for k in range(N)]
C = [k - A[k] for k in range(N)]
C = Counter(C)
ans = 0
for e in B:
	ans += C[e]
print(ans)


N = int(input())
L = [0] * 404040
A = map(int, input().split())
ans = 0
for (i, a) in enumerate(A):
	ia = i - a
	if ia >= 0:
		ans += L[ia]
	ai = a + i
	if ai < 404040:
		L[ai] += 1
print(ans)


from collections import defaultdict
b = defaultdict(int)
c = defaultdict(int)
n = int(input())
a = map(int, input().split())
for (idx, i) in enumerate(a, start=1):
	b[i - idx] += 1
	c[i + idx] += 1
ans = 0
for (k, v) in b.items():
	ans += v * c[-1 * k]
print(ans)


from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
cnt = defaultdict(int)
ans = 0
for i in range(n):
	k = i - A[i]
	ans += cnt[k]
	cnt[i + A[i]] += 1
print(ans)


from collections import defaultdict

def main():
	(n, *a) = map(int, open(0).read().split())
	(d, s) = (defaultdict(int), 0)
	for (i, x) in enumerate(a):
		d[i + x] += 1
		s += d[i - x]
	print(s)
main()


n = int(input())
a = list(map(int, input().split()))
count = {}
for i in range(len(a)):
	minus = i + 1 - a[i]
	if minus in count:
		count[minus] += 1
	else:
		count[minus] = 1
total = 0
for i in range(len(a)):
	plus = a[i] + (i + 1)
	if plus in count:
		total += count[plus]
print(total)


from collections import defaultdict
n = int(input())
lis = list(map(int, input().split()))
rem = defaultdict(int)
ans = 0
for (i, x) in enumerate(lis):
	ans += rem[i - x]
	rem[i + x] += 1
print(ans)


(n, *l) = map(int, open(0).read().split())
(d, a) = ({}, 0)
for i in range(n):
	d[i + l[i]] = d.get(i + l[i], 0) + 1
	a += d.get(i - l[i], 0)
print(a)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ans = 0
l = []
r = []
for (i, j) in enumerate(a):
	l.append(i + j)
	r.append(i - j)
b = Counter(r)
for i in l:
	ans += b.get(i, 0)
print(ans)


n = int(input())
a = list(map(int, input().split()))
k = []
ans = 0
for i in range(400005):
	k.append(0)
for i in range(n):
	if i - a[i] >= 0:
		ans += k[i - a[i]]
	if a[i] + i < 400005:
		k[a[i] + i] += 1
print(ans)


from collections import Counter
n = int(input())
p = Counter()
q = Counter()
for (i, x) in enumerate(input().split()):
	p[i - int(x)] += 1
	q[i + int(x)] += 1
print(sum((p[x] * q[x] for x in p.keys())))


def getInts():
	return [int(x) for x in input().split()]
[N] = getInts()
As = getInts()
A = {}
for i in range(1, N + 1):
	A[i] = As[i - 1]
L = {}
R = {}
for i in range(1, N + 1):
	if i - A[i] not in L:
		L[i - A[i]] = 1
	else:
		L[i - A[i]] += 1
	if i + A[i] not in R:
		R[i + A[i]] = 1
	else:
		R[i + A[i]] += 1
count = 0
for k in list(R.keys()):
	if k in L:
		count += R[k] * L[k]
print(count)


N = int(input())
A = list(map(int, input().split()))
dict1 = {}
for i in range(1, N + 1):
	tmp = i + A[i - 1]
	if tmp not in dict1:
		dict1[tmp] = 1
	else:
		dict1[tmp] += 1
dict2 = {}
for i in range(1, N + 1):
	tmp = i - A[i - 1]
	if tmp not in dict2:
		dict2[tmp] = 1
	else:
		dict2[tmp] += 1
ans = 0
for (k, v) in list(dict1.items()):
	if k in dict2:
		ans += v * dict2[k]
print(ans)


from collections import Counter
n = int(input())
c = Counter()
ans = 0
for (i, a) in enumerate(map(int, input().split())):
	ans += c[i - a]
	c[a + i] += 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
d = {}
for i in range(len(A)):
	d.setdefault(i - A[i], 0)
	d[i - A[i]] += 1
ans = 0
for i in range(len(A)):
	if d.get(i + A[i]):
		ans += d.get(i + A[i])
print(ans)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = [a + i for (i, a) in enumerate(A)]
C = [j - a for (j, a) in enumerate(A)]
(B, C) = (Counter(B), Counter(C))
ans = 0
for k in B.keys():
	ans += B[k] * C[k]
print(ans)


from collections import defaultdict
N = int(input())
(*A,) = map(int, input().split())
ans = 0
diff_list = []
count = defaultdict(int)
for i in range(1, N):
	if i == A[0] + A[i]:
		ans += 1
	d1 = A[i] - A[0]
	d2 = i
	diff_list.append(d1 + d2)
	count[A[0] + A[i] - i] += 1
for i in range(N - 1):
	count[A[0] + A[i + 1] - (i + 1)] -= 1
	d = diff_list[i]
	ans += count[-d]
print(ans)


import sys, collections
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = []
C = []
for (i, a) in enumerate(A):
	B.append(i + a)
	C.append(i - a)
cnt = 0
Bc = collections.Counter(B)
Cc = collections.Counter(C)
for (key, val) in list(Bc.items()):
	cnt += val * Cc[key]
print(cnt)


(n, *l) = map(int, open(0).read().split())
from collections import *
c = Counter()
a = 0
for i in range(n):
	c[i + l[i]] += 1
	a += c[i - l[i]] * (i > l[i])
print(a)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = [i - a[i] for i in range(n)]
cnt = Counter(b)
ans = 0
for i in range(n):
	ans += cnt[i + a[i]]
print(ans)


N = int(input())
A = list(map(int, input().split()))
d = [0] * N
ans = 0
for i in range(N):
	a = A[i]
	(l, r) = (i + a, i - a)
	if 0 <= l < N:
		d[l] += 1
	if 0 <= r < N:
		ans += d[r]
print(ans)


N = int(input())
A = list(map(int, input().split()))
ans = 0
L = [0] * N
R = list()
for i in range(N):
	R.append(i - A[i])
	if i + A[i] <= N - 1:
		L[i + A[i]] += 1
for r in R:
	if r > 0:
		ans += L[r]
print(ans)


from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
B = defaultdict(int)
res = 0
for i in range(n):
	B[A[i] + i] += 1
	if i - A[i] in B:
		res += B[i - A[i]]
print(res)


from collections import defaultdict

def main():
	d = defaultdict(int)
	d2 = defaultdict(int)
	N = int(input())
	A = list(map(int, input().split()))
	for i in range(N):
		d[i + 1 + A[i]] += 1
		d2[max(0, i + 1 - A[i])] += 1
	ans = 0
	for (k, v) in d.items():
		if k == 0:
			continue
		ans += v * d2[k]
	print(ans)

def __starting_point():
	main()
__starting_point()


input()
counts = {}
ans = 0
for (i, h) in enumerate(map(int, input().split())):
	i += 1
	ans += counts.get(i - h, 0)
	counts[i + h] = counts.get(i + h, 0) + 1
print(ans)


import collections
n = int(input())
a = list(map(int, input().split()))
memo = collections.defaultdict(int)
ans = 0
for (i, x) in enumerate(a, 1):
	ans += memo[i - x]
	memo[i + x] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(n):
	if i + 1 - a[i] in dic:
		ans += dic[i + 1 - a[i]]
	if a[i] + (i + 1) in dic:
		dic[i + 1 + a[i]] = dic[i + 1 + a[i]] + 1
	else:
		dic[i + 1 + a[i]] = 1
print(ans)


from collections import defaultdict
N = int(input())
X = list(map(int, input().split()))
ctr = defaultdict(int)
ans = 0
for i in range(N):
	ctr[i + X[i]] += 1
	ans += ctr[i - X[i]]
print(ans)


from collections import defaultdict
import numpy as np
import collections
N = int(input())
As = list(map(int, input().split()))
B = defaultdict(int)
ans = 0
for (index, A) in enumerate(As):
	ans += B[index - A]
	B[index + A] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = [i + a[i] for i in range(n)]
r = [i - a[i] for i in range(n)]
lc = {}
rc = {}
for i in range(n):
	lc[l[i]] = 0
	lc[r[i]] = 0
	rc[r[i]] = 0
	rc[l[i]] = 0
for i in range(n):
	lc[l[i]] += 1
	rc[r[i]] += 1
ans = 0
for i in set(lc.keys()):
	ans += rc[i] * lc[i]
print(ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
jc = [0] * n
for i in range(n):
	jc[i] += i + 1 - a[i]
jcc = Counter(jc)
count = 0
for j in range(n):
	count += jcc[a[j] + j + 1]
print(count)


n = int(input())
a = list(map(int, input().split()))
l = [i + a[i] for i in range(n)]
r = [i - a[i] for i in range(n)]
x = {}
y = {}
for i in range(n):
	x[l[i]] = 0
	y[l[i]] = 0
	y[r[i]] = 0
for i in range(n):
	x[l[i]] += 1
	y[r[i]] += 1
ans = 0
for i in set(x.keys()):
	ans += x[i] * y[i]
print(ans)


from collections import defaultdict
N = int(input())
A = [int(_) for _ in input().split()]
F = defaultdict(int)
B = defaultdict(int)
for (i, v) in enumerate(A):
	F[i + v] += 1
	B[i - v] += 1
ans = 0
for i in F:
	ans += F[i] * B[i]
print(ans)


N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
plus_h = {}
minus_h = {}
for i in range(N):
	p = i + 1 + A_list[i]
	m = i + 1 - A_list[i]
	plus_h.setdefault(p, 0)
	plus_h[p] += 1
	minus_h.setdefault(m, 0)
	minus_h[m] += 1
cnt = 0
for k in plus_h:
	if k in minus_h:
		cnt += plus_h[k] * minus_h[k]
print(cnt)


N = int(input())
A = list(map(int, input().split(' ')))
S = {}
cnt = 0
for i in range(N):
	if i - A[i] in S:
		cnt += S[i - A[i]]
	t = A[i] + i
	if t in S:
		S[t] += 1
	else:
		S[t] = 1
print(cnt)


import collections
N = int(input())
A = [int(i) for i in input().split()]
B = collections.Counter([A[i] + i + 1 for i in range(N)])
ans = 0
for i in range(N):
	ans += B[i + 1 - A[i]]
print(ans)


n = int(input())
l = list(map(int, input().split()))
c = 0
x = []
y = {}
for i in range(n):
	x.append(l[i] + i)
	if i - l[i] in y:
		y[i - l[i]] += 1
	else:
		y[i - l[i]] = 1
for i in x:
	if i in y:
		c += y[i]
print(c)


N = int(input())
A = list(map(int, input().split()))
d = {}
a = 0
for i in range(N):
	n = A[i]
	if i - n in d:
		a += d[i - n]
	if n + i in d:
		d[n + i] += 1
	else:
		d[n + i] = 1
print(a)


N = int(input())
A = list(map(int, input().split()))
NA = []
for i in range(N):
	NA.append(A[i] - i)
from collections import Counter
d = Counter(NA)
cnt = 0
for i in range(N - 1):
	cnt += d[-i - A[i]]
print(cnt)


import collections

def main():
	N = int(input())
	A = list(map(int, input().split()))
	A1 = []
	A2 = []
	for (i, a) in enumerate(A):
		A1.append(i + 1 + a)
		A2.append(i + 1 - a)
	A1count = list(collections.Counter(A1).items())
	A2count = collections.Counter(A2)
	ans = 0
	for (a, cnt) in A1count:
		ans += A2count[a] * cnt
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
A = list(map(int, input().split()))
C = sorted([-A[i] - i for i in range(n)])
from bisect import *
print(sum((bisect(C, b) - bisect_left(C, b) for b in [A[i] - i for i in range(n)])))


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = [a + i for (i, a) in enumerate(A)]
R = [j - a for (j, a) in enumerate(A)]
(L, R) = (Counter(L), Counter(R))
ans = 0
for k in L.keys():
	ans += L[k] * R[k]
print(ans)


N = int(input())
arr = list(map(int, input().split()))
cnt_arr = [0] * N
ans = 0
for i in range(N):
	if arr[i] + i + 1 < N:
		cnt_arr[arr[i] + i + 1] += 1
	if i + 1 - arr[i] > 0:
		ans += cnt_arr[i + 1 - arr[i]]
print(ans)


n = int(input())
a = list(map(int, input().split()))
mae = {}
ans = 0
for i in range(n):
	mae[i + a[i]] = mae.get(i + a[i], 0) + 1
	ans += mae.get(i - a[i], 0)
print(ans)


from collections import Counter

def main():
	n = int(input())
	lst = list(map(int, input().split()))
	lst1 = Counter([i + x for (i, x) in enumerate(lst)])
	lst2 = Counter([i - x for (i, x) in enumerate(lst)])
	sm = 0
	for x in lst1:
		if x in lst2:
			sm += lst1[x] * lst2[x]
	print(sm)
main()


N = int(input())
Alist = list(map(int, input().split()))
Aplu = []
Amin = dict()
for i in range(N):
	A = Alist[i]
	Aplu.append(A + (i + 1))
	if i + 1 - A not in Amin:
		Amin[i + 1 - A] = 1
	else:
		Amin[i + 1 - A] += 1
Answer = 0
for k in Aplu:
	if k in Amin:
		Answer += Amin[k]
print(Answer)


n = int(input())
a = list(map(int, input().split()))
k = 0
b = {}
for i in range(n):
	if a[i] + i in b:
		b[a[i] + i] += 1
	else:
		b[a[i] + i] = 1
	if i - a[i] in b:
		k += b[i - a[i]]
print(k)


N = int(input())
A = list(map(int, input().split()))
A = [0] + A
Sam = []
Dif = []
D2 = [0] * 200000
for i in range(len(A)):
	Sam.append(i + A[i])
	if i - A[i] > 0:
		Dif.append(i - A[i])
for dif in Dif:
	D2[dif] += 1
count = 0
for sam in Sam:
	if sam < len(D2):
		count += D2[sam]
print(count)


n = int(input())
a = list(map(int, input().split()))
b = []
c = 0
for i in range(n * 2):
	b.append(0)
for i in range(n):
	if i + a[i] <= n:
		b[i + a[i]] += 1
	if i >= a[i]:
		c += b[i - a[i]]
print(c)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = [i + ai for (i, ai) in enumerate(a)]
c = Counter((i - ai for (i, ai) in enumerate(a)))
ans = 0
for bi in b:
	ans += c[bi]
print(ans)


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

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
d = [0 for i in range(n)]
for i in range(n):
	t = i - a[i]
	if t >= 0:
		d[t] += 1
s = 0
for i in range(n):
	t = i + a[i]
	if t < n:
		s += d[t]
print(s)


n = int(input())
a = list(map(int, input().split()))
b = [0] * n
ans = 0
for i in range(n):
	if i + a[i] < n:
		b[i + a[i]] += 1
	if a[i] <= i and b[i - a[i]]:
		ans += b[i - a[i]]
print(ans)


from collections import Counter as C
n = int(input())
a = list(map(int, input().split()))
l = C([i + a[i] for i in range(n)])
r = C([i - a[i] for i in range(n)])
b = 0
for i in l.keys():
	b += l[i] * r[i]
print(b)


delta = {}
n = int(input())
k = 0
a = list(map(int, input().split()))
for (i, e) in enumerate(a):
	delta[i - e] = delta.get(i - e, 0) + 1
for (i, e) in enumerate(a):
	k += delta.get(e + i, 0)
print(k)


N = int(input())
L = list(map(int, input().split()))
import copy
U = copy.copy(L)
for i in range(0, N):
	L[i] += i + 1
	U[i] = -U[i] + (i + 1)
L = sorted(L)
U = sorted(U)
import bisect
count = 0
for i in range(0, N):
	count += bisect.bisect_right(U, L[i]) - bisect.bisect_left(U, L[i])
print(count)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q1 = []
q2 = []
for i in range(n):
	q1.append(i + a[i])
	q2.append(i - a[i])
c2 = Counter(q2)
ans = 0
for i in q1:
	ans += c2[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
l = []
r = []
for i in range(n):
	nu = i + 1
	x = a[i]
	l.append(x + nu)
	r.append(nu - x)
di1 = {}
di2 = {}
for i in range(0, n):
	if i == n - 1:
		continue
	else:
		if l[i] not in di1:
			di1[l[i]] = 0
		di1[l[i]] += 1
		if r[i + 1] not in di2:
			di2[r[i + 1]] = 0
		di2[r[i + 1]] += 1
		if r[i + 1] in di1:
			ans += di1[r[i + 1]]
print(ans)


N = int(input())
A = list(map(int, input().split()))
A_i = {}
ans = 0
for i in range(N):
	if i - A[i] in A_i:
		ans += A_i[i - A[i]]
	if i + A[i] in A_i:
		A_i[i + A[i]] += 1
	else:
		A_i[i + A[i]] = 1
print(ans)


from collections import Counter
N = int(input())
(*A,) = map(int, input().split())
A = [a - i for (i, a) in enumerate(A)]
S = Counter(A)
ans = 0
for (i, a) in enumerate(A):
	ans += S[-2 * i - a]
print(ans)


N = int(input())
A = [int(x) for x in input().split()]
counter = {}
for i in range(N):
	counter[i + A[i]] = 0
ans = 0
for i in range(N):
	if i - A[i] in counter:
		ans += counter[i - A[i]]
	counter[i + A[i]] += 1
print(ans)


from collections import Counter
n = int(input())
A = list(map(int, input().split()))
A_pos = [A[x] + x for x in range(n)]
A_neg = [-A[x] + x for x in range(n)]
C_pos = Counter(A_pos)
C_neg = Counter(A_neg)
ans = 0
for c in C_pos:
	ans += C_pos[c] * C_neg[c]
print(ans)


import numpy as np
from collections import Counter
n = int(input())
a = np.array(list(map(int, input().split())))
ni = np.array([i for i in range(n)])
ap = a + ni
an = (a - ni) * -1
cp = Counter(ap)
cn = Counter(an)
ans = 0
for i in cp.keys():
	ans += cp[i] * cn[i]
print(ans)


import math
from math import gcd, pi, sqrt
INF = float('inf')
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
import bisect
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return list(map(int, input().split()))

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	N = i_input()
	A = i_list()
	L = [i + k for (i, k) in enumerate(A)]
	R = [i - k for (i, k) in enumerate(A)]
	countR = Counter(R)
	ans = 0
	for l in L:
		ans += countR[l]
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
(b1, b2, dic, ans) = ([], [], {}, 0)
for (i, j) in enumerate(a):
	b1.append(j - i)
	b2.append(-j - i)
for (i, j) in zip(b1, b2):
	if i in dic:
		ans += dic[i]
	if j in dic:
		dic[j] += 1
	else:
		dic[j] = 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
start = [0] * N
ans = 0
for i in range(N):
	if i + A[i] + 1 < N:
		start[i + A[i] + 1] += 1
for i in range(N):
	if i - A[i] + 1 < 0:
		continue
	if i - A[i] + 1 >= N:
		continue
	ans += start[i - A[i] + 1]
print(ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = [i - v for (i, v) in enumerate(a)]
check = Counter(c)
ans = 0
for (i, v) in enumerate(a):
	ans += check[i + v]
print(ans)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
found = 0
dt = defaultdict(int)
for n in range(N):
	found += dt[n - A[n]]
	dt[n + A[n]] += 1
print(found)


from collections import defaultdict
N = int(input())
src = list(map(int, input().split()))
ans = 0
d = defaultdict(int)
e = []
for (i, s) in enumerate(src, 1):
	l = i + s
	r = i - s
	d[l] += 1
	ans += d[r]
print(ans)


import collections
N = int(input())
A = list(map(int, input().split()))
mp = {}
ans = 0
for p in range(N):
	if p - A[p] + 1 in mp:
		ans += mp[p - A[p] + 1]
	if p + A[p] + 1 in mp:
		mp[p + A[p] + 1] += 1
	else:
		mp[p + A[p] + 1] = 1
print(ans)


n = int(input())
y = list(map(int, input().split()))
from collections import Counter
lhs = Counter([j + y[j] for j in range(n)])
rhs = Counter([j - y[j] for j in range(n)])
count = 0
for i in lhs:
	if i in rhs:
		count += lhs[i] * rhs[i]
print(count)


import collections
n = int(input())
a = [0] + list(map(int, input().split()))
a_pos = [a[i] + i for i in range(1, n + 1)]
a_neg = [-a[i] + i for i in range(1, n + 1)]
c_pos = collections.Counter(a_pos)
c_neg = collections.Counter(a_neg)
ans = 0
for c in c_pos:
	ans += c_pos[c] * c_neg[c]
print(ans)


n = int(input())
a = list(map(int, input().split()))
num1 = [0] * (2 * 10 ** 5 + 10)
num2 = [0] * (2 * 10 ** 5 + 10)
for i in range(n):
	if a[i] + i + 1 < 2 * 10 ** 5 + 5:
		num1[a[i] + i + 1] += 1
	if a[i] + 1 < i + 1:
		num2[-a[i] + i + 1] += 1
ans = 0
for i in range(len(num1)):
	ans += num1[i] * num2[i]
print(ans)


n = int(input())
A = list(map(int, input().split()))
from collections import defaultdict
dic = defaultdict(lambda : 0)
ans = 0
for (i, a) in enumerate(A):
	ans += dic[i - a]
	dic[a + i] += 1
print(ans)


N = int(input())
A = [int(num) for num in input().split()]
S = {-A[0]: 1}
ans = 0
for i in range(1, N):
	ans += S.get(A[i] - i, 0)
	S[-A[i] - i] = S.get(-A[i] - i, 0) + 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(0, N):
	x = i - A[i]
	y = i + A[i]
	if x in dic:
		ans += dic[x]
	if y not in dic:
		dic[y] = 0
	dic[y] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(n):
	r = i - a[i]
	ans += dic.get(r, 0)
	l = a[i] + i
	dic[l] = dic.get(l, 0) + 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
an = 0
d = {}
for i in range(n):
	d[l[i] + i] = d.get(l[i] + i, 0) + 1
	an += d.get(i - l[i], 0)
print(an)


from collections import Counter
n = int(input())
A = list(map(int, input().split()))
P = [i + a + 1 for (i, a) in enumerate(A)]
Q = [j - a + 1 for (j, a) in enumerate(A)]
cQ = Counter(Q)
ans = 0
for p in P:
	ans += cQ[p]
print(ans)


n = int(input())
A = list(map(int, input().split()))
X = {}
ans = 0
for i in range(n):
	L = i + A[i]
	R = i - A[i]
	if L not in X:
		X[L] = 0
	X[L] += 1
	if R in X:
		ans += X[R]
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = [0] * 10 ** 6
ans = 0
for i in range(n):
	if a[i] < 2 * 10 ** 5:
		if i - a[i] >= 0:
			ans += b[i - a[i]]
		b[a[i] + i] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
num = dict()
ans = 0
for i in range(n):
	num[i + a[i]] = 0
for i in range(n):
	if i - a[i] in num:
		ans += num[i - a[i]]
	num[i + a[i]] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
dp = [0] * n
ans = 0
for (i, j) in enumerate(a):
	if i + j < n:
		dp[i + j] += 1
	if 0 < i - j:
		ans += dp[i - j]
print(ans)


n = int(input())
a = list(map(int, input().split()))
res = 0
dict = {}
dict[a[0] + 1] = 1
for i in range(1, n):
	res += dict.get(i + 1 - a[i], 0)
	dict[a[i] + i + 1] = dict.get(a[i] + i + 1, 0) + 1
print(res)


n = int(input())
dic = {}
ans = 0
d = input().split(' ')
for i in range(0, len(d)):
	k = int(d[i])
	if i - k in dic:
		ans += dic[i - k]
	if i + k in dic:
		dic[i + k] += 1
	else:
		dic[i + k] = 1
print(ans)


(n, *l) = map(int, open(0).read().split())
from collections import *
d = defaultdict(int)
a = 0
for i in range(n):
	d[i + l[i]] += 1
	a += d[i - l[i]] * (i > l[i])
print(a)


n = int(input())
l = list(map(int, input().split()))
d = {}
ans = 0
for i in range(n):
	if i - l[i] in d:
		ans += d[i - l[i]]
	if i + l[i] in d:
		d[i + l[i]] += 1
	else:
		d[i + l[i]] = 1
print(ans)


import sys
from collections import Counter
N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
P = [i + a for (i, a) in enumerate(A, start=1)]
Q = [j - a for (j, a) in enumerate(A, start=1)]
res = 0
C = Counter(Q)
for p in P:
	res += C[p]
print(res)


from sys import stdin, stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
d = {}
ans = 0
for i in range(n):
	d[a[i] + i] = d.get(a[i] + i, 0) + 1
for i in range(n):
	ans += d.get(i - a[i], 0)
print(ans)


N = int(input())
A = list(map(int, input().split()))
B = [A[i] - i for i in range(N)]
from collections import Counter
c = Counter(B)
r = 0
for i in range(N):
	r += c[-A[i] - i]
print(r)


n = int(input())
a = map(int, input().split())
(b, c) = ([], [])
for (i, q) in enumerate(a):
	b.append(i + q)
	c.append(i - q)
from collections import *
b = Counter(b).items()
c = Counter(c)
z = 0
for (d, e) in b:
	z += e * c[d]
print(z)


from collections import Counter
N = int(input())
As = list(map(int, input().split()))
ct = Counter()
ans = 0
for (i, a) in enumerate(As):
	ans += ct[i - a]
	ct[i + a] += 1
print(ans)


from collections import Counter
n = int(input())
a = list(list(map(int, input().split())))
ma = [i - a[i] for i in range(n)]
r = Counter(ma)
ans = 0
for i in range(n):
	ans += r[i + a[i]]
print(ans)


n = int(input())
l = list(map(int, input().split()))
a = []
b = {}
ans = 0
for i in range(n):
	a.append(i + l[i])
	b[i - l[i]] = b.get(i - l[i], 0) + 1
for av in a:
	ans = ans + b.get(av, 0)
print(ans)


N = int(input())
A = [int(x) for x in input().split()]
res = {}
count = 0
for i in range(N):
	L = i + 1 + A[i]
	res[L] = res.get(L, 0) + 1
for i in range(N):
	R = i + 1 - A[i]
	count = res.get(R, 0) + count
print(count)


import collections
import bisect
n = int(input())
cnt = collections.defaultdict(list)
dat = list(map(int, input().split()))
buf = []
for i in range(n):
	cnt[i - dat[i]].append(i)
res = 0
for i in range(n):
	x = i + dat[i]
	if x in cnt:
		res += len(cnt[x]) - bisect.bisect_left(cnt[x], x)
print(res)


import collections
N = int(input())
A = list(map(int, input().split()))
plus = [0] * N
minus = [0] * N
for i in range(N):
	plus[i] = i + 1 + A[i]
	minus[i] = i + 1 - A[i]
plus = dict(collections.Counter(plus))
minus = dict(collections.Counter(minus))
ans = 0
for i in list(plus.keys()):
	if i in minus:
		ans += plus[i] * minus[i]
print(ans)


n = int(input())
arr = list(map(int, input().split()))
addarr = [i + 1 + arr[i] for i in range(n)]
diffarr = [i + 1 - arr[i] for i in range(n)]
from collections import Counter
cnt = Counter([addarr[0]])
ans = 0
for i in range(1, n):
	tmp = diffarr[i]
	ans += cnt[tmp]
	cnt.update([addarr[i]])
print(ans)


import collections
(_, A) = open(0)
(P, Q) = map(collections.Counter, zip(*[[i - a, i + a] for (i, a) in enumerate(map(int, A.split()))]))
print(sum((P[i] * Q[i] for i in range(6 ** 7))))


n = int(input())
a = list(map(int, input().split()))
dic = dict()
for (i, j) in enumerate(a, start=1):
	if dic.get(i - j):
		dic[i - j] += 1
	else:
		dic[i - j] = 1
ans = 0
for (i, j) in enumerate(a, start=1):
	if dic.get(i + j):
		ans += dic[i + j]
print(ans)


import sys
from bisect import bisect_right, bisect_left
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	n = int(input())
	A = list(map(int, input().split()))
	(A_i, A_j) = ([], [])
	for i in range(n):
		A_i.append(-A[i] - (i + 1))
	for j in range(n):
		A_j.append(A[j] - (j + 1))
	A_j.sort()
	res = 0
	for a in A_i:
		idx_1 = bisect_left(A_j, a)
		idx_2 = bisect_right(A_j, a)
		res += idx_2 - idx_1
	print(res)

def __starting_point():
	resolve()
__starting_point()


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
i_plus_A = Counter([i + A[i] for i in range(N)])
i_minus_A = [i - A[i] for i in range(N)]
print(sum((i_plus_A[x] for x in i_minus_A)))


N = int(input())
(*A,) = map(int, input().split())
J = [0] * N
j = 0
while j < N:
	J[j] = j - A[j]
	j += 1
import collections
C = collections.Counter(J)
ans = 0
i = 0
while i < N:
	ans += C[i + A[i]]
	i += 1
print(ans)


(n, *A) = map(int, open(0).read().split())
(ans, d) = (0, {})
for (i, a) in enumerate(A, 1):
	(x, y) = (i + a, i - a)
	d[x] = d.get(x, 0) + 1
	ans += d.get(y, 0)
print(ans)


N = int(input())
(*A,) = map(int, input().split())
ans = 0
cnt = {}
for (j, a) in enumerate(A[::-1]):
	j = N - 1 - j
	ans += cnt.get(a + j, 0)
	cnt[j - a] = cnt.get(j - a, 0) + 1
print(ans)


from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
H = defaultdict(int)
ans = 0
for (i, v) in enumerate(A):
	ans += H[i - v]
	H[i + v] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
ipa = {}
ima = {}
for i in range(n):
	p = i + a[i]
	if p in ipa:
		ipa[p] += 1
	else:
		ipa[p] = 1
	m = i - a[i]
	if m in ima:
		ima[m] += 1
	else:
		ima[m] = 1
ans = 0
for k in ipa:
	if k in ima:
		ans += ipa[k] * ima[k]
print(ans)


n = int(input())
a = list(map(int, input().split()))
x = []
y = {}
for (i, elem) in enumerate(a):
	x.append(i + a[i])
	y[i - a[i]] = y.get(i - a[i], 0) + 1
ans = 0
for i in x:
	ans += y.get(i, 0)
print(ans)


from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
ct = Counter((a - i for (i, a) in enumerate(A)))
ans = 0
for (i, a) in enumerate(A):
	ans += ct[-a - i]
print(ans)