Problem:
 Score: 500 points    Problem Statement  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 1 6
2 3 3 1 3 1      Sample Output 1 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 .       Sample Input 2 6
5 2 4 2 8 8      Sample Output 2 0  No pair satisfies the condition, so you should print 0 .       Sample Input 3 32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5      Sample Output 3 22

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
S = []
T = []
for i in range(1,N+1):
    S.append(i+A[i-1])
    T.append(i-A[i-1])

L = []
for i in range(N):
    L.append(S[i]-1)

from collections import Counter
M = Counter(L)
out = 0
for i in range(N):
    if (T[i]-1>=0)and(len(L)-1>=T[i]-1):
        out += M[T[i]-1]
        if T[i]==S[i]:
            out += -1
print(out)

Solution (Python):


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]
mp = lambda :map(int,input().split())

n = inp()
x = ip()
ctr = 0
a = [i+x[i] for i in range(n)]
b = [i-x[i] for i in range(n)]

dt1 = {} 
for i in a: dt1[i] = dt1.get(i,0)+1
dt2 = {} 
for i in b: dt2[i] = dt2.get(i,0)+1

for i in dt1:
    if i in dt2:
        ctr += dt1[i]*dt2[i]
print(ctr)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = solve(n, a)
    print(ans)


def solve(n, a):
    x = {}
    for i in range(n):
        tmp = i - a[i] + 1
        if tmp >= 0:
            if tmp in x:
                x[tmp] += 1
            else:
                x[tmp] = 1
    ans = 0
    for i in range(n):
        tmp = a[i] + i + 1
        if tmp in x:
            ans += x[tmp]
    return ans


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l1 = []
l2 = []

for i, h in enumerate(a):
    l1.append(i + h+1)
    l2.append(i - h+1)

c1 = Counter(l1)
c2 = Counter(l2)

cnt = 0

for h in (c1.keys() | c2.keys()):
    if h in c1.keys() and h in c2.keys():
        cnt += c1[h] * c2[h]

print(cnt)

Solution (Python):
from collections import Counter
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = Counter([e+i+1 for i,e in enumerate(a)])
    c = Counter([i+1-e for i,e in enumerate(a) if i+1-e > 1])
    ans = 0
    for i in c:
        ans += b[i] * c[i]
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
sa = [0]*n
wa = [0]*n

ans = 0
for i in range(n):
    sa[i] = a[i]-i
    wa[i] = a[i]+i
b = Counter(wa)
c = Counter(sa)
    
for i in b:
    ans += b[i]*c[-i]
            
print(ans)

Solution (Python):

import sys
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
dic = defaultdict(int)
for i, a in enumerate(A):
    x = a - i
    if x in dic:
        dic[x] += 1
    else:
        dic[x] = 1

answer = 0
for i, a in enumerate(A):
    y = a + i
    answer += dic[-y]
    x = a - i
    dic[x] -= 1

print(answer)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))




from collections import defaultdict
add = defaultdict(int)
sub = defaultdict(int)

ans = 0
for i in range(N):
    ans += add[i+1 - A[i]] 
    ans += sub[i+1 + A[i]] 
    add[i+1 + A[i]] += 1
    sub[i+1 - A[i]] += 1

print(ans)

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

Solution (Python):
def main():

    from collections import Counter
    n = int(input())
    l = list(map(int,input().split()))

    l1 = []
    for i in range(n):
        l1.append(i-l[i])

    c = Counter(l1)
    count = 0
    for i in range(n-1):
        a = 2*i-l1[i]
        if a in c:
            count += c[a]
    print(count)
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

ans_list = [0] * N
total = 0
for i in range(N):
    if i + A[i] < N:
        ans_list[i + A[i]] += 1
    if i - A[i] >= 0:
        total += ans_list[i - A[i]]

print(total)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = []
C = []
D = [0]*N
E = [0]*N
t = 0
for i in range(N):
    B.append(i+1-A[i])
    C.append(i+1+A[i])
for i in range(N):
    if B[i] > 0 and B[i] <= N:
        D[B[i]-1] += 1
    if C[i] <= N:
        E[C[i]-1] += 1
