Problem:
 Score: 500 points    Problem Statement  You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.  There are N attendees in the party, and they are given attendee numbers from 1 through N . The height of Attendee i is A_i .  According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.   The absolute difference of their attendee numbers is equal to the sum of their heights.   There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?  P.S.: We cannot let you know the secret.      Constraints   All values in input are integers.  2 \leq N \leq 2 \times 10^5  1 \leq A_i \leq 10^9\ (1 \leq i \leq N)         Input  Input is given from Standard Input in the following format:  N  A_1  A_2  \dots  A_N       Output  Print the number of pairs satisfying the condition.        Sample Input 1 6
2 3 3 1 3 1      Sample Output 1 3   A_1 + A_4 = 3 , so the pair of Attendee 1 and 4 satisfy the condition.  A_2 + A_6 = 4 , so the pair of Attendee 2 and 6 satisfy the condition.  A_4 + A_6 = 2 , so the pair of Attendee 4 and 6 satisfy the condition.   No other pair satisfies the condition, so you should print 3 .       Sample Input 2 6
5 2 4 2 8 8      Sample Output 2 0  No pair satisfies the condition, so you should print 0 .       Sample Input 3 32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5      Sample Output 3 22

Solution (Python):
from collections import Counter
n = int(input())
ns = list(map(int, input().split()))
xma = [x - a for x, a in enumerate(ns)]
xpa = [x + a for x, a in enumerate(ns)]
m = Counter(xma)
p = Counter(xpa)
cnt = 0
for key, value in m.items():
    if key in p:
        cnt += value * p[key]
print(cnt)

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

tasi=[0]*n
hiki=[0]*n

for i in range(n):
    wa=i+a[i]
    sa=i-a[i]
    if(wa<n):
        tasi[wa]+=1
    if(sa>=0):
        hiki[sa]+=1

ans=0

for i in range(n):
    ans+=tasi[i]*hiki[i]

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
B = [A[i]+i for i in range(N)]
C = [i-A[i] for i in range(N)]
d1 = defaultdict(lambda:0)
d2 = defaultdict(lambda:0)
for b in B:
    d1[b] += 1
for c in C:
    d2[c] += 1
ans = 0
for b in d1:
    ans += d1[b]*d2[b]

print(ans)

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

print(ans)

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

R = {}

for i in range(1 , N):
  t = A[0] + A[i] - i
  if t in R:
    R[t] += 1
  else:
    R[t] = 1

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

print(ans)

Solution (Python):
from collections import Counter

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

ct = Counter(a - i for i, a in enumerate(A))
ans = 0
for i, a in enumerate(A):
    ans += ct[-a - i]
print(ans)

Solution (Python):
from collections import defaultdict


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

hs = defaultdict(int)
cnt = 0

for i, height in enumerate(al):
    num = i + 1
    if i-height in hs:
        cnt += hs[i-height]
    hs[i+height] += 1
print(cnt)

Solution (Python):
from collections import defaultdict
n=int(input())
A=[int(i) for i in input().split()]
d=defaultdict(int)

b=[A[i] - (i+1) for i in range(n)]
c=[A[i] + (i+1) for i in range(n)]

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
d=[0 for i in range(n)]
for i in range(n):
  t=i-a[i]
  if t>=0:
    d[t]+=1
s=0
for i in range(n):
  t=i+a[i]
  if t<n:
    s+=d[t]
print(s)

Solution (Python):
import collections

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

result = 0
ai = [0]*n
aj = [0]*n

for i in range(n):
    ai[i] = a[i]+i+1
    aj[i] = i+1-a[i]
aj_num = collections.Counter(aj)
    
for i in range(n-1):
    aj_num[aj[i]] -= 1
    result += aj_num[ai[i]]
    
print(result)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    dic = {}
    ans = 0
    for i in range(n):
        x = a[i] - (i+1)
        if x in dic:
            ans += dic[x]
        y = -1 * a[i] - (i+1)
        if y in dic:
            dic[y] += 1
        else:
            dic[y] = 1
    print(ans)

