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

def main():
    
    n = int(input())
    a = list(map(int, input().split()))
    
    L = [0]*n
    R = [0]*n
    for i,ai in enumerate(a):
        L[i] = i+ai
        R[i] = i-ai
    
    count = 0
    c = Counter(R)
    for Li in L:
        count += c.get(Li,0)

    print(count)

main()

Solution (Python):
import collections

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

tmp = [0 for _ in range(N)]
for i in range(N):
  tmp[i] = (i + 1) + A[i]

c = collections.Counter(tmp)

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

print(ans)
  
'''
i < jとする
A[i] + A[j] = j - i
A[i] + i = j - A[j]
K = j - A[j]
'''

Solution (Python):
import sys






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

ans = 0

d = {}

for j in range(n):
    a1 = j - a[j]
    try:
        ans += d[a1]
    except KeyError:
        d[a1] = 0

    a2 = j + a[j]
    try:
        d[a2] += 1
    except KeyError:
        d[a2] = 1

print(ans)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *
































def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007




def main():
	N = inputInt()
	A = inputList()

	mp = {}
	ans = 0
	for i in range(N):
		ii = i+1
		tmp = ii - A[i]
		if tmp in mp:
			ans += mp[tmp]
		tmp = ii + A[i]
		if tmp in mp:
			mp[tmp] += 1
		else:
			mp[tmp] = 1

	print(ans)





def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)



def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv



def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)



if __name__ == "__main__":
	main()

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

Solution (Python):


N = int(input())
A = list(map(int, input().split()))
count=0
L = [0]*N
R = [0]*N
N2=2*N
hash_L=[0]*N2
hash_R=[0]*N2

sheet_L=[0]*N2
sheet_R=[0]*N2
for i in range(N):
    L[i]=A[i]+i+1
    if L[i]<N2:
        if sheet_L[L[i]]==0:
            hash_L[L[i]]=L[i]
            sheet_L[L[i]]=1
        else:
            sheet_L[L[i]]=sheet_L[L[i]]+1

    R[i]=-A[i]+i+1
    if R[i]>0:
        if sheet_R[R[i]]==0:
            hash_R[R[i]]=R[i]
            sheet_R[R[i]]=1
        else:
            sheet_R[R[i]]=sheet_R[R[i]]+1


for i in range(2*N):
    if not hash_L[i]==0:
        if hash_L[i]==hash_R[i]:
            count=count+sheet_L[i]*sheet_R[i]


print("{}".format(count))

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

result=0

D={}

for j in range(N):
    if j+A[j] in D:
        D[j+A[j]] += 1
    else:
        D[j+A[j]]=1

for j in range(N):
    if j-A[j] in D:
        result += D[j-A[j]]

print(result)

Solution (Python):
from collections import defaultdict

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

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

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
import collections
D=collections.defaultdict(int)
ans=0
for i in range(n):
  D[i - A[i]]+=1
for i in range(n):
  ans+=D[A[i]+i]
print(ans)

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
import collections
D=collections.defaultdict(int)
ans=0
for i in range(n):
  D[A[i]+i]+=1
for i in range(n):
  ans+=D[i-A[i]]
print(ans)

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

count = {}
ans = 0
for i in range(N):
    if (i - A[i]) in count:
        ans += count[i - A[i]]

    if (i + A[i]) in count:
        count[i + A[i]] += 1
    else:
        count[i + A[i]] = 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter, defaultdict

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    a = [0] * n
    b = [0] * n
    for i in range(n):
        a[i] = i + v[i]
        b[i] = i - v[i]

    b = Counter(b)
    ans = 0
    for c in a:
        ans += b.get(c, 0)
    print(ans)

if __name__ == '__main__':
    main()

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

ans = 0
dic = {}
for i, a in enumerate(alist):
  if dic.get(str(i-a)) is not None:
    ans += dic[str(i-a)]
  if dic.get(str(i+a)) is not None:
    dic[str(i+a)] += 1
  else:
    dic[str(i+a)] = 1
