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):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

m1 = dict()
for i, v in enumerate(a):
    t = (i+1) + v
    if t not in m1:
        m1[t] = set()
    m1[t].add(i+1)

m2 = dict()
for i, v in enumerate(a):
    t = (i+1) - v
    if t <= 1:
        continue
    if t not in m1:
        continue
    if t not in m2:
        m2[t] = set()
    m2[t].add(i+1)

ans = 0
for k in m2:
    ans += len(m1[k]) * len(m2[k])

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
add_dic = {}
sub_dic = {}

for i in range(n):
    add_tmp = i + a[i]
    sub_tmp = i - a[i]
    if not add_tmp in add_dic.keys():
        add_dic[add_tmp] = 1
    else:
        add_dic[add_tmp] += 1
    if not sub_tmp in sub_dic.keys():
        sub_dic[sub_tmp] = 1
    else:
        sub_dic[sub_tmp] += 1

ans = 0
for k, v in add_dic.items():
    if k in sub_dic.keys():
        ans += v * sub_dic[k]
print(ans)

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

r1 = [(i+1)+A[i] for i in range(n)]
r2 = [(i+1)-A[i] for i in range(n)]
co1 = collections.Counter(r1)
co2 = collections.Counter(r2)
ans = 0
for num,c1 in co1.items():
    c2 = co2[num]
    ans+=c1*c2
print(ans)

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

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

X = dict()
ans = 0
for i in range(N):
    L = i + A[i]
    R = i - A[i]
    if L not in X:
        X[L] = 1
    else:
        X[L] += 1
    if R in X:
        ans += X[R]
        
print(ans)

Solution (Python):
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    ii = collections.defaultdict(int)
    jj = collections.defaultdict(int)

    for i, aa in enumerate(a):
        ii[i+aa] += 1
        jj[i-aa] += 1

    ans = 0


    ans = 0
    for k in ii:
        ans += ii[k]*jj[k]
    print(ans)
if __name__=='__main__':
    main()

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

d={}
for i in range(N):
    if i-A[i]>0:
        if str(i-A[i]) in d:
            d[str(i-A[i])]+=1
        else:
            d[str(i-A[i])]=1

ans=0
for j in range(N):
    if str(j+A[j]) in d:
        ans+=d[str(j+A[j])]
print(ans)

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

Solution (Python):
from collections import defaultdict

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

m = defaultdict(int)
ans = 0
for i in range(N):
    ans += m[i-A[i]]
    m[i+A[i]] += 1

print(ans)

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

X = dict()
ans = 0
for i in range(N):
    L = i + A[i]
    if L not in X:
        X[L] = 1
    else:
        X[L] += 1

for i in range(N):
    R = i - A[i]
    if R in X:
        ans += X[R]
        
print(ans)

Solution (Python):
from bisect import bisect_left,bisect_right

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

diff_AB = [(i+1-A[i]) for i in range(N)]
diff_AB.sort()

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

print(ans)

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

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

Solution (Python):
N= int(input())
A = list(map(int,input().split()))
dict_L = {}
for i in range(N):
    if(i+1+A[i] in dict_L.keys()):
        dict_L[i+1+A[i]] += 1
    else:
        dict_L[i+1+A[i]] = 1
cnt = 0
for j in range(N):
    R = j+1-A[j]
    if(R in dict_L.keys()):
        cnt += dict_L[R]
print(cnt)

Solution (Python):
from collections import Counter

def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = 0
    l1 = []
    for ea in a:
        l1.append(cnt - ea)
        cnt += 1
    l1c = Counter(l1)
    r = 0
    for i2 in range(n):
        r += l1c[i2 + a[i2]]
    print(int(r))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

cai = {}
caj = {}
vali = set()
valj = set()
for ai, aj in zip(AI, AJ):
    if not ai in cai:
        cai[ai] = 0
    if not aj in caj:
        caj[aj] = 0

    cai[ai] += 1
    vali.add(ai)

    caj[aj] += 1
    valj.add(aj)

