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())
List=list(map(int,input().split()))
a=max(List)
count=0
for i in range(1,2*a+1):
    for k in range(n-i+1):
        if List[k+i-1]+List[k-1]==i:
            count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right
from heapq import heappush, heapify, heappop
N = int(input())
A = list(map(int, input().split()))
c = []
b = []
for i in range(N):
    heappush(c, 10**7*(A[i]+i)+i)
    b.append(i-A[i])
ans = 0
heapify(c)
a = []
inds = []
for i in range(N):
    x = heappop(c)
    a.append(x//(10**7))
    inds.append(x%(10**7))
for i in range(N):
    if b[i] <= 0:
        continue
    ind1 = bisect_left(a, b[i])
    ind2 = bisect_right(a, b[i])
    for j in range(ind1, ind2):
        if inds[j] > i:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))

dp = []
base_num = A_list[0]
for i in range(1, N):
    dp.append(i - (base_num + A_list[i]))

ans = 0
for i in range(N):
    print(base_num - A_list[i] - i)
    ans += dp.count(-1 * (base_num - A_list[i] - i))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
B = [0] * (n)
C = [0] * (n)
kouho = defaultdict(int)
ans = 0
for i in range(n):
    ans += kouho[abs(A[i] - (i + 1))]
    kouho[A[i] + (i + 1)] += 1

print(ans)

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]
    if i + 21 < n:
        n_aa = i + 21
    else:
        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:
import collections
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[]
for i in range(n):
    b.append(abs(a[i]-i+1))
#print(b)
ans=0
b=collections.Counter(b)
for i in b.values():
    ans+=i*(i-1)//2
print(ans)

#print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    print(N)
    h_list = list(map(int, input().split()))
    print(h_list)
    c_list = list(itertools.combinations(range(N),2))
    ans = 0

    for c in c_list:
            if abs(c[0] - c[1]) == h_list[c[0]] + h_list[c[1]]:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import bisect


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    negA = []
    idx_negA = []
    for i, a in enumerate(A):
        negA.append(a - i)
        idx_negA.append(i)

    negA = sorted(negA)
    ans = 0
    for i in range(N):
        searched_idx = bisect.bisect(negA, i - A[i])
        # print(i, searched_idx)
        if searched_idx == N:
            continue
        else:
            if idx_negA[searched_idx] > i:
                while negA[searched_idx - 1] == i - A[i] and searched_idx <= N:
                    ans += 1
                    searched_idx += 1

    print(ans)

Submission status: Wrong Answer

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

count = 0
for a in range(1, n + 1):
    for b in range(a + 1, n + 1):
        print(a, b)
        if abs(a - b) == alist[a-1] + alist[b-1]:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:

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

for s in range(1, n-2):
    for t in range(s+A[s-1]+1, n+1):
        if A[s-1] + A[t-1] == t-s:
            pn += 1

print(pn)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    A_1 = list(map(int, input().split()))
    B_l = [1 - A_1[0]]

    sum = 0
    
    for i in range(1, N):
        if A_1[i] in B_l:
            sum += 1

        B_l = list(map(lambda x: x+1, B_l))
        B_l.append(2 - A_1[i])

        
    print(sum)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = 0
Ai = [A[i] + i for i in range(N)]
Aj = [j + A[j] for j in range(N)]
setAi = set(Ai)
setAj = set(Aj)

intersection = setAi.intersection(setAj)
print(len(intersection))

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
                continue
    if (h - j) in values:
        for i,ai in values[j - h]:
            if i < 0 and j < -i:
                count += 1
                continue

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
A = input().split()
Ai = [int(s) for s in A]
count = 0
for x, y in itertools.combinations(range(N), 2):
        if abs(x-y)+100 == Ai[x]+Ai[y]:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
# dp = [0]*N
# for i in range(N-1):
#     t = A[i]
#     if t > 200000:
#         continue
#     for j in range(i+t+1, N):
#         if j-i == t+A[j]:
#             cnt += 1
# print(cnt)

# i<j
# j-i = A[i]+A[j]
# j-A[j] = i+A[i]
# j+A[j] = i-A[i]

dp = [0]*(4*2*10**5+10)
for i in range(N):
    num = A[i]
    if num > 200000:
        continue   
    dp[i+num] += 1
    dp[i-num] += 1

