Problem:


Score: 500 points

Problem Statement

You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.

There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.

According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.

The absolute difference of their attendee numbers is equal to the sum of their heights.

There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?

P.S.: We cannot let you know the secret.

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the number of pairs satisfying the condition.

Sample Input 1

6
2 3 3 1 3 1

Sample Output 1

3

A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.

A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.

A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.

No other pair satisfies the condition, so you should print 3.

Sample Input 2

6
5 2 4 2 8 8

Sample Output 2

0

No pair satisfies the condition, so you should print 0.

Sample Input 3

32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Sample Output 3

22



Sample input:
6
2 3 3 1 3 1


Sample output:
3

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
A=deque(map(int,input().split()))
S=0
for i in range(N):
    for j in range(N-i):
        if j==A[0]+A[j]:
            S+=1
        A.popleft
print(S)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for a,b in itertools.combinations(range(N+1),2):
    if abs(a - b) == A[a-1] + A[b-1] :
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
hlist = list(map(int, input().split()))
alist = list(range(1, n+1))

shlist = []
for height in hlist:
    if height < n - 1:
        shlist.append(height)

ans = 0
# The absolute difference of their attendee numbers is equal to the sum of their heights.
for i, h1 in enumerate(shlist):
    for j, h2 in enumerate(shlist):
        if abs(i-j) == h1+h2:
            ans += 1
print(ans//2)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

amax = max(a)
s = 0
for k in range(n):
    for i in range(k + a[k], min([n, k + amax + a[k]])):
        if a[k] + a[i] == i - k:
            s += 1
print(s)

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

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

tmp_1 = Counter([i - A[i] for i in range(n)])
tmp_2 = Counter([i + A[i] for i in range(n)])
res = 0

for i in range(max(max(tmp_1.keys()), max(tmp_2.keys()))):
    if i in tmp_1.keys() and i in tmp_2.keys():
        res += tmp_1[i] * tmp_2[i]

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math , sys

N  = int( input() )

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

M = max( [ i + A[i] for i in range(N) ])

B = [0 for _ in range(2*M + 1)]

ans = 0

for i in range(N):
    if i - A[i] >=0:
        ans += B[i - A[i]]
    B[i + A[i]]+=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(1,n):
  for j in range(0,i):
    st=j
    while st+i<=n-1:
      x=a[st]
      y=a[st+i]
      if x+y==i:
        ans+=1
      st=st+i
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = [a+i for i, a in enumerate(A)]
C = [j-a for j, a in enumerate(A)]
b_min = min(B)
b_max = max(B)
B, C = Counter(B), Counter(C)
ans = 0
for k in range(b_min, b_max):
    ans += B[k]*C[k]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().rstrip().split()]
cnt=0
for i in range(N):
  for j in range(i+1,N):
    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()) )

left = [i+A[i] for i in range(n)]
right = [i-A[i] for i in range(n)]

ans = 0

for l in left:
    ans += right.count(l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
import numpy as np

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

b = copy.copy(a)

cnt = 0
for i in range(n-1):
  a.pop(0)
  b.pop(-1)
  l = np.array(a) + np.array(b)
  cnt += list(l).count(i+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,n):
    if j-i == a[i]+a[j]:
      cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    L = [i+A[i-1] for i in range(1,N+1)]
    R = [i-A[i-1] for i in range(1,N+1)]
    import collections
    Lcnter = collections.Counter(L)
    Rcnter = collections.Counter(R)
    values = set(Lcnter.keys()) & set(Rcnter.keys())
    ans = 0
    for i in values:
        if i in L and i in R:
            ans += Lcnter[i]*Rcnter[i]
    print(ans)
    


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    L = [i+A[i-1] for i in range(1,N+1)]
    R = [i-A[i-1] for i in range(1,N+1)]
    import collections
    Lcnter = collections.Counter(L)
    Rcnter = collections.Counter(R)
    limit = max(max(Lcnter.keys()), max(Rcnter.keys()))
    ans = 0
    for i in range(limit+1):
        if i in L and i in R:
            ans += Lcnter[i]*Rcnter[i]
    print(ans)
    


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

j_Aj = [0]

for j, aj in enumerate(a):
    j_Aj.append(j + 1 - aj)
i_Ai = [0] * (max(j_Aj)+1)
ans = 0
for j, j_aj in enumerate(j_Aj):
    if j == 0:
        continue
    if j_aj >= 2:
        ans += i_Ai[j_aj]
    if j + a[j - 1]<=max(j_Aj):
        i_Ai[j + a[j - 1]] += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]