print(ans)

Solution (Python):
from collections import Counter

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

b=[]
c=[]

for n,i in enumerate(a,1):
    b.append(n-i)
    c.append(n+i)


col = Counter(c)
ans=0

for bb in b:
    ans += col[bb]

print(ans)

Solution (Python):
def Main(N, A):
    d = {}
    d2 = {}
    ans = 0
    for i in range(N):
        p = i+A[i]
        if p not in d:
            d[p] = []
        d[p].append(i)
    for i in range(N):
        q = i-A[i]
        if q not in d2:
            d2[q] = []
        d2[q].append(i)
    for k, v in d.items():
        if len(v) > 0 and k in d2:
            ans += len(v) * len(d2[k])
    return ans
        
    
def main():
    N = int(input())
    A = list(map(int, input().split()))
    print(Main(N, A))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
L, R = {}, {}
for n in range(N):
    L[n + A[n]] = L.get(n + A[n], 0) + 1
    R[n - A[n]] = R.get(n - A[n], 0) + 1
print(sum([R.get(k, 0) * v for k, v in L.items()]))

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


ans = 0
mp = {}
for i in range(N):
    i_kou = i + 1 + A[i]
    if i_kou in mp:
        mp[i_kou] += 1
    else:
        mp[i_kou] = 1
    j_kou = i + 1 - A[i]
    if j_kou in mp:
        ans += mp[j_kou]
print(ans)

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

ia = {}
pair = 0
for j, a in enumerate(la):
  ia[j + a] = ia.get(j + a, 0) + 1

for j, a in enumerate(la): 
  pair += ia.get(j - a, 0)

print(pair)

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

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

print(sum([up_lift[i] * down_lift[i] for i in range(N)]))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
up_lift = [0]*N
down_lift = [0]*N
for i in range(N):
    if i + A[i] < N:
        up_lift[i + A[i]] += 1
    if i - A[i] >= 0:
        down_lift[i - A[i]] += 1


ans = 0
for i in range(N):
    ans += up_lift[i] * down_lift[i]
print(ans)

Solution (Python):


import numpy as np

N = int(input())
A = [int(_) for _ in input().split()]









nmax = int(2e5 + 1)
X = [0] * nmax
Y = [0] * nmax
for n, a in enumerate(A):
    x = n - a
    y = n + a
    if x >= 0 and x < nmax:
        X[x] += 1
    if y >= 0 and y < nmax:
        Y[y] += 1
ret = 0
for x, y in zip(X, Y):
    ret += x * y
print(ret)

Solution (Python):
from collections import defaultdict

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

ans = 0

R = defaultdict(int) 


for i ,Ai in enumerate(A,1):
  R[i+Ai]+=1

L = defaultdict(int) 
for j ,Aj in enumerate(A,1):
  L[j-Aj]+=1

for i in R:
  ans+=R.get(i,0)*L.get(i,0)

print(ans)

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

r = []
l = []

for i,j in enumerate(a):
    r.append(i+j)
    l.append(i-j)
    
ans = 0

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

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    L = defaultdict(int)
    for i in range(N):
        L[(i + 1 + A[i])] += 1
    R = defaultdict(int)
    for i in range(N):
        R[i + 1 - A[i]] += 1
    ans = 0
    for k, v in L.items():
        ans += v * R[k]
    print(ans)


def main():
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict

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

r = defaultdict(int)
l = defaultdict(int)

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

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

print(ans)

Solution (Python):

import bisect

N = int(input()) 
A_list = [0] + [int(e) for e in input().split()]













Rj = [j - A_list[j] for j in range(1,N+1)]

X_Li_dict = dict()
for i in range(1,N+1):
    X = i + A_list[i]
    if X not in X_Li_dict:
        X_Li_dict[X] = set()

    X_Li_dict[X].add(i)