for num in dp:
    if num > 1:
        cnt += num*(num-1)//2

print(cnt//2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))

dp = []
base_num = A_list[0]
for i in range(1, N):
    dp.append(i - (base_num + A_list[i]))

ans = 0
for i in range(N):
    ans += dp.count(base_num - A_list[i] - i)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
a = [int(i) for i in input().split()]
l = list(itertools.permutations(a, 2))
ans = 0
for i in range(len(l)):
  for j in range(i+1, n):
    if j-i == l[i][1]+l[i][0]:
      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) or (i2 < n and s_h_plus_i[i2] == -hmi):
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

from collections import Counter

C = Counter(A)
D = Counter(B)

E = list(C.keys())
F = list(D.keys())


ans = 0
for i in E:
    ans += C[i]*D[i]

print(ans//2)

Submission status: Wrong Answer

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

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

ans=0
left = 0
right = 1
while left < right and right < n:
    print(left,right,l[left][0] + l[right][0] , abs(l[left][1] - l[right][1]))
    if l[left][0] + l[right][0] > abs(l[left][1] - l[right][1]) or left+1==right:
        right += 1
    elif l[left][0] + l[right][0] == abs(l[left][1] - l[right][1]):
        ans += 1
        right += 1  #ここ
    elif l[left][0] + l[right][0] < abs(l[left][1] - l[right][1]) or left + 1 != right:
        left+=1

print(ans)

Submission status: Wrong Answer

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

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

for s in range(1, n-2):
    if s+A[s-1] > n:
        break
    for t in range(s+A[s-1]+1, n+1):
        if A[s-1] + A[t-1] == t-s:
            pn += 1

print(pn)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_l = list(map(int,input().split()))
ia = list(enumerate(a_l))
del_l = []
for j in range(n):
    if ia[j][1] >= n-1:
        del_l.append(j)
for j in del_l[::-1]:
    del ia[j]
        
count = 0
i = 0
while True:
    if i > len(ia)-1:
        break
    i1, a1 = ia[i]
    if a1 >= n-1-i1:
        del ia[i]
        continue
    for i2, a2 in ia[i1+a1+1:n]:
        if (i2-i1) == (a2+a1):
            count += 1
    i += 1

print(count)

Submission status: Wrong Answer

Solution code:
"""
全列挙では間に合わない。

dpでもない気がする。
NlogN以下で求めないと行けない。

あるいは枝刈りすればいいのか？
すべてのペアで成立する可能性もあるし。

O(N)で解けるな
"""
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(N):
    B.append((A[i]-(i+1),i))

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

count = set()
i = 0
j = len(B)-1

while i < j:
    if B[i][0] + B[j][0] == 0:
        if B[i][1] != B[j][1]:
            a = max(B[i][1],B[j][1])
            b = min(B[i][1],B[j][1])
            count.add((a,b))
        if B[i][0] == B[i+1][0]:
            i += 1
            continue
        else:
            j -= 1
            continue
    if B[i][0] + B[j][0] < 0:
        i += 1
        continue
    else:
        j -= 1
        continue 
print(len(count))

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
# b = a -1 とすると、bi+bj = -2*i or -2+j となるi,jを見つける
# sortして2分探索すると解ける
b = [a[i] - i - 1 for i in range(0, n)]
b.sort()
ans = 0
for i in range(n):
    # b[i]を固定して2分担s買う
    r = bisect.bisect_right(b, -b[i] - 2 * i)
    l = bisect.bisect_left(b, -b[i] - 2 * i)
    if l != r:
        ans += r - l
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())

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

cnt = 0

for i, j in itertools.product(range(N), range(N)):
        s = abs((i+1)-(j+1))
        if s == A[i]+A[j]:
            cnt +=1
print(cnt/2)

Submission status: Wrong Answer

Solution code:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))

  for i in range(1,N):
    AA[i] = AA[i] - i
  #print(AA)
  AA_d = AA.copy()
  cnt = 0
  AA_l = list(set(AA_d))
  for i in AA_l:
    cnt += int(AA_d.count(i)*(AA_d.count(i)+1)/2)-1
  print(cnt)
solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
Alist=list(map(int,input().split()))
result=[[0]*(N)]*N

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

total = 0
for i in result:
    total += sum(i)
print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
k=0
t=max(a)
p=min(a)
for i in range(n):
    r=min(n,a[i]+t)
    s=max(0,a[i]+p)
    for j in range(s,r):
        if a[j]+a[i]==abs(j-i):
            k+=1
print(k)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
pl = []
sb = []
for i in range(len(a)):
	pl.append(i+int(a[i])+1)
	if i - int(a[i]) > 1:
		sb.append(i-int(a[i])+1)


if len(sb) == 0:
	print('0')
else:

# spl = sorted(pl)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	# t = min(ssb)

	cnt = 0

	for i in ipl:
		for j in ssb:
			if i == j:
				cnt += 1
			if i < j:
				break

	print(cnt)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    A_1 = list(map(int, input().split()))
    B_l = [1 - A_1[0]]

    sum = 0
    
    for i in range(1, N):
        if A_1[i] in B_l:
            sum += 1

        B_l = list(map(lambda x: x+1, B_l))
        B_l.append(1 - A_1[i])

        
    print(sum)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    a=LIST()
    an=[]
    ans=0
    for i in range(n):
        an.append(0-(a[i]-i-1))
    an=sorted(an)
    #print(an)
    for i in range(n):
        temp=i+1+a[i]
        ans+=an.count(temp)
    print(int(ans/2))
    
if __name__ == '__main__':
    do()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

m=max(a_list)
cnt=0

for i,a in enumerate(a_list):
    if i+a+m>N:
        lim=N
    else:
        lim=i+a+m
    for j in range(i+a-1,lim):
        if a+a_list[j]==j-i:
            cnt+=1

print(cnt)

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
while i < len(sum1) and j < len(diff1):
    if sum1[i][0]==diff1[j][0]:
        if sum1[i][1]<diff1[j][1]:
            count += 1
        j += 1
        continue
    if sum1[i][0]<diff1[j][0]:
        i += 1
        continue
    j += 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-a[len(a)-1]):
    for j in range(i+a[i]+1,n):
        if j-i==a[i]+a[j]:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

ans = 0

for i, a in enumerate(A):
    for j, b in enumerate(A[i+a+1:]):
        if j  == b:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

# print(A)
ans = 0

for i in range(N):
    ans += sum((A + A[i]) - [abs(i - j) for j in range(N)] == 0)


print(ans / 2)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[]
for i in range(n):
    b.append(a[i]-i+1)
#print(b)
ans=0
b=collections.Counter(b)
for i in b.values():
    i=abs(i)
    ans+=max(0,i*(i-1)//2)
print(ans)

#print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
from collections import deque
ans = deque()

for i in range(n-1):
    for j in range(i+1,n):
        ans.append(abs(a[i]-a[j]) - (j-i))

ans = list(ans)
print(ans.count(0)-1)

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    x = int(readline())

    ab = [i**5 for i in range(70)]

    C = combinations_with_replacement(ab, 2)
    for a, b in C:
        if a + b == x:
            print(int(pow(b, 0.2)), -int(pow(a, 0.2)))
            break
        
        if b - a == x:
            print(int(pow(b, 0.2)), int(pow(a, 0.2)))
            break


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    A_1 = list(map(int, input().split()))
    B_l = [1 - A_1[0]]

    sum = 0
    
    for i in range(1, N):
        if A_1[i] in B_l:
            sum += 1

        B_l = list(map(lambda x: x+1, B_l))
        B_l.append(0 - A_1[i])

        
    print(sum)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
cnt=0
a=[int(e) for e in input().split()]
for i in range(1,n):
    if n-i>=a[i]-1:
        for j in range(i+1,n+1):
            if a[i-1]+a[j-1]==j-i:
                cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
A = [int(i) for i in input().split()]
d = []
for i in range(N):
    d.append([i+1-A[i], i+1+A[i]])

d.sort()
keys = [r[0] for r in d]
ans = []

for i in range(N):
    tmp = keys[i+1:]
    b = bisect.bisect_left(tmp, d[i][1])
    if 0<= b < len(tmp):
        ans.append(b)

print(len(ans))

Submission status: Wrong Answer

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

for a in range(1, n+1):
    for b in range(1, n+1):
        if a >= b :
            continue
        if abs(a - b) == H[a] + H[b]:
            print(a, b, a-b)
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = []
Adif = []
for i, j in enumerate(A):
    Asum.append(i-j)
    Adif.append(i+j)
ind = len(A)
Adif = ([0]*ind)+Adif
Asum = np.array(Asum)
Adif = np.array(Adif)

ans = 0
for i in range(1, ind):
    temp = (Asum == Adif[ind-i:2*ind-i])

    ans += temp.sum()

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[]
for i in range(n):
    b.append(a[i]-i+1)
#print(b)
ans=0
b=collections.Counter(b)
for i in b.values():
    ans+=i*(i-1)//2
print(ans)

#print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

for i in range(N):
  A[i] = [i, A[i]]
  
"""
for i in range(N):
  if A[i][1] > 2 * 10**5:
    del A[i]
if len(A) < 2:
  print(0)
  continue
"""
  
for p in itertools.combinations(A, 2):
  if abs(p[0][0]-p[1][0]) == p[0][1]+p[1][1]:
    cnt += 1

print(int(cnt/2))

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()
C.sort()
ans=0
for a in C:
    l1=-1
    r1=N-1
    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:
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]

