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())
aa=list(map(int,input().split()))
dic={}
ans=0
for i in range(n):
	x=i-aa[i]
	y=i+aa[i]
	if i>0:
		if x in dic:
			ans+=dic[x]
	if y in dic:
		dic[y]+=1
	else:
		dic[y]=1
print(ans)

Solution (Python):
N = int(input())
An = list(map(int,input().split()))
countN = 0
sum = [0]*N
for i, name in enumerate(An):
    if i + name < N:
        sum[i+name] = sum[i+name] + 1
    if i - name >= 0:
        countN = countN + sum[i-name]
print(countN)

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

lst = [0] * N

ans = 0
for i in range(N):
    if i + 1 + A[i] < N: 
        lst[i + A[i]] += 1
    if i + 1 - A[i] >= 1:
        ans += lst[i - A[i]]

print(ans)

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

Aii = [i+A[i] for i in range(N)]
Ajj = [j-A[j] for j in range(N)]
import bisect

Ajj.sort()
ans = 0
for a in Aii:
    right = bisect.bisect_right(Ajj, a)
    left = bisect.bisect_left(Ajj, a)
    ans += right-left
print(ans)

Solution (Python):
import collections
n=int(input())
A=list(map(int,input().split()))
B = [ i-A[i]    for i in range(n)]
C = [ i+A[i]    for i in range(n)]
b = collections.Counter(B)
c = collections.Counter(C)
ans =0
cnt = 0
 
for i in b.keys():
  ans +=c[i]*b[i]
     
print(ans)

Solution (Python):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
d1 = defaultdict(int)
d2 = defaultdict(int)
for i,a in enumerate(A):
    d1[i+a] += 1
    d2[i-a] += 1
ans = 0
for k,v in d1.items():
    ans += v*d2[k]
print(ans)

Solution (Python):
from collections import Counter

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

l = []
r = []
for i, ai in enumerate(a):
   l.append(i+ai)
   r.append(i-ai)

ans = 0
b = Counter(r)
for i in l:
   ans += b.get(i, 0)

print(ans)

Solution (Python):
from collections import defaultdict

n=int(input())
a= list(map(int, input().split()))
r=[0]*n
l=[0]*n

for i,x in enumerate(a):
    l[i]=i+x
    r[i]=i-x

d=defaultdict(int)
ans=0
for i in range(n):
    d[l[i]]+=1
    ans+=d[r[i]]
print(ans)

Solution (Python):
import collections
n=int(input())
a = list(map(int, input().split()))
an=0
ii=[]
jj=[]
for i in range(n):
    ii.append(i+a[i])
    jj.append(i-a[i])
jjj=collections.Counter(jj)
for i in range(n):
    an+=jjj[ii[i]]
print(an)

Solution (Python):
n = int(input())
heights = [int(ch) for ch in input().split()]
ans = 0
dict = {}
for i in range(len(heights)):
    key = i+heights[i]
    if key in dict.keys():
        dict[key] += 1
    else:
        dict[key] = 1
for i in range(len(heights)):
    key = i-heights[i]
    if key in dict.keys():
        ans+=dict[key]
print(ans)

Solution (Python):

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

import sys
import numpy as np
import itertools

sys.setrecursionlimit(10 ** 9)

N = int(input())
A = np.array(list(map(int,input().split())))
B = np.arange(N)
x = B - A
y = B + A

x = x[x>0]
y = y[y<N]
x_count = np.bincount(x, minlength = N)
y_count = np.bincount(y, minlength = N)

ans = np.sum(x_count * y_count)

print(ans)

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

R=[[] for _ in range(N)]
L=[[] for _ in range(N)]
for i in range(N):
    L[i].append(i+A[i])
    R[i].append(i-A[i])
L.sort()
R.sort()