for i in range(N):
    t += D[i]*E[i]
print(t)

Solution (Python):
n = int(input())
As = list(map(int, input().split()))

as1 = [-(a+i) for i,a in enumerate(As)]
as2 = [a-i for i,a in enumerate(As)]

from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)
cnt = 0

for a1,a2 in zip(as1,as2):
    d1[a1] += 1
    d2[a2] += 1


for k in d1.keys():
    cnt += d1[k]*d2[k]
print(cnt)

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))

ret = 0
my_dict = dict()

for i in range(1, len(a_list)):
    diff = a_list[i] + a_list[0] - i
    if diff in my_dict:
        my_dict[diff].append(i)
    else:
        my_dict[diff] = [i]
    if diff == 0:
        ret += 1

for i in range(1, len(a_list)):
    diff = a_list[i] - a_list[0] + i
    if (-diff) in my_dict:
        tmp_list = my_dict[-diff]
        while len(tmp_list) >= 1:
            if tmp_list[0] <= i:
                tmp_list.pop(0)
            else:
                break
        ret += len(tmp_list)

print(ret)

Solution (Python):
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)

Solution (Python):
N = int(input())
no = [i for i in range(N)]
A = list(map(int, input().split()))

no_minus_height = {}

total = 0
for i in range(N-1,-1,-1):
    no_plus_height = no[i]+A[i]
    try:
        total += no_minus_height[no_plus_height]
    except:
        pass
    
    try:
        no_minus_height[no[i]-A[i]] += 1
    except:
        no_minus_height[no[i]-A[i]] = 1
print(total)

Solution (Python):
import sys
from collections import Counter
readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().split()))
C = Counter()
ans = 0
for i in range(1, N+1):
    a = A[i-1]
    ans += C[i-a]
    C[a+i] += 1
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Api = [ai + i for i, ai in enumerate(A)]
jmA = [j - aj for j, aj in enumerate(A)]
count_Api = Counter(Api)
count_jmA = Counter(jmA)
ans = 0
for api, count in count_Api.items():
    ans += count * count_jmA[api]
print(ans)

Solution (Python):

import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate, permutations
import sys
import bisect


sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
lmii = lambda: list(map(int, input().split()))
lmsi = lambda: list(map(str, input().split()))
smii = lambda: sorted(map(int, input().split()))




N = ii()
A = lmii()

bd = defaultdict(int)
ac = defaultdict(int)
for i in range(N):
    a = b = i + 1
    c = d = A[i]
    bd[b-d] += 1
    ac[a+c] += 1

ans = 0
for k, v in bd.items():
    ans += v * ac[k]

print(ans)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ap, am = [], []
for i in range(n):
    ap.append(i + 1 + a[i])
    am.append(i + 1 - a[i])

from collections import Counter
dicp = Counter(ap)
dicm = Counter(am)

ans = 0
for i, j in dicp.items():
    if i in dicm:
        ans += j * dicm[i]
print(ans)

Solution (Python):

import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  
  sys.stderr.write(_s+"\n")

from collections import defaultdict

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

B = []
D = defaultdict(lambda: 0)

for i in range(N):
	B.append([i,A[i]])
	
	k = i - A[i]
	D[k] += 1

ans=0
for i in range(N):
	k = i + A[i]
	ans += D[k]


print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)


def main():
    N = int(input())
    A = [int(c) for c in input().split()]

    
    lists = [0] * (N + 1)
    for i, a in enumerate(A):
        if i <= a:
            continue
        lists[i + 1 - a] += 1
    
    num = 0
    for i, a in enumerate(A):
        idx = i + 1
        if idx + a <= N:
            num += lists[idx + a]
    print(num)







if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
dif = []
for i in range(N):
    dif.append((i+1)-A[i])

counter = Counter(dif)

ans = 0
for i in range(N):
    ans += counter[(i+1)+A[i]]

print(ans)

Solution (Python):
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))

import collections
n = int(input())
a = lmp()
plus = []
minus = []
for i in range(n):
    plus.append(i+1+a[i])
for i in range(n):
    minus.append(i+1-a[i])
p = list(collections.Counter(plus).items())
m = collections.Counter(minus)


