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:
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)]
lc = {}
rc = {}
for i in range(n):
    lc[l[i]] = 0
    lc[r[i]] = 0
    rc[r[i]] = 0
    rc[l[i]] = 0
for i in range(n):
    lc[l[i]] += 1
    rc[r[i]] += 1
ans = 0
for i in range(n):
    if rc[l[i]] and lc[l[i]]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

B = np.zeros(11 * 10**8, dtype = "uint16")

ans = 0

for index, A in enumerate(As):
    if(index - A >= 0):
        ans += B[index-A]

    B[index+A] += 1
#    print(list(B[:20]))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

B = np.zeros(11 * 10**8, dtype = "int16")

ans = 0

for index, A in enumerate(As):
    if(index - A >= 0):
        ans += B[index-A]

    B[index+A] += 1
#    print(list(B[:20]))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

B = np.zeros(3 * 10**9, dtype = "int8")

ans = 0

for index, A in enumerate(As):
    ans += B[index-A]

    B[index+A] += 1
#    print(list(B[:20]))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

B = np.zeros(2 * 10**9, dtype = "int8")

ans = 0

for index, A in enumerate(As):
    if(index - A >= 0):
        ans += B[index-A]

    B[index+A] += 1
#    print(list(B[:20]))

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

N = int(input())

A = list(map(int, input().split()))
Ap = [i - A[i] for i in range(N)]
Ap.sort()

print(Ap)
ans = 0
for i in range(N):
	ans += bisect_right(Ap, i + A[i]) - bisect_left(Ap, i + A[i])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [i for i in map(int, input().split()) if i < n]
num = len(a)
ans = 0

for i in range(num):
    for j in range(i+1, num):
        if a[i]+a[j] == j-i:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
y=list(map(int,input().split()))
from collections import Counter
lhs=Counter([j+y[j] for j in range(n)])
rhs=Counter([j-y[j] for j in range(n)])
count=0
for i in lhs:
   if i in rhs:
      count+=lhs[i]+rhs[i]

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
nump=[0]*n
numm=[0]*n
setm=set()
for i in range(n):
    nump[i]=a[i]+i+1
    numm[i]=i+1-a[i]
    setm.add(i+1-a[i])
ans=0
for i in range(n):
    if nump[i]>n:
        break
    if nump[i] in setm:
        ans+=numm.count(nump[i])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


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

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

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

        if diff in d.keys():
            ans += d[diff]

        summed = i + a[i]

        if diff in d.keys():
            d[summed] += 1
        else:
            d[summed] = 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = [0]
A += list(map(int, input().split()))
cnt = 0
L = [- 10 ** 6]
R = [- 10 ** 6]

for i in range(1, N + 1):
    L.append(i + A[i])
    R.append(i - A[i])
L.sort()
print(L)
print(R)
for j in range(1, N + 1):
    x = bisect.bisect_left(L, R[j])
    while R[j] == L[x]:
        cnt += 1
        x += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

p = [i+Ai for i, Ai in zip(range(1, N+1), A)]
q = [j-Aj for j, Aj in zip(range(1, N+1), A)]

pc = Counter(p)
qc = Counter(q)

r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys())

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+1, N):
        if j-1 == A[i]+A[j]:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

def getInts():
    return [ int(x) for x in input().split() ]

[N] = getInts()
As = getInts()

maxV = max(As)
minV = min(As)

count = 0
for i in range(N):
    r2 = min(i+1+As[i]+minV, N-1)
    for j in range(r2, N):
        if As[j]+As[i] == abs(i-j):
            count += 1
print(count+1)

Submission status: Wrong Answer

Solution code:
import sys
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n = Ii()
a = Li()
x = [0]*n
ans = 0
for i in range(n): 
  print(x)
  if a[i]+i < n:
    x[a[i]+i] += 1
  if i-a[i] >= 0:
    ans += x[i-a[i]]
      
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

# N = 32
# A = [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 = 6
# A = [2, 3, 3, 1, 3, 1]

i = [k for k in range(1,N+1)]
j = [k for k in range(1,N+1)]

Li = [i[k]+A[k] for k in range(N)]
Rj = [j[k]-A[k] for k in range(N)]