print(spy_dict)

counter = 0
for v in itertools.permutations(range(1,N+1),2):
    if spy_dict[v[0]] + spy_dict[v[1]] == abs(v[0] - v[1]):
        counter += 1

print(counter/2)

Submission status: Wrong Answer

Solution code:
n=int(input())
cnt=0
a=[int(e) for e in input().split()]
for i in range(1,n):
    if n-i>=a[i]:
        for j in range(i+1,n+1):
            if a[i-1]+a[j-1]==j-i:
                cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(_) for _ in input().split(" ")]

ans=0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
an = map(int,input().split())
A = list(an)
y=0
for i in range(n-1):
    for j in range(i+1, n):
        if(A[i] + A[j] == j -i):
            y=y+1
            break
            
print(y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

na =[[0]*n for i in range(n)]
for i in range(n):
	na[i][0] = i
	na[i][1] = a[i]

na.sort()

y = 0
for i in range(n):
	if na[i][1]>n:
		y = i
		break
else:
	y = n
	
c = 0
for i in range(y-1):
	for j in range(i+1,y):
		if abs(na[i][0]-na[j][0]) == na[i][1]+na[j][1]:
			c += 1

print(c)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
A = list(map(int, input().split()))
A_dict = {}
ans = 0

for i in range(len(A)):
    if (i+1) <=2 * 10**5:
        A_dict[i+1] = A[i]

for k_1, v_1 in sorted(A_dict.items(), key=lambda x:x[1], reverse=True):
    for k_2, v_2 in sorted(A_dict.items(), key=lambda x:x[1], reverse=True):
        if v_1 + v_2 > 2 * 10 ** 5:
            break
        if abs(k_2 - k_1) == v_1 + v_2:
            ans += 1

print(ans // 2)

Submission status: Wrong Answer

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

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

for s in range(1, n+1):
    if s+A[s-1] > n:
        break
    for t in range(s+A[s-1]+1, n+1):
        if A[s-1] + A[t-1] == t-s:
            pn += 1

print(pn)

Submission status: Wrong Answer

Solution code:
def main():
  import collections
  N = int(input())
  sanka_l = list(map(int, input().split()))
  c_l = collections.Counter(sanka_l)
  num_list = list(c_l.keys())
  num_cou = list(c_l.values())
  K = len(num_list)
  count = 0
  for i in range(K):
    A = num_list[i]
    if num_cou[i] > 1:
      for j in range(i, K):
        B = num_list[j]
        sum = A + B
        for p in range(N-sum):
          if sanka_l[p] + sanka_l[p+sum] == sum:
            count += 1
    else:
      for j in range(i+1, K):
        B = num_list[j]
        sum = A + B
        for p in range(N-sum):
          if sanka_l[p] + sanka_l[p+sum] == sum:
            count += 1
  print(count)
    
main()

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
alist=list(map(int,input().split()))
blist=copy.deepcopy(alist)

sum=0
for i,a in enumerate(alist):
    for j in range(i+a,n):
        if j-i ==a+blist[j]:
            sum+=1
            print(i,j)

print(sum)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

Submission status: Wrong Answer

Solution code:
N = int(input())
As = [int(n) for n in input().split()]
# len(As) = N
# Ai = 身長
c = 0
for i, ai in enumerate(As):
    # i + ai = 最低これだけ先が無いとダメ
    j0 = i + ai
    if j0 >= N-1:
        continue
    j = 1
    while True:
        if j == As[j0+j]:
            c += 1
        if j0+j >= N-j:
            break
        if N-j0-j == As[N-j]:
            c += 1
        j+=1
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
pl = []
sb = []
for i in range(len(a)):
	pl.append(i+int(a[i])+1)
	if i - int(a[i]) > 1:
		sb.append(i-int(a[i])+1)


if len(sb) == 0:
	print('0')
else:

# spl = sorted(pl)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)
	# tl = [0] * max(ipl)
	tl = [0] * 2000000
	for i in ssb:
		if int(i)-1 < len(tl):
			tl[int(i)-1] += 1
	print(pl)
	print(sb)
	print(tl)
	cnt = 0
	for i in pl:
		if int(i)-1 < len(tl):
			cnt += tl[int(i)-1]

	print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
*A, = map(int, input().split())
t = [[A[i], i] for i in range(N)]
t.sort()

ta = [v for v, i in t]
ti = [i for v, i in t]

ans = 0
for i in range(N):
    r = N-i-ta[i]
    ri = bisect.bisect_right(ta, r)
    for j in range(i+1, ri):
        if (ta[i]+ta[j]) == abs(ti[i]-ti[j]):
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
d={}
def diff(a,b):
    if a>b:
        return(a-b)
    else:
        return(b-a)
for i in range(0,len(l)):
    if l[i]>2*10**5:
        pass
    else:
        d[i+1]=l[i]

l=list(d.keys())
for i in range(0,len(l)):
    for j in range(i+1,len(l)):
        if diff(i,j)==d[l[j]]+d[l[i]]:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
N,*A = map(int,open(0).read().split())
cnt = 0
for i in range(N):
    ind = A[i] + 1 + i
    if ind < N and A[A[i] + 1 + i] == 1:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0

    for i,i_height in enumerate(A):
        for j, j_height in enumerate(A):
            if i<=j:
                continue
            if i-j == i_height + j_height:
                print(i,j)
                ans += 1
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

# A[0]との和 - idxの差
box = [0] * (n - 1)

for i in range(n - 1):
  box[i] = A[0] + A[i + 1] - i - 1

ans = 0
for a in A:
  ans += sum(i == (A[0] - a) for i in box)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_l = list(map(int,input().split()))
ia = list(enumerate(a_l))
del_l = []
for j in range(n):
    if ia[j][1] >= n-1:
        del_l.append(j)

for j in del_l[::-1]:
    del ia[j]
        
count = 0
for i1, a1 in ia[:-1]:
    if a1 >= n-1-i1:
        continue
    for i2, a2 in ia[i1+a1+1:n]:
        if (i2-i1) == (a2+a1):
            count += 1

print(count)

Submission status: Wrong Answer

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

count = 0
for i in range(n):
    if A[i] == i: continue
    for j in range(i+1,n):
        if A[i]+A[j] == j-i: count += 1
print(count)

Submission status: Wrong Answer

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

ans =0
for i in range(n):
    a = l[i]
    for j in range(i+a+1,n):
        if l[j] == j+1:
            ans+=1
            break
            
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  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-i == A[i] + A[j]:
        ans += 1
        print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
pl = []
sb = []
for i in range(len(a)):
	pl.append(i+int(a[i])+1)
	if i - int(a[i]) > 1:
		sb.append(i-int(a[i])+1)


if len(sb) == 0:
	print('0')
else:

# spl = sorted(pl)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)
	# tl = [0] * max(ipl)
	tl = [0] * 2000000
	for i in ssb:
		if int(i)-1 < len(tl):
			tl[int(i)-1] += 1
	# print(pl)
	# print(sb)
	# print(tl)
	cnt = 0
	for i in pl:
		if int(i)-1 < len(tl):
			cnt += tl[int(i)-1]

	print(cnt)