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

Solution (Python):
import collections
cc = collections.Counter()
count = 0
n = raw_input()
for i,e in enumerate(map(int, raw_input().split())):
	count += cc[e - i]
	cc[-e-  i] +=1
print count

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

    dict1 = {}
    dict2 = {}

    for i in range(n):
        a1 = a[i] + i + 1
        a2 = i + 1 - a[i]
        if a1 in dict1:
            dict1[a1] += 1
        else:
            dict1[a1] = 1
        if a2 in dict2:
            dict2[a2] += 1
        else:
            dict2[a2] = 1
    ans = 0
    for i in dict1:
        if i in dict2:
            ans += dict1[i]*dict2[i]
    print(ans)
            
resolve()

Solution (Python):
from collections import Counter


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

X = Counter([i - a for i, a in enumerate(A)])

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

print(ans)

Solution (Python):
N = 6
ARR = [2, 3, 3, 1, 3, 1]




N = 32
ARR = [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]

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


def calculate(n, arr):
    A = {}
    B = {}

    for i in range(1, n + 1):
        Ai = arr[i - 1]
        Aj = arr[i - 1]

        a = Ai + i
        b = (i - Aj)

        if A.get(a) == None:
            A.__setitem__(a, [i])
        else:
            tmp = A.__getitem__(a)
            tmp.append(i)
            A.__setitem__(a, tmp)

        if B.get(b) == None:
            B.__setitem__(b, [i])
        else:
            tmp = B.__getitem__(b)
            tmp.append(i)
            B.__setitem__(b, tmp)

    result = 0
    for key in A.keys():
        l1 = len(A.get(key))

        if B.get(key) != None:
            l2 = len(B.get(key))
            result += l1 * l2

    print(result)


calculate(N, ARR)

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

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

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

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

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

ans = 0
dp = dict()

for i in range(n):
    a_p = a[i] + i+1
    a_m = i+1 -a[i]
    if a_p in dp:
        dp[a_p] = dp[a_p] + 1
    else:
        dp[a_p] = 1
    if a_m in dp:
        ans = ans + dp[a_m]


print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')







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

    memo = {}
    ans = 0
    for i, a in enumerate(A):
        i = i + 1
        
        ans = ans + memo.get(i - a, 0)
        memo[a + i] = memo.get(a + i, 0) + 1
    print(ans)


if __name__ == '__main__':
    solve()

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

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

ap = {}
am = {}


for i in range(1,n+1):
    j = i - 1

    if (i + a[j]) in ap:
        ap[i+a[j]] = ap[i+a[j]] + 1
    else:
        ap[i+a[j]] = 1
    
    if (i - a[j]) in am:
        am[i-a[j]] = am[i-a[j]] + 1
    else:
        am[i-a[j]] = 1

ans = 0
for i in ap.keys():
    if i in am:
        ans += am[i] * ap[i]
print(ans)

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

I = [i+a for i,a in enumerate(A, start=1)]
J = [i-a for i,a in enumerate(A, start=1)]


dic = {}
ans = 0

for i in range(N):
    if I[i] in dic:
        dic[I[i]] += 1
    else:
        dic[I[i]] = 1
    if J[i] in dic:
        ans += dic[J[i]]



print(ans)

Solution (Python):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  if 2 <= i - v <= 100000001:
    c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in b.items():
  for j in L:
    if v in c:
      ans += len(c[v])
print(ans)

Solution (Python):
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    n = ri()
    A = rl()
    types = dd(int)
    ans = 0
    for i, h in enumerate(A):
        j = i + 1
        ans += types[j - h]
        types[j + h] += 1
    print (ans)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

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

plus = {}
minus = {}
for i in range(n):
    p = i + 1 + a[i]
    m = i + 1 - a[i]
    if p not in plus:
        plus[p] = 0
    if m not in minus:
        minus[m] = 0
    plus[p] += 1
    minus[m] += 1

cnt = 0
for i in plus.keys():
    if i in minus:
        cnt += plus[i]*minus[i]

print(cnt)

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



input = sys.stdin.readline

def main():

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


    wa = defaultdict(int)
    sa = defaultdict(int)

    for i in range(1,N+1):
        wa[i+A[i-1]] +=1
        sa[i-A[i-1]]+=1

    ans = 0
    for j in range(N):
        ans += wa[j] *sa[j]

    print(ans)


if __name__ == "__main__":
    main()

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

ans = 0

dic = {}
for i in range(N):
    temp = i + A[i]
    if temp in dic:
        dic[temp] += 1
    else:
        dic[temp] = 1
        
for i in range(N):
    temp = i - A[i]
    if temp in dic:
        ans += dic[temp]

print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")


def solve():
    n = II()
    a = LI()
    d = defaultdict(int)
    ans = 0
    for i in range(n):
        x = i + 1 - a[i]
        ans += d[x]
        d[a[i] + i + 1] += 1
    print(ans)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