Li = collections.Counter(Li)

counter = 0
for r in Rj:
    counter += Li[r]

Submission status: Wrong Answer

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

#index,h
pp =[]
pm = []
all_set = set()
for i in range(N):

    pp.append(i + A[i])
    pm.append( i - A[i])

count = 0
c = collections.Counter(pp)
#print(c)
for i in range(N):
    count += c[pm[i]] 
    print(c[pm[i]])

    #count += pp.count(pm[i])
    #count += pm.count(pp[i])

print(count)

Submission status: Wrong Answer

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

#index,h
pp =[]
pm = []
all_set = set()
for i in range(N):

    pp.append(i + A[i])
    pm.append( i - A[i])

count = 0
c = collections.Counter(pp)
print(c)
for i in range(N):
    count += c[pm[i]] 
    print(c[pm[i]])

    #count += pp.count(pm[i])
    #count += pm.count(pp[i])

print(count)

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
#写経
#https://atcoder.jp/contests/abc166/submissions/12796059

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
            print(i)
            print("h1")
            print(dp)
        x = i - ai
        if x >= 0:
            ans += dp[x]
            print("h2")

    print(ans)
resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
1

Submission status: Wrong Answer

Solution code:

import glob
import numpy as np
import sys
from bisect import bisect_left

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\166\\E'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class E(Common):

    def resolve(self):

        N = int( self.input_data())
        tmp = list(map(int, self.input_data().split()))
        A = []
        for i in range(N):
            A.append([i+1, tmp[i], -1*(i+1+tmp[i]), i+1-tmp[i]])

        A_sorted1 = sorted(A, key=lambda x: x[2])
        A_sorted2 = sorted(A, key=lambda x: x[3])

        count =0
        for a1 in range(1,N+1):
            keys1 = [a[2] for a in A_sorted1]
            keys2 = [a[3] for a in A_sorted2]
            a2_range = bisect_left(keys1, A[a1-1][1]-a1)
            while(True):
                if a2_range >= N:
                    break
                if A_sorted1[a2_range][2] == A[a1-1][1]-a1:
                    count += 1
                    a2_range +=1
                else:
                    break

            a2_range = bisect_left(keys2, A[a1-1][1]+a1)
            while(True):
                if a2_range >= N:
                    break
                if A_sorted1[a2_range][3] == A[a1-1][1]+a1:
                    count += 1
                    a2_range += 1
                else:
                    break

        if count > 0:
            count -= 1
        print(str(count))

solver = E(REL_PATH)
solver.exec_resolve()

Submission status: Wrong Answer

Solution code:
import collections
import sys
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    ans = 0
    c = collections.Counter()

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

    print(c)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
maxi = 2 * pow(10, 5)
A = [int(i) for i in input().split() if int(i) < maxi]
print(A)
# A[i]は問題では1から始まるので注意
# A[i], A[j]について、|j-i| == A[j]-A[i]なら極秘情報の取引をする
# この条件を満たすペアの数
# modはとらなくてよいぐらい
# i, jは2*10^5の程度だから全件で10^10の程度, A[i]は10^9の程度
# j > iとして良い。j-iの値を固定して計算はできる。
# いったんこれぐらいで始めてみよう

# だめだった
# 値の範囲で搾ろう。足し算だから
counter = 0

for i in range(len(A)):
    gap = 0
    for j in range(i+1, len(A)):
        gap += 1
        if A[j] + A[i] == gap:
            counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
print(A)
# A[i]は問題では1から始まるので注意
# A[i], A[j]について、|j-i| == A[j]-A[i]なら極秘情報の取引をする
# この条件を満たすペアの数
# modはとらなくてよいぐらい
# i, jは2*10^5の程度だから全件で10^10の程度, A[i]は10^9の程度
# j > iとして良い。j-iの値を固定して計算はできる。
# いったんこれぐらいで始めてみよう
counter = 0
for i in range(N):
    for j in range(i+1, N):
        if A[j] + A[i] == j - i:
            counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

#cnt = 0
#for i in range(N):
#  for j in range(i, N):
#    if j - i == A[i] + A[j]:
#      cnt += 1