i,j=0,0
out=0
while i<N and j<N:
    if L[i]>R[j]:
        j+=1
        continue
    elif L[i]<R[j]:
        i+=1
        continue
    if L[i] == R[j]:
        k=0
        while L[i+k]==R[j]:
            k+=1
            if i+k==N:
                break
        l=0
        while L[i]==R[j+l]:
            l+=1
            if j+l==N:
                break
        out+=k*l
        i,j=i+k,j+l


print(out)

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

B = []
for j in range(n):
    B.append(j - A[j])

C = []
for i in range(n):
    C.append(i + A[i])

d = defaultdict(int)

for j in C:
    d[j] += 1

count = 0
for k in B:
    count += d[k]

print(count)

Solution (Python):
from collections import defaultdict

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

d=defaultdict(int)
ans=0

for i, item in enumerate(a):
    d[i+item]+=1
for i, item in enumerate(a):
    ans+=d[i-item]

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):
from collections import defaultdict

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

d=defaultdict(int)
ans=0

for i, item in enumerate(a):
    d[i+item]+=1
    ans+=d[i-item]

print(ans)

Solution (Python):
n = int(input())
a = input().split()
pl = []
sb = []
for i in range(len(a)):
	pl.append(i+int(a[i])+1)
	if i - int(a[i]) > 0:
		sb.append(i-int(a[i])+1)


if len(sb) == 0:
	print('0')
else:


	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)
	
	tl = [0] * 2000000	
	for i in ssb:
		if int(i)-1 < len(tl):
			tl[int(i)-1] += 1
	
	
	
	cnt = 0
	for i in pl:
		if int(i)-1 < len(tl):
			cnt += tl[int(i)-1]

	print(cnt)

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

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

b = a[:]
c = a[:]
for i in range(N):
    b[i] += i
    c[i] -= i

cnt1 = Counter(b)
cnt2 = Counter(c)

lst = list(cnt1.keys())
lst.sort()

ans = 0

for i in range(len(lst)):
    ans += cnt1[lst[i]] * cnt2[-lst[i]]

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
values = list(map(int, input().split()))
keys = list(range(1, N + 1))

memo = defaultdict(int)
count = 0
for i, x in enumerate(values):
    count += memo[i - x]
    memo[i + x] += 1
print(count)

Solution (Python):



import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math

import bisect

class Counter(dict):

    def __init__(self, l=None):
        if l is None:
            return
        for e in l:
            self[e] += 1

    def __missing__(self, key):
        self[key] = 0
        return self[key]

def make_i_list(height_list):
    i_list = [0] * len(height_list) 
    for i, h in enumerate(height_list):
        i_list[i] = h + i
    i_list.pop(0) 
    return i_list

def make_j_list(height_list):
    j_list = [0] * len(height_list) 
    for j, h in enumerate(height_list):
        j_list[j] = - h + j
    j_list.pop(0) 
    return j_list

def make_same_ij_person_dict(i_list, j_list, same_ij_person_dict):
    for key in range(1, len(i_list)): 
        if i_list[key] == j_list[key]:
            value = i_list[key]
            same_ij_person_dict[value] += 1


if __name__ == '__main__':
    num_person = int(input())
    height_list = [0] + list(map(int, input().split())) 
    i_list = make_i_list(height_list)
    j_list = make_j_list(height_list)
    i_dict = Counter(i_list) 
    j_dict = Counter(j_list) 
    
    
    
    
    
    
    
    ans_count = 0
    for value in i_dict.keys():
        if value in j_dict.keys():
            ans_count += i_dict[value] * j_dict[value]
    print(ans_count)

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    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]
    Y.sort()

    res = 0
    for x in X:
        res += bisect.bisect_right(Y, x) - bisect.bisect_left(Y, x)
    
    print(res)


if __name__ == '__main__':
    main()

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

cnt_dic = {}

for i, a in enumerate(A, start=1):
    t = i + a

    if t in cnt_dic:
        cnt_dic[t] += 1
    else:
        cnt_dic[t] = 1


