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):
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)

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

Solution (Python):
from collections import defaultdict
n = int(input())

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

dic = defaultdict(int)

ans = 0



for i in range(len(a)):
    
    t = i - a[i]
    ans += dic[t]
    dic[a[i]+i] += 1

print(ans)

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

Solution (Python):

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)

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





ms = [0]*N
ps = [0]*N
for i in range(N):
    ms[i],ps[i] = (i+1)-A[i],(i+1)+A[i]

msc,psc = {},{}
mi,pi = 0,0
out = 0
while mi<N:
    msc[ms[mi]] = msc.get(ms[mi],0)+1
    out += psc.get(ms[mi],0)
    psc[ps[mi]] = psc.get(ps[pi],0)+1
    mi+=1
    pi+=1
print(out)

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

if __name__ == '__main__':
    main()

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

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

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

from collections import defaultdict
dic = defaultdict(int)

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

Solution (Python):








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)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

plus = [i+a for i, a in enumerate(As)]
minus = [i-a for i, a in enumerate(As)]
from collections import Counter

pc = Counter(plus)
mc = Counter(minus)
ans = 0
for p, cnt in pc.most_common():
    ans += cnt*mc[p]
print(ans)

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

Solution (Python):
N = int(input())
As = list(map(int,input().split()))
dic = {}
array = []
x = As[0]
init = 1 - x
for i in range(1,N):
    v = init + i - 1 - As[i]
    array.append(v)
    if v not in dic:
        dic[v] = 1
    else:
        dic[v] += 1
if 0 in dic:
    ans = dic[0]
else:
    ans = 0

for i in range(1,N):
    y = As[i] + i - x
    z = array[i-1]
    dic[z] -= 1
    if y in dic:
        ans += dic[y]
print(ans)

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

Solution (Python):
import sys

input=sys.stdin.buffer.readline





def RD(): return sys.stdin.read()


def II(): return int(input())


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


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))




from collections import defaultdict

def main():
	n=II()
	A=LI()
	
	X=defaultdict(int)
	Y=defaultdict(int)
	
	for i,v in enumerate(A):
		X[i+v]+=1
		Y[i-v]+=1
	
	ans=0
	for k,v in X.items():
		ans+=v*Y[k]
	print(ans)
	
	







if __name__=="__main__":
	main()

Solution (Python):
import sys

input=sys.stdin.buffer.readline





def RD(): return sys.stdin.read()


def II(): return int(input())


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


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))




from collections import defaultdict

def main():
	n=II()
	A=LI()
	
	X=defaultdict(int)
	Y=defaultdict(int)
	
	for i,v in enumerate(A):
		X[i+v]+=1
		Y[i-v]+=1
	
	ans=0
	for k,v in X.items():
		ans+=v*Y[k]
	print(ans)
	
	







if __name__=="__main__":
	main()

Solution (Python):
import sys

from collections import defaultdict


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    A = [None] + input_int_list()
    ans = 0
    d = defaultdict(int)
    
    
    
    
    
    for i in range(n, 0, -1):
        cur = i + A[i]
        ans += d[cur]
        d[i - A[i]] += 1
    print(ans)

    return


if __name__ == "__main__":
    main()

Solution (Python):
import math , sys

N  = int( input() )

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

def Prime(x):
    ub=int(math.sqrt(x))+2
    if x==2 or x==3 or x==5 or x==7:
        return True
    for i in range(2,ub):
        if x%i==0:
            return False
    return True

y = N
while not Prime(y):
    y+=1

def h1(x):
    return x % y
def h2(x):
    return 1+ x%(y-1)
def h(x,i):
    return (h1(x) + i*h2(x)) % y

def insert(T,x):
    i=0
    while True:
        j=h(x,i)
        if T[j][0]== -1:
            T[j][0]=x
            T[j][1]=1
            return j
        elif x ==T[j][0]:
            T[j][1]+=1
            return j
        else:
            i+=1

def search(T,x):
    i=0
    while True:
        j=h(x,i)
        if T[j][0] == x:
            return T[j][1]
        elif T[j][0] == -1:
            return -1
        else:
            i+=1

T = [[-1,0] for _ in range(y)]
for i in range(N):
    insert(T , i + A[i])
ans =0
        
for j in range(N):
    if j - A[j]>=0:
        s = search(T, j - A[j])
        if s >=0:
            ans+=s
print(ans)

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

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
plus=[]
minus=[]
for i in range(N):
  plus.append(A[i]+i+1)
  minus.append(-A[i]+i+1)
from collections import Counter
p=Counter(plus)
m=Counter(minus)
sp=set()
for k in p.keys():
  sp.add(k)
ans=0
for k,v in m.items():
  if k in sp:
    ans+=v*p[k]
print(ans)

Solution (Python):
from collections import Counter

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

A = [i + n for i, n in enumerate(nums, start=1)]
B = [j - n for j, n in enumerate(nums, start=1)]
BC = Counter(B)
answer = 0
for a in A:
  answer += BC[a]
print(answer)

