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: Time Limit Exceeded

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

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  c[i - v].append(i)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(enumerate(map(int, readline().split()), 1))

ans = 0
for (i, b), (j, c) in combinations(a, 2):
  # print(f'{i=} {b=} {j=} {c=} {i-j=} {b+c=}')
  if abs(i - j) == abs(b + c):
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from bisect import bisect_right

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

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

cnt = defaultdict(list)
for i in range(n):
	cnt[b[i]].append(i)

ans = 0
for i in range(n):
	k = bisect_right(cnt[c[i]], i)
	ans += len(cnt[c[i]][k:])

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

N = i()
A = l()
L = []
L2 = []
for i in range(N):
    L.append(i+A[i]+1)
    L2.append(i-A[i]+1)
ans = 0
for l in L:
    c = L2.count(l)
    ans += c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = list(map(int,input().split()))
di = sorted(ls)
mx = di[-1]+di[-2]
mn = di[0]+di[1]
p = 0
for i in range(mn,mx+1):
    for j in range(n-i):
        if i == ls[j]+ls[j+i]:
            p += 1
print(p)

Submission status: Time Limit Exceeded

Solution code:
def CHK():
    N = int(input())
    A = list(map(int,input().split()))
    L=[]
    cnt = 0
    for i in range(N):
        L.append(i + A[i])
        R = i - A[i]
        cnt += L.count(R)
    print(cnt)

CHK()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


L=[]
cnt = 0
for i in range(N):
    L.append(i + A[i])
    R = i - A[i]
    if R in L:
        cnt += L.count(R)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

cnt = 0
for iter in itertools.combinations(range(0,N),2):
    if abs(iter[0] - iter[1]) == A[iter[0]] + A[iter[1]]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

B=[]
C=[]
for i,a in enumerate(A):
  B.append(a-i)
  C.append(-a-i)
ans=0
for b in B:    
  ans+=C.count(b)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# E - This Message Will Self-Destruct in 5s
from bisect import *
N = int(input())
A = list(map(int,input().split()))
l = []
ans = 0
for j in range(N):
    tmp = j-A[j]
    ans += bisect_right(l,tmp)-bisect_left(l,tmp)
    insort(l,A[j]+j)
print(ans)

Submission status: Time Limit Exceeded

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

pair_count = 0

for i in range(N):
    for j in range(i+1,N):
        if abs(i-j) == A[i]+A[j]:
            pair_count+=1

print(pair_count)

Submission status: Time Limit Exceeded

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

a_max = max(a_list)
count = 0
for i in range(N):
    for j in range(max(0, i-a_list[i]-a_max), max(0, i-a_list[i])):
        if abs(i-j) == (a_list[i]+a_list[j]):
            count += 1
    
#    for j in range(min(N, i+a_list[i]), min(N, i+a_list[i]+a_max)):
#        if abs(i-j) == (a_list[i]+a_list[j]):
#            print('b', i, j)
#            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

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

ans = 0
for s in range(n):
    for e in range(s + 1, n):
        if e - s == aL[s] + aL[e]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
calc = []
for i in range(1, N+1):
  tmp = i - high[i-1]
  calc.append(i + high[i-1])
  if tmp in calc[:-1]:
    cnt += calc[:-1].count(tmp)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

cnt = 0

for tup in itertools.combinations(range(N), 2):
  if abs(tup[0]-tup[1]) == (high[tup[0]]+high[tup[1]]):
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    count = 0
    for i in range(1,N):
        A_roll = np.roll(A, i)
        count += sum((A + A_roll)[i:] == i)
    print(count)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np
def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    Aindex = np.array(list(itertools.combinations(range(N),2)))
    count = 0
    for i in range(len(Aindex)):
        if A[Aindex[i,0]] + A[Aindex[i,1]] == abs(Aindex[i,0] - Aindex[i,1]):
            count += 1
    print(count)
resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