ans = 0
for i in range(len(p)):
    tar = p[i][0]
    num = p[i][1]
    if tar in m:
        ans += num * m[tar]
print(ans)

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
y = []
z =[]
for i in range(len(x)):
    y.append(x[i]+i)
    z.append(i-x[i])
count = 0 
dic = {}
for i in range(len(z)):
    if z[i] in dic :
        dic[z[i]]+= 1
    else :
        dic[z[i]] = 1
for i in range(len(y)) :
    dic[z[i]]-= 1 
    if y[i] in dic :
        count += dic[y[i]]
print(count)

Solution (Python):
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(range(len(seq)), key=seq.__getitem__)

def solve(N, A):
    
    X = np.array([i-A[i] for i in range(N)], dtype=np.int)
    
    Y = np.array([i+A[i] for i in range(N)], dtype=np.int)
    keys = np.argsort(X)
    X = X[keys]  
    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))

Solution (Python):
import collections

def solve(k, r):
    count = {}
    ans = 0
    for i, n in enumerate(r):
        target = i-n
        ans += count.get(target, 0)
        count[i+n] = count.get(i+n, 0)+1
    return ans
k = int(input())
r = list(map(int, input().split()))
print(solve(k, r))

Solution (Python):
n = int(input())
A = list(map(int,input().split()))

score = {}

for i, a in enumerate(A):
  if i ==0:
    continue
  
  s = i-a
  if s not in score:
    score[s] = 0
  score[s]+=1

from bisect import bisect_left
ans = 0
for i, a in enumerate(A):
  if i+a in score:
    ans += score[i+a]
print(ans)

Solution (Python):
import collections

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

l = [0 for _ in range(n)]

for i in range(n):
	l[i] = a[i]-i-1

count = collections.Counter(l)


ans = 0
for i in range(n):
	ans += count[-i-1-a[i]]

print(ans)

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
B = [0]*N
count = dict()
for i in range(1,N):
    B[i] = i-A[i]
    if B[i] in count:
        count[B[i]] += 1
    else:
        count[B[i]] = 1
total = 0
for i in range(N):
    if A[i]+i in count:
        total += count[A[i]+i]
    if i!= 0:
        count[B[i]] -= 1
print(total)

Solution (Python):

"""
Created on Sun May  3 21:27:48 2020
"""

import sys
import numpy as np
import itertools

sys.setrecursionlimit(10 ** 9)


mod = 10**9+7

N = int(input())

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

A = np.array(A)
B = np.arange(N)

x = A - B
y = A + B

x.sort()
y.sort()

ans = 0
i, j = 0, N - 1

x1, y1 = 0, 0
while i < N and j >= 0:
    if -x[i] < y[j]:
        j -= 1
    elif -x[i] > y[j]:
        i += 1
    else:
        x1,y1 = 1, 1
        pre = y[j]
        while pre == -x[i+1]:
            x1 += 1
            i += 1

        while pre == y[j-1]:
            y1 += 1
            j -= 1

        i += 1
        j -= 1
        ans += x1 * y1


print(ans)

Solution (Python):
N=int(input())
Hik=[0]*N
A=list(map(int,input().split()))
B=0
for i in range(N):
 Hik[max(-A[i]+N-1-i,0)]+=1
for j in range(N):
 if 0<=A[N-1-j]+j and A[N-1-j]+j<=N-1:
  B+=Hik[A[N-1-j]+j]
 Hik[max(-A[N-1-j]+j,0)]+=1
print(B)

Solution (Python):
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)

Solution (Python):
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


def main():
    N = int(input())
    A = inpl()
    Api = [a + i + 1 for i, a in enumerate(A)]
    Ami = [i + 1 - a for i, a in enumerate(A)]
    Api.sort()
    Ami.sort()
    
    
    ans = 0
    for a in Api:
        ans += bisect_right(Ami, a) - bisect_left(Ami, a)
    print(ans)

    return


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict

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

plus = defaultdict(int)

for i in range(n):
    plus[i+a[i]] += 1

pair = 0
for j in range(n):
    pair += plus[j-a[j]]

print(pair)

Solution (Python):
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)