if __name__ == "__main__":
    main()

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

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

bi = [0] * n
ci = [0] * n

for i, aa in enumerate(ai):
    bi[i] = aa + i
    ci[i] = aa - i



bi_dict = {}
ci_dict = {}
for i in range(n):
    bi_dict[bi[i]] = bi_dict.get(bi[i], 0) + 1
    ci_dict[ci[i]] = ci_dict.get(ci[i], 0) + 1

ans = 0
for b in bi_dict:
    ans += bi_dict[b] * ci_dict.get(-b, 0)
print(ans)

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





d1 = {}
d2 = {}
for i in range(n):
    if a[i]+i in d1:
        d1[a[i]+i] += 1
    else:
        d1[a[i]+i] = 1
    if -(a[i]-i) in d2:
        d2[-(a[i]-i)] += 1
    else:
        d2[-(a[i]-i)] = 1
ans = 0
for i in d1:
    if i in d2:
        ans += d1[i] * d2[i]
print(ans)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
key = [0]*n
for i in range(n):
  if a[i]+i >= n:
    continue
  key[a[i]+i] += 1
ans = 0
for i in range(n):
  if i-a[i] < 0:
    continue
  ans += key[i-a[i]]
print(ans)

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

li1 = [i+1-A[i] for i in range(N)]
li2 = [A[i]+i+1 for i in range(N)]

cnt = [0 for i in range(2*N+1)]
for i in li2:
    if i<len(cnt)-1:
        cnt[i] += 1

ans = 0
for i in li1:
    if i>=0:
        ans += cnt[i]
print(ans)

Solution (Python):
from collections import defaultdict,Counter
N = int(input())
A = [int(c) for c in input().split()]
B = [c-i for i,c in enumerate(A)]
dic = defaultdict(int)
Cnt = Counter(B)
ans = 0
for i,c in enumerate(B):
  dic[c] += 1
  ans += Cnt[-2*i-c]-dic[-2*i-c]
print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = {}
    r = 0
    for i, v in enumerate(A, start = 1):
        if -i-v in d:
            d[-i-v] += 1
        else:
            d[-i-v] = 1
        if v-i in d:
            r += d[v-i]
    return r
print(main())

Solution (Python):
N = int(input())
Attendees = list(map(int, input().split()))
Groups = [[0,0] for _ in range(N)]
for pos, number in enumerate(Attendees):
    if pos - number >= 0:
        Groups[pos - number][0] += 1

    if pos + number < N:
        Groups[pos + number][1] += 1

ans = 0
for elt in Groups:
    ans += elt[0] * elt[1]
print(ans)

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

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

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

print(ans)

Solution (Python):
import collections

n = int(input())
a = [int(i) for i in input().split()]
a_i = [i - aa for i, aa in enumerate(a)]
a_j = [j + aa for j, aa in enumerate(a)]

ci = collections.Counter(a_i)
cj = collections.Counter(a_j)
ans = 0
for item, value in ci.items():
    if item in cj.keys():
        ans += cj[item] * ci[item]
print(ans)

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

s = [i + 1 + a[i] for i in range(n)]
dic = {}
for i in range(n):
    d = i + 1 - a[i]
    if d in dic:
        dic[d] += 1
    else:
        dic[d] = 1
ans = sum([dic[si] if si in dic else 0 for si in s])
print(ans)

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

al_m = [i - idx for idx, i in enumerate(al)]
al_m2 = [-i - idx for idx, i in enumerate(al)]

al_p = [i + idx for idx, i in enumerate(al)]
al_p2 = [-i + idx for idx, i in enumerate(al)]

from collections import defaultdict
dic = defaultdict(int)

ans = 0
for a in al_m:
    dic[a] += 1
for a in al_m2:
    ans += dic[a]

dic = defaultdict(int)
for a in al_p:
    dic[a] += 1
for a in al_p2:
    ans += dic[a]