Ap = [A[i]+i for i in range(len(A))]
Am = [i-A[i] for i in range(len(A))]

S = set(Ap) & set(Am)

Cp = Counter(Ap)
Cm = Counter(Am)

cnt = 0
for i in S:
  cnt += Cp[i]*Cm[i]

Submission status: Wrong Answer

Solution code:
N  = int(input())
a  = list(map(int,input().split()))
i = 0
key =0
while i <N:
	j=0
	if a[i] > N- i:
		pass
	else:
		while j<N:
			if abs(i-j) < a[i] or j < i:
				j = i+a[i] +1
			elif a[i] + a[j] == abs(i-j):
				key +=1
			j+=1
	i += 1

print(key)

Submission status: Wrong Answer

Solution code:
N  = int(input())
a  = list(map(int,input().split()))
key = 0
for i in range(N):
	if N - i <a[i] or (abs(N-a[i])< i and a[i] > i):
		pass
	else:
		for j in range(N-(i+1)):
			if j+1 <= a[i]:
				pass
			elif a[i] + a[j+i+1] == j +1:
				print(a[i],a[j+i+1])
				key +=1

print(key)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

cnt = 0
d = defaultdict(int)
for key in a:
    d[key] += 1

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

print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
A=[int(number) for number in a]
pluss=[]
minuss=[]
number=1
for a in A:
    plus=a+number
    minus=abs(a-number)
    pluss.append(plus)
    minuss.append(minus)
    number+=1
answer=0
suuji=0
for n in pluss:
    answers=minuss[suuji:]
    answer+=answers.count(n)
    suuji+=1


print(answer)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
hList = list(map(int, input().split()))
count = 0
n_p = collections.Counter([ i + hList[i] for i in range(len(hList))])

for i in range(N):
  if i - hList[i] > 1:
    count += n_p.get(i - hList[i], 0)

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
hList = list(map(int, input().split()))
count = 0
nList = [ i + hList[i] for i in range(len(hList))]

for i in range(N):
  tmpVal = i - hList[i]
  if tmpVal < 2:
    continue
  count += nList[i-tmpVal:i+1].count(tmpVal)

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
hList = list(map(int, input().split()))
count = 0
nList = [ i + hList[i] for i in range(len(hList))]

for i in range(N):
  tmpVal = i - hList[i]
  if tmpVal < 2:
    continue
  count += nList.count(tmpVal)

print(count)

Submission status: Wrong Answer

Solution code:
from random import randint

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

last = {}
ans = 0;

for _ in range(10**6):
    x = randint(0, n-1)
    y = randint(0, n-1)
    if abs(x-y) == a[x]+a[y] and last.get((x, y), "Hola") == "Hola":
        ans += 1;
        last[(x, y)] = 1;
        last[(y, x)] = 1;

print(ans)

Submission status: Wrong Answer

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

ai = []
aj = []
ans = 0
aiajmin = -9999999


for i in range(n):
    ai.append(i+l[i])

for j in range(n):
    aj.append(j-l[j])

#print(ai)
#print(aj)
    
aiajmin = min(max(ai),max(aj))

for x in range(n):
    if(ai[x] <= aiajmin):
        ans = ans + aj.count(ai[x])
    else:
        break
    
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split(" ")))
c=0
for i in range(n):
  for j in range(i+1,n):
    if l[j]>n-1-j:
      continue
    if l[i]+l[j]==j-i:
      c+=1
      
print(c)

Submission status: Wrong Answer

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

tmp_A = sorted(tmp_A)
min_h = sum(tmp_A[0:2])
max_h = sum(tmp_A[-2:])

print(min_h)
print(max_h)

ans = 0
for n in range(1, N + 1):
    now_h = A[n]
    min_i = max(n + 1, min(min_h, N))
    max_i = min(max_h + n + 1, N + 1)
    for i in range(min_i, max_i):
        if A[n] + A[i] is abs(n - i):
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input()) + 1
A = [0] + [int(i) for i in input().split()]
i_Ai = [i + A[i] for i in range(N)]
j_Aj = [j - A[j] for j in range(0, N)]
cnt = 0

if max(A) - min(A) > N:
    print(0)