cnt = 0
for i, a in enumerate(A, start=1):
    if i - a <= 0:
        continue

    if i - a in cnt_dic:
        cnt += cnt_dic[i - a]

print(cnt)

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    A1 = [i + a for i, a in enumerate(A)]
    A2 = [i - a for i, a in enumerate(A)]
    c1 = Counter(A1)
    c2 = Counter(A2)
    c2_keys = set(c2.keys())
    ans = 0
    for key, val in c1.items():
        if key in c2_keys:
            ans += val * c2[key]

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
L = defaultdict(int)
R = defaultdict(int)
for i, a in enumerate(A):
    L[a+i] += 1
    R[i-a] += 1
ans = 0
for k, v in L.items():
    ans += v*R[k]
print(ans)

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    A1 = [i + a for i, a in enumerate(A)]
    A2 = [i - a for i, a in enumerate(A)]
    c1 = Counter(A1)
    c2 = Counter(A2)
    c2_keys = c2.keys()
    ans = 0
    for key, val in c1.items():
        if key in c2_keys:
            ans += val * c2[key]

    print(ans)

if __name__ == '__main__':
    main()

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


if __name__ == "__main__":
    main()

Solution (Python):
from collections import*
def solve():
    n = int(input())
    a = list(map(int, input().split()))

    l = []
    r = []
    for i, j in enumerate(a):
        l += [i + j]
        r += [i - j]

    cnt = 0
    l = Counter(l)
    for r in r:
        cnt += l.get(r, 0)

    
    return cnt




print(solve())

Solution (Python):
N=int(input())
ls=[int(s) for s in input().split()]
dicA={}
dicB={}
for i in range(N):
  a=i+ls[i]
  if a in dicA:
    dicA[a]+=1
  else:
    dicA[a]=1
  b=i-ls[i]
  if b in dicB:
    dicB[b]+=1
  else:
    dicB[b]=1
ans=0
for a,na in dicA.items():
  if a in dicB:
    ans+=na*dicB[a]
print(ans)

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

Solution (Python):
from collections import Counter

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

ans = 0

c = Counter()

for idx, a in enumerate(A):
    idx += 1
    
    ans += c[idx-a]
    c[idx+a] += 1
    
print(ans)

Solution (Python):
from collections import Counter
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)]
ans=0
Lc=Counter(L)
Rc=Counter(R)
for key,value in Lc.items():
    ans+=value*Rc.get(key,0)
print(ans)

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

Solution (Python):

import numpy as np


MOD = 1000000007


N = int(input())

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

M = {}
res = 0
for i in range(len(A)):
    if (A[i]+i) not in M:
        M[A[i]+i] = 1
    else:
        M[A[i]+i] +=1
    
    if (i - A[i]) in M:
        res+=M[i-A[i]]

print(res)

Solution (Python):
from collections import defaultdict
n = int(input())
a_ls = list(map(int, input().split()))
L_dict = defaultdict(int)
for i in range(n):
    Li = a_ls[i] + i + 1
    L_dict[Li] += 1

ans = 0
for j in range(n):
    Rj = j + 1 - a_ls[j]
    ans += L_dict[Rj]
print(ans)

Solution (Python):
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])

H = [0]*(5*(10**5))
L = [0]*(5*(10**5))

for i in range(N):
    if A[i] <= 2*(10**5):
        H[A[i]+i] += 1
    if i-A[i] >= 0:
        L[i-A[i]] += 1

ans = 0

for i in range(5*(10**5)):
    ans += H[i]*L[i]

print(ans)

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

a = list(map(int, input().split()))
ri = defaultdict(lambda: 0)
lj = defaultdict(lambda: 0)

ret = 0
for i in range(n):
	ri[a[i]+i]+=1
	lj[i-a[i]]+=1

for k in ri:
	if(lj[k] >= 1):
		ret+=ri[k]*lj[k]
	


print(ret)

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

Solution (Python):

from collections import*

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