Solution (Python):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
Ai = [(i + 1) - a for i, a in enumerate(A)]
Aj = [(j + 1) + a for j, a in enumerate(A)]
cntAi = defaultdict(lambda: 0)
for ai in Ai:
    cntAi[ai] += 1

ans = 0
for ai, aj in zip(Ai, Aj):
    cntAi[ai] -= 1
    ans += cntAi[aj]
print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())

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

dic = defaultdict(int)

ans = 0

for i in range(N):
    t = i - A[i]
    ans += dic[t]
    dic[i+A[i]] += 1

print(ans)

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

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

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

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

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

plus=[0]*1000000
minus=[0]*1000000

for i in range(n):
  ene=i+1
  pin=a[i]
  pl,mi=ene+pin,ene-pin
  if 0<=pl<1000000:
    plus[pl]+=1
  if 0<=mi<1000000:
    minus[mi]+=1
  
for i in range(1000000):
  ans+=plus[i]*minus[i]
  

print(ans)

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

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

Solution (Python):

from collections import Counter

N=int(input())
A=[0]+list(map(int,input().split()))

Ai=[]
Aj=[]

for i in range(1,N+1):
    Ai.append(i+A[i])
    Aj.append(i-A[i])
    
ci=Counter(Ai).items()
cj=Counter(Aj)
res=0
for c,n in ci:
    m=cj[c]
    res+=m*n
print(res)

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

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

Solution (Python):
from collections import defaultdict

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




memo = defaultdict(int)

ans = 0
for i in range(N):
    target = i - A[i]
    ans += memo[target]
    memo[A[i]+i] += 1
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
p=[]
m=[]
for i in range(n):
    p.append(i+a[i])
    m.append(i-a[i])
x=[0]*(2*n)
y=[0]*(2*n)
ans=0
for i in range(n):
    if 0<=p[i]<=(2*n)-1:
        x[p[i]]+=1
    if 0<=m[i]<=(2*n)-1:
        y[m[i]]+=1
for i in range(n):
    ans+=x[i]*y[i]
print(ans)

Solution (Python):
from collections import Counter

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

left = [i+A[i] for i in range(n)]
right = [i-A[i] for i in range(n)]

r_counter = Counter(right)

ans = 0

for l in left:
    ans += r_counter[l]

print(ans)

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

Solution (Python):
from bisect import bisect_left, bisect_right

N = int(input())

A = list(map(int, input().split()))
Ap = [i - A[i] for i in range(N)]
Ap.sort()

ans = 0
for i in range(N):
	ans += bisect_right(Ap, i + A[i]) - bisect_left(Ap, i + A[i])

print(ans)

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

num = {}
ans = 0
for i, v in enumerate(A):
    p = v+i
    m = i-v
    if p not in num:
        num[p] = 1
    else:
        num[p] += 1
    if m in num:
        ans += num[m]
print(ans)

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

Solution (Python):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    L = [i+A[i-1] for i in range(1,N+1)]
    R = [i-A[i-1] for i in range(1,N+1)]
    import collections
    Lcnter = collections.Counter(L)
    Rcnter = collections.Counter(R)
    values = set(Lcnter.keys()) & set(Rcnter.keys())
    ans = 0
    for i in values:
        ans += Lcnter[i]*Rcnter[i]
    print(ans)
    


if __name__ == "__main__":
    resolve()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

j_Aj = [0]

for j, aj in enumerate(a):
    j_Aj.append(j + 1 - aj)
maxj=max(j_Aj)
i_Ai = [0] * (maxj+1)
ans = 0
for j, j_aj in enumerate(j_Aj):
    if j == 0:
        continue
    if j_aj >= 2:
        ans += i_Ai[j_aj]
    if j + a[j - 1]<=maxj:
        i_Ai[j + a[j - 1]] += 1
print(ans)

Solution (Python):
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):
    num[i+a[i]] += 1
    
for i in range(n):
    if i-a[i] in num:
        ans += num[i-a[i]]
        
print(ans)

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

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

Solution (Python):
n = int(input())
lst = [int(i) for i in input().split()]

dic = {}
count = 0
for i in range(n):
  num = lst[i]
  a = i + num
  if a not in dic:
    dic[a] = 1
  else:
    dic[a] += 1
  b = i - num
  if b in dic:
    count += dic[b]
print(count)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
np,nm=[],[]
for i in range(N):
    np.append(A[i]+i)
    nm.append(i-A[i])
sp,sm=sorted(np),sorted(nm)
ans=0
for i in range(N):
    p,m=np[i],nm[i]
    l,r=-1,N
    while not l+1==r:
        x=(l+r)//2
        if sm[x]<=p:
            l=x
        else:
            r=x
    tmp=l
    l,r=-1,N
    while not l+1==r:
        x=(l+r)//2
        if sm[x]<p:
            l=x
        else:
            r=x
    ans+=tmp-l
    l,r=-1,N
    while not l+1==r:
        x=(l+r)//2
        if sp[x]<=m:
            l=x
        else:
            r=x
    tmp=l
    l,r=-1,N
    while not l+1==r:
        x=(l+r)//2
        if sp[x]<m:
            l=x
        else:
            r=x
    ans+=tmp-l