dic = {}
for i in range(n):
  a = lst[i]
  if a >= n - 1:
    continue
  if a not in dic:
    dic[a] = set()
  dic[a].add(i)
#print(dic)
count = 0
for a in dic.keys():
  set_ = dic[a]
  for index in set_:
    b = a + index
    if b > n:
      continue
    for c in dic.keys():
      j = b + c
      if j in dic[c]:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]

dic = {}
for i in range(n):
  a = lst[i]
  if a >= n - 1:
    continue
  if a not in dic:
    dic[a] = set()
  dic[a].add(i)
#print(dic)
count = 0
for a in dic.keys():
  set_ = dic[a]
  for index in set_:
    b = a + index
    if b > n:
      continue
    for c in range(n - b):
      if c in dic:
        j = b + c
        if j in dic[c]:
          count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
np,nm=[],[]
for i in range(N):
    np.append(A[i]+i)
    nm.append(i-A[i])
sp,sm=sorted(np),sorted(nm)
ans=0
for i in range(N):
    p,m=np[i],nm[i]
    l,r=0,N
    while not l+1==r:
        x=(l+r)//2
        if sm[x]<=p:
            l=x
        else:
            r=x
    while sm[l]==p and l>=0:
        ans+=1
        l-=1
    l,r=0,N
    while not l+1==r:
        x=(l+r)//2
        if sp[x]<=m:
            l=x
        else:
            r=x
    while sp[l]==m and l>=0:
        ans+=1
        l-=1