Solution (Python):
n =  int(input())
a = list(map(int,input().split()))
a_after = [a[i] - i for i in range(n)]
from collections import Counter
cnt = Counter()
for v in a_after:
    cnt[v] += 1
ret = 0  
for i in range(n):
    v = a[i] - i
    cnt[v] -= 1
    ret += cnt[-v-2*i]

print(ret)

Solution (Python):
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)

Solution (Python):
n = int(input())

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

A_minus = []
minus_A_minus = []

for i in range(n):
    A_minus.append(As[i] - i - 1)
    minus_A_minus.append(-As[i] - i - 1)

dic_AM = {}
dic_MAM = {}

for i in range(n):
    AM = A_minus[i]
    MAM = minus_A_minus[i]
    if dic_AM.get(AM, None) is None:
        dic_AM[AM] = 1
    else:
        dic_AM[AM] += 1
    if dic_MAM.get(MAM, None) is None:
        dic_MAM[MAM] = 1
    else:
        dic_MAM[MAM] += 1

ans = 0

for k in dic_AM:
    if k in dic_MAM:
        ans += dic_AM[k] * dic_MAM[k]

print(ans)

Solution (Python):
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))
N = int(input())
A = inpl()
X = defaultdict(int)
Y = defaultdict(int)
for i in range(N):
    x = A[i] + i
    y = A[i] - i
    X[x] += 1
    if y < 0:
        Y[y] += 1
ans = 0
for y, k in Y.items():
    ans += k * X[-y]
print(ans)

Solution (Python):
from collections import Counter
N, A = int(input()), list(map(int, input().split()))
temp = [0] * N
for i in range(1, N+1):
    temp[i-1] = i + A[i-1]
temp = Counter(temp)
result = 0
for j in range(1, N+1):
    s = temp.get(j - A[j-1])
    if s != None:
        result += s
print(result)

Solution (Python):

import sys
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))

    A_ex = [(i, a) for i, a in enumerate(A)]

    
    counter = Counter()
    cnt = 0
    for i, a in A_ex[::-1]:
        cnt += counter[i+A[i]]
        counter[i-A[i]] += 1
    print(cnt)

    return


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = [int(x) for x in input().split(' ')]

left = [0] * N
right = [0] * N

for i, a in enumerate(A):
  if i - a >=0:
    right[i-a] += 1
  if i + a < N:
    left[i + a] += 1


ans = 0
for l, r in zip(left, right):
  ans += l*r
print(ans)

Solution (Python):
n = int(input())
a = tuple(map(int, input().split()))

a = tuple(a[i]+i for i in range(n))

d = {}
ret = 0
for i in range(n):
    q = i*2 - a[i]
    if q in d:
        ret = ret + d[q]
    if a[i] in d:
        d[a[i]] = d[a[i]] + 1
    else:
        d[a[i]] = 1

print(ret)

Solution (Python):
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A = map(int, read().split())

memo = defaultdict(int)
answer = 0
for i, x in enumerate(A, 1):
    answer += memo[i - x]
    memo[x + i] += 1

print(answer)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
wa={}
sa={}
i=1
for x in a:
    w=x+i
    s=i-x
    if w in wa:
        wa[w]+=1
    else:
        wa[w]=1
    if s in sa:
        sa[s]+=1
    else:
        sa[s]=1
    i+=1
ans=0
for k,v in wa.items():
    if k in sa:
        ans+=sa[k]*v


print(ans)

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

Solution (Python):
from _collections import defaultdict
n=int(input())
A=list(map(int,input().split()))

X=[A[i]-(i+1) for i in range(n)]
Y=[-A[i]-(i+1) for i in range(n)]
ans=0

P=defaultdict(int)
Q=defaultdict(int)

for x in X:
    P[x]+=1
for y in Y:
    Q[y]+=1

p=set(P.keys())
q=set(Q.keys())

r=p&q

for key in r:
    ans+=P[key]*Q[key]
print(ans)

Solution (Python):

def task(n, a):
    total = 0
    tl = [0] * n
    tr = [0] * n

    for i in range(0, n):
        l = i - a[i]
        r = i + a[i]

        if l >= 0:
            tl[l] += 1

        if r < n:
            tr[r] += 1

    for i in range(0, n):
        if tl[i] > 0 and tr[i] > 0:
            total += tl[i] * tr[i]

    print(total)


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