l = []
r = []
for i, j in enumerate(a):
    l += [i + j]
    r += [i - j]

c = 0
l = Counter(l)
for r in r:
    c += l.get(r, 0)
print(c)

Solution (Python):







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

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

dicY=dict()
for y in Y:
    if not y in dicY:
        dicY[y]=1
    else:
        dicY[y]+=1
count=0
for x in X:
    if x in dicY:
        count+=dicY[x]
print(count)

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

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

values = dict()

count = 0
for i, h in enumerate(heights):
    left = i + h
    if left in values:
        values[left].append((i, h))
    else:
        values[left] = [(i, h)]

    r = i - h
    if r in values:
        count += len(values[r])


print(count)

Solution (Python):
from collections import Counter

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

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

Solution (Python):
import collections

N=int(input())
L,R=[0]*N,[0]*N
for i,a in enumerate(input().split()):
  L[i],R[i]=i+int(a)+1,i+1-int(a)

l=collections.Counter(L)
r=collections.Counter(R)
t=0
for i in l.keys():
  t+=l[i]*r[i]

print(t)

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

Solution (Python):
import numpy as np

n = int(input())

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

x = {}
y = {}

ans = 0

for i in range(n):
  x.setdefault((i+a[i]), []).append(i) 
  y.setdefault((i-a[i]), []).append(i)

z = list(set(x.keys()) & set(y.keys()))





for i in z:
  if x[i][len(x[i])-1] < y[i][0]:
    n = len(y[i]) * len(x[i])
    ans += n
    
    
    
    

  else:
    for j in range(len(x[i])):
      
      
      
      ans += sum(1 for k in y[i] if x[i][j] < k)

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):
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):
def solve():
    n=int(input())
    A=list(map(int,input().split()))
    l=[]
    r=[]
    d={}
    x=[]
    for i in range(n):
        l.append(i+A[i])
        r.append(i-A[i])
        if(i+A[i] not in d):
            d[i+A[i]]=[0,0]
            x.append(i+A[i])
        if(i-A[i] not in d):
            d[i-A[i]]=[0,0]
            x.append(i-A[i])
        d[i+A[i]][0]+=1
        d[i-A[i]][1]+=1
    ans=0
    for i in x:
        ans+=d[i][0]*d[i][1]
    print(ans)
solve()

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
count = 0
l_array = []
r_array = []
for i, X in enumerate(A):
    l_array.append(i + X)
    r_array.append(i - X)

counter = Counter(r_array)

for x in l_array:
    count += counter.get(x, 0)
print(count)

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
li=[]
ans=0

for i,var in enumerate(a,1):
    li.append(i+var)

li=collections.Counter(li)

for j,var in enumerate(a,1):
    ans+=li[j-var]

print(ans)

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

from collections import defaultdict
d = defaultdict(int)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
L1 = list()
D2 = dict()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    if num2 not in D2:
        D2[num2] = 1
    else:
        D2[num2] += 1
ret = 0
retlist = dict()
for l in L1:
    if l in D2.keys():
        ret += D2[l]
print(ret)

Solution (Python):
from collections import Counter

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

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

Solution (Python):
from collections import Counter

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

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
i_plus_A = Counter([i + A[i] for i in range(N)])
i_minus_A = [i - A[i] for i in range(N)]
ans = 0
for x in i_minus_A:
    ans += i_plus_A[x]
print(ans)

Solution (Python):
from collections import defaultdict

if __name__ == '__main__':
    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):
import collections
N = int(input())
A = list(map(int, input().split()))

L = []
R = []

ans = 0

for i in range(N):
    L.append(i + A[i])
    R.append(i - A[i])

r = collections.Counter(R)

for l in L:
    ans += r[l]

print(ans)

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

from collections import defaultdict
l = defaultdict(int)
r = defaultdict(int)

for i in range(n):
    l[i - a[i]] += 1
    r[i + a[i]] += 1
ans = 0
for li in l:
    ans += l[li] * r[li]