X_Rj_dict = dict()
for j in range(1,N+1):
    X = j - A_list[j]
    if X not in X_Rj_dict:
        X_Rj_dict[X] = set()
        
    X_Rj_dict[X].add(j)

ans = 0

for X_Li in X_Li_dict.items():
    X = X_Li[0]
    i_set = X_Li[1]
    
    

    if X in X_Rj_dict:
        j_list = list(X_Rj_dict[X])
        j_list.sort(reverse=False)
        
        for i in i_set:
            ans_add = len(j_list) - bisect.bisect_right(j_list,i)
            
            ans += ans_add

print(ans)

Solution (Python):
from collections import defaultdict

n=int(input())
A=list(map(int,input().split()))
B=defaultdict(int)
res=0

for i in range(n):
	B[A[i]+i]+=1
	if i-A[i] in B:
		res+=B[i-A[i]]

print(res)

Solution (Python):
import numpy as np
import sys
import math
read = sys.stdin.readline

N = int(read().rstrip())
A = list(map(int,read().rstrip().split()))
da = []
for i , a in enumerate(A):
    da.append([i,a])

dR = {}
dL = {}

ans = 0
for d in reversed(da):
    r = d[0] + d[1] + 1
    l = d[0] - d[1] + 1 
    if r in dR:
        dR[r] += 1
    else:
        dR[r] = 1

    if r in dL:
        ans += dL[r]

    if l in dL :
        dL[l] += 1
    else:
        dL[l] = 1  

print(ans)

Solution (Python):
import numpy as np
import sys
import math
import collections
read = sys.stdin.readline

N = int(read().rstrip())
A = list(map(int,read().rstrip().split()))
da = []
for i , a in enumerate(A):
    da.append([i,a])

dR = collections.defaultdict(int)
dL = collections.defaultdict(int)

ans = 0
for d in reversed(da):
    r = d[0] + d[1] + 1
    l = d[0] - d[1] + 1 

    dR[r] += 1

    ans += dL[r]

    dL[l] += 1  

print(ans)

Solution (Python):
import numpy as np
import sys
import math
import collections
read = sys.stdin.readline

N = int(read().rstrip())
A = list(map(int,read().rstrip().split()))
da = []
for i , a in enumerate(A):
    da.append([i,a])

dR = collections.defaultdict(int)
dL = collections.defaultdict(int)

ans = 0
for d in reversed(da):
    r = d[0] + d[1] + 1
    l = d[0] - d[1] + 1 

    dR[r] += 1

    ans += dL[r]

    dL[l] += 1  

print(ans)

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

left = defaultdict(int)
for i in range(n):
    left[i + a[i]] += 1

ans = 0
for i in range(n):
    sub = i - a[i]
    if sub in left:
        ans += left[sub]

print(ans)

Solution (Python):


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


i_minus_Ai = [0] * (N+1)
j_plus_Aj = [0] * (N+1)

for i in range(1, N+1):
    minus = i - A[i]
    plus = i + A[i]
    
    if(2 <= minus and minus <= N):
        i_minus_Ai[minus] += 1
    if(2 <= plus and plus <= N):
        j_plus_Aj[plus] += 1


ans = 0
for i in range(N+1):
    ans += i_minus_Ai[i] * j_plus_Aj[i]
print(ans)

Solution (Python):




def input_int_list_with_length(length=None):
    if length == None:
        length = int(input())
    return list(map(int, input().split()))[:length]


def solve(N, A):
    ans = 0
    L = {}
    for i in range(N):
        l = i+A[i]
        if l in L:
            L[l] += 1
        else:
            L[l] = 1
    for i in range(N):
        r = i-A[i]
        if r in L:
            ans += L[r]

    print(ans)


def main():
    A = input_int_list_with_length()
    solve(len(A), A)


if __name__ == '__main__':
    main()

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

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

i_plus_Ai = [0]*n
j_minus_Aj = [0]*n
for i in range(n):
    if 0 <= i+a[i] < n:
        i_plus_Ai[i+a[i]] += 1
    if 0 <= i-a[i] < n:
        j_minus_Aj[i-a[i]] += 1