task(n, a)

Solution (Python):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
ap = defaultdict(int)
for i in range(n):
    ap[i - a[i]] += 1

ans = 0
for i in range(n):
    ans += ap[a[i] + i]
print(ans)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

po = [0 for i in range(5*(10**5)+1)]
if n-1-a[0] >= 0:
    po[n-1-a[0]] = 1
ans = 0
for i in range(1,n):
    ppo = n-1-i + a[i]
    if ppo > 5*(10**5):
        if n-i-1 - a[i] >= 0:
            po[n-i-1 - a[i]] += 1
        continue
    if ppo >= 0:
        ans += po[ppo]
    if n-i-1 - a[i] >= 0:
        po[n-i-1 - a[i]] += 1
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

add1 = []
sub1 = []
for i in range(n):
    add1.append(a[i] + i)
    sub1.append(i - a[i])

dict1 = {}
dict2 = {}
for i in add1:
    if i in dict1:
        dict1[i] += 1
    else:
        dict1[i] = 1
for i in sub1:
    if i in dict2:
        dict2[i] += 1
    else:
        dict2[i] = 1

sorted1 = sorted(dict1.items(), key = lambda x: x[0])
sorted2 = sorted(dict2.items(), key = lambda x: x[0])
cnt1 = 0
cnt2 = 0
ans = 0

while cnt1 < len(sorted1) and cnt2 < len(sorted2):
    if sorted1[cnt1][0] == sorted2[cnt2][0]:
        ans += sorted1[cnt1][1] * sorted2[cnt2][1]
        cnt1 += 1
        cnt2 += 1
    elif sorted1[cnt1][0] > sorted2[cnt2][0]:
        cnt2 += 1
    else:
        cnt1 += 1

print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys, bisect, math, itertools
from functools import lru_cache

sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

n = inp()
a = inpl()
dp = defaultdict(int)
ans=0
for i in range(n):
    
    if i-a[i]>=0:
        ans += dp[i - a[i]]
    
    dp[i + a[i]] += 1

print(ans)

Solution (Python):






"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(values: List[int]) -> int:
    all_values = defaultdict(int)
    for i, v in enumerate(values):
        i += 1
        all_values[i + v] += 1
    result = 0
    LOG.debug((all_values))
    for i, v in enumerate(values):
        i += 1
        result += all_values[i - v]
    return result


def do_job():
    "Do the work"
    LOG.debug("Start working")
    
    N = int(input())
    values = list(map(int, input().split()))
    assert len(values) == N
    
    
    
    result = solve(values)
    print(result)


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case 
    
    


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None

if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            
            
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)

Solution (Python):
from collections import defaultdict
from bisect import bisect_right

N = int(input())
arr = list(map(int, input().split()))
val2idx = defaultdict(list)
for j, aj in enumerate(arr):
    val2idx[j - aj].append(j)

ans = 0
for i, ai in enumerate(arr):
    if ai + i in val2idx:
        res = bisect_right(val2idx[ai + i], i)
        ans += len(val2idx[ai + i]) - res
print(ans)

Solution (Python):
import bisect
import collections
n = int(input())
a = list(map(int,input().split()))





x = [a[i]+i for i in range(n)]
y = [a[i]-i for i in range(n)]

c = collections.Counter(y)
cnt = 0
for i in range(n):
	cnt += c[-x[i]]
print(cnt)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

freq=dict()
for i in range(n):
    a[i]-=i
    try:
        freq[a[i]]+=1
    except:
        freq[a[i]]=1

ans =0
for i in range(n):
    try:
        ans+=freq[-a[i]-2*i]
    except:
        pass
    freq[a[i]]-=1

print(ans)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()

for i in range(1,n):
    alis[i] -= i

from collections import defaultdict as dl
d1 = dl(int)
d2 = dl(int)
for i in range(n):
    d1[alis[i]] += 1

ans = 0
ima = 0
for i in range(n-1):
    d2[alis[i]] += 1
    tmp = -(ima + alis[i])
    ans += d1[tmp] - d2[tmp]
    ima += 2