print(ans//2)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
cnt1 = {}
cnt2 = {}
for i in range(n):
    x = a[i] + i
    y = i- a[i]
    if x not in cnt1:cnt1[x] = 1
    else:cnt1[x] += 1
    if y not in cnt2:cnt2[y] = 1
    else:cnt2[y] += 1
ans = 0
for num in cnt1:
    if num not in cnt2:continue
    x = cnt2[num]
    ans += x*cnt1[num]
for num in cnt2:
    if num not in cnt1:continue
    x = cnt1[num]
    ans += x*cnt2[num]
ans //= 2
print(ans)

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


cnt = 0
starts = [0 for _ in range(n)]
for i, v in enumerate(a):
    next_idx = v + i + 1
    if next_idx < n:
        starts[next_idx] += 1
    if 0 <= i - v + 1 <= n-1:
        cnt += starts[i - v + 1]
print(cnt)

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

d = {}
res = 0
for _i, a in enumerate(A):
    i = _i + 1
    if i - a in d:
        res += d[i - a]
    d[a + i] = 1 if a + i not in d else d[a+i] + 1

print(res)

Solution (Python):
from collections import Counter

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

B = [0]*N
for i in range(N):
    B[i] = i - A[i]

C = Counter(B)

ans = 0
for j in range(N-1):
    d = A[j]+j
    ans += C[d]
    C[B[j]] -= 1

print(ans)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
r=[0 for i in range(n)]
l=[0 for i in range(n)]

for i in range(n):
    if A[i]+i<n:
        r[A[i]+i]+=1
    if i-A[i]>=0:
        l[i-A[i]]+=1

ans=0
for i in range(n):
    ans+=r[i]*l[i]
print(ans)

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

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

def main():
    mod=10**9+7
    N=I()
    A=LI()
    
    from collections import defaultdict
    dd1 = defaultdict(int)
    dd2 = defaultdict(int)
    
    for i in range(N):
        dd1[A[i]+i]+=1
        dd2[i-A[i]]+=1
        
    ans=0    
    for k,v in dd1.items():
        ans+=v*dd2[k]
        
    print(ans)
    
main()

Solution (Python):
from collections import Counter

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

Bs = [i-A for i, A in enumerate(As)]
cnt = Counter(Bs)

ans = 0
for L in range(N):
    AL = As[L]
    cnt[L-AL] -= 1
    ans += cnt[L+AL]

print(ans)

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

sum_dict = {}
diff_dict = {}
for i in range(N):
    try:
        sum_dict[i + A[i]] += 1
    except:
        sum_dict[i + A[i]] = 1
    try:
        diff_dict[i - A[i]] += 1
    except:
        diff_dict[i - A[i]] = 1
ans = 0
for key in sum_dict:
    try:
        ans += sum_dict[key] * diff_dict[key]
    except:
        pass
print(ans)

Solution (Python):
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    cnt=defaultdict(int)
    n=II()
    aa=LI()
    pp=[]
    mm=[]
    for i,a in enumerate(aa):
        pp.append(i+aa[i])
        mm.append(i-aa[i])
    
    
    ans=0
    for p,m in zip(pp[::-1],mm[::-1]):
        ans+=cnt[p]
        if m>0:cnt[m]+=1
    print(ans)

main()

Solution (Python):
import collections
N = int(input())
A = [int(_) for _ in input().split()]
B = [v - i for i, v in enumerate(A)]
C = collections.Counter(B)
ans = 0
for i, b in enumerate(B):
    C[b] -= 1
    ans += C[-(b + 2 * i)]
print(ans)

Solution (Python):
import sys
from collections import defaultdict as dd
from bisect import bisect_left as bl
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = a[: ]
res = 0
for i in range(N): b[i] -= i
d = dd(list)
for i in range(N): d[b[i]].append(i)
for i in range(N):
  x = b[i] + i * 2
  j = bl(d[-x], i)
  res += len(d[-x]) - j
print(res)

Solution (Python):
import bisect
n = int(input())
a = list(map(int, input().split()))
ans = 0
l_dp = []
r_dp = []
for i in range(n):
    l_dp.append(a[i]+i)
    r_dp.append(n-i-1-a[n-i-1])
r_dp.sort()
for i in l_dp:
    if i < 0 or i >= n: continue
    l_index = bisect.bisect_left(r_dp, i)
    r_index = bisect.bisect_right(r_dp, i)
    ans += r_index - l_index
print(ans)

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

ans=0
dic=defaultdict(int)

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

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

Dic1={}
set1=set()
for i in range(1,N+1):
    temp=i-A[i]
    if temp in set1:
        Dic1[temp]=Dic1[temp]+1
    else:
        Dic1[temp]=1
        set1.add(temp)



Dic2={}
set2=set()
for j in range(1,N+1):
    temp=j+A[j]
    if temp in set2:
        Dic2[temp]=Dic2[temp]+1
    else:
        Dic2[temp]=1
        set2.add(temp)




ans=0
for k in range(len(set1)):
    now=set1.pop()
    if now in set2:
        ans+=Dic1[now]*Dic2[now]

print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
sa = defaultdict(int)
for i,x in enumerate(a):
    sa[(i+1)-x] += 1
res = 0
for i,x in enumerate(a):
    res += sa[i+1+x]
print(res)

Solution (Python):
from collections import Counter

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

li1 = [i + e for i, e in enumerate(a, 1)]
li2 = [i - e for i, e in enumerate(a, 1)]

c1 = Counter(li1)
c2 = Counter(li2)

ans = 0
for k, v in c1.items():
    v2 = c2[k]
    ans += v * v2

print(ans)

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

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

dict_ = {}

ans = 0
for i in range(N):
  k = (i+1) - A[i]
  if k in dict_:
    ans += dict_[k]
  ad = (i+1) + A[i]
  if ad in dict_:
    dict_[ad] = dict_[ad] + 1
  else:
    dict_[ad] = 1

print(ans)

Solution (Python):

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

count = 0
dict_height = {}

for i in range(N):
  target = i+1-A[i]
  if target in dict_height.keys():
    count += dict_height[target]
  height = i+1+A[i]
  if height in dict_height.keys():
    dict_height[height] += 1
  else:
    dict_height[height] = 1

print(count)

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

B = {}

for i in range(N):
    
    c = i + 1 - A[i]
    if c not in B.keys():
        B[c] = 1
    else: B[c] += 1



ans = 0
for i in range(N):
    c = A[i] + i + 1
    if c in B.keys():
        ans += B[c]
print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
d = defaultdict(list)
A = list(map(int, input().split()))
li = []
for i in range(N):
    a = A[i]
    li.append(i+a)
    d[i-a].append(i)
ans = 0
for x in li:
    ans += len(d[x])
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mem={}
for i in range(n):
    if i+1-a[i] not in mem:
        mem[i+1-a[i]]=[0,1]
    else:
        mem[i + 1 - a[i]][1]+=1
    if i+1+a[i] not in mem:
        mem[i+1+a[i]]=[1,0]
    else:
        mem[i+1+a[i]][0]+=1
s=0
mem2=list(mem.values())
for i in range(len(mem2)):
    s+=mem2[i][0]*mem2[i][1]
print(s)

Solution (Python):



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


def main():
    d = {N - A[-1]: 1}
    ans = 0
    for i in range(N - 2, -1, -1):
        x = i + 1 + A[i]
        ans += 0 if x not in d else d[x]
        y = i + 1 - A[i]
        if y in d:
            d[y] += 1
        else:
            d[y] = 1
    
    print(ans)


if __name__ == "__main__":
    main()

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):
  if i-arr[i-1] in cnt:
    ans+=cnt[i-arr[i-1]]
  cnt[i+arr[i-1]]+=1