cnt = 0
for i, j in zip(i_plus_Ai, j_minus_Aj):
    cnt += i*j
print(cnt)

Solution (Python):

import sys
imput = sys.stdin.readline
def main():
    
    from collections import Counter
    N = int(input())
    A = list(map(int, input().split()))


    B = [i-a for i, a in enumerate(A) if i-a > 0]    
    C = [i+a for i, a in enumerate(A)]
    D = Counter(C)

    answer = 0
    for b in B:
        answer += D[b]

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

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

mp = [0] * n

ans = 0

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

print(ans)

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

diffMax = 2 * max(heights)
diffMin = 2 * min(heights)

cnt = 0

arrSize = min([max([i + heights[i] for i in range(len(heights))]),max([i - heights[i] for i in range(len(heights))])]) + 1

seppenPlus = [0] * arrSize
seppenMinus = [0] * arrSize


for i in range(len(heights)):
    seppenPlusNum = i + heights[i]
    seppenMinusNum = i - heights[i]

    if seppenPlusNum < arrSize:
    	seppenPlus[seppenPlusNum] += 1

    if seppenMinusNum >= 0:
        seppenMinus[seppenMinusNum] += 1

for i in range(len(seppenPlus)):
    cnt += seppenPlus[i] * seppenMinus[i]

print(cnt)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
num = {}
cnt = 0
for i in range(n):
    i_minus_Ai = i-a[i]
    if i_minus_Ai in num:
        cnt += num[i_minus_Ai]

    i_plus_Ai = i+a[i]
    if i_plus_Ai in num:
        num[i_plus_Ai] += 1
    else:
        num[i_plus_Ai] = 1
print(cnt)

Solution (Python):
import numpy as np
import sys
import math
read = sys.stdin.readline

N = int(read().rstrip())
A = list(map(int,read().rstrip().split()))
da = []
for i , a in enumerate(A):
    da.append([i,a])

dR = {}
dL = {}

ans = 0
for d in reversed(da):
    r = d[0] + d[1] + 1
    l = d[0] - d[1] + 1 
    if r in dR:
        dR[r] += 1
    else:
        dR[r] = 1

    if r in dL:
        ans += dL[r]

    if l in dL :
        dL[l] += 1
    else:
        dL[l] = 1  

print(ans)

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

B = {}
for i, a in enumerate(A):
    aa1 = i + 1 - a
    if aa1 > 0:
        if aa1 not in B:
            B[aa1] = []
        B[aa1].append((i + 1, a))

count = 0
for i, a in enumerate(A):
    aa1 = i + 1 + a
    if aa1 in B:
        count += len(B[aa1])
print(count)

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

b = [j - i for i, j in enumerate(a, start=1)]

count = {}
for i, j in enumerate(a, start=1):
    num = -i-j
    if num not in count:
        count[num] = 0
    count[num] += 1
result = sum([count.get(i, 0) for i in b])
print(result)

Solution (Python):
from math import sqrt

person = int(input())
longs = list(map(int, input().split(" ")))

longsi_dic = {}
for i in range(len(longs)):
    if str(i + longs[i]) not in longsi_dic:
        longsi_dic[str(i + longs[i])] = 0
    longsi_dic[str(i + longs[i])] += 1

longsj_dic = {}
for j in range(len(longs)):
    if str(j - longs[j]) not in longsj_dic:
        longsj_dic[str(j - longs[j])] = 0
    longsj_dic[str(j - longs[j])] += 1

sum = 0
for val, sumi in longsi_dic.items():
    if val not in longsj_dic:
        continue
    sum += int(sumi) * int(longsj_dic[val])

print(sum)

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

main()

Solution (Python):
N = int(input())
A = [int(v) for v in input().split()]
L, R = {}, {}
for i,a in enumerate(A):
  l,r = i+a,i-a
  if l not in L: L[l]=0
  if r not in R: R[r]=0
  L[l]+=1
  R[r]+=1