count = 0
for val in vali & valj:
    count += cai[val] * caj[val]

print(count)

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

ans=0
for i,a in enumerate(A,1):
    SUB=i-a
    ans += D_sub[SUB]
    D_sub[i+a]+=1

print(ans)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x=[]
y=[]
for i in range(n):
    x.append(i+a[i])
    y.append(i-a[i])
x=Counter(x)    
y=Counter(y)
s=set(x.keys()).union(set(y.keys()))

ans=0
for k in s:
    ans += x[k]*y[k]
print(ans)

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

ans = 0
for k, v in L.items():
    ans += v * R[k]
print(ans)

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

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

count = 0

for i in range(N):
    l = i + A[i]
    r = i - A[i]
    if r in L.keys():
        count += L[r]
    if l in L.keys():
        L[l] += 1
    else:
        L[l] = 1
print(count)

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

X = dict()
ans = 0
for i in range(N):
    L = i + A[i]
    if L not in X:
        X[L] = 1
    else:
        X[L] += 1

for i in range(N):
    R = i - A[i]
    if R in X:
        ans += X[R]
        
print(ans)

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

dic_l={}
dic_r={}
for i in range(n):
    a = a_inputs[i]+(i+1)
    b = (i+1)-a_inputs[i]
    dic_l[a]=dic_l.get(a,0)+1
    dic_r[b]=dic_r.get(b,0)+1

ans=0
for key in dic_l.keys():
    ans+=dic_l[key]*dic_r.get(key,0)
    
print(ans)

Solution (Python):
n=int(input())
ap=[int(x) for x in input().split()]
L={}
R={}
for i,a in enumerate(ap):
  if i+a in L:
    L[i+a]+=1
  else:
    L[i+a]=1
  if i-a in R:
    R[i-a]+=1
  else:
    R[i-a]=1
ans=0
for i in range(n):
  if i in L and i in R:
    ans += L[i]*R[i]
print(ans)

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

L_dict = {}
R_dict = {}

for i, v in enumerate(A_list):
    l = i + v
    r = i - v
    if not l in L_dict.keys():
        L_dict[l] = [i]
    else:
        L_dict[l].append(i)
    
    if not r in R_dict.keys():
        R_dict[r] = [i]
    else:
        R_dict[r].append(i)

res = 0
for r in R_dict.keys():
    if r in L_dict.keys():
        res += len(R_dict[r]) * len(L_dict[r])
print(res)

Solution (Python):
from bisect import bisect_left, bisect, insort