print(ans//2)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
ans=[list() for i in range(N)]
ans2=0
for i in range(N):
  a=L[i]+i
  if a<N:
    ans[a].append(0)
for i in range(1,N):
  ans[i]+=[k+1 for k in ans[i-1]]
for i in range(N):
  ans2+=ans[i].count(L[i])
print(ans2)

Submission status: Time Limit Exceeded

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

maxVal = N + max(A)
ans = 0

L = defaultdict(int)
R = defaultdict(int)
for x in range(1, maxVal+1):
    for i in range(1, N+1):
        if i + A[i-1] == x:
            L[i+A[i-1]] += 1

    for j in range(1, N+1):
        if j - A[j-1] == x:
            R[j-A[j-1]] += 1


for x in range(1, maxVal+1):
    ans += L[x] * R[x]

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=[int(i) for i in input().split()]



def count(num_list):
    l=len(num_list)
    num_array=np.array(num_list[1:])
    check=np.array(range(1,l))-num_list[0]
    ans=num_array-check
    return l-np.count_nonzero(ans)-1
ans=0
for i in range(0,n-1):
    check_list=a[i:]
    ans+=count(check_list)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
 
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
hs = Is()

ans = 0
for h in range(1, n):
  for x in range(n-h):
    ans += 1 if hs[x] + hs[x+h] == h else 0
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# ni - nj = ai + aj (i>j)
# ai - ni = - aj - nj

a1 = [a[i] - (i+1) for i in range(n)]
a2 = [- a[i] - (i+1) for i in range(n)]
ans = 0
for i in range(n):
    ans += a2.count(a1[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = list(map(int,input().split()))
di = []
cnt = 0
for i in range(n):
    if i == 0:
        for j in range(1,n):
            di.append(ls[j]+ls[i])
            if ls[j] + ls[i] == abs(j-i):
                cnt += 1
    else:
        for j in range(i+1,n):
            if di[j-1]+di[i-1]-ls[0]*2 == j-i:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = list(map(int, input().split()))
ans = 0
list = []
#A1からAnにそれぞれ番号を振る
for i in range(a):
    list.append((i+1, b[i]))
list_1 = []
list_2 = []
#i+Aiとi-Aiを計算してリストに入れる
for i in range(a):
  list_1.append(i+1+b[i])
  list_2.append(i+1-b[i])
#2つのリストに共通する要素を抽出
ans_list = set(list_1) & set(list_2)
#2つのリストにおける共通要素の出現回数を掛けてansに加算
for i in ans_list:
  ans += list_1.count(i)*list_2.count(i)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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(i+1-a[i])
  c.append(a[i]+i+1)
for i in range(n-1):
  for j in range(i+1,n):
    if b[j]==c[i]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

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

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]

count = 0
for i in range(n):
  a = lst[i]
  if n - i - 1 <= a:
    continue
  for j in range(i + 1, n):
    if j - i > a:
      b = lst[j]
      if j - i == a + b:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from copy import deepcopy
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a2 = deepcopy(a)

    for j1 in range(1, n):
        a2[j1] -= j1
    r = 0
    for i1 in range(n - 1):
        r += a2[i1+1:].count(-(a[i1]+i1))
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    a = tuple(map(int, input().split()))

    r = 0
    for i1 in range(n - 1):
        for i2 in range(1, n - i1):
            r += a[i1+i2] == i2 - a[i1]
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
member = list(map(int,input().split()))
member_height = np.array(member)
ans = 0
member_num = np.arange(1,N+1)
for i in range(N):
    member_num -= 1
    check = member_num - member_height
    ans += np.count_nonzero(member_height[i]==check)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



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

Submission status: Time Limit Exceeded

Solution code:
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

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

B = []
for i,a in enumerate(A):
    if a <= N-1:
        B.append([a,i])
if len(B)==0:
    print(0)
    exit()
B.sort()
cnt = 0
for i in range(len(B)):
    for j in range(i+1,len(B)):
        if B[i][0]+B[j][0]==abs(B[i][1]-B[j][1]):
            cnt +=1
        if B[i][0]+B[j][0]>=N:
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
B = []
for i,a in enumerate(A):
    B.append([a,i])
B.sort()
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if B[i][0]+B[j][0]==abs(B[i][1]-B[j][1]):
            cnt +=1
        if B[i][0]+B[j][0]>=N:
            break
print(cnt)

Submission status: Time Limit Exceeded

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)]

p = {}
m = {}
for i in range(N):
    if L[i] not in p:
        p[L[i]] = 1
    else:
        p[L[i]] += 1
for i in range(N):
    if R[i] not in m:
        m[R[i]] = 1
    else:
        m[R[i]] += 1

lower = min(min(p), min(m))
upper = max(max(p), max(m))
ans = 0
for x in range(lower, upper + 1):
    if x in p and x in m:
        ans += p[x] * m[x]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
p = [i + A[i] for i in range(N)]
m = [j - A[j] for j in range(N)]
a = min(p)
b = max(m)
for i in range(a,b+1):
    if i in p and i in m:
        ans += p.count(i) * m.count(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):
    for j in range(i+1,N):
        if j-i == A[i] + A[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
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])
for j in range(1, N + 1):
    cnt += L.count(R[j])

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力

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


cnt = 0

for i in range(n - 1):
    if a[i] < 200000:
        for j in range(i + 1, n):
            if j - i == a[i] + a[j]:
                cnt += 1

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力

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 j - i == a[i] + a[j]:
            cnt += 1

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力

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 abs(j - i) == abs(a[i] + a[j]):
            cnt += 1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ni = np.array([i for i in range(n)])

