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:
#!/usr/bin/env python3
import sys
from itertools import combinations


def solve(N, A):
    # bg = []
    # sm = []
    cl = set()
    for i in range(N):
        if A[i] <= i - 1:
            # bg.append(i)
            cl.add(i)
        if A[i] >= 1 - i:
            # sm.append(i)
            cl.add(i)
    L = list(combinations(cl, 2))
    ct = 0
    for l in L:
        if abs(l[0] - l[1]) == A[l[0]] + A[l[1]]:
            ct += 1
    print(ct)
    # L = list(combinations(range(N), 2))
    # ct = 0
    # for l in L:
    #     if abs(l[0] - l[1]) == A[l[0]] + A[l[1]]:
    #         ct += 1
    # print(ct)
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
            for line in sys.stdin:
                for word in line.split():
                    yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    A = [int(next(tokens)) for _ in range(N)]
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
arg = np.argsort(A)
B = np.sort(A)
count = 0
for i in range(N):
    for j in range(i+1,N):
        if B[i] + B[j] ==  abs(arg[j] - arg[i]):
            count += 1
        if B[i] + B[j] > N:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())

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

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

print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[[i+1,0] for i in range(n)]
for i,v in enumerate(list(map(int,input().split()))):
    a[i][1]=v
a.sort(key=lambda x: x[1])
ans=0
for i,v in enumerate(a):
    for j in range(i+1,n):
        tmp=a[j][1]+v[1]
        if tmp>=n:
            break
        if tmp==abs(v[0]-a[j][0]):
            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 j-i==a[j]+a[i]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
h = [int(x) for x in input().split(" ")]


cnt = 0
for i in range(1, N):
    left = 0
    right = i
    while(right < N):
        if h[right] + h[left] == i:
            cnt += 1
            #print((left, right))
        left += 1
        right += 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):
    for j in range(i+1,N):
        if A[i]+A[j] == j-i:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    A = kwargs["A"]
    res = 0
    R = [[0 for j in range(n + 1)] for i in range(n + 1)]

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

    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            R[i][j] = R[0][i] + R[0][j]

            if j - i == R[i][j]:
                res += 1

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    kwargs["n"] = [int(i) for i in cin][0]
    #kwargs["n"], kwargs["k"] = [int(i) for i in cin]

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    kwargs["A"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(N-1):
  H=A[i]
  if i+H+2>N:
    continue
  for j in range(i+H+1,N):
    if H+i-j==-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):
    for j in range(a[i] + 1 + i, n):
        if j - i == a[j] + a[i]:ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N=int(input())
A_values=list(map(int,input().split()))
#A_keys=[i+1 for i in range(N)]
#A_dict=dict(zip(A_keys,A_values))
l=[i for i in range(N)]

temp=0

#for i in range(N-2):
#  for j in range(i+2,N):
for i,j in itertools.combinations(l, 2):
  if abs(i-j)==A_values[i]+A_values[j]:
    temp+=1
print(temp)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=0
a=list(map(int,input().split()))
now=max(a)
matc=list([] for i in range(n+2*now))
for i in range(n):
  matc[now-a[i]].append([i,0])
  matc[now+a[i]].append([i,1])
  now+=1
matc=filter(lambda x: x != [], matc)
#print(matc)
for j in matc: 
  count0=0
  count1=0
  for k in j:
    if k[1]==0:
      count0+=1
    else:
      count1+=1
  ans+=count0*count1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = eval(input())
A = [eval(v) for v in input().strip().split(" ")]

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
A = np.array(list(map(int, input().split())))
X = A+np.arange(N)+1
S = A*(-1)+np.arange(N)+1
Ans=0
for i in range(N):
    Ans+=S[i:].tolist().count(X[i])
print(Ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

npar = np.array(a)
npl = np.arange(n)
ans = 0
for i in npl:

    c = npar + npar[i]
    c = c - (npl - i)

    ans += n - np.count_nonzero(c)

print(ans)

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = [int(x) for x in input().split()]
cnt = 0
for i in range(n):
    num = a_list[i]
    for j in range(i + num, len(a_list)):
        if a_list[i] + a_list[j] == j - i:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_lst = [int(elem) for elem in input().split()]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int( input() )
array_a = input().split()

h_min = 10 ** 9
for a in array_a:
    if h_min > int( a ):
        h_min = int( a )

cnt = 0
for i in range( n ):
    h_i = int( array_a[i] )
    for j in range( i + h_i + h_min, n ):
        h_j = int( array_a[j] )
        if j - i == h_i + h_j:
            cnt = 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):
    if i == N-1:
        if A[i]+A[N-1] == 1:
            cnt += 1
    else:
        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())
hgts = list(map(lambda x:int(x),input().split()))
susp = 0
for i in range(n-1):
  for j in range(i+1,n):
    if j-i==hgts[i]+hgts[j]:
      susp += 1