else:
    for i in range(1, N):
        for j in range(i_Ai[i], N):
            if j_Aj[j] == i_Ai[i]:
                cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input()) + 1
A = [0] + [int(i) for i in input().split()]

cnt = 0

if max(A) - min(A) > N:
    print(0)
else:
    for i in range(1, N):
        i_Ai = i + A[i]
        for j in range(i + A[i], N):
            if (j - A[j]) == i_Ai:
                cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input()) + 1
A = [0] + [int(i) for i in input().split()]

MAX_AI = 10 ** 9
cnt = 0

if max(A) - min(A) > N:
	print(0)
else:
	for i in range(1, N):
		if MAX_AI >= i + A[i]:
			for j in range(i + A[i], N):
				if (j - i) == (A[i] + A[j]):
					cnt += 1
	print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
count=0
A={}
for i,j in enumerate(a):
    A[i+j]=0
    #print(A)
    if i-j in A:
        count+=A[i-j]
    if i+j in a:
        A[i+j]+=1
    else:
        A[i+j]=1

count=sum(A.values())
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
count=0
A={}
for i,j in enumerate(a):
    A[i+j]=0
    #print(A)
    if i-j in A.keys():
        count+=1
    if i+j in a:
        A[i+j]+=1
    else:
        A[i+j]=1

count=sum(A.values())
print(count)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
count = 0
Plist = []
for i in range(1, n+1):
    Plist.append(i + a_list[i-1])
    if i - a_list[i-1] in Plist:
        
        
        count += 1

print(count)

Submission status: Wrong Answer

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

max = max(l) * 2

ans = 0

for i in range(n):
    
    if l[i] <= n / 2 :
        j = i + l[i]
        while(j < n and j <= i+max):
    
            if j- i == l[i]+l[j]:
                ans = ans + 1
                #print(abs(j-i),l[i]+l[j],i,j)
            j = j + 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())	# 使わない

# j - i = A[i] + A[j] から、
# i + A[i] = j - A[j] となり、iとjが独立するため、同時並行で処理
L = defaultdict(lambda: 0)
R = defaultdict(lambda: 0)
for i, val in enumerate(map(int, input().split())):
  L[i - val] += 1	# i - val <= j - A[j]
  R[i + val] += 1	# i + val <= i + A[i]
  
print(L)
print("===")
print(R)

cnt = 0
for key, val in L.items():
  if key > 0:
    cnt += L[key] * R[key]
    
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import *
n = int(input())
a = list(map(int, input().split()))
c = Counter()
r = 0
for i in range(n):
    r += c[a[i]+i] 
    c[i-a[i]] += 1
print(r)

Submission status: Wrong Answer

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

max = max(l) * 2

ans = 0

for i in range(n):
    j = i + 1
    if l[i] <= n / 2 :
        while(j < n and j <= i+max):
    
            if abs(j- i) == l[i]+l[j]:
                ans = ans + 1
                #print(abs(j-i),l[i]+l[j],i,j)
            j = j + 1
print(ans)

Submission status: Wrong Answer

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


ans = 0

d1 = {}
d2 = {}
for i in range(N):
    if i+1 + A[i] in d1:
        d1[i+1 + A[i]] += 1
    else:
        d1[i+1 + A[i]] = 1
    if i+1 - A[i] in d2:
        d2[i+1 - A[i]] += 1
    else:
        d2[i+1 - A[i]] = 1


for a in d1.keys():
    if a in d2:
        # print(d2[a])
        ans += d2[a]
        ans += d1[a]-1


# print(d1)
# print(d2)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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 = collections.Counter(L)

countR = collections.Counter(R)


print([countL[n] * countR[n] for n in countL.keys()])

Submission status: Wrong Answer

Solution code:
N = int(input())

height = input()
height = height.split()
height = [int(s) for s in height]

count = 0

iAi = [0] * N
jAj = [0] * N

for i in range(N):
    iAi[i] = i+1 + height[i]
    jAj[i] = i+1 -height[i]

for i in range(N):
    if jAj.count(iAi[i]) >= 1:
        count +=1


