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):
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N = Int()
A = IntList()

B = []

for i in range(N):
    B.append(-A[i]-(i+1))
    A[i] -= i+1
    
from collections import defaultdict

G = defaultdict(list)

for i in range(N):
    G[A[i]].append(i)
    
ans = 0
import bisect

for i in range(N):
    query = B[i]
    L = len(G[query]) - bisect.bisect(G[query],i)
    ans += L

print(ans)

Solution (Python):
import bisect
n=int(input())
a=list(map(int,input().split()))
s=[a[i]+i for i in range(n)]
di=[i-a[i] for i in range(n)]
di.sort()
ans=0
for i in range(n):
    ans+=bisect.bisect_right(di,s[i])-bisect.bisect_left(di,s[i])
print(ans)

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

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

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

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    dic = defaultdict(int)
    n = inp()
    a = inpl()
    ans = 0
    for i in range(n):
        ans += dic[i-a[i]]
        dic[a[i]+i] += 1
    print(ans)
    
if __name__ == "__main__":
    main()

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

B, C = [], []
for i in range(N):
    B.append(A[i]+i)
    C.append(-A[i]+i)

B.sort()
C.sort()

num = [0] * 500000
for i in range(N):
    if B[i] < 0 or B[i] >= 500000:
         continue
    num[B[i]] += 1
ans = 0
for i in range(N):
    if C[i] < 0 or C[i] >= 500000:
         continue
    ans += num[C[i]]
print(ans)

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

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

d = dict()
res = 0


d[n-1-a[-1]] = 1

for i in range(n-2,-1,-1):
    if a[i]+i in d:
        res += d[a[i] + i]
    
    if i-a[i] in d:
        d[i-a[i]] += 1
    else:
        d[i-a[i]] = 1

print(res)

Solution (Python):
import os
from collections import Counter

import sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



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

A = np.array(A, dtype=int)
B = (A + np.arange(1, N + 1)).tolist()
C = (A - np.arange(1, N + 1)).tolist()

c_cnt = Counter(C)
ans = 0
for k, b in Counter(B).items():
    ans += c_cnt[-k] * b
print(ans)

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

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

first_s = [0 for _ in range(n)]
sec_s = [0 for _ in range(n)]

for i in range(n):
	sec_s[i] = a[i] - i
	
	first_s[i] = -i - a[i]




seen_first_s = {}
ans = 0
for i in range(n):
	if sec_s[i] in seen_first_s:
		ans += seen_first_s[sec_s[i]]
	seen_first_s[first_s[i]] = seen_first_s.get(first_s[i], 0) + 1
print(ans)

Solution (Python):
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = []
    c = []
    for i in range(n):
        b.append(a[i] + i + 1)
        c.append(i + 1 - a[i])
    b = list(Counter(b).items())
    c = Counter(c)
    answer = 0
    for i, n in b:
        if i in c:
            answer += n * c[i]
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict


def solve(n, aaa):
    fff = aaa.copy()
    for i in range(n):
        fff[i] -= i
    ans = 0
    count = defaultdict(int)
    for i in range(n - 1, -1, -1):
        ans += count[-i - aaa[i]]
        count[fff[i]] += 1
    return ans


n = int(input())
aaa = list(map(int, input().split()))
print(solve(n, aaa))

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = [i+1+a[i] for i in range(n)]
c = [(j+1)-a[j] for j in range(n)]
d = Counter(c)
ans = 0
for i in range(n):
    ans += d[b[i]]
print(ans)

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

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

D = {}
for i in range(n):
    try:
        D[i-A[i]] += 1
    except:
        D[i-A[i]] = 1



ans = 0
for i in range(n):
    D[i-A[i]] -= 1
    
    try:
        ans += D[i+A[i]]
    except:
        continue

print(ans)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
C = collections.Counter()
for i ,ai in enumerate(A):
  ans += C[i-ai]
  C[ai+i] += 1
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
A1 = list(map(int, input().split()))
A2 = [-1 * A1[i] for i in range(N)]

for i in range(N):
    A1[i] -= i
    A2[i] -= i

C1 = Counter(A1)
C2 = Counter(A2)
res = 0
for c1 in C1.keys():
    res += C1[c1] * C2[c1]
print(res)

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

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

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

B1 = []
B2 = []
for i, a in enumerate(A):
    B1.append(a-i)
    B2.append(-a-i)

dic = {}

ans = 0
for b1, b2 in zip(B1, B2):
    if b1 in dic:
        ans += dic[b1]
    if b2 in dic:
        dic[b2] += 1
    else:
        dic[b2] = 1

print(ans)

Solution (Python):
from collections import *

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

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

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

X = [a - i for i, a in enumerate(A, start=1)]
Y = [-a - i for i, a in enumerate(A, start=1)]
memo = defaultdict(int)
ans = 0

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

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