print(susp)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(participant)-1):
  for j in range(i+1, len(participant)):
    if j - i == participant[i] + participant[j]:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
N=II()
A=LI()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
import sys
input = sys.stdin.readline

n = int(input())
memberlist = [i for i in range(1,n+1)]
lengthlist = list(map(int, input().replace("\n","").split()))

combilist = list(combinations(memberlist, 2))

ans = 0
for i in range(len(combilist)):
    """
    print(list(combilist[i]))
    print(abs(list(combilist[i])[0] - list(combilist[i])[1]))
    print(lengthlist[list(combilist[i])[0]-1] + lengthlist[list(combilist[i])[1]-1])
    print("----------")
    """
    if abs(list(combilist[i])[0] - list(combilist[i])[1]) == (lengthlist[list(combilist[i])[0]-1] + lengthlist[list(combilist[i])[1]-1]):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
s=set(a)
r=0
for i in range(len(a)):
    for _a in s:
        index=a[i]+_a+i
        if index<len(a) and a[index]==_a:
            r+=1
print(r)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
A = list(map(int, input().split()))
ans, d = 0, dict()

for i in range(N):
    diff = A[i] + A[0] - i 
    if d.get(diff) == None:
        d[diff] = [i]
    else:
        d[diff].append(i)

diff = 0
if d.get(0) != None:
    ans += len(d[0])

for i in range(1, N):
    diff -= A[i] - A[i-1] + 1
    dl = d.get(diff) 
    if dl != None:
        index = bisect.bisect_right(dl, i)        
        d[diff] = d[diff][index:]
        ans += len(d[diff])

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n=ii()
    a=lmis()
    a_m=sorted(a)
    mm=a_m[-1]+a_m[-2]+1
    cnt=0
    for i in range(len(a)-2):
        for j in range(i+2,min(i+mm,len(a))):
            if j-i==a[i]+a[j]:
                cnt+=1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

cnt = deque([])
res = 0

for i, a in enumerate(reversed(A)):
  cnt = deque([e - 1 for e in cnt])
  res += cnt.count(-a)
  cnt.append(a)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(1000000)




def main():
    n = int(input())
    a_dic = {}
    i = 0
    count = 0
    for a in map(int, input().split()):
        a_dic[i] = a
        for j in range(i):
            if i - j == a + a_dic[j]:
                count += 1
        i += 1

    # for i in range(n):
    #     ai = a_dic[i]
    #     for j in range(i+1, n):
    #         # combi = (i,j)
    #         if j - i == ai + a_dic[j]:
    #             count += 1
    print(count)



main()

# sys.setrecursionlimit(1000000)
#
#
#
#
# def main():
#     n = int(input())
#     x_dic = {}
#     y_dic = {}
#     i = 0
#     for a in map(int, input().split()):
#         x_dic[i] = a + i
#         y_dic[i] = i - a
#
#         i += 1
#
#     count = 0
#     for i in range(n):
#         ai = a_dic[i]
#         for j in range(i+1, n):
#             # combi = (i,j)
#             if j - i == ai + a_dic[j]:
#                 count += 1
#     print(count)
#
#
#
# main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(_) for _ in input().split()]
ans=0
for i in range(n):
    t=a[i]
    for j in range(i,n):
        ans+=a[j]==j-i-t
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(max(i+1, 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()))
m=0
for i in range(N-1):
  for j in range(N-1-i):
    k=i+j+1
    if j+1==A[i]+A[k]:
      m=m+1
print(m)

Submission status: Time Limit Exceeded

Solution code:
#import itertools

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

for i in range(n):
    jc = a[i]
    for j in a[a[i]:]:
        if a[i] + j == jc - i:
            c += 1
        jc += 1

#for i in itertools.combinations(range(n), 2):
#    if a[i[0]] + a[i[1]] == i[1] - i[0]:
#        c += 1

print(c)

Submission status: Time Limit Exceeded

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

import numpy as np


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

index_list = np.arange(N)

count = 0
for i in range(N):
    h = heights[i]
    count += np.count_nonzero((heights + i + h)[i+1:] == index_list[i+1:])

print(f"{count}")

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
u=0
for i in range(1,N):
  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: Time Limit Exceeded

Solution code:
n=int(input())
a=[0]*n
a[:]=map(int,input().split())
import numpy as np
r=0
for ii in range(n):
  for jj in np.arange(ii+1,n):
    if a[ii]+a[jj]==abs(ii-jj):
      r+=1