from collections import defaultdict

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

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

print(ans)

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

ld=defaultdict(int)
rd=defaultdict(int)
for i in range(n):
    l=i+a[i]
    r=i-a[i]
    ld[l]+=1
    rd[r]+=1
ans=0
for i,j in ld.items():
    ans+=j*rd[i]

print(ans)

Solution (Python):
from collections import Counter

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

arr1 = []
arr2 = []
for i in range(1, n + 1):
    arr1.append(i - a[i - 1])
    arr2.append(i + a[i - 1])
    
dis1 = Counter(arr1)
dis2 = Counter(arr2)

ans = 0
for i in dis1.keys():
    ans += dis1[i] * dis2[i]

print(ans)

Solution (Python):
from collections import defaultdict

def main():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(lambda : 0)
    ans = 0
    for i, ai in enumerate(a):
        sa = i - ai
        ans += d[sa]
        wa = i + ai
        d[wa] += 1
    print(ans)
        

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bigger = [None]*n
    smaller = [None]*n
    for i, ai in enumerate(a):
        bigger[i] = i - ai
        smaller[i] = i + ai
    b = sorted(Counter(bigger).items())
    s = sorted(Counter(smaller).items())
    nb = len(b)
    ns = len(s)
    b.append((10**10, 0))
    s.append((10**11, 0))
    i, j = 0, 0
    ans = 0
    while i < nb or j < ns:
        bi, nbi = b[i]
        si, nsi = s[j]
        if bi == si:
            ans += nbi*nsi
            i += 1
            j += 1
        elif bi > si:
            j += 1
        else:
            i += 1
    print(ans)
        

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
import collections
B=[]
C=[]
for i,a in enumerate(A):
  B.append(a-i)
  C.append(-a-i)
C=collections.Counter(C)
ans=0
for b in B:    
  ans+=C[b]
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])
  r.append(i-a[i])

count_l = collections.Counter(l)
count_r = collections.Counter(r)

ans = 0
for i in count_l:
  ans += count_r.get(i,0) * count_l[i]
      
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])
  r.append(i-a[i])

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

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
minus = Counter([i - a[i] for i in range(n)])
plus = Counter([i + a[i] for i in range(n)])

cnt = 0
for i in minus:
    if i in plus:
        cnt += minus[i] * plus[i]
print(cnt)

Solution (Python):
import collections

def list_count(l):
    return collections.Counter(l)

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

l=[i+a[i] for i in range(len(a))]
m=[i-a[i] for i in range(len(a))]

mlist=list_count(m)

mlist0=mlist[m[0]]
mlist[m[0]]=mlist0-1

ans=0
for i in range(len(l)-1):
    ansi=mlist.get(l[i], 0)
    ans+=ansi

    mlist[m[i]]=mlist[m[i]]-1

print(ans)

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
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()))

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

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
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()))

dic=defaultdict(int)
ans=0
for i in range(n):
    ans+=dic[i-a[i]]
    dic[a[i]+i]+=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 in range(n):
    ans += d[i - a[i]]
    d[a[i] + i] += 1

print(ans)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
L = []
L2 = [0]*(10**6)
for i in range(N):
    if i+A[i]+1 < 10**6:
        L.append(i+A[i]+1)
    if i-A[i]+1 >= 0 and i-A[i]+1 < 10**6:
        L2[i-A[i]+1] += 1
ans = 0
for l in L:
    ans += L2[l]
print(ans)

Solution (Python):
from collections import Counter

def CHK():
    N = int(input())
    A = list(map(int,input().split()))
    L=[]
    R=[]
    cnt = 0
    for i in range(N):
        L.append(i + A[i])
    L_Cnt=Counter(L)

    for i in range(N):
        chk = i -A[i]
        cnt += L_Cnt[chk]
    print(cnt)

CHK()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
f={}
f2={}
for i in range(n):
    z=i+a[i]
    z1=i-a[i]
    
    try:
        f[z]+=1
    except:
        f[z]=1
    try:
        f2[z1]+=1
    except:
        f2[z1]=1
s=0
for i in f.keys():
    if(i in f2):
        s+=f[i]*f2[i]
print(s)

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

P = [i + a for i, a in enumerate(A, start=1)]
Q = [j - a for j, a in enumerate(A, start=1)]

Q = Counter(Q)

cnt = 0
for p in P:
    cnt += Q[p]

print(cnt)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
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()
d = defaultdict(int)
for i,x in enumerate(a):
    d[i+1-x] += 1
res = 0
for i,x in enumerate(a):
    res += d[i+1+x]
print(res)

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

ans = 0
for x in l:
  if x in r:
    ans += l[x] * r[x]
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = []
c = {}

