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



Sample input:
6
2 3 3 1 3 1


Sample output:
3

Submission status: Wrong Answer

Solution code:
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 fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

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

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

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

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

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

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

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

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

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

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

c.sort()
# print(c)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a1=[]
a2=[]
for i in range(n):
  a1.append(i+1-a[i])
for i in range(n):
  a2.append(i+1+a[i])
count=0
p=0
q=1
while q==n:
  if a1[q]==a2[p]:
    count+=1
  p+=1
  if p==q:
    p=0
    q+=1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
c,d=dict(),dict()
for i in range(n):
    if a[i]-i-1 in c:
        c[a[i]-i-1]+=1
    else:
        c[a[i]-i-1]=1
    if a[i]+i+1 in d:
        d[a[i]+i+1]+=1
    else:
        d[a[i]+i+1]=1
ans=0
for i in c:
    if i in d:
        ans+=(c[i]*d[i])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def main():
    n = int(input())
    l = defaultdict(int)
    r = defaultdict(int)
    for i, ai in enumerate(map(int, input().split())):
        l[i - ai] += 1
        r[i + ai] += 1
    print(sum(l[i] * r[i] for i in range(2, n)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

index = list(range(1,N+1))

R = [index[i] - A[i] for i in range(N)]
L = [index[j] + A[j] for j in range(N)]

R_dict = collections.Counter(R)
L_dict = collections.Counter(L)

ans=0
for i in R_dict.keys()&L_dict.keys():
    # print(R_dict[i])
    # print(L_dict[i])
    ans+=L_dict[i]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
ans = 0

for i, x in enumerate(A, 1):
    ans += D[i-x]
    D[x+i] += 1

print(ans, D)

Submission status: Wrong Answer

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

index = list(range(1,N+1))

R = [index[i] - A[i] for i in range(N)]
L = [index[j] + A[j] for j in range(N)]

R_dict = collections.Counter(R)
L_dict = collections.Counter(L)

ans=0
for i in R_dict.keys()&L_dict.keys():
    ans+=max(R_dict[i], L_dict[i])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input()) #1行目のNを取得する
S = list(range(1,N+1))
A = list(map(int, input().split()))
K = 0
D =dict(zip(S,A))
for i in range(1,N+1):
  for m in range(i,N-i+1):
    if abs(i-m) == D[i]+D[m]:
      K = K + 1
      
print(int(K))

Submission status: Wrong Answer

Solution code:
N = int(input()) #1行目のNを取得する
S = list(range(1,N+1))
A = list(map(int, input().split()))
K = 0
D =dict(zip(S,A))
for i in range(1,N+1):
  for m in range(i,N+1):
    if abs(i-m) == D[i]+D[m]:
      K = K + 1
      
print(int(K/2))

Submission status: Wrong Answer

Solution code:
import math
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def pop2(li):
	c=1
	i=li.pop(0)
	while 1:
		j=li.pop(0)
		if j==i:
			c+=1
		else:
			break
	return i,c,[j]+li

n = readInt()
a = readInts()

li = []
ri = []

for i in range(n):
	li.append(i+a[i])
	ri.append(i-a[i])

li.sort()
ri.sort()

res = 0

tar = []#list(set(li)&set(ri))

for i in tar:
	res+=li.count(i)*ri.count(i)

print(res)

Submission status: Wrong Answer

Solution code:
def is_ok(mid: int, target: int, ls: []):
    return target <= ls[mid]


def bi_search(target: int, ls: []):
    ng = -1
    ok = len(ls)

    cnt = 0
    while ok - ng > 1:
        mid = ng + int((ok - ng) / 2)
        cnt += 1
        if is_ok(mid, target, ls):
            ok = mid
        else:
            ng = mid
    return cnt


def main():
    n = int(input())
    l_dic = {}
    r_dic = {}
    i = 0
    for a in map(int, input().split()):
        ld = l_dic.setdefault(i + a, [])
        ld.append(i)
        rd = r_dic.setdefault(i - a, [])
        rd.append(i)
        i += 1

    count = 0
    for rk, rv_list in r_dic.items():
        if rk not in l_dic:
            continue
        lv_list = l_dic[rk]
        for rv in rv_list:
            count += bi_search(rv, lv_list)
            # for lv in lv_list:
            #     if lv < rv:
            #         count += 1
            #     else:
            #         break

    print(count)


main()

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
L_i=[i+1 for i in range(len(L))]

cnt=0
for i in range(N):
    P_L= [m+L[i] for m in L[i:]]
    P_L_i = [x for x in range(N-i)]
    print(P_L)
    print(P_L_i)
    cnt = cnt + sum([w==z for (w, z) in zip(P_L,P_L_i)])
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
hight = list(map(int, input().split()))

def smaller(n,m):
  if n >= m:
    return m
  else:
    return n

a = 0

for i in range(0,N):
  for j in range(i+1,smaller(N,i+70)):
    if j-i == hight[i] + hight[j]:
      a = a+1

print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
hight = list(map(int, input().split()))

def smaller(n,m):
  if n >= m:
    return m
  else:
    return n

a = 0

for i in range(0,N):
  for j in range(i+1,smaller(N,i+50)):
    if j-i == hight[i] + hight[j]:
      a = a+1

print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
hight = list(map(int, input().split()))

def smaller(n,m):
  if n >= m:
    return m
  else:
    return n

a = 0

for i in range(0,N):
  for j in range(i+1,smaller(N,i+100)):
    if j-i == hight[i] + hight[j]:
      a = a+1

print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
hight = list(map(int, input().split()))

a = 0

for i in range(0,N):
  for j in range(i+1,N):
    if j-1 == hight[i] + hight[j]:
      a = a+1

print(a)

Submission status: Wrong Answer

Solution code:

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

i_plus_Ai = [i + 1 + l[i] for i in range(len(l))]
i_minus_Ai = [j + 1 - l[j] for j in range(len(l))]

cnt = 0
for i in range(len(l)):
    if i_plus_Ai[i] in i_minus_Ai:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
li =  list(map(int, input().split()))

index = [i for i in range(n)]
print(index)
x = [i + li[i] for i in index]
y = [i - li[i] for i in index]

r = 0
for i in x:
    r += y.count(i)
print(r)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N,*A = map(int,open(0).read().split())
#j - i = Aj + Ai
#j - Aj = Ai + i
#L = i + Ai, R = j - Aj とおく
L = []
R = []
for i in range(N):
    L.append(i+1 + A[i])
    R.append(i+1 - A[i])
l = Counter(L)
r = Counter(R)
 
cnt = 0
a=[]
for i in range(1,N+1):
    if i in l and i in r:
        cnt += max(l[i], r[i])
        a.append(i)
print(cnt)

Submission status: Wrong Answer

Solution code:
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)]
sum=0
for i in L:
  if i in R:
    sum=sum+1