print(ans)

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

N = int(input())

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

T = defaultdict(list)
for i,a in enumerate(A):
    T[a-i].append(i)

cnt = 0
for i,a in enumerate(A):
    x = -a-i
    if x in T:
        l = T[x]
        cnt += len(l) - bisect(l, i)

print(cnt)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
i, j = [], []
for s in range(n):
    num = s+1
    i.append(a[s]+num)
    j.append(num-a[s])
x = Counter(j)
result = 0
for p in range(n-1):
    if i[p] in x:
        result += x[i[p]]
    x[j[p]] += 1 
print(result)

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

def s_in():
    return input()

def n_in():
    return int(input())

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

n=n_in()
A=l_in()
B=[i-A[i] for i in range(n)]

from collections import Counter
c= Counter(B)

res = 0
for i in range(n):
    res += c[A[i]+i]

print(res)

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(N)]
R=[0 for i in range(N)]

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


print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





N = inputI()
A = inputIL()

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

key = list(set(a)|set(b))
dic = {k:0 for k in key}
for k in a:
  dic[k] += 1

ans = 0
for i in range(N):
  dic[a[i]] -= 1
  ans += dic[b[i]]

print(ans)

Solution (Python):
from collections import defaultdict

def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))

n = inp()
nums = [0] + inlt()
num_dict = defaultdict(int)
cnt = 0
for i in range(1,n + 1):
    num_dict[i - nums[i]] += 1