n = int(input())
nums = list(map(int, input().split()))
ans = 0
for f in range(1,n):
    for l in range(f+1, n+1):
        if(abs(f-l)==nums[f-1]+nums[l-1]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
arr = list(map(int, input().split()))
i_arr =[]
j_arr =[]

ans = 0
for i in range(N):
    i_arr.append(i+arr[i])
    dic = collections.Counter(i_arr)
    j_arr.append(-1*arr[i]+i)
    ans += dic[j_arr[-1]]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arr = list(map(int, input().split()))
i_arr =[]
j_arr =[]

for i in range(N):
    i_arr.append(i+arr[i])
    j_arr.append(-1*arr[i]+i)

ans = 0
for i in range(N):
    for j in range(i,N):
        if i_arr[i] == j_arr[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import glob
import numpy as np
import sys

# 問題ごとのディレクトリのトップからの相対パス
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())
        A = list(map(int, self.input_data().split()))
        A.insert(0,0)
        count =0
        for a1 in range(1,N+1):
            for a2 in range(a1+1,N+1):
                if A[a1] + A[a2] == abs(a1-a2):
                    count += 1

        print(str(count))

solver = E(REL_PATH)
solver.exec_resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
    N=int(sys.stdin.readline())
    A=list(map(int,sys.stdin.readline().split()))
    res=0
    for i in range(N):
        for j in range(i+1,N):
            if A[i]+A[j]==abs(j-i):res+=1
    print(res)
if __name__=='__main__':main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# 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):
    bi = i+A[i]
    for j in range(i+1, N):
        if j-A[j] == bi:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

# 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
B = [i+A[i] for i in range(N)]
C = [j-A[j] for j in range(N)]
for i in range(N):
    bi = B[i]
    for j in range(i+1, N):
        if C[j] == bi:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

# 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
B = [i+A[i] for i in range(N)]
C = [j-A[j] for j in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if C[j] == B[i]:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())
a  = list(map(int,input().split()))
i = 0
key =0
r =[0]*N
h =[0]*N
for i in range(N):
	r[i] = a[i]+i
for i in range(N):
	h[i] = i-a[i]
i=0
while i <N:
	j=r[i]
	while j<N:	
		if r[i] == h[j]:
			key +=1
		j += 1
	i+=1

print(key)

Submission status: Time Limit Exceeded

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
			else :
				j+=1
			if j >= N:
				break			
			if a[i] + a[j] == abs(i-j):
				key +=1

	i += 1

print(key)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
tempi=[0]*n
tempj=[0]*n
for i in range(n):
  tempi[i]=a[i]+i+1
for i in range(n):
  tempj[i]=-a[i]+i+1
for i in range(n):
  ans=ans+tempj.count(tempi[i])
print(ans)

Submission status: Time Limit Exceeded

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)-a[i]):
			#if j+1 <= a[i] or N - <a[i]:
			#	pass
			if a[j+i+1+a[i]] == j +1:
			#	print(a[i],a[j+i+1+a[i]],i,i+j+1+a[i])
				key +=1

print(key)

Submission status: Time Limit Exceeded

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:
				key +=1

print(key)

Submission status: Time Limit Exceeded

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  # j-i=Ai+Aj
  # Ai+i=j-Aj

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

  ans=0
  for i,x in enumerate(a[i:]):
    ans+=b.count(x)

  for i,x in enumerate(b[i:]):
    ans+=a.count(x)

  return ans

# main()
print(main())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np 
N = int(input())
A = list(map(int, input().split()))
A =np.array(A,dtype=int)
id =np.arange(1,N+1)

count =0
for i in range(1,N+1):
    x2_big = id[i+1:] -A[i+1:] #各人のidと身長の差
    x1 = i +A[i-1] #iの身長とidの和
    count += np.count_nonzero(x1 ==x2_big)     
    
    """x2_small = id[:i] +A[:i] #各人のidと身長の差
    x1 = i -A[i-1] #iの身長とidの和
    count += np.count_nonzero(x1 ==x2_small)     
    """
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np 
N = int(input())
A = list(map(int, input().split()))
A =np.array(A,dtype=int)
id =np.arange(1,N+1)

count =0
for i in range(1,N+1):
    x2_big = id[i+1:] -A[i+1:] #各人のidと身長の差
    x1 = i +A[i-1] #iの身長とidの和
    count += np.count_nonzero(x1 ==x2_big)     
    
    x2_small = id[:i] +A[:i] #各人のidと身長の差
    x1 = i -A[i-1] #iの身長とidの和
    count += np.count_nonzero(x1 ==x2_small)     