count = 0
for X in L:
  if X not in R: continue
  count += L[X]*R[X]
print(count)

Solution (Python):
from itertools import combinations

def detect_v1(N, A):
    count = 0
    for n, m in combinations(range(len(A)), 2):
        if abs(n - m) == A[n] + A[m]:
            count += 1

    
    return count






from collections import defaultdict

def detect_v2(N, A):
    dict_i = defaultdict(set)

    count = 0
    for n in range(N):
        dict_i[n +  A[n]].add(n)
        
        if n - A[n] in dict_i:
            count += len(dict_i[n - A[n]])

    
    
    return count

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    c = detect_v2(N, A)
    print(c)

Solution (Python):
n = int(input())
a = [num for num in map(int, input().split())]
a.insert(0, 0)




ans = 0
m = {}

for j in range(1, n+1):
  
  j_val = j - a[j]
  if j_val in m:
    ans += m[j_val]
  
  
  i_val = a[j]+j
  if i_val in m:
    m[i_val] += 1
  else:
    m[i_val] = 1
print(ans)

Solution (Python):


n = int(input())

a = input().split()

count = 0

r = [(n - int(m)) for n,m in enumerate(a)]
l = [(n + int(m)) for n,m in enumerate(a)]

r.remove(r[0])
l.remove(l[-1])

mar = max(r)
mir = min(r)
mal = max(l)
mil = min(l)

R = {}
L = {}

for n,m in zip(r,l):
    R[n] = 0
    L[m] = 0

for n,m in zip(r,l):
    R[n] += 1
    L[m] += 1

for i in R.keys():
    if i in L.keys():
        count += R[i] * L[i]

print("{}".format(count))

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

Solution (Python):
import collections

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

i_s = [i + 1 + Heights[i] for i in range(N)]
j_s = [j + 1 - Heights[j] for j in range(N)]

CTR_i = collections.Counter(i_s)
CTR_j = collections.Counter(j_s)

i_value = CTR_i.keys()
total = 0

for v in i_value:
    N_i = CTR_i[v]
    N_j = CTR_j[v]
    
    total += N_i * N_j

print(total)

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

b=[]
for i in range(n):
    b.append(a[i]-i)

c = collections.Counter(b)

m=0
for i in range(n):
    m+=c[-(i+a[i])]
    c[a[i]-i]-=1
print(m)

Solution (Python):
from collections import defaultdict as dfd

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

d = dfd(int)
ans = 0

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


print(ans)

Solution (Python):


from collections import Counter

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


diff = Counter(a[j] - (j+1) for j in range(n))


count = sum(diff[-a[i] - (i+1)] for i in range(n))
print(count)

Solution (Python):



n=int(input())
a=list(map(int,input().split()))
import collections 
d=collections.defaultdict(int)
ans=0

for i in range(n):
    left=i-a[i]
    ans+=d[left]
    d[a[i]+i]+=1
    
print(ans)

Solution (Python):
def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))

    npa = ct([i+1+j for i, j in enumerate(a)])
    nma = ct([i+1-j for i, j in enumerate(a)])

    cnt = 0

    for i, j in npa.items():
        cnt += j*nma[i]
    print(cnt)


main()

Solution (Python):
def main():
    int(input())

    d = {}
    ans = 0
    d_get = d.get
    for i, height in enumerate(input().split()):
        height = int(height)
        
        
        got = d_get(i + height) or 0
        d[i + height] = got + 1
        ans += d_get(i - height) or 0

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):







def main():
    int(input())

    d = {}
    ans = 0
    d_setdefault = d.setdefault
    d_get = d.get
    for i, height in enumerate(input().split()):
        height = int(height)
        
        
        got = d_get(i + height) or 0
        d[i + height] = got + 1
        ans += d_setdefault(i - height, 0)

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):