print(ans)

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

Solution (Python):
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math





start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

ans = 0
d = defaultdict(int)
for i in range(N):
    ans += d[Adif[i]]
    d[Asum[i]] += 1

print(ans)

Solution (Python):
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math





start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

ans = 0
d = defaultdict(int)
for i in range(N):
    ans += d[Adif[i]]
    d[Asum[i]] += 1

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 0
"""
A[i] + A[j] = j - i
<=> A[i] + i = j - A[j]
"""
L_i = [A[i] + i for i in range(N)]
L_j = [j - A[j] for j in range(N)]

ans_lis = [0] * (2*(10**5))
for x in L_i:
    if x < 2*(10**5):
        ans_lis[x-1] += 1
for y in L_j:
    if y > 0:
        ans += ans_lis[y-1]
print(ans)

Solution (Python):
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math



input = sys.stdin.readline

start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

ans = 0
d = defaultdict(int)
for i in range(N):
    ans += d[Adif[i]]
    d[Asum[i]] += 1

print(ans)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
a = na()

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

print(ans)

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

Solution (Python):




def solve(arr,n):
    hashmap=dict()
    for index in range(1,n+1):
        key=index+arr[index-1]
        if hashmap.get(key)!=None:
            hashmap[key]+=1
        else:
            hashmap[key]=1    
    count=0
    for index in range(1,n+1):
        key=index-arr[index-1]
        if hashmap.get(key)!=None:
            count+=hashmap[key]
    return count        






n=int(input())
arr=[int(i) for i in input().split()]
print(solve(arr,n))

Solution (Python):
from collections import Counter
n = int(input())
ai = list(map(int,input().split()))
pl = []
mi = []
for i in range(n):
    pl.append(i+ai[i])
    mi.append(i-ai[i])
x = Counter(pl)
y = Counter(mi)
cnt = 0
for i in x.keys():
    cnt += x[i]*y[i]
print(cnt)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

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

import collections
n = int(input())
a = LI()
ans = 0
r = []
l = []
for i in range(n):
    r.append(i+a[i])
    l.append(i-a[i])
cr =  collections.Counter(r)
cl =  collections.Counter(l)
for k,v in cr.items():
    ans += v*cl[k]
print(ans)

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
l=[]
r=[]
for i in range(n):
  l.append(i+a[i]+1)
  r.append(i-a[i]+1)
cl=collections.Counter(l)
cr=collections.Counter(r)
ans=0
for k,v in cl.items():
  ans+=v*cr[k]
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ai,aj=[],[]
for i in range(n):
  aj.append(i-a[i])
  ai.append(i+a[i])
c1=Counter(ai)
c2=Counter(aj)
ans=0
for k in c1.keys():
  ans+=c1[k]*c2[k]
print(ans)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint

INF = float("inf")

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())


c = []
for i in range(n):
    
    if i<a[i]:
        pass
    else:
        c.append(i-a[i])



c.sort()


ans = 0
for i in range(n):
    m = i + a[i]
    ans += mycount(c,m)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 0
plus_lis = [A[i] + i for i in range(N)]
minus_lis = [k - A[k] for k in range(N)]

ans_lis = [0] * 10 ** 6
for x in plus_lis:
    if x < 10 ** 6:
        ans_lis[x-1] += 1
for y in minus_lis:
    if y > 0:
        ans += ans_lis[y-1]
print(ans)

Solution (Python):
from collections import defaultdict
d1=defaultdict(int)
d2=defaultdict(int)
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n):
    d1[a[i]+i+1]+=1
    d2[i+1-a[i]]+=1
for v in d1.keys():
    s+=d1[v]*d2[v]
print(s)

Solution (Python):
from collections import Counter
n=int(input())
alist=list(map(int,input().split()))
a1=[]
a2=[]
for i,a in enumerate(alist):
  a2.append(i-a)
  a1.append(i+a)