Solution (Python):
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())


from collections import Counter
def solve(N, A):
    
    
    
    
    
    
    B = [x-i for i,x in enumerate(A)]
    count = Counter()
    ans = 0
    for i in xrange(N - 1, -1, -1):
        ans += count[-B[i] - 2*i]
        count[B[i]] += 1
    return ans
    


    
print solve(rri(), rrm())

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):
  ans+=D[i-A[i]]
  D[A[i]+i]+=1
print(ans)

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

Solution (Python):
from bisect import *
n = int(input())
A = list(map(int,input().split()))
s = {}

ans = 0
for i,a in enumerate(A):
    if a+i not in s.keys():s[a+i] = 0
    
    s[a+i] += 1
    if i-a not in s:continue
    ans += s[i-a]
    
    
print(ans)

Solution (Python):
from collections import Counter

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

l1 = Counter([i + 1 - A[i]for i in range(N)])
l2 = Counter([i + 1 + A[i]for i in range(N)])

ret = 0
for k, v in l1.items() :
  ret += v * l2[k]
  
print(ret)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = {}
    for i, a in enumerate(A):
        B[i - a] = B.get(i - a, 0) + 1
    r = 0
    for i, a in enumerate(A):
        B[i - a] -= 1
        r += B.get(a + i, 0)
    return r

print(main())

Solution (Python):


import sys
readline = sys.stdin.readline
read = sys.stdin.read


n,*a = [int(i) for i in read().split()]

from collections import Counter
d = Counter()

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

print(ans)

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

Solution (Python):
from collections import defaultdict

dd = defaultdict(int)

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

for i in range(1,N):
    dd[i+1-A[i]] += 1
ans = 0
for i in range(N-1):
    ans += dd[A[i]+i+1]
    dd[i+1-A[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):
    left = a[i]-i
    ans += d[left]
    d[-a[i]-i] += 1
print(ans)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    d = defaultdict(lambda : 0)
    ans = 0
    for i,ai in enumerate(a):
        ans += d[-ai+i]
        d[ai+i] += 1
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
D = {}
A = [int(a) for a in input().split()]
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)

Solution (Python):
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]


p = Counter()
q = Counter()

for i in range(n):
    p[i-a[i]] += 1
    q[i+a[i]] += 1
    
ans = 0

for x in p.keys():
    ans += p[x]*q[x]

print(ans)

Solution (Python):
import bisect
N=int(input())
A=[int(i) for i in input().split()]
X=sorted([i-A[i] for i in range(N)])
Y=sorted([i+A[i] for i in range(N)])
ans=0
for i in range(N):
    l=bisect.bisect_left(Y,X[i])
    r=bisect.bisect_right(Y,X[i])
    ans+=r-l
print(ans)

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

N = int(input())
A = list(map(int, input().split()))
plus = [A[i] + i for i in range(N)]
minus = [A[i] - i for i in range(N)]
cnt = defaultdict(int)
ans = 0
for i in range(N):
    ans += cnt[-minus[i]]
    cnt[plus[i]] += 1
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
m = {}
ans = 0
for i in range(n):
    if i - a[i] in m:
        ans += m[i - a[i]]
    j = i + a[i]
    if j in m:
        m[j] += 1
    else:
        m[j] = 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)[::-1]:
    ans+=d[-a[i]-i]
    d[a[i]-i]+=1
print(ans)

Solution (Python):
from collections import defaultdict
def main():
    n=int(input())
    A=list(map(int,input().split()))
    B,C=[0]*n,[0]*n
    for i,a in enumerate(A):
        B[i]=a+i
        C[i]=i-a
    D=defaultdict(int)
    D[C[-1]]+=1
    ans=0
    for i in range(n-1)[::-1]:
        ans+=D[B[i]]
        D[C[i]]+=1
    print(ans)
    
if __name__=='__main__':
    main()

Solution (Python):

N = int(input())

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

dic = {}
ans = 0

for j in range(N):

    now = A[j] - (j+1)

    if now in dic:
        ans += dic[now]

    pl = -1 * A[j] - (j+1)

    if pl not in dic:
        dic[pl] = 1
    else:
        dic[pl] += 1

print (ans)

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

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

    AA = [0] * N
    for i, a in enumerate(A):
        AA[i] = -a + i + 1
    ans = 0
    C = defaultdict(int)
    for i in range(N-2, -1, -1):
        C[AA[i+1]] += 1
        ans += C[A[i] + i + 1]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


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


N = inp()
aa = inpl()


ajs = []
ais = []

for i, a in enumerate(aa):
    ajs.append(a - i)
    ais.append(-a - i)


cnt = defaultdict(int)
ans = 0
for ai, aj in zip(ais, ajs):
    ans += cnt[aj]
    cnt[ai] += 1


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



if __name__ == '__main__':
    solve()