print(ans)

Solution (Python):
if __name__ == '__main__':
    from sys import stdin
    from collections import defaultdict  
    from collections import Counter
    
    
    input = stdin.readline


    n = int(input())

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

    up = defaultdict(int)
    down = defaultdict(int)
    for i in range(n):
        up[i+aa[i]] += 1
        down[i-aa[i]] += 1
    
    count_up = Counter(up)
    count_down = Counter(down)

    ans = 0

    for key, value in count_up.items():
        ans += count_down[key]*value
    print(ans)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
t1 = []
t2 = []
for i in range(n):
    t1.append(l[i] + i)
    t2.append(i - l[i])
count = {}
for i in t1: count[i] = 0
for i in t2: count[i] = 0
for i in t1: count[i] -= -1
ans = 0
for i in t2:
    if i > 0:
        if count[i] != 0:
            ans += count[i]
print(ans)

Solution (Python):
import math
from functools import reduce
from collections import deque,defaultdict
import sys
sys.setrecursionlimit(10**7)

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


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]


def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

n,*A = get_all_int()

X = defaultdict(int)

ans = 0
for i in range(n):
    
    ans += X[i-A[i]]
    X[A[i] + i] += 1



print(ans)

Solution (Python):
n = int(input())

arr = list(map(int, input().split()))
ar2 = [0] * n

for i in range(n):
    x = i-arr[i]
    if x >= 0:
        ar2[x] += 1

total = 0
for i in range(n):
    x = i+arr[i]
    if x < n:
        total += ar2[x]

print(total)

Solution (Python):
from collections import Counter

n=int(input())
*a,=map(int, input().split( ))
b=[a[i]-i for i in range(n)]
c =[-a[i]-i for i in range(n)]
bc=Counter(b)
cc=Counter(c)

ans=0

for k in bc:
    if k in cc:
        ans+= bc[k]*cc[k]
print(ans)

Solution (Python):
from collections import defaultdict


N = int(input())
A = list(map(int, input().split()))
count = defaultdict(int)
res = 0
for i, a in enumerate(A):
    if i - a in count:
        res += count[i - a]
    count[i + a] += 1
print(res)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = [a[i]+i+1 for i in range(n)]
c = [j+1-a[j] for j in range(n)]
b.sort()
c.sort()
b.append(float("inf"))
c.append(float("inf"))
i = 0
j = 0
count = 0
bc = 1
cc = 1
while True:
  if b[i] > c[j]:
    j += 1
  elif b[i] < c[j]:
    i += 1
  else:
    if b[i] == b[i+1]:
      bc += 1
      i += 1
    elif c[j] == c[j+1]:
      cc += 1
      j += 1
    else:
      count += bc*cc
      bc = 1
      cc = 1
      i += 1
      j += 1
  if i >= n and j >= n:
    break
  if i == n+1:
    i = n
  if j == n+1:
    j = n
print(count)

Solution (Python):
from collections import defaultdict
import collections
N = int(input())
a = list(map(int,(input().split())))
b = list(range(N))
wa = [0]*N
sa = [0]*N
for i in range(N):
    wa[i] = a[i]+b[i]
    sa[i] = b[i]-a[i]

cw = collections.Counter(wa)
cs = collections.Counter(sa)
dw = defaultdict(lambda:0)
ds = defaultdict(lambda:0)

for k in cw:
    dw[k] = cw[k] 
for k in cs:
    ds[k] = cs[k] 

mash = []
for i in range(N):
    mash.append(wa[i])
    mash.append(sa[i])
mash = set(mash)

ans = 0
for num in mash:
    ans += dw[num]*ds[num]

print(ans)

Solution (Python):
import collections
n = int(input())
a = list(map(int, input().split()))
x = []
for i in range(n):
    x.append(a[i]-i)
y = []
for j in range(n):
    y.append(-(a[j]+j))
    
X = collections.Counter(x)
Y = collections.Counter(y)



ans = 0
z = X.keys()

for i in z:
    p =X.get(i,0)
    q =Y.get(i,0)
    ans += p*q
print(ans)