def main():
    int(input())

    d = {}
    ans = 0
    d_setdefault = d.setdefault
    for i, height in enumerate(input().split()):
        height = int(height)
        
        
        d_setdefault(i + height, 0)
        d[i + height] += 1
        ans += d_setdefault(i - height, 0)

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):







def main():
    int(input())

    d = {}
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        
        
        d.setdefault(i + height, 0)
        d[i + height] += 1
        ans += d.setdefault(i - height, 0)

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):







def main():
    int(input())

    d = {}
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        
        
        got = d.get(i + height) or 0
        d[i + height] = got + 1
        ans += d.get(i - height) or 0

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
class Map(dict):
    def __missing__(self, key):
        self[key] = 0
        return 0


def main():
    int(input())

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        
        
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
class Map(dict):
    def __missing__(self, key):
        return 0


def main():
    int(input())

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
class Map(dict):
    default_value = 0

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


def main():
    int(input())

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
class Map(dict):
    def __missing__(self, key):
        default_value = 0
        self[key] = default_value
        return default_value


def main():
    int(input())

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
import collections
n = int(raw_input())
hs = map(int, raw_input().split(' '))
def f(nums):
	cc,count = collections.Counter(), 0

	
	for i in range(len(nums)-1, -1, -1):
		count += cc[nums[i] + i]
		cc[i - nums[i]]+=1
	return count
		


print f(hs)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np
    from collections import Counter
    N = int(input())
    A = np.array(list(map(int, input().split())))

    count = 0

    tmp = np.arange(N)
    X = A-tmp
    Y = A+tmp

    
    
    XX = Counter(list(X))
    YY = Counter(list(Y))

    count = 0
    
    
    for number, c in XX.items():
        count += YY[-number] * c
        
    print(count)


if __name__ == "__main__":
    main()

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

J=[0]*N
j=0
while j<N:
    J[j]=j-A[j]
    j+=1

import collections
C = collections.Counter(J)

ans=0
i=0
while i<N:
    ans+=C[i+A[i]]
    i+=1

print(ans)

Solution (Python):
import collections
goukei = 0

N = int(input())
Ai = list(map(int, input().split()))
number = [j for j in range(1, N+1, 1)]
plus_Ai = [x + y for (x, y) in zip(Ai, number)]
minus_Ai = [x - y for (y, x) in zip(Ai, number)]
c = collections.Counter(plus_Ai)

for i in minus_Ai:
    goukei += c[i]
print(goukei)

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

J=[0]*N
j=0
while j<N:
    J[j]=j-A[j]
    j+=1

import collections
C = collections.Counter(J)

ans=0
i=0
while i<N:
    ans+=C[i+A[i]]
    i+=1

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
seq = [(int(x),i) for i, x in enumerate(input().split())]
seq1 =(i-x for x,i in seq)
seq2 =(i+x for x,i in seq)

d1 = dict()
d2 = dict()
s1 = set()
s2 = set()
for val in seq1:
    try:
        d1[val] += 1
    except:
        d1[val] = 1
for val in seq2:
    try:
        d2[val] += 1
    except:
        d2[val] = 1

ans = 0
for key in d1:
    try:
        ans += d1[key] * d2[key]
    except:
        pass

print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
d = {}
x = 0

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

print(x)

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    6
    2 3 3 1 3 1

    j-i = A[i]+A[j]
    A[i]+i = j-A[j]
    L[i] = A[i]+i
    R[i] = i-A[i]
    """
    N = read_int()
    A = read_ints()
    L = sorted(a+i for i, a in enumerate(A))
    R = sorted(i-a for i, a in enumerate(A))
    i, j = 0, 0
    count = 0
    total = 0
    prev_a = None
    for a in L:
        if a != prev_a:
            count = 0
            while j < len(R) and a >= R[j]:
                if a == R[j]:
                    count += 1
                else:
                    count = 0
                j += 1
        total += count
        prev_a = a
    return total


if __name__ == '__main__':
    print(solve())