ap = a + ni
an = (a - ni) * -1
an.sort()
ans = 0
for j in an[::-1]:
  if j <= 0:break
  for i in ap:
    if j == i:
      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):
  x = i+a[i]
  for j in range(x+1, n):
      if j - x == 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):
    for j in range(i+a[i]-1, n):
        if a[i] + a[j] == abs(i-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 + 1, n):
        if j - i == a[i] + a[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.zeros(N, dtype='int32')
    count = 0
    C = {}
    for i in range(N):
        x = i - A[i]
        cx = C.get(x, ([],[]))
        C[x] = (cx[0], cx[1] + [i])
        x = i + A[i]
        cx = C.get(x, ([],[]))
        C[x] = (cx[0] + [i], cx[1])
    for a,b in C.values():
        count += len(a) * len(b)

    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.zeros(N, dtype='int32')
    count = 0
    i = 0
    for j in range(i+1, N):
        B[j] = A[i] + A[j] - j
    count += np.count_nonzero(B[i+1:] == 0)
    for i in range(1, N-1):
        count += np.count_nonzero(B[i+1:] == -(-A[0] + A[i] + i))
    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.zeros(N, dtype='int32')
    count = 0
    i = 0
    for j in range(i+1, N):
        B[j] = A[i] + A[j] - (j - i)
    count += np.count_nonzero(B[i+1:] == 0)
    for i in range(1, N-1):
        B += A[i] - A[i-1] # 身長
        B += 1 # 番号
        count += np.count_nonzero(B[i+1:] == 0)
    print(count)
main()

Submission status: Time Limit Exceeded

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+As[i]+minV, N-1)
    for j in range(r2, N):
        if As[j]+As[i] == abs(i-j):
            count += 1
print(count)

Submission status: Time Limit Exceeded

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):
    r1, r2 = max(0, i+1-As[i]-minV), min(i+1+As[i]+maxV, N-1)
    for j in range(r1, r2+1):
        if As[j]+As[i] == abs((j+1)-(i+1)):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dat = list(map(int, input().split()))
buf = []
for i in range(n):
    buf.append(i - dat[i])
#print(buf)
res = 0
for i in range(n):
    x = i + dat[i]
    for j in range(i+1, n):
        if x == buf[j]:
            res += 1
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

number = [i for i in range(1,n+1)]

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [0]
A.extend(list(map(int,input().split())))
pair = 0

for i in range(1,n+1):
  for j in range(i+1,n+1):
    num = abs(i-j)
    if A[i]+A[j] == num:
      pair += 1
      
print(pair)

Submission status: Time Limit Exceeded

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

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


res = 0
for i in range(N):
    if A[i] >= N:
        continue
    for j in range(i,N):
        if abs(i-j) == A[i] + A[j]:
            res += 1

print(res)

Submission status: Time Limit Exceeded

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

ct = 0
for i in range(n):
    k = 0
    for j in range(Ai[i] + i,n):
        if Ai[j] == k:
            ct += 1
        k += 1

print(ct)

Submission status: Time Limit Exceeded

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

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

for i in range(N):
  sign[i] += A[i]

count = 0
for i in range(1,N):
  temp = i+1-A[i]
  for j in range(i):
    if sign[j]==temp:count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t = list(map(int, input().split()))
r = []
ans = 0
for i in range(len(t)):
  r.append(i+1 + t[i])
for i in range(len(t)):
  if((i+1 - t[i]) >= 1):
    ans += r.count(i+1-t[i])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#index,h
pp =[]
pm = []
mp = []
mm = []
for i in range(N):
    pp.append(i + A[i])
    pm.append( i - A[i])
    mp.append(-i + A[i])
    mm.append(-i - A[i])
count = 0
for i in range(N):
    count += pp.count(pm[i])
    #count += pm.count(pp[i])
print(count)

Submission status: Time Limit Exceeded

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

a_p = [0]*n
a_m = [0]*n
ans = 0

for i in range(n):
    a_p[i] = a[i] + i+1
    a_m[i] = i+1 -a[i]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if a_p[i] == a_m[j]:
            ans = ans + 1

print(ans)

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)
  if i - v > 1:
    c[i - v].append(i)
c = dict(c)
# print(f'{b=}')
# print(f'{c=}')

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

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)
c = dict(c)

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

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)
c = dict(c)

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