for i in range(1,n + 1):
    ii = i + nums[i]
    jj = i - nums[i]
    if num_dict[jj] > 0:
        num_dict[jj] -= 1
    cnt += num_dict[ii]
    

print(cnt)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    aii = [0 for _ in range(N)]
    negajj = [0 for _ in range(N)]
    for i, a in enumerate(A):
        i += 1
        aii[i-1] = a + i
        negajj[i-1] = -(a - i)
    setaii = collections.Counter(aii)
    setnegajj = collections.Counter(negajj)
    cnt = 0
    for elem in aii:
        cnt += setnegajj[elem]
    print(cnt)
main()

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

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

l = [0] * len(A)
r = [0] * len(A)

for i,a in enumerate(A):
    if i - a >= 0:
        l[i - a] += 1
    if i + a < len(A):
        r[i + a] += 1

ans = 0

for x,y in zip(l, r):
    ans += x * y

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
B = [i+a for i, a in enumerate(A)]
C = [j-a for j, a in enumerate(A)]

bc = Counter(B)
cc = Counter(C)

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = list(range(1, n + 1))
B = LI()
ans = 0
D = defaultdict(int)
for i in range(n - 1):
    D[A[i] + B[i]] += 1
    ans += D[A[i + 1] - B[i + 1]]

D2 = defaultdict(int)
for i in range(n - 1, 0, -1):
    D2[A[i] - B[i]] += 1
    ans += D2[A[i - 1] + B[i - 1]]

print(ans // 2)

Solution (Python):
from collections import defaultdict
import bisect
def f():
    return []

d=defaultdict(f)
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)]
for i in range(n):
    d[y[i]].append(i)

ans=0
for i in range(n):
    p=x[i]
    ans+=len(d[p])-bisect.bisect_right(d[p],i)
print(ans)

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

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

a_j = []
a_i = []

for i in range(n):
    a_j.append((i + 1) - a[i])
    a_i.append((i + 1) + a[i])

from collections import Counter

c1 = Counter(a_i)
c2 = Counter(a_j)
ans = 0
for c in c1.keys():
    ans += c1[c]*c2[c]
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, Counter
from sys import exit
import math


def main():
    n = getN()
    nums = getList()
    den = [num - i for i, num in enumerate(nums)]
    cnt = Counter(den)
    ans = 0
    for i in range(n-1):
        k1, k2 = nums[i], nums[i+1]
        su = k1 + k2
        tgt = den[i+1] - su + 1
        if tgt in cnt.keys():
            ans += cnt[tgt]
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):




from collections import defaultdict