print(r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
l = list(map(int, input().split()))
s = set()
for idx, height in enumerate(l):
    for in_idx, in_height in enumerate(l):
        if idx == in_idx:
            continue
        if abs(idx - in_idx) == height + in_height:
            if idx > in_idx:
                s.add((in_idx, idx))
            else:
                s.add((idx, in_idx))
print(len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input().strip())
A = [int(i) for i in input().split()]
res = 0
for n in range(N):
    for m in range(n+1,N):
        if m - n == A[n] + A[m]:
            res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

J = list(itertools.combinations([i for i in range(N)], 2))

for i in range(len(J)):
  if J[i][1]-J[i][0] == A[J[i][1]]+A[J[i][0]]:
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    r = 0
    for i1 in range(n-1):
        tall = a[i1]
        for i2 in range(i1 + tall+1, n):
            r += (i2 - i1) == tall + a[i2]

    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

ans = sum(list(
  A[i+1:].count(-A[i] - 2 * i) for i in range(N)
))
  
print(ans)

Submission status: Time Limit Exceeded

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

cnt = []
res = 0

for i, a in enumerate(reversed(A)):
  cnt = [e - 1 for e in cnt]
  res += cnt.count(-a)
  cnt.append(a)

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split())) 
ans = 0
cnt = 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n=int(input())
a_list=list(map(int, input().strip().split()))

name_list=np.arange(n)

count = 0

for i in range(n):
    for j in range(i,n):
        sa = abs(name_list[i]-name_list[j])
        if sa == a_list[i] + a_list[j]:
            count +=1

print(count)

Submission status: Time Limit Exceeded

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 + 1
    if j0 >= N:
        continue
    for j1, aj in enumerate(As[j0:]):
        j = j0 + j1
        diff = j-i
        if ai + aj == diff:
            c += 1
print(c)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  N = int(input())
  sanka_l = list(map(int, input().split()))
  count = 0
  min_num = min(sanka_l)
  for i in range(N):
    if sanka_l[i] >= N-(i+1):
      continue
    for j in range(i, N):
      if sanka_l[i] + sanka_l[j] == j - i:
        count += 1
  print(count)
      
main()

Submission status: Time Limit Exceeded

Solution code:
def solve(N:int,A:list) -> int:
    total = 0
    for n1 in range(1,N+1):
        for n2 in range(1,N+1):
            if(n1 == n2): continue
            if(abs(n2 - n1) == A[n1-1]+A[n2 - 1]):
                total+=1
    return total//2
def main():
    N = int(input())
    A = list(map(int,input().split()))
    # solve()
    print(solve(N,A))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

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

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 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()))
g = 0
for x in range(len(a)):
    for y in range(x+1, len(a)):
        if a[x] + a[y] == abs(x-y):
            g += 1
print(g)

Submission status: Time Limit Exceeded

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

from itertools import combinations

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    for j in range(i+1, 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()))
ans = 0
for i in range(N):
  #print(i, "------------------------------")
  k = A[i]
  for j in range(i + k, N):
    #print(j - i, A[i] + A[j])
    if j - i == A[i] + A[j]:
      #print(i, j, A[i], A[j])
      ans += 1
else:
  print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(_) for _ in input().split()]
ans=0
for i in range(n):
    for j in range(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()))
ans=0
AA=[]
M=0
for i in range(N):
    if A[i]<N:
        M=max(A[i],M)

m=min(A)
cnt=0
for i in range(N):
    LM=min(i+M+A[i]+1,N)
    lm=max(i+m+A[i],i+1)
    for j in range(lm,LM):
        cnt+=1
        if j-i==abs(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
plist = []
for i in range(N):
    ans += plist.count(i+1 - A[i])
    plist.append(i+1 + A[i])
print(ans)

Submission status: Time Limit Exceeded

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

cnt=0
for i in range(N):
    if i + As[i]>N:
        continue
    for j in range(i+As[i],N):
        if j-i == As[i] + As[j]:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

cnt = 0
for c in itertools.combinations(range(n), 2):
    if abs(c[0] - c[1]) == a[c[0]] + a[c[1]]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

Solution code:


def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())
    a_list = list(map(int, input().split()))
    count = 0
    for i in range(1, n):
        a = a_list[i]
        if i + a <= 0:
            continue
        for j in range(i - a):
            if a + a_list[j] == i - j:
                count += 1

    print(count)






# x = list(map(int, input().split()))

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import sys
input=sys.stdin.readline
N = int(input().rstrip('\n'))
As = {}
As2=[int(x) for x in input().rstrip('\n').split()]
for i in range(N):
  As[i] = As2[i]
comb = [x for x in combinations(range(N),2)]
res = 0
for i in comb:
  a = As[i[0]] + As[i[1]]
  b = abs(i[1]-i[0])
  if a == b:
    res += 1
print(res)

Submission status: Time Limit Exceeded

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

  print(count)

if __name__ == "__main__":
    main()

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = [e+i+1 for i,e in enumerate(a)]
    c = [i+1-e for i,e in enumerate(a) if i+1-e > 1]
    ans = 0
    for i in c:
        ans += b.count(i)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A_values=list(map(int,input().split()))
#A_keys=[i+1 for i in range(N)]
#A_dict=dict(zip(A_keys,A_values))
temp=0

for i in range(N-2):
  for j in range(i+2,N):
    if abs(i-j)==A_values[i]+A_values[j]:
      temp+=1
print(temp)