def main():
    n = int(input())
    a = list(map(int, input().split()))
    h_plus_i = [ai+i for i, ai in enumerate(a, 1)]
    h_minus_i = [ai-i for i, ai in enumerate(a, 1)]
    s_h_plus_i = list(sorted(h_plus_i))
    s_h_minus_i = list(sorted(h_minus_i))
    ans = 0
    for hpi, hmi in zip(h_plus_i, h_minus_i):
        i1 = bisect_left(s_h_minus_i, -hpi)
        i2 = bisect_left(s_h_plus_i, -hmi)
        if (i1 < n and s_h_minus_i[i1] == -hpi):
            ans += bisect_left(s_h_minus_i, -hpi+1)-i1
        if (i2 < n and s_h_plus_i[i2] == -hmi):
            ans += bisect_left(s_h_plus_i, -hmi+1)-i2
            
    print(ans//2)

if __name__ == "__main__":
    main()

Solution (Python):
N =int(input())
A = list(map(int,input().split()))
d ={}
r ={}
ans =0
for x in range(N):
    d[x] =0
    r[x] =0
for x in range(N):
    dt = A[x]+x
    rt = x-A[x]
    if dt<N:
        d[dt] +=1
    if rt >-1:
        r[rt] +=1
for x in range(N):
    if d[x] !=0 and r[x]!=0:
        ans = ans + d[x]*r[x]
print(ans)

Solution (Python):
N = int(input())
A = list((i, j) for i, j in enumerate(map(int, input().split())))
dictL = {}
dictR = {}

ans = 0
for i in range(N):
    l, r = A[i][1] + A[i][0], A[i][0] - A[i][1]
    if l not in dictL:
        dictL[l] = 1
    else:
        dictL[l] += 1
    if r not in dictR:
        dictR[r] = 1
    else:
        dictR[r] += 1

for i in dictL.keys():
    if i in dictR.keys():
        ans += dictL[i] * dictR[i]
        
print(ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
C=[]
for i in range(n):
    C.append([i+A[i],0])
    C.append([i-A[i],1])
C.sort()
now=C[0][0]
c0=0
c1=0
ans=0
for c in C:
    if now==c[0]:
        if c[1]==0:
            c0+=1
        else:
            c1+=1
    else:
        ans+=c0*c1
        c0=0
        c1=0
        if c[1]==0:
            c0+=1
        else:
            c1+=1
        now=c[0]
ans+=c0*c1
print(ans)

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

L={}
R={}
for i in range(1,len(A)+1):
  L[str(i+A[i-1])] = L.get(str(i+A[i-1]),0)+1
  R[str(i-A[i-1])] = R.get(str(i-A[i-1]),0)+1

ans = 0
for i in range(1,N+1):
  if str(i) in L and str(i) in R:
    ans += L[str(i)] * R[str(i)]

print(ans)

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

for i, a in enumerate(A):
    ai[i + 1 + a] += 1
    aj[i + 1 - a] += 1

ans = 0
for k, v in ai.items():
    ans += v * aj[k]
print(ans)

Solution (Python):
import numpy as np
from collections import Counter

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

sum = np.arange(n) + a
diff = np.arange(n) - a
sum_c = Counter(sum)
diff_c = Counter(diff)

res = 0
for k, v in sum_c.items():
    res += diff_c[k] * v
print(res)

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

x_occurance = {}
minus = []
for i in range(N):
	p = A[i] + i
	m = i - A[i]
	x_occurance[p] = x_occurance.get(p, 0) + 1
	minus.append(m)

count = 0
for i in range(N):
	count += x_occurance.get(minus[i], 0) 

print count

Solution (Python):

from collections import defaultdict


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





ls = defaultdict(int)
rs = defaultdict(int)
for i, a in enumerate(A):
    ls[a+i+1] += 1
    rs[i+1-a] += 1


ans = 0

for i in range(2, N):
    ans += ls[i] * rs[i] 

print(ans)

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

c = 0
for i in range(2, n):
    if i in l and i in r:
        c += l[i]*r[i]
print(c)

Solution (Python):
import collections

n = int(input())
a = list(map(int, input().split()))
L = [i + ai for i, ai in enumerate(a)]
R = [i - ai for i, ai in enumerate(a)]
t = collections.Counter(L)
u = collections.Counter(R)
ans = 0
for i in t.keys():
    ans += t[i]*u[i]
print(ans)

Solution (Python):


from pprint import pprint
from collections import deque, defaultdict
import math
import itertools
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float("inf")

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

min_diff = 1
max_diff = N - 1

dl = defaultdict(list)
dr = defaultdict(list)
for i in range(1, N + 1):
    key = i + A[i-1]
    dl[key].append(i)
    key = i - A[i-1]
    if key > 0:
        dr[key].append(i)



count = 0
for diff in range(min_diff, max_diff + 1):
    count += len(dl[diff]) * len(dr[diff])
print(count)

Solution (Python):
from collections import Counter
inputs = open(0).readlines()
n = int(inputs[0])
*A, = (map(int, inputs[1].split()))
B = Counter([a+i for i, a in enumerate(A, 1)])
C = Counter([i-a for i, a in enumerate(A, 1)])
ans = 0
for k, v in B.items():
    if k in C:
        ans += C[k]*v
print(ans)

Solution (Python):
import math
import fractions
import collections
import itertools
import pprint
N=int(input())
A=list(map(int,input().split()))
plus=[]
minus=[]
cnt=0
for i in range(N):
    plus.append(A[i]+(i+1))
    minus.append(A[i]-(i+1))
c1=collections.Counter(plus)
c2=collections.Counter(minus)
l2=[]

values=list(c2.values())	
key=list(c2.keys())	
for i in range(len(key)):
    l2.append([key[i],values[i]])

for i in range(len(l2)):
    cnt=cnt+l2[i][1]*c1[-l2[i][0]]
print(cnt)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
lst1 = {}
lst2 = {}
ans = 0
for i in range(len(a)):
  val1 = str(i + a[i])
  val2 = str(i - a[i])
  if val2 in lst1.keys():
    ans += lst1[val2]
  if val1 in lst1.keys():
    lst1[val1] += 1
  else:
    lst1[val1] = 1
print(ans)

Solution (Python):
from collections import Counter

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

L = [A[i]+i for i in range(N)]
R = [j-A[j] for j in range(N)]

l = Counter(L)
r = Counter(R)

ans = 0
for i in l.keys():
    ans += l[i]*r[i]

print(ans)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
l=[i+a for i,a in enumerate(a)]
r=[i-a for i,a in enumerate(a)]
cl=Counter(l)
cr=Counter(r)
ans=0
for j in cl.keys():
  ans+=cl[j]*cr[j]
print(ans)

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

Solution (Python):
from collections import Counter

def main():
    n = int(input())
    a = tuple([int(t)for t in input().split()])

    d_1 = {}
    d_2 = {}

    for i,a_i in enumerate(a):
        d_1.setdefault(i+a_i,0)
        d_1[i+a_i]+=1

    for j,a_j in enumerate(a):
        d_2.setdefault(j-a_j,0)
        d_2[j-a_j]+=1

    ans = 0
    for key in d_1.keys():
        if key in d_2.keys():
            ans += d_1[key]*d_2[key]

    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
cnt = 0
N = int(input())
A = list(map(int, input().split()))
minus_list = [j - A[j] for j in range(N)]
counter = Counter(minus_list)
for i in range(N):
    add = A[i] + i
    cnt += counter[add]
print(cnt)

Solution (Python):
import numpy as np
from collections import Counter
n = int(input())
i = np.arange(n)
a = np.array(list(map(int, input().split())))
p = i + a
m = i - a
pc = Counter(p)
mc = Counter(m)
ans = sum([cnt * mc[x] for x, cnt in pc.items()])
print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
r = np.array(range(N))
X = r+A
Y = r-A
ans = 0
x_dic = {}
y_dic = {}
for x in X:
    if x in x_dic:
        x_dic[x] += 1
    else:
        x_dic[x] = 1
  
for y in Y:
    if y in y_dic:
        y_dic[y] += 1
    else:
        y_dic[y] = 1

for x in x_dic:
    if x in y_dic:
        ans += x_dic[x]*y_dic[x]        
print(ans)

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

Solution (Python):
import collections

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

L = [A[x]+x+1 for x in range(N)]
R = [x+1-A[x] for x in range(N)]

cL = collections.Counter(L)
cR = collections.Counter(R)

cRlist = list(cR.keys())

for i in range(len(cRlist)):
    tmp = cRlist[i]
    ans += cR.get(tmp,0) * cL.get(tmp,0)
    
print(ans)

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

ans = 0
L = {}
R = {}
for i in range(n):
    if i+a[i] in L:
        L[i+a[i]].append(i)
    else:
        L[i+a[i]] = [i]
    if i-a[i] in R:
        R[i-a[i]].append(i)
    else:
        R[i-a[i]] = [i]
for i in range(n):
    if i in L and i in R:
        ans += len(L[i])*len(R[i])
print(ans)

Solution (Python):
def main(n,a_):
  from collections import defaultdict
  lr=[[i+ai,i-ai] for i,ai in enumerate(a_)]
  rs=defaultdict(lambda:0)
  ls=defaultdict(lambda:0)
  ans=0
  for l,r in lr:
    rs[r]+=1
    ls[l]+=1
  for k in rs.keys():
    ans+=rs[k]*ls[k]
  print(ans)
if __name__=='__main__':
  n=int(input())
  a_=list(map(int,input().split()))
  
  
  main(n,a_)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
r = {}
for i in range(n):
    try:
        r[i-a[i]] += 1
    except:
        r[i-a[i]] = 1
cnt = 0
for i in range(n):
    r[i-a[i]] -= 1
    try:
        cnt += r[i+a[i]]
    except:
        pass
print(cnt)

Solution (Python):
import collections as col

n = int(input())
a = [0] + list(map(int,input().split()))

def binp(arr, val):
    left,right = 0,len(arr)-1
    while left <= right:
        mid = (left+right)//2
        if val==arr[mid]: return 1
        elif val>=arr[mid]: left = mid+1
        else: right = mid-1
    return 0

ap = [a[i] + i for i in range(1,n+1)]
an = [i - a[i] for i in range(1,n+1)]
counter = col.Counter(an)

ans = 0
for ele in ap:
    ans += counter[ele]

print(ans)

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

Solution (Python):
import collections

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

L = [i+j for i, j in enumerate(A)]
R = [i-j for i, j in enumerate(A)]

l = collections.Counter(L)
r = collections.Counter(R)

ans = 0
for i in l.keys():
    ans += l[i]*r[i]

print(ans)

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

ans = 0
sum = {} 

for r in range(n):
  ans += sum.get(r - a[r], 0)
  sum[r + a[r]] = sum.get(r + a[r], 0) + 1
  
  
    
    
      
print(ans)

Solution (Python):
def main():
  import bisect
  n=int(input())
  a=list(map(int,input().split()))
  b=[a[i]+i+1 for i in range(n)]
  c=[i+1-a[i] for i in range(n)]
  b.sort()
  c.sort()
  ans=0
  for i in b:
    x=bisect.bisect_left(c,i)
    y=bisect.bisect_right(c,i)
    z=y-x
    ans+=z
  print(ans)
if __name__=='__main__':
  main()

Solution (Python):
import numpy as np
from collections import defaultdict

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

idxs = np.arange(n)
L, R = idxs + a, idxs - a

count = 0
d = defaultdict(int)
for i in range(n-1):
    d[L[i]] += 1
    count += d[R[i+1]]

print(count)

Solution (Python):
from collections import defaultdict

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

r = defaultdict(int)
l = defaultdict(int)
for i in range(n):
    r[al[i]+i] += 1
    l[i-al[i]] += 1

res = 0
for k in r:
    res += r[k]*l[k]

print(res)

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

cnt = defaultdict(int)
ans = 0
for i, a in enumerate(A, start=1):
    ans += cnt[-a + i]
    cnt[a + i] += 1

print(ans)

Solution (Python):
import sys
from collections import Counter

N = int(sys.stdin.readline().rstrip())
As = list(map(int, sys.stdin.readline().rstrip().split()))

ll = [0] * N
lr = [0] * N
for i, a in enumerate(As):
    ll[i] = i + a
    lr[i] = i - a

cl = Counter(ll)
cr = Counter(lr)

ans = 0
for l in cl.keys():
    ans += cl[l] * cr[l]

print(ans)

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

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

c = [0]*n
d = [0]*n

for i, j in enumerate(a):
    c[i] = i + j

for i, j in enumerate(a):
    d[i] = i - j

x = {}
for i, j in enumerate(c):
    if j not in x:
        x[j]=[i]
    else:
        x[j].append(i)
ans = 0
for i in d:
    if i not in x:
        continue
    else:
        ans += len(x[i])
print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
A = [int(n) for n in input().split()]
record = defaultdict(int)
count = 0
for i in range(len(A)):
    cur = i-A[i]
    count += record[cur]
    record[i+A[i]] += 1
print(count)

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

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

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

p = collections.Counter() 
n = collections.Counter() 
for i in range(N):
  p[i+A[i]] += 1
  n[i-A[i]] += 1
  
ans = 0
for i in p.keys():
  ans += p[i]*n[i]
print(ans)

Solution (Python):
from collections import defaultdict

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

mp = defaultdict(lambda: [0, 0])
for i in range(1, N+1):
    L = i + A[i-1]
    R = i - A[i-1]
    mp[L][0] += 1
    mp[R][1] += 1

ans = 0
for v in mp.values():
    ans += v[0] * v[1]
print(ans)

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

Solution (Python):
def solve(n, xs):

    ans = 0
    tmp = {}
    for i in range(n-1, -1, -1):
        l = i+1 + xs[i]
        r = i+1 - xs[i]

        if l in tmp:
            ans += tmp[l]

        if r in tmp:
            tmp[r] += 1
        else:
            tmp[r] = 1

    return ans
if __name__ == "__main__":
    n = int(input())
    xs = [int(i) for i in input().split()]
    print(solve(n, xs))

Solution (Python):
from collections import defaultdict

n = int(input())
height = list(map(int, input().split()))
ans = 0

d = defaultdict(int)

for i in range(n):
    x = i+height[i]
    d[x] += 1

for i in range(n):
    x = i-height[i]
    ans += d[x]

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
from collections import Counter
L = [i+a for i, a in enumerate(A)]
R = [i-a for i, a in enumerate(A)]
l = Counter(L)
r = Counter(R)
ans = 0
for i in l.keys():
    ans += l[i]*r[i]
print(ans)

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

L_list = {}
R_list = {}
cnt = 0
for i in range(N):
    L = i+1 + A[i]
    R = i+1 - A[i]

    if L in R_list.keys():
        cnt += R_list[L]
    if R in L_list.keys():
        cnt += L_list[R]

    if L in L_list.keys():
        L_list[L] += 1
    else:
        L_list[L] = 1
    if R in R_list.keys():
        R_list[R] += 1
    else:
        R_list[R] = 1

print(cnt)

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

L = [A[i] + (i + 1) for i in range(N)]
R = [(i + 1) - A[i] for i in range(N)]
import collections
dL = dict(collections.Counter(L))
dR = dict(collections.Counter(R))

ans = 0
for k in dL.keys():
    ans += dL[k] * dR.get(k, 0)
print(ans)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
L = [0] * 2 * N
R = [0] * 2 * N
for i in range(N):
    l = i + A[i]
    if l < N: L[l] += 1
    r = i - A[i]
    if r > 0: R[r] += 1
ans = 0 
for i in range(N):
    ans += L[i] * R[i]
print(ans)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
A = LI()

ans = 0
d = defaultdict(int)

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

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

ans = 0
r = {}
l = {}

for i, a in enumerate(A):
    if i - a in l:
        l[i - a] += 1
    else:
        l[i - a] = 1

    if i + a in r:
        r[i + a] += 1
    else:
        r[i + a] = 1

for k in r:
    if k in l:
        ans += r[k] * l[k]

print(ans)

Solution (Python):
import numpy as np
import collections
n = int(input())
A = np.array(list(map(int,input().split())))
B = np.array([i+1 for i in range(n)])
C,D = A+B,B-A
ans = 0

c = collections.Counter(C)
d = collections.Counter(D)
ans = 0
for i in c.keys():
    ans += c[i]*d[i]
print(ans)

Solution (Python):
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def main():

    N = int(input())
    a = list(map(int,input().split()))
    pl = defaultdict(int)
    ans = 0
    for i,num in enumerate(a):
        s = num+i
        t = num-i
        ans += pl[-t]
        pl[s] += 1

    print(ans)
    
if __name__ == "__main__":
    main()

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

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

I=[]
for i in range(n-1):
    I.append(0)
    
for i in range(n):
    if A[i]+i>=1 and A[i]+i<=n-1:
        I[A[i]+i-1]+=1


J=[]
for i in range(n-1):
    J.append(0)

for j in range(n):
    if j-A[j]>=1 and j-A[j]<=n-1:
        J[j-A[j]-1]+=1

s=0
for i in range(n-1):
    s+=I[i]*J[i]

print(s)

Solution (Python):
n = int(input())
a_array = list(map(int, input().split()))
a_array.insert(0, 0)
x_sum = {}
x_dis = {}

for i in range(1, n+1):
    a_sum = i + a_array[i]
    if a_sum in x_sum:
        x_sum[a_sum].append(i)
    else:
        x_sum[a_sum] = [i]
    if not(a_sum in x_dis):
        x_dis[a_sum] = []

    a_dis = i - a_array[i]
    if a_dis > 0:
        if a_dis in x_dis:
            x_dis[a_dis].append(i)
        else:
            x_dis[a_dis] = [i]
        if not(a_dis in x_sum):
            x_sum[a_dis] = []



count = 0
for k in x_sum.keys():
    count += len(x_sum[k]) * len(x_dis[k])

print(count)

Solution (Python):
from collections import defaultdict
def E():
    N = int(input())
    A = [int(n) for n in input().split()]
    record = defaultdict(int)
    count = 0
    for i in range(len(A)):
        cur = i-A[i]
        count += record[cur]
        record[i+A[i]] += 1
    
    print(count)

E()

Solution (Python):
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A = list(map(int, rl().split()))
    
    d = defaultdict(int)
    ans = 0
    for i in range(N)[::-1]:
        ans += d[-A[i] - i]
        d[A[i] - i] += 1
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import collections

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

L = [item+i for i, item in enumerate(A)]
R = [i - item for i, item in enumerate(A)]


C1 = collections.Counter(L)
C2 = collections.Counter(R)

ans = 0
for k, v in C1.items():
    if k in C2:
        ans += v * C2[k]
print(ans)

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

print(ans)

Solution (Python):
import collections
n=int(input())
s=list(map(int, input().split()))
L=[i+a for i,a in enumerate(s)]
R=[i-a for i,a in enumerate(s)] 
t=collections.Counter(L)
u=collections.Counter(R)
ans = 0
for i in t.keys():
  ans+=t[i]*u[i]
print(ans)

Solution (Python):
from collections import Counter

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

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

cx = Counter(x)
cy = Counter(y)

ans = 0
for i in cx.keys():
    ans += cx[i] * cy[i]

print(ans)

Solution (Python):
import collections
n=int(input())
s=list(map(int, input().split()))
L=[i+a for i,a in enumerate(s)]
R=[i-a for i,a in enumerate(s)] 
t=collections.Counter(L)
u=collections.Counter(R)
ans = 0
for i in t.keys():
  ans+=t[i]*u[i]
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
R = [A[i] + i for i in range(n)]
L = [-A[i] + i for i in range(n)]
R_c = dict(Counter(R))
L_c = dict(Counter(L))
vals = set(R) & set(L)
ans = 0
for v in vals:
    r = 0 if R_c.get(v) is None else R_c[v]
    l = 0 if L_c.get(v) is None else L_c[v]
    ans += r*l
print(ans)

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

lx = {}
rx = {}

for i, ai in enumerate(a):
    li = (i + 1) + ai
    ri = (i + 1) - ai
    if li not in lx:
        lx[li] = set()
    lx[li].add(i + 1)
    if ri not in rx:
        rx[ri] = set()
    rx[ri].add(i + 1)



answer = 0
for x in lx.keys():
    if x in rx:
        s = lx[x]
        t = rx[x] - lx[x]
        answer += len(s) * len(t)

print(answer)

Solution (Python):
from collections import Counter

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

ai=[]
aj=[]

for i,a in enumerate(A):
    ai.append(i+1-a)
    aj.append(i+1+a)

ajc=Counter(aj)
ret=0
for x in ai:
    ret+=ajc.get(x,0)

print(ret)

Solution (Python):
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_plus_index = list(A[i]+i+1 for i in range(N))
    A_plus_index = Counter(A_plus_index)
    index_minus_A = list(i+1-A[i] for i in range(N))
    ans = 0
    for a in index_minus_A:
        ans += A_plus_index.get(a, 0)
    print(ans)


if __name__ == "__main__":
    main()