def main():
    N = int(input())
    A = list(map(int,input().split()))
    D = defaultdict(int)
    for i in range(N):
        D[A[i]+i] +=1
    s = 0
    for i in range(N):
        s += D[i-A[i]]
    print(s)
    pass

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
plus = {}  
minus = {}  
for i in range(n):
    try:
        plus[i + a[i]] += 1
    except:
        plus[i + a[i]] = 1
    
    if i - a[i] > 0:
        try:
            minus[i - a[i]] += 1
        except:
            minus[i - a[i]] = 1

ans = 0
for key in plus.keys() & minus.keys():
    ans += plus[key] * minus[key]
print(ans)

Solution (Python):
def examA():
    S = SI()
    if S=="ARC":
        ans = "ABC"
    else:
        ans = "ARC"
    print(ans)
    return

def examB():
    N, K = LI()
    snuke = set(range(1,N+1))
    for _ in range(K):
        d = I()
        A = LI()
        for a in A:
            snuke.discard(a)
    ans = len(snuke)
    print(ans)
    return

def examC():
    N, M = LI()
    H = LI()
    good = set(range(1,N+1))
    for _ in range(M):
        a, b = LI()
        if H[a-1]>=H[b-1]:
            good.discard(b)
        if H[b-1]>=H[a-1]:
            good.discard(a)
    ans = len(good)
    print(ans)
    return

def examD():
    X = I()
    
    for a in range(-1000,1000):
        for b in range(-1000,1000):
            if a**5-b**5==X:
                print(a,b)
                return
    return

def examE():
    N = I()
    A = LI()
    B = [0]*N
    D = defaultdict(int)
    for i in range(N):
        B[i] = A[i]-i
        c = A[i]+i
        D[c] += 1
    
    
    ans = 0
    for b in B:
        ans += D[-b]
    print(ans)
    return

def examF():
    N, A, B, C = LI()
    S = [SI()for _ in range(N)]
    ans = [""]*N


    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

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

Solution (Python):
from collections import Counter
n,*a=map(int,open(0).read().split())
b=[a[i]+(i+1) for i in range(n)]
c=[(i+1)-a[i] for i in range(n)]
k=set(b)&set(c)
b=Counter(b)
c=Counter(c)
ans=0
for i in k:
  ans+=b[i]*c[i]
print(ans)

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

Solution (Python):
from collections import Counter


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    l1 = [i-a[i] for i in range(n)]
    l2 = [a[i]+i for i in range(n)]
    c1 = Counter(l1)
    c2 = Counter(l2)
    ans = 0
    for i in l1:
        ans += c2[i]
    print(ans)


if __name__ == '__main__':
    solve()

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

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
info = [0 for i in range(10**6)]
mid = 5*10**5

for i in range(n):
    if(a[i]<=2*10**5):
        num = a[i] - i
        info[mid + num] += 1

ans = 0
for i in range(n):
    if(a[i]<=2*10**5):
        num = a[i] - i
        ans += info[mid + num - a[i]*2]

print(ans)

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

res = 0
dic=dd(int)

for i in range(1,N):
    tmp = a[i]-i
    dic[tmp] += 1
for i in range(N-1):
    tgt = -a[i]-i
    res += dic[tgt]
print(res)

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

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

Solution (Python):
import collections
import math
import operator as op
from functools import reduce
from collections import Counter
import numpy as np
import math
import bisect
import heapq


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    N = get_input(int)
    A = get_inputs(int)

    ans = 0
    Ai_plus_i = collections.Counter()
    for j in range(1, N+1):
        A_j = A[j-1]

        ans += Ai_plus_i[j - A_j]
        Ai_plus_i[A_j + j] += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
N = int(input())
A = [int(hoge) for hoge in input().split()]
Plus = []
Minus = []
for n,a in enumerate(A):
    Plus.append(n + a)
    Minus.append(n - a)
CPlus = Counter(Plus)
CMinus = Counter(Minus)
ans = 0
for p in Plus:
    ans +=CMinus[p]
print(ans)

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

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

print(ans)