print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    heights = list(map(int, input().split()))

    """
    for j>i, j-i = Ai + Aj
    i + Ai = j -Aj
    """

    L = [0] * N
    R = [0] * N

    count = 0
    for i, height in enumerate(heights):
        left = i + height
        right = i - height
        
        if left < N:
            L[left] += 1

        if right > 0:
            R[right] += 1
            count += L[right] * R[right]    

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

height = input()
height = height.split()
height = [int(s) for s in height]

count = 0

for i in range(N):
  for j in range(i+1, N):
    if j-1 == height[i] + height[j]:
      count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[i for i in map(int,input().split())]
B=[]
C=[]
for i in range(N):
  B.append(A[i]+i+1)
for j in range(N):
  C.append(A[j]-j-1)
c=0
for a in range(N):
  for b in range(N):
    if a>b and B[a]==C[b]:
      c+=1
    if a<=b and B[a]==-C[b]:
      c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split(' ')))
kotae = 0
for i in range(N):
  for j in range(N-i):
    if i == j:
      continue
    if abs(i-j) == h[i]+h[j]:
      kotae+=1
print(kotae)

Submission status: Wrong Answer

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

ls = []
rs = []
for i, num in enumerate(a, 1):
    ls.append(-1*num+i)
    rs.append(num+i)

count = 0
for r in rs:
    if r in ls:
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
assert n >= 2
a = [int(x) for x in input().split()]
assert len(a) == n
ap = Counter([i + x for i, x in enumerate(a)])
am = Counter([i - x for i, x in enumerate(a)])
count = sum([v * ap.get(k, 0) for k, v in am.items() if k > 1])
print(count)

Submission status: Wrong Answer

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

max = max(l) * 2

ans = 0

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

    while(j < n and j <= i+max):

        if abs(j- i) == l[i]+l[j]:
            ans = ans + 1
            print(abs(j-i),l[i]+l[j],i,j)
        j = j + 1
print(ans)

Submission status: Wrong Answer

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

check = {}
ans = 0

for i in range(N):
    x = i - A[i]
    y = A[i] + i
    ans += check.get(x, 0)
    check.setdefault(y, 0)
    check[y] += 1

print(ans)
print(check)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = input().split()
pare = N*(N-1)/2
pares = 0
for i in range(N):
    for j in range(N):
        if abs(i-j) == As[i] + As[j] :
            pares += 1
print(pares)

Submission status: Wrong Answer

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

b = [i for i in a if i < n]

ans = 0
for j in range(len(b)):
    for k in range(j+1, len(b)):
        #print(j,k)
        if  a[j] + a[k] == abs(j - k):
           #print(j,k, a[j],a[k])
           ans = ans + 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

for i in range(N):
    for j in range(N-i-A[i]):
        k=i+j+A[i]
        if A[i]+A[k]==abs(i-k):
            count = count+1
            print("{} {}".format(i+1,k+1))



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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

for i in range(N):
    for j in range(N-i):
        k=i+j
        if A[i]+A[k]==abs(i-k):
            count = count+1
            print("{} {}".format(i+1,k+1))



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

Submission status: Wrong Answer

Solution code:
x = int(input())
l = [int(x) for x in input().split()]
counter = 0
for p in range(x):
  if l[p] > x:
    break
  for q in range(p):
    if p - q  == l[p] + l[q]:
      counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
k = (n*(n-1))//2

for i in range(1,n+1):
  for j in range(1,n+1):
    if abs(i-j) == a[i-1]+a[j-1]:
      ans +=1
print(ans/2)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
  N = int(input())
  
  list_n = range(1, N, 1)
  list_A = list(map(int, input().split(" ")))
  
  num_pair = 0
  for i in range(N-1, 2, -1):
    for j in range(i-1, 1, -1):
      sum_A = list_A[i] + list_A[j]
      if sum_A == abs(i - j):
        num_pair += 1
        
  print(num_pair)

Submission status: Wrong Answer

Solution code:
from math import sqrt

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

sum = 0
for i in range(person):
    for j in range(i, min(i + longs[i], person)):
        if (j - i) == longs[i] + longs[j]:
            sum += 1
print(sum)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
count = 0
b = []
c = []

for i in range(n):
    b.append(a[i]+i)
    c.append(i-a[i])