aa=Counter(a2)
count=0
for k in a1:
  count+=aa.get(k,0)
print(count)

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

L = dd(set)
R = dd(set)
for i, a in enumerate(A):
    x = i + a
    L[x].add(i)
    x = i - a
    R[x].add(i)




counter = 0
for num in list(set(L.keys()) & set(R.keys())):
    counter += len(L[num]) * len(R[num])

print(counter)

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

X1_dict = {}
X2_dict = {}
inp_list = list(map(int, input().split(" ")))
for i, a_i in enumerate(inp_list):
	X1 = i + 1 + a_i
	X2 = i + 1 - a_i
	if X1 in X1_dict.keys():
		X1_dict[X1] += 1
	else:
		X1_dict[X1] = 1
	if X2 in X2_dict.keys():
		X2_dict[X2] += 1
	else:
		X2_dict[X2] = 1

answer = 0
for key, value in X1_dict.items():
	if key in X2_dict.keys():
		answer += value * X2_dict[key]
		
print(answer)

Solution (Python):
def lower_bound(arr,tar):
    def _lower_bound(first,length):
        if(length==0):
            return first

        half = length//2
        middle = first+half
        if arr[middle]<tar:
            return _lower_bound(middle+1,length-half-1)
        else:
            return _lower_bound(first,half)
    return _lower_bound(0,len(arr))

def upper_bound(arr,tar):
    def _upper_bound(first,length):
        if(length==0):
            return first

        half = length//2
        middle = first+half
        if arr[middle]>tar:
            return _upper_bound(first,half)
        else:
            return _upper_bound(middle+1,length-half-1)
    return _upper_bound(0,len(arr))

N=int(input())
a=list(map(int,input().split()))
L = [(i+1)+a[i] for i in range(N)]
R = [(i+1)-a[i] for i in range(N)]
R.sort()

s=0
for it in L:
    s+=upper_bound(R,it)-lower_bound(R,it)
print(s)

Solution (Python):
from collections import Counter

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

l = []
r = []
for i,j in enumerate(A):
    l.append(i+j)
    r.append(i-j)

num_l = Counter(l)
num_r = Counter(r)

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

Solution (Python):
from collections import defaultdict

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

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

ans = 0
for key in di.keys():
  ans += dj[key] * di[key]

print(ans)

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

Aii=[0]*(N)
Ajj=[0]*(N)

for i in range(N):
    x=A[i]+i+1
    y=i+1-A[i]
    if 1<x<N: Aii[x]+=1
    if 1<y<N: Ajj[y]+=1

ans=0
for i in range(N):
    ans+=Aii[i]*Ajj[i]

print(ans)

Solution (Python):
import collections
n=int(input())
a=list(map(int, input().split()))
ans=0
b=[]
c=[]
for i in range(n):
    b.append(i+a[i])
    c.append(i-a[i])
b=collections.Counter(b)
c=collections.Counter(c)
for i in range((10**5)*2):
    ans+=b[i]*c[i]



print(ans)

Solution (Python):
import collections
n=int(input())
a=list(map(int, input().split()))
ans=0
b=[]
c=[]
for i in range(n):
    b.append(i+a[i])
    c.append(i-a[i])
b=collections.Counter(b)
c=collections.Counter(c)
for i in range((10**5)*2):
    ans+=b[i]*c[i]



print(ans)

Solution (Python):



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


num_dic = {}
ans = 0


for i in range(1, N+1):
    a = a_nums[i-1] + i
    if not a in num_dic:
        num_dic[a] = 1
    else:
        num_dic[a] += 1


for j in range(1, N+1):
    b = j - a_nums[j-1]
    if b in num_dic:
        ans += num_dic[b]


print(ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
L=[]
R=[]
for i in range(n):
  L.append(i+A[i])
  R.append(i-A[i])
from collections import Counter
zisyo=Counter(R)
ans=0
for i in L:
  ans=ans+zisyo.get(i,0)
print(ans)

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

print(ans)