print(count//2)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np 
N = int(input())
A = list(map(int, input().split()))
A =np.array(A,dtype=int)
id =np.arange(1,N+1)

count =0
for i in range(1,N+1):
    x1 = A +A[i-1]
    x2 = abs(id -i)
    count += np.count_nonzero(x1 -x2 ==0)     
print(count//2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = 0
B =[]
for i in range(N):
    if A[i] > N:
        continue
    B.append([i,A[i]])
for i in range(len(B)):
    for j in range(len(B)-1,i+1,-1):
        if B[i][1] + B[j][1] == B[j][0] - B[i][0]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

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


resolve()

Submission status: Time Limit Exceeded

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

A=list(map(int,input().split()))
B=[]
C=[]
ans=0

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

for i in B:
  ans+=C.count(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum = 0
l_list = []
r_list = []
for i, a_ in enumerate(a):
    l_list.append(i + a[i])
    r_list.append(i - a[i])

for i, left in enumerate(l_list):
    sum += r_list[i:].count(left)

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
dicta = {}
for i in range(n):
    dicta[i + 1] = a[i]
for i in range(1, n + 1):
    if dicta[i] > n:
        del dicta[i]

s = 0
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        if ((i in dicta) == False) | ((j in dicta) == False):
            continue
        ndif = abs(i - j)
        tsum = dicta[i] + dicta[j]
        if ndif == tsum:
            s += 1

print(s)

Submission status: Time Limit Exceeded

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

s = 0
for i in range(n):
    for j in range(i + 1, n):
        ndif = abs(i - j)
        tsum = a[i] + a[j]
        if ndif == tsum:
            s += 1

print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(int(i) for i in input().split())  
A = np.array(A)
cnt = 0
for i in range(N-1):
  A_tmp = A[i+1:]
  A_tmp = A_tmp - np.array(list(range(len(A_tmp)))) - 1 + A[i] 
  cnt += np.count_nonzero(A_tmp== 0)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy
N = int(input())
A = list(int(i) for i in input().split())  
A = np.array(A)
A_index = np.array(list(range(N)))+1
cnt = 0
for i in range(N-1):
  A_tmp = A.copy()
  A_index_tmp = A_index.copy()
  A_index_tmp -= i+1
  A_tmp += A[i]
  A_tmp -= A_index_tmp
  cnt += np.count_nonzero(A_tmp[i+1:] == 0)
print(cnt)

Submission status: Time Limit Exceeded

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

count = 0

for k in range(1, n):
    for l in range(k+1, n+1):
        if l - k == a[k-1] + a[l-1]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())

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

num = 0

num_sum = 0

count = 0

for ((i,_),(j,_)) in itertools.combinations(enumerate(A), 2):
    
    num = abs(i-j)

    num_sum = A[i] + A[j]

    if num == num_sum:
        
        count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[0]*n
a=list(map(int,input().split()))
L=[]
R=[]
ans=0
for i in range(n):
    L.append(i-a[i])
    R.append(i+a[i])
    ans+=L.count(R[i])+R.count(L[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p < n:
        if p in l:
            l[p] = l[p]+[i]
        else:
            l[p] = [i]
    if q > 0:
        if q in r:
            r[q] = r[q]+[i]
        else:
            r[q] = [i]
ans = 0
for i in l:
    if i in r:
        ans+= len(l[i])*len(r[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p in l:
        l[p] = l[p]+[i]
    else:
        l[p] = [i]
    if q in r:
        r[q] = r[q]+[i]
    else:
        r[q] = [i]
ans = 0
for i in l:
    if i in r:
        ans+= len(l[i])*len(r[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = []
r = []
for i in range(n):
    l += [i+a[i]]
    r += [i-a[i]]
ans = 0
for i in range(n):
    ans+=r.count(l[i])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
# sys.setrecursionlimit(2000000)

def main():
    N = int(input())
    As = [int(s) for s in input().split()]

    ans = 0
    for i in range(N):
        if ( i + 1 )- As[i] <= 0:
            continue

        for k in range(i):
            if (i + 1) - (k + 1) == As[i] + As[k]:
                ans += 1

    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
ar=np.array(list(map(int, input().split())))
ans=0
ar_r = np.arange(1, N-1)
for i in range(N):
    if N-(i+ar[i]) >= 2:
        ans += sum( ar[i+1+ar[i]:]==ar_r[:N-(i+ar[i])-1] )
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
ar=np.array(list(map(int, input().split())))
ans=0
ar_r = np.array(list(range(1, N-1)))
for i in range(N):
    if N-(i+ar[i]) >= 2:
        ans += sum( ar[i+1+ar[i]:]==ar_r[:N-(i+ar[i])-1] )
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
ar=np.array(list(map(int, input().split())))
ans=0

for i in range(N):
    if N-(i+ar[i]) >= 2:
        ans += sum( ar[i+1+ar[i]:]==np.array(list(range(1, N-(i+ar[i])))) )
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:

def main():
    pass
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(N-1, 0,-1):
        if i >= A[i] and i-A[i] >= 0:
            for k in range(0,i-A[i]):
                if i-k == A[i] + A[k]:
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():
    pass
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(N-1, 0,-1):
        if i-A[i] >= 0:
            for k in range(0,i-A[i]):
                
                if i-k == A[i] + A[k]:
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
high=list(map(int,input().split()))
high_i=[]
high_j=[]
ans=0

for m in range(N):
    tmp_i=m+high[m]
    high_i.append(tmp_i)

for n in range(N):
    tmp_j=n-high[n]
    high_j.append(tmp_j)

for p in range(N):
    for q in range(p+1,N):
        if high_i[p]==high_j[q]:
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split(" ")]
r = [i+1-j for i, j in enumerate(a)]
l = [j+i+1 for i, j in enumerate(a)]
ans = 0
for i in set(r):
    p = r.count(i)
    q = l.count(i)
    ans += p*q
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split(" ")])
c = np.arange(1, n)
ans = 0
for i in range(n):
    ans += np.sum(a[i+1:]+a[i] == c[:n-i-1])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split()))
k=0
for x in range(n):
    for y in range(x+1,n):
        ax=a[x]
        ay=a[y]
        if (abs(x-y)==ax+ay):
            k+=1
print(k)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
p = list(map(int, input().split()))
sum = [i + 1 + x for i, x in enumerate(p)]
dif = [i + 1 - x for i, x in enumerate(p)]
ans = 0

for i in range(N):
    ans += sum.count(dif[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
p = list(map(int, input().split()))
sum = [i + 1 + x for i, x in enumerate(p)]
dif = [i + 1 - x for i, x in enumerate(p)]
ans = 0

for i in range(N):
    for j in range(i + 1, N):
        if dif[j] == sum[i]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#j-i=Ai+Aj(j>i)
#j-Aj=Ai+i

#Lj=Ri=X
from bisect import bisect_left

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

    L={}
    R={}
    for i in range(N):
        l=(i+1)-A[i]
        r=A[i]+i+1
        if (l in L.keys()):
            L[l].append(i+1)
        else:
            L[l]=[i+1]
        if (r in R.keys()):
            R[r].append(i+1)
        else:
            R[r]=[i+1]
    
    L_zip=zip(L.keys(),L.values())
    R_zip=zip(R.keys(),R.values())

    L_zip=sorted(L_zip)
    R_zip=sorted(R_zip)

    R_key,R_value=zip(*R_zip)

    res=0


    for l,l_index in L_zip:
        if l>0:
            ind=bisect_left(R_key ,l)
            if R_key[ind]==l:
                for l in l_index:
                    for r in R_value[ind]:
                        if l>r:
                            res+=1
            if ind>=1:
                R_key=R_key[ind-1:]
                R_value=R_value[ind-1:]

    print(res)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
X, Y = [], []
for i in range(N):
    X.append(i + 1 + A[i])
    Y.append(i + 1 - A[i])
X.sort()
Y.sort()
y = 0
c = 0
for i in range(N):
    if X[i] > Y[-1]:
        break
    for j in range(y, N):
        if X[i] == Y[j]:
            c += 1
            y = Y[j]
        if X[i] < Y[j]:
            break
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
X, Y = [], []
for i in range(N):
    X.append(i + 1 + A[i])
    Y.append(i + 1 - A[i])
X.sort()
Y.sort()
c = 0
for i in range(N):
    if X[i] > Y[-1]:
        break
    for j in range(N):
        if X[i] == Y[j]:
            c += 1
        if X[i] < Y[j]:
            break
print(c)

Submission status: Time Limit Exceeded

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=number-a
    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)