ans = 0
for i in range(n):
    b.append(a[i]+i+1)
    x = -a[i]+i+1
    if x in c:
        c[x] += 1
    else:
        c[x] = 1
for i in range(n):
    if b[i] in c:
        ans += c[b[i]]
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 math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

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

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]







n = I()
a = RI()

I = []
for i in range(n):
    I.append( a[i] + (i+1) )

J = []
for j in range(n):
    J.append( (j+1) - a[j] )
J.sort()

c = 0
for i in range(n):
    b = I[i]
    c += mycount(J,b)

print(c)

Solution (Python):
import sys
from collections import defaultdict, deque
import math


from bisect import bisect_left, bisect_right





input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7

def divide(k):
    return pow(k, MOD-2, MOD)


def make_nck(n):
    ret = [1]
    for i in range(1, n+1):
        ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)

    
    return ret

def make_nigojyo(n):
    ret = [1]

    for i in range(1, n+1):
        ret.append((ret[-1] * 25) % MOD)

    
    return ret


def solve():
    n = getN()
    nums = getList()

    agentss = [num - i for i, num in enumerate(nums)]
    agents = [-num - i for i, num in enumerate(nums)]
    agents.sort()
    agentss.sort()
    ans = 0
    for ag in agentss:
        ans += bisect_right(agents, ag) - bisect_left(agents,ag)
        
        
    print(ans)
    
    


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    
    solve()

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

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = []
    c = {}
    answer = 0
    for i in range(n):
        b.append(a[i] + i + 1)
        tmp = -a[i] + i + 1
        if tmp in c:
            c[tmp] += 1
        else:
            c[tmp] = 1
    for i in range(n):
        if b[i] in c:
            answer += c[b[i]]
    print(answer)


if __name__ == '__main__':
    main()

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

ja1 = []
ja2 = []
for i in range(1,n+1):
  ja1.append(i-a[i-1])
  ja2.append(i+a[i-1])

s = Counter(ja1)
t = Counter(ja2)

su = 0
for i in s.keys():
  su += s[i]*t[i]
print(su)

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

from collections import Counter

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

C1 = Counter(L1)
C2 = Counter(L2)
C = Counter(L1+L2)

ans = 0
for k in C.keys():
    ans += C1[k]*C2[k]
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N = INT()
A = LIST()

A1 = [A[i]+i+1 for i in range(N)]
A2 = [i+1-A[i] for i in range(N)]

C1 = Counter(A1)
C2 = Counter(A2)

ans = 0
for x in C1.keys():
	ans += C1[x]*C2[x]

print(ans)

Solution (Python):
from collections import defaultdict

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

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

print(ans)

Solution (Python):
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
llst = [0] * N
rlst = [0] * N

for i in range(N - 1):
    llst[i] = (i + 1) + a[i]
    rlst[-i - 1] = (N - i) - a[-i - 1]

d = defaultdict(int)
for i in range(1, N):
    d[rlst[i]] += 1

cnt = 0
for i in range(N - 1):
    cnt += d[llst[i]]

print(cnt)

Solution (Python):
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
llst = [0] * N
rlst = [0] * N

for i in range(N - 1):
    llst[i] = (i + 1) + a[i]
    rlst[-i - 1] = (N - i) - a[-i - 1]

d = defaultdict(int)
for i in range(1, N):
    d[rlst[i]] += 1

cnt = 0
for i in range(N - 1):
    cnt += d[llst[i]]

print(cnt)

Solution (Python):
from collections import defaultdict

N, *A = map(int, open(0).read().split())

ctr1 = defaultdict(int)
ctr2 = defaultdict(int)
for i in range(N):
    ctr2[i + A[i]] += 1
    if i - A[i] > 0:
        ctr1[i - A[i]] += 1

ans = 0
for v in ctr1:
    ans += ctr1[v] * ctr2[v]
print(ans)

Solution (Python):




N=int(input())
A=list(map(int,input().split()))
cnt=[0]*300000
ans=0
for i in range(N):
    if i-A[i]>=0:
        ans=ans+cnt[i-A[i]]
    if i+A[i]<len(cnt):
        cnt[i+A[i]]=cnt[i+A[i]]+1
print(ans)

Solution (Python):

from bisect import *
N = int(input())
A = list(map(int,input().split()))
l = []
ans = 0
for j in range(N):
    tmp = j-A[j]
    ans += bisect_right(l,tmp)-bisect_left(l,tmp)
    insort(l,A[j]+j)
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A1 = []
A2 = []

for i in range(1,N+1):
   A1.append(i + A[i-1])
   A2.append(i - A[i-1])
  
c1 = Counter(A1)
c2 = Counter(A2)

result = 0
for k in set(c1).intersection(c2):
    result += c1[k] * c2[k]
print(result)