print(ans//2)

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

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

maxVal = N + max(A)
ans = 0

candidatesL = defaultdict(int)
for i in range(1, N+1):
    candidatesL[i+A[i-1]] += 1

candidatesR = defaultdict(int)
for j in range(1, N+1):
    candidatesR[j-A[j-1]] += 1

ans = 0
for x in candidatesL.keys():
    ans += candidatesL[x] * candidatesR[x]

print(ans)

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

Solution (Python):
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	n = int(input())
	
	
	al = lin()
	aal=[i-v for i,v in enumerate(al)]
	ccl = collections.Counter(aal)
	ret = 0
	
	for i, v in enumerate(al):
		ccl[i-v] -= 1
		if i+v in ccl:
			ret += ccl[i+v]
		
	print(ret)
		
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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

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

Solution (Python):

import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    A = LI()

    counter_add = cl.Counter()
    counter_sub = cl.Counter()
    for i in range(N):
        add = i + 1 + A[i]
        sub = i + 1 - A[i]
        counter_add.update({str(add): 1})
        counter_sub.update({str(sub): 1})

    ans = 0
    for key, val in counter_add.items():
        ans += val * counter_sub[key]

    print(ans)


main()

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

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

Solution (Python):
def Binary_Search_Small_Count(A,x,equal=False,sort=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()

    if A[0]>x or ((not equal) and A[0]==x):
        return 0

    L,R=0,len(A)
    while R-L>1:
        C=L+(R-L)//2
        if A[C]<x or (equal and A[C]==x):
            L=C
        else:
            R=C

    return L+1

def Binary_Search_Equal_Count(A,x,sort=False):
    """2分探索によって,xの個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"を超える"がx"以上"になる
    """

    if sort:
        A.sort()

    if x<A[0] or A[-1]<x:
        return 0

    X=Binary_Search_Small_Count(A,x,equal=True)
    Y=Binary_Search_Small_Count(A,x,equal=False)
    return X-Y

N=int(input())
A=["*"]+list(map(int,input().split()))

B=[0]*N
for j in range(1,N+1):
    B[j-1]=j-A[j]
B.sort()

K=0
del A[0]
for i in range(1,N+1):
    K+=Binary_Search_Equal_Count(B,i+A[i-1],False)
print(K)

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

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

Solution (Python):
import bisect

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




a1 = sorted([a[i] - (i+1) for i in range(n)])
a2 = sorted([- a[i] - (i+1) for i in range(n)])
ans = 0
for i in range(n):
    left = bisect.bisect_left(a2, a1[i])
    right = bisect.bisect_right(a2, a1[i])
    ans += (right - left)
print(ans)

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

Solution (Python):
from collections import defaultdict

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

'''
方針:
- 各A_i,(i<h)ごとにf(h,j)=A_h+A_j-|h-j|の値がf(i,j)に比べてどれだけ変化するかを計算し、
リストに格納(①)
- 各要素A_k,(j<k)ごとにf(i,k)=A_i+A_k-|i-k|の値がf(i,j)に比べてどれだけ変化するかを
計算し、カウントをとる(②)
- 再度ループを回して①と②を照合し、値が一致する組数をansに加算
'''

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)

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

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = dict(Counter([i+A[i] for i in range(N)]))
R = dict(Counter([i-A[i] for i in range(N)]))
cnt = 0
for x in L:
    cnt += L[x]*R.get(x, 0)
print(cnt)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=dict(Counter([i-j for i,j in enumerate(a)]))
c=dict(Counter([i+j for i,j in enumerate(a)]))
cnt=0
for i in b:
  cnt+=b[i]*c.get(i,0)
print(cnt)

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

Solution (Python):
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 plus.keys():
  
  if i in minus:
    
    ans += plus[i] * minus[i]
    

print(ans)

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

if __name__ == "__main__":
    resolve()

Solution (Python):
n,*aa = map(int, open(0).read().split())
from collections import Counter
l_cnt = Counter()
r_cnt = Counter()

for i,a in enumerate(aa):
    l_cnt[i+a] += 1

for i,a in enumerate(aa):
    if i-a in l_cnt:
        r_cnt[i-a] += 1

ans = 0
for key in r_cnt:
    ans += l_cnt[key] * r_cnt[key]
print(ans)

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

B,C=[],[]
for i,j in enumerate(A):
    B.append(i+j+1)
    C.append((i+1)-j)

B,C=Counter(B),Counter(C)
ans=0
for i,j in B.items():
    ans +=j*C[i]
print(ans)

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

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

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

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

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

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

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 idx, x in enumerate(A, 1):  
    
    
    
    
    
    answer += memo[idx - x]
    memo[idx + x] += 1

print(answer)

Solution (Python):



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 dict1.items():
    if k in dict2:
        ans += v * dict2[k]
print(ans)