print(sum)

Submission status: Wrong Answer

Solution code:
"""

"""

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

cnt = 0
for i in range(len(l)):
    for j in range(i+1, len(l)):
        if abs(l[i] - l[j]) == i + j + 2:
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
D={}
E={}
for i in range(N):
  a=i+1+A[i]
  b=i+1-A[i]
  D.setdefault(a-1,0)
  E.setdefault(b-1,0)
  D[a-1]+=1
  E[b-1]+=1
print(D,E)
ans=0
for i in D:
  if i in E:
    ans+=D[i]*E[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A=list(map(int,input().split()))
cnt=0
B=[]
C=[]
for i,a in enumerate(A):
    B.append(A[i]+i)
    C.append(A[i]-i)
from collections import Counter
Bd=dict(Counter(B))
Cd=dict(Counter(C))
cnt=0
for k in Bd.keys():
    b=Bd.get(k)
    c=Cd.get(k)
    if b and c:
        cnt+=b*c
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
D={}
E={}
for i in range(N):
  a=i+A[i]
  b=i+A[i]
  D.setdefault(a,0)
  E.setdefault(b,0)
  D[a]+=1
  E[b]+=1
ans=0
for i in D.keys():
  if i in E.keys():
    ans+=D[i]*E[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools

n = int(input())
a = list(map(int, input().split()))
g = sorted(a)[-1] + sorted(a)[-2]

ans = 0
s = set()
for i in range(1, n-g+1):
    for p in itertools.combinations(range(i, g+i), 2):
        s.add(p)

for  p in s:
        if abs(p[0] - p[1]) == a[p[0]-1] + a[p[1]-1]: ans += 1

print(ans)

Submission status: Wrong Answer

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

l=dict()
r=dict()

for i in range(n):
    if a[i]-i-1 in l:
        l[a[i]-i-1]+=1
    else:
        l[a[i]-i-1]=1
    if a[i]+i+1 in r:
        r[-a[i]-i-1]+=1
    else:
        r[-a[i]-i-1]=1

res=0
for (key,item) in l.items():
    res+=item*r.get(key,0)
print(res)

Submission status: Wrong Answer

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

d = [0]*N
ans = 0
for i in range(N):
    a = A[i]
    l,r = i+a, i-a
    if 2 <= l < N:
        d[l] += 1
    if 2 <= r < N:
        ans += d[r]

print(ans)

Submission status: Wrong Answer

Solution code:
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq


#n,k=list(map(int,input().split()))
n=int(input())
#n=10**3
a=list(map(int,input().split()))
c=defaultdict(int)
for i in range(n):
    ii=i+1
    c[ii+a[i]]+=1
    c[abs(ii-a[i])]+=1
ans=0
for each in c.keys():
    ans+=max(0,c[each]-1)

print(ans)

Submission status: Wrong Answer

Solution code:
#回答を見た後に実装

from collections import defaultdict
import itertools

def main():
    N = int(input())
    A = tuple(int(c) for c in input().split(' '))
    L = []
    R = []
    for i, a in enumerate(A):
        L.append(i+a)
        R.append(i-a)
    print(L)
    print(R)
    L_t = defaultdict(list)
    for i, l in enumerate(L):
        L_t[l].append(i)
    R_t = defaultdict(list)
    for j, r in enumerate(R):
        R_t[r].append(j)

    x_max = max(L)
    x_min = min(R)
    cnt = 0
    for x in range(x_min, x_max+1):
        l_candidate = L_t[x]
        r_candidate = R_t[x]
        if len(l_candidate) == 0 or len(r_candidate) == 0:
            continue
        else:
            answer_set = set()
            for i,j in itertools.product(l_candidate, r_candidate):
                answer_set.add((i,j))
            cnt += len(answer_set)

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

d = [0]*N
ans = 0
for i in range(N):
    a = A[i]
    l,r = i+a, i-a
    if l < N:
        d[l] += 1
    if r >= 2:
        d[r] += 1
    if r in d:
        ans += d[r]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
dic = {}
ans = 0
for i, a in enumerate(A):
    L = i + a
    if L not in dic:
        dic[L] = 1
    else:
        dic[L] += 1
for j in range(n):
    R = j - a
    if R in dic:
        ans += dic[R]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
#K = int(input())
#N,K = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))
c=0
l=[]
r=[]
for i in range(N):
    l.append(A[i]+i+1)
    r.append(i+1-A[i])

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

Submission status: Wrong Answer

Solution code:
# 二分探索モジュール bisect
# 添字はiとjの分で相殺(本当の添字は+1が必要だが[(i+1)-(j+1)]なのでいらない(以下は式変形))
import bisect
N = int(input())
A = list(map(int, input().split()))
X = [A[i]+i for i in range(N)]
Y = [j - A[j] for j in range(N)]
ans = 0
X.sort()
for i in range(N):
    ans += bisect.bisect_left(Y,X[i]) - bisect.bisect_right(Y,X[i])
print(ans)


'''
bisect 二分探索モジュール
A = [1,1,3,3,3,4,5,6]
B = 3
bisect.bisect_left(A, b) 配列Aにbが左から何番目に入るかを返す #2
bisect.bisect_right(A,b) 配列Aにbが右から何晩目に入るかを返す #5
'''

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
l_1 = []
l_2 = []

for i in range(N):
  l_1.append(i+A[i])
  l_2.append(i-A[i])
  
for num in range(2, max(l_2)+1):
  ans += l_1.count(num)*l_2.count(num)
      
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
L = [0]*n
R = [0]*n
cnt=0
for i in range(n):
    L[i] = i+a[i]
    R[i] = i-a[i]
z1=Counter(L)
z2=Counter(R)
print(z1)
print(z2)
cnt=0
for k1,v1 in z1.items():
    v2 = z2[k1]
    cnt += v1*v2
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))

height_minus_index_list = []
height_plus_index_list = []
height_plus_index_inverse_list = []

for i in range(n):
    height_minus_index_list.append(a_list[i] - (i + 1))
    height_plus_index_list.append(a_list[i] + (i + 1))
    height_plus_index_inverse_list.append(-1 * (a_list[i] + (i + 1)))

match_count = 0
for hmi in height_minus_index_list:
    match_count += height_plus_index_list.count(hmi)
    match_count += height_plus_index_inverse_list.count(hmi)

print(match_count)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))

l2=list(range(n))

import itertools
l3=list(itertools.combinations(l2, 2))

count=0
for i in l3:
    if i[0]+l[i[0]]==i[1]+l[i[1]]:
        count+=1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
N = [i for i in range(n)]
A = list(map(int,input().split()))
L = [N[i]+A[i] for i in range(n)]
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if L[i] == L[j]:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect, insort

def main():
    n = int(input())
    a = list(map(int, input().split()))
    h_plus_i = [ai+i for i, ai in enumerate(a, 1)]
    h_minus_i = [ai-i for i, ai in enumerate(a, 1)]
    s_h_plus_i = list(sorted(h_plus_i))
    s_h_minus_i = list(sorted(h_minus_i))
    ans = 0
    for hpi, hmi in zip(h_plus_i, h_minus_i):
        i1 = bisect_left(s_h_minus_i, -hpi)
        i2 = bisect_left(s_h_plus_i, -hmi)
        if (i1 < n and s_h_minus_i[i1] == -hpi):
            ans += bisect_left(s_h_minus_i, -hpi+1)-i1
        elif (i2 < n and s_h_plus_i[i2] == -hmi):
            ans += bisect_left(s_h_plus_i, -hmi+1)-i2
            
    print(ans//2)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
heights=list(map(int,input().split(" ")))
for i in range(n):
    heights[i]-=i
res=len(heights)-len(set(heights))
if res==0:
    print(0)
else:
    print(res+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
heights=list(map(int,input().split(" ")))
for i in range(n):
    heights[i]-=i
res=len(heights)-len(set(heights))
if res==0:
    print(0)
else:
    print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
heights=list(map(int,input().split(" ")))
res=0
for i in range(n):
    heights[i]-=i

print(len(set(heights)))

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

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

comb = np.array(list(itertools.combinations(Al, 2))).sum(axis = 1)
comb_i = np.array(list(itertools.combinations(np.arange(1, N+1), 2))).mean(axis = 1)

print((comb == comb_i).sum())

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
res = 0
dict = {}
dict[a[0]] = 1
for i in range(1,n):
  res += dict.get(abs(a[i]-i-1),0)
  dict[a[i]+i+1] = dict.get(a[i]+i+1,0) + 1
print(res)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

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

comb = np.array(list(itertools.combinations(Al, 2))).sum(axis = 1)
comb_i = np.array(list(itertools.combinations(np.arange(1, N+1), 2))).sum(axis = 1)

print((comb == comb_i).sum())

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline().rstrip())
As = list(map(int, sys.stdin.readline().rstrip().split()))

ll = [0] * N
lr = [0] * N
for i in range(N):
    ll[i] = i + 1 + As[i]
    lr[i] = i + 1 - As[i]

print(ll, lr)

ans = 0
for l in ll:
    ans += lr.count(l)

print(ans)

Submission status: Wrong Answer

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

A_1 = [0]*N
A_2 = [0]*N
for i in range(N):
    A_1[i] = A[i] + i
    A_2[i] = i - A[i]
A_1.sort()
A_2.sort()
i = 0
j = 0
count = 0
while i < N and j < N:
    if A_1[i] > A_2[j]:
        j += 1
    elif A_1[i] < A_2[j]:
        i += 1
    else:
        x = A_1.count(A_1[i])
        y = A_2.count(A_2[j])
        count += x*y
        i += x
        j += y
        
count

Submission status: Wrong Answer

Solution code:
x=int(input())
a=0
b=0
for i in range(-500,500):
  for j in range(-100,100):
    if i**5-j**5==x:
      a=i
      b=j
      break
  else:
    continue
  break
print(a,b)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float("inf")

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

min_diff = 1
max_diff = N - 1

d = defaultdict(list)
for i in range(N):
    key = i + 1 + A[i]
    d[key].append(i + 1)
# pprint(dict(d))

count = 0
for diff in range(min_diff, max_diff + 1):
    count += len(d[diff])

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
list1=list(map(int, input().split()))
l = []
for a,b in enumerate(list1):
    l.append([a,b])
sum1 = []
diff1 = []
for pair in l:
    sum1.append([pair[0]+pair[1], pair[0]])
for pair in l:
    diff1.append([pair[0]-pair[1], pair[0]])
sum1.sort()
diff1.sort()
i = 0
j = 0
count = 0
#print(sum1, diff1)
while i < len(sum1) and j < len(diff1):
    #if i==len(sum1):i=len(sum1)-1
    #if j==len(diff1):j=len(diff1)-1
    #print(sum1[i], diff1[j])
    if sum1[i][0]==diff1[j][0]:
        #if sum1[i][1]<diff1[j][1]:
        count += 1
        #j += 1
        if i < len(sum1)-1 and sum1[i][0]==sum1[i+1][0]:
            i += 1
        else:
            j += 1
        continue
    if sum1[i][0]<diff1[j][0]:
        i += 1
        continue
    j += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
index = np.array(list(range(1, N+1)))
A = np.array(list(map(int, input().split())))
a = index + A
d = list((index - A))
ans= 0
c = 1
for i in a:
  ans += d[:c].count(i)
  c += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
l_1 = []
l_2 = []

for i in range(N):
  if A[i] < (10**5)*2:
    l_1.append(A[i]+i)
    l_2.append(i-A[i])
  
for num in range(2, max(l_2)+1):
  ans += l_1.count(num)*l_2.count(num)
      
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(200010)]
R=[0 for i in range(200010)]
for i in range(N):
    if A[i]+i<100010:
        L[A[i]+i]+=1
    if -A[i]+i>0:
        R[-A[i]+i]+=1
ans=0
for i in range(200010):
    ans+=L[i]*R[i]
print(ans)

Submission status: Wrong Answer

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

add = dict()
sub = dict()
for i, ai in enumerate(a):
    if i+ai in add.keys():
        add[i+ai] += 1
    else:
        add[i+ai] = 1
    if i-ai in sub.keys():
        add[i-ai] += 1
    else:
        add[i-ai] = 1

cnt = 0
for ak, av in add.items():
    if ak not in sub.keys(): continue
    cnt += av*sub[ak]

print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0

for i in range(n):
    a_height = h_list[i]
    n_aa = i + a_height + 10 + 1
    if n_aa > n:
        n_aa = n
    for k in range(i + 1 + a_height, n_aa):
        b_height = h_list[k]
        if k - i == a_height + b_height:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
goukei = 0

N = int(input()) * (-1)
Ai = list(map(int, input().split()))
number = [j for j in range(0, N, -1)]
new_ai = number + Ai
new_ai = [x + y for (x, y) in zip(Ai, number)]
for i in range(len(Ai)):
    goukei += new_ai.count(-(Ai[i] - i))
print(goukei)

Submission status: Wrong Answer

Solution code:
goukei = 0

N = int(input()) * (-1)
Ai = list(map(int, input().split()))
number = [j for j in range(0, N, -1)]
new_ai = number + Ai
new_ai = [x + y for (x, y) in zip(Ai, number)]
for i in range(len(Ai)):
    goukei += new_ai.count(-(Ai[i] - 1))
print(goukei)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
AJ = tuple(a - i for i, a in enumerate(A))

maxnum = 2*10**5
count = 0
for i in range(0, N-1):
    if A[i] >= maxnum:
        break

    iai  = i + A[i]
    for aj in AJ[iai+1:]:
        if iai + aj == 0:
            count += 1

print(count)

Submission status: Wrong Answer

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

ij = defaultdict(int)
ji = defaultdict(int)

As = list(map(int, input().split()))
for j in range(n):
  ij[j+As[j]] += 1
  ji[j-As[j]] += 1
print(sum(ij[k] * ji[k] for k in ji.keys() if k > 1))

Submission status: Wrong Answer

Solution code:
n = int(input())
from collections import defaultdict
a = list(map(int,input().split()))
ans = 0
dp = defaultdict(int)
for e,i in enumerate(a,1):
    if i - e >= 0 :ans += dp[i-e]
    dp[i+e]+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Al = list(map(int, input().split()))

result = 0
for i in range(N):
    for j in range(i+1, N):
        if Al[j] - Al[i] == j-i:
            result += 1
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
from collections import defaultdict
a = list(map(int,input().split()))
ans = 0
dp = defaultdict(int)
for e,i in enumerate(a):
    if i - e >= 0 :ans += dp[i-e]
    dp[i+e]+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    x = int(input())

    i = 0
    while True:
        j = i ** 5
        a1, a2 = x + j, x - j

        p = a1 ** (1 / 5)
        q = a2 ** (1 / 5) if a2 >= 0 else abs(a2) ** (1 / 5) * -1

        f = int(p) - p == 0
        g = int(q) - q == 0
        if f:
            print(int(p), i)
            break
        if g:
            print(int(q), -1 * i)
            break

        i += 1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int,input().split())))
B = np.array([i+1 for i in range(n)])
C,D = A+B,B-A
ans = 0
for i in C:
    ans += np.count_nonzero(D==i)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
import copy
ori = copy.copy(A)

for i in range(N):
    A[i] -= (N - 1) - i
# print(A)
# import collections
# dct = dict(collections.Counter(A))
# print(dct)
# m = min(A)
# cnt = 0
# for check in range(m, 0):
#
#     if dct.get(check, 0):
#         print(check)
#         cnt += dct[check] * dct.get(check + 2, 0)
# print(cnt)
remove = 0
for i in range(N-2):
    if ori[i] != 1 and ori[i] == ori[i + 2]:
        remove += 1
# for i in range(N - 1):
#     if ori[i] + 1 == ori[i + 1]:
#         remove += 1
# print(remove)
# print(ori)
# print(cnt - remove)

bucket = {}
cnt = 0
for i in range(N):
    if A[i] <= 1:
        temp = bucket.setdefault(A[i], 0)
        bucket[A[i]] = temp + 1
        cnt += bucket.setdefault(A[i] - 2, 0)
# print(A)
# print(bucket)
print(cnt - remove)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
sysread = sys.stdin.readline
sys.setrecursionlimit(10**7)

def run():
    N = int(input())
    A = list(map(int, sysread().split()))

    import numpy as np
    N = 200000
    A = np.random.randint(1, N, size=N)

    A = [(idx, val) for idx, val in enumerate(A, 1) if val < N]

    ret = 0
    store = [0] * N
    for idx, val in A:
        ret += store[idx - val]
        try:
            store[idx + val] += 1
        except:
            continue
    print(ret)

if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
n = int(input())
from collections import defaultdict
a = list(map(int,input().split()))
ans = 0
dp = defaultdict(int)
for e,i in enumerate(a):
    dp[i+e]+=1
    if i - e >= 0 :ans += dp[i-e]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int, input().split()))
ans=0
for i in range(2,N-1):
  for j in range(0,N-i):
    if A[j]+A[j+i]==i:
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# 32:35
n = int(input())

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

values = dict()

for i, h in enumerate(heights):
    if (i - h) in values:
        values[i - h].append((i, h))
    else:
        values[i - h] = [(i,h)]
    if (-i -h ) in values:
        values[-i-h].append((-i, h))
    else:
        values[-i-h] = [(-i,h)]

count = 0
for j, h in enumerate(heights):
    if (j + h) in values:
        for i, ai in values[j + h]:
            if i > 0 and i > j:
                count += 1
    elif (h - j) in values:
        for i,ai in values[j - h]:
            if i < 0 and j > -i:
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
for j in range(n-2):
    for i in range(j+1,n-1):
        if a[j] + a[i] == i-j:
          count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# 32:35
n = int(input())

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

values = dict()

for i, h in enumerate(heights):
    if (i - h) in values:
        values[i - h].append((i, h))
    else:
        values[i - h] = [(i,h)]
    if (-i -h ) in values:
        values[-i-h].append((-i, h))
    else:
        values[-i-h] = [(-i,h)]

count = 0
for j, h in enumerate(heights):
    if (j + h) in values:
        for i, ai in values[j + h]:
            if i > 0 and i > j:
                count += 1
    elif (h - j) in values:
        for i,ai in values[j - h]:
            if i < 0 and j < -i:
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  for j in range(i+a[i]+2,n):  
    if j-i==a[i]+a[j]:
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
C=[0]*N

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

B.sort()
B.insert(0,-2000000000)
B.append(2000000000)
C.sort()
ans=0
for a in C:
    l1=0
    r1=N
    while r1-l1>1:
        m1=(l1+r1)//2
        if B[m1] < a:
            l1=m1
        else:
            r1=m1
    l2=0
    r2=N
    while r2-l2>1:
        m2=(l2+r2)//2
        if B[m2] <= a:
            l2=m2
        else:
            r2=m2
    if l2==0 and l1 == -1:
        pass
    else:
        ans += l2-l1
    print(l2,l1)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + list(map(int,input().split()))

def binp(arr, val):
    left,right = 0,len(arr)-1
    while left <= right:
        mid = (left+right)//2
        if val==arr[mid]: return 1
        elif val>=arr[mid]: left = mid+1
        else: right = mid-1
    return 0

ap = [a[i] + i for i in range(1,n+1)]
an = [a[i] - i for i in range(1,n+1)]
an.sort()



ans = 0
for ele in ap:
    if binp(an,-ele): ans += 1

print(ans)