t = Counter(b)
for s in c:
    count += t[s]
    print(t[s],s)
print(t,1)
print(count)

Submission status: Wrong Answer

Solution code:
x = int(input())

for a in range(-117, 120):
    for b in range(-117, 120):
        if x == a**5 - b**5:
            print(a, b)
            break
    else:
        continue
    break

Submission status: Wrong Answer

Solution code:
x = int(input())

for a in range(-117, 120):
    for b in range(-117, 200):
        if x == a**5 - b**5:
            print(a, b)
            break

Submission status: Wrong Answer

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


##Miss 1
# from itertools import combinations

# comb = list(combinations([i for i in range(N)],2))

# cnt=0
# for i in comb:
#     if Agents[i[0]] + Agents[i[1]] == abs(i[0] - i[1]):
#         print(i[0],i[1])
#         cnt+=1

# print(cnt)

# Miss 2
# for i in range(0,N):
#     k=Agents[i]-(i+1)
#     if k<i:
#         k=i+1
#     for j in range(k,N):
#         if Agents[i]+Agents[j]==abs(i-j):
#             # print(i,j,Agents[i],Agents[j])
#             cnt+=1


L={}
for i in range(N):
    L['{}'.format(i+1)]=i+1 + Agents[i]
R={}
for j in range(N):
    R['{}'.format(j+1)]=j+1 - Agents[j]

print(L)
print(R)

cnt=0

for key,value in L.items():
    for key2,value2 in R.items():
        if int(key) < int(key2) and value == value2:
            cnt+=1


print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

L = {}
R = {}

for i in range(N):
  t = A[i]+i
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  s = i - A[i]
  if s in R:
    R[s] += 1
  else:
    R[s] = 1  
print(L,R)
ans = 0
for i in range(N):
  t = A[i]+i
  #ans += R[t]
  if t in R.keys():
    ans += R[t]
    print(t,R[t])
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
height_list = list(map(int,input().split()))

spy_dict = {}
for i in range(0,N):
    spy_dict[i+1] = height_list[i]

L_dict = {}
R_dict = {}
for i in spy_dict:
    L = i + spy_dict[i]
    L_dict[i] = L
    R = i - spy_dict[i]
    R_dict[i] = R

counter = 0
for i in range(1,N):
    for j in range(i+1,N+1):
        print(i, j)
        if L_dict[i] == R_dict[j]:
            counter += 1

print(counter)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

memo = defaultdict(int)
ans = 0
for i, h in enumerate(A, start=1):
    ans += memo[h+i]
    memo[i-h] += 1

print(ans)

Submission status: Wrong Answer

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

i = 0
ans = 0
while i < n-1:
    j = a[i] + 1
    t = 1
    while j<n:
        if t == a[i] + a[j]:
            ans += 1
        j += 1
        t += 1
    i += 1

print(ans)

Submission status: Wrong Answer

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

B = []
for j in range(n):
    B.append(j - A[j])

C = []
for i in range(n):
    C.append(i + A[i])

d = defaultdict(int)

for j in A:
    d[j] += 1

count = 0
for k in B:
    count += d[k]

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
A = A[A<=2*(10**5)]

H = [0]*(5*(10**5))
L = [0]*(5*(10**5))

for i in range(len(A)):
    H[A[i]+i] += 1
    if i-A[i] >= 0:
        L[i-A[i]] += 1

ans = 0

for i in range(5*(10**5)):
    ans += H[i]*L[i]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
i_plus_A = Counter([i + A[i] for i in range(N)])
i_minus_A = [i - A[i] for i in range(N)]
i_minus_A = [x for x in i_minus_A if x > 1]
print(sum(i_plus_A[x] for x in i_minus_A))

Submission status: Wrong Answer

Solution code:
x,r=int(input()),range(-99,99);[i**5-x-j**5or exit(print(i,j))for i in r for j in r]

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[a.index(i)+1-i for i in a]
c=[a.index(i)+1+i for i in a]
from collections import defaultdict
B=defaultdict(int)
C=defaultdict(int)
for i in range(len(a)):
  B[b[i]]+=1
  C[c[i]]+=1
ans=0
for i in B:
  ans+=B[i]*C[i]
print(ans)