Solution (Python):
from collections import defaultdict
iim = lambda: map(int, input().rstrip().split())
 
def resolve():
    N = int(input())
    A = list(iim())
    ans = 0
    dp = [0]*N
    for i, ai in enumerate(A):
        x = i + ai
        if x < N:
            dp[x] += 1
        x = i - ai
        if x >= 0:
            ans += dp[x]
    print(ans)
resolve()

Solution (Python):
def main():
  
  

  
  
  from collections import defaultdict

  
  
  
  if 'get_ipython' in globals(): 
    
    n = 6
    A = [2, 3, 3, 1, 3, 1]

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

  
  d = defaultdict(int)
  ans = 0
  for j in range(n):
    Dif = j - A[j]
    ans += d[Dif]
    Sum = A[j] + j
    d[Sum] += 1
  print(ans)
  
main()

Solution (Python):
'''
i<j としたとき求めたいのは
i + Ai = j - Aj の組み合わせの数
そこで各々の Li = i + Ai, Ri = i - Aiを計算し辞書型で保持しておく
'''
from collections import defaultdict

N =int(input())
A = list(map(int,input().split()))
Li = defaultdict(int)
Ri = defaultdict(int)
for i,a in enumerate(A,start=1):
    Li[i+a] += 1
    Ri[i-a] += 1

ans = 0
for k,v in Li.items():
    if k in Ri:
        ans += Li[k]*Ri[k]

print(ans)

Solution (Python):
from collections import defaultdict

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

dd = defaultdict(int)

ans = 0
for i in range(n):
    diff = i - A[i]
    ans += dd[diff]
    summ = A[i] + i
    dd[summ] += 1

print(ans)

Solution (Python):
import math

n = int(input())
aL = list(map(int, input().split(" ")))

d1 = {}
d2 = {}
for i in range(n):
    d1i = i - aL[i]
    d2i = i + aL[i]

    if d1i in d1:
        d1[d1i] += 1
    else:
        d1[d1i] = 1

    if d2i in d2:
        d2[d2i] += 1
    else:
        d2[d2i] = 1

ans = 0
for k, v in d2.items():
    if k in d1:
        ans += v * d1[k]

print(ans)

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

Aminus = [a - i - 1 for i, a in enumerate(A)]

from collections import defaultdict
Aplus = defaultdict(int)
for i, a in enumerate(A):
    Aplus[i + 1 + a] += 1


ans = 0
for i in range(len(A)):
    ans += Aplus[-(Aminus[i])]
    if -(A[i] + i + 1) == A[i] - i - 1:
        ans -= 1
print(ans)

Solution (Python):

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

ans = 0
i_plus_h_dic = {}

for i, a in enumerate(al):
    input_val = a+i
    i_plus_h_dic.setdefault(input_val,0)
    i_plus_h_dic[input_val] += 1

    comp_val = i - a
    if comp_val in i_plus_h_dic:
        ans += i_plus_h_dic[comp_val]


print(ans)

Solution (Python):
"""
i - j = A[i] + A[j]
> i - A[i] = j + A[j]
i > j
"""
from collections import defaultdict

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

ans = 0
calc = defaultdict(int)
for i in range(1, N+1):
  ans += calc[i - high[i-1]]
  calc[i + high[i-1]] += 1

print(ans)

Solution (Python):
"""
i - j = A[i] + A[j]
> i - A[i] = j + A[j]
i > j
"""
N = int(input())
high = list(map(int, input().split()))

ans = 0
calc = {}
for i in range(1, N+1):
  try:
    ans += calc[i - high[i-1]]
  except KeyError:
    pass
  if (i + high[i-1]) in calc.keys():
    calc[i + high[i-1]] += 1
  else:
    calc[i + high[i-1]] = 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)]
countl = Counter(l)
countr = Counter(r)
ans = sum([countl[i]*countr[i] for i in countl.keys()])
print(ans)

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

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



li = [[0]*N,[0]*N ]

for index,a in enumerate(A):
    li[0][index] = a- index
    li[1][index]= -a - index


from collections import Counter


cou_one = Counter(li[0])
cou_two = Counter(li[1])




counter = 0
for key,value in cou_one.items():
    counter += cou_two[key]*value


print(counter)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
 
ans = 0
l = [0]*N
u = [0]*N

for i in range(N):
  b = i - A[i]
  c = i + A[i]
  if 0 < b < N:
    l[b] += 1
  if 0 < c < N:
    u[c] += 1

for i in range(N):
  ans += l[i]*u[i]

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
count = defaultdict(int)
ans = 0
for i in range(N):
    ans += count[i-A[i]]
    count[A[i]+i] += 1
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
import decimal


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

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


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()
    memo = defaultdict(int)

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


def main():
    
    
    
    
    
    solve()


if __name__ == "__main__":
    main()

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