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 itertools
k = int(input())
l = [i for i in range(k)]
h = list(map(int, input().split()))
c = list(itertools.combinations(l, 2))
re = 0
for i in c:
  sa = i[1] - i[0]
  wa = h[i[0]] + h[i[1]]
  if sa == wa:
    re += 1

print(re)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

comb = itertools.combinations(range(N), 2)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(1000000)




def main():
    n = int(input())
    a_dic = {}
    i = 0
    for a in map(int, input().split()):
        a_dic[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=list(map(int,input().split()))
count=0
for i in range(N):
    if N-A[i]<=0:
        continue
    for j in range(i+A[i]-1,N):
        if i!=j:
            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):
  if i+1+A[i]< N:
    for j in range(i+1+A[i],N):
      if j-i == A[i] +A[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 = 最低これだけ先が無いとダメ
    if i + ai >= N:
        continue
    for j in range(i+ai,N):
        aj = As[j]
        diff = j-i
        if ai + aj == diff:
            c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

def main():
  N = int(input())

  height = [i for i in list(map(int, input().split()))]

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

import itertools

seq = (x for x in range(N))
ptr = list(itertools.combinations(seq,2))
ans = 0
for i in range(len(ptr)):
    if A[ptr[i][0]]+A[ptr[i][1]]==ptr[i][1]-ptr[i][0]:
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

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

s = 0
for i in range(1, n):
    for k in range(0, n - i):
        if a[k] > i:
            continue
        else:
            if a[k] + a[k + i] == i:
                s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=0
t=[]
for i in range(N):
    ans+=t.count(A[i]-i)
    t.append(-A[i]-i)
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)
ans=0
for i in range(n):
  ans+=np.count_nonzero(r[:n-i-1]-l[i+1:]==l[i])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
hlist = input().split(" ")
count = 0
for i in range(int(N)):
  for j in range(i  + 1, int(N)):
    if (int(hlist[i]) + int(hlist[j])) == (j - i):
      count = 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):
    a = A[i]
    for j in range(min(A[i] + i, N), N):
        if a + A[j] == j - i:
            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):
    start = i + A[i]
    for j in range(start,N):
        if A[j] == j-start:
            count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,*A=map(int,open(0).read().split())
ans=0
for i in range(1,n):
  for j in range(n):
    if j+i<n:
      if A[j]+A[j+i]==i:
        ans+=1
    else:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    count = 0
    for index, a in enumerate(A):
        for plus, b in enumerate(A[index+1:]):
            # print(index, index + plus + 1 ,a + b)
            if plus + 1 == a + b:
                count += 1
    
    print(count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
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
    if d.get(diff) != None:
        j = 0
        while j < len(d[diff]) and d[diff][j] <= i:
            j += 1
        d[diff] = d[diff][j:]
        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+1, N):
    if (j > A[j]) and (j-i == A[i]+A[j]):
      ans += 1
      
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 + 1, N):
        diff = abs(i - j)
        if A[i] + A[j] == diff:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

input()
A = {i: int(height) for i, height in enumerate(input().split(), 1)}

res = 0
for a1_id, a2_id in combinations(A.keys(), 2):
    if abs(a1_id - a2_id) == (A[a1_id] + A[a2_id]):
        res += 1

print(res)

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

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

cnt = 0
dist = [a[0]-1]
for ai in a[1:]:
    cnt += dist.count(-ai)
    dist.append(ai)
    dist = list(map(lambda x: x-1, dist))

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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)
ans=0
for i in range(n):
  x=l[i+1:]+np.full(n-i-1,l[i])-r[:n-i-1]
  ans+=np.count_nonzero(x)
print(n*(n-1)//2-ans)

Submission status: Time Limit Exceeded

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

    cnt = 0
    for d in range(N):
        for i in range(N-d):
            if A[i] + A[i+d] == d:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range( n ):
    h_i = int( array_a[i] )
    for j in range( i + h_i, 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()))
a=[[i,ai] for i,ai in enumerate(a_)]
ans=0
for i,ai in a:
  c=len([[j,aj]for j,aj in a if j>i and ai+i==j-aj])
  ans+=c
print(ans)

Submission status: Time Limit Exceeded

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]
mp = lambda :map(int,input().split())

n = inp()
x = ip()
ctr = 0
for i in range(n-1):
    for j in range(i+1,n):
        if (j-i) == x[i]+x[j]:
            ctr += 1
print(ctr)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count=0
F=[]

for i,a in enumerate(A):
    if i<=1:
        F.append(a)
        continue
    for j,f in enumerate(F):
        if i-j==a+f:
            count+=1
    F.append(a)

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-1):
    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:
n = int(input())

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

for i in range(n):
    for j in range(n):
        if(i != j):
            tmp = i - j
            tmp = abs(tmp)
            if(tmp == list[i] + list[j]):
                count += 1

print(int(count/2))

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:
N = int(input())
height = list(map(int, input().split()))
count = 0

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

print(int(count / 2))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(1000000)




def main():
    n = int(input())
    a_dic = {}
    i = 0
    for a in list(map(int, input().split())):
        a_dic[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=list(map(int,input().split()))
ans=0
t=[]
for i in range(N):
    for j in t:
        if A[i]==j+i:
            ans+=1
    t.append(-A[i]-i)
print(ans)

Submission status: Time Limit Exceeded

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

D = [0]
for i in range(N):
    D.append(A[i]+D[i])
ans = 0
for i in range(N):
    a = i+A[i]
    S = D[N]-D[i+1]
    for absij in range(1,N-a):
        j = a+absij
        if absij>S:break
        if A[i]+A[j]==j-i:
            ans+=1
        S-=A[j]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
  if a[i] < 2*10**5-1:
    l.append((i, a[i]))
count = 0
for i in range(len(l)-1):
  for j in range(i+1, len(l)):
    if l[j][0]-l[i][0] == l[j][1]+l[i][1]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n=int(input())
idx=np.arange(1,n+1)
a=np.array(list(map(int,input().split())))
ans=0
for i in range(n):
    aa=a.copy()
    aa+=a[i]+i+1
    mask= idx==aa
    ans+=np.count_nonzero(mask)

print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
#create date: 2020-05-03 21:37

import sys
stdin = sys.stdin

import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = np.array(na())
    b = np.arange(1, n+1)
    #print(a, b)
    ans = 0
    for i in range(n):
        anow = a[i]
        j = i+anow+1
        if j < n:
            ans += sum(a[j:]== b[:n-j])
    print(ans)


if __name__ == "__main__":
    main()

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
MOD = 1000000007


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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = sum([1 for i,a in enumerate(A) 
           for j in range(len(A)) 
           if j != i and abs(i-j) == A[i]+A[j]
          ])      
print(int(cnt/2))

Submission status: Time Limit Exceeded

Solution code:

def input_from_console():
    n = int(input())
    m_list = map(int, input().split())
    return n, m_list


def solve(n, m_list):
    total = 0
    for i in range(n):
        for ii in range(i, n):
            if m_list[i] + m_list[ii] == abs(i - ii):
                total += 1
    return total

def main():
    n, m_list = input_from_console()

    print(solve(n, list(m_list)))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Time Limit Exceeded

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

cnt = 0
for n1 in range(N-1):
    a1 = A[n1]
    for n2 in range(n1+a1, N):
        f = a1 + A[n2] - n2 + n1
        if f==0:
            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(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()))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

# input
n = int(input())
inp_ls = input().split(" ")
a_ls = np.array([int(e) for e in inp_ls[:n]])

cnt = 0
for i in range(n-1):
	abs_val = i+1
	l0 = a_ls[:-abs_val]
	l1 = a_ls[abs_val:]
	h_sum_ls = l0+l1
	cnt += np.count_nonzero(h_sum_ls == abs_val)

# result
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline().rstrip())
As = list(map(int, sys.stdin.readline().rstrip().split()))

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections

def solve(K, r):
    dic = collections.defaultdict(set)
    for i, n in enumerate(r):
        dic[n].add(i)
    ans = 0
    for i, n in enumerate(r):
        for k in range(i,K):
            target_sum = abs(k-i)-n
            if k in dic[target_sum]:
                ans+=1
    return ans
k = int(input())
r = list(map(int, input().split()))
print(solve(k, r))

Submission status: Time Limit Exceeded

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

coms = itertools.combinations(range(n), 2)
result = 0
for com in coms:
    if np.abs(com[0] - com[1]) == a[com[0]] + a[com[1]]:
        result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from itertools import combinations


def solve(N, A):
    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:
n = int(input())
agents = [int(m) for m in input().split(" ")]

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

print(count)

Submission status: Time Limit Exceeded

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

X=[A[i]-(i+1) for i in range(n)]
Y=[-A[i]-(i+1) for i in range(n)]
ans=0
X.sort()

for y in Y:
    i=bisect.bisect_left(X,y)
    for j in range(i,n):
        if X[j]==y:
            ans+=1
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(yes)

Submission status: Time Limit Exceeded

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

from itertools import combinations

ans = [1 for a, b in combinations(range(1, n+1), 2) if b - a == (A[a-1] + A[b-1])]

print(sum(ans))

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):
    for j in range(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:
studentNumber = int(input())
hightList = list(map(int, input().split()))
count = 0
for i in range(studentNumber-1):
    temp = hightList[i]
    for j in range(i+1, studentNumber):
        if(hightList[j] + temp == j - i):
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

l = [0]*n

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

print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()
 
import itertools

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
a=input().split(" ")
b=list(range(n))
g=0
for v in itertools.combinations(b, 2):
  x=int(v[0])
  y=int(v[1])
  if abs(x-y)==int(a[x])+int(a[y]):
    g=g+1
print(g)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N,*A = map(int,open(0).read().split())
cnt = 0
for a in range(1,N):
    for b in range(a+1,N+1):
        if abs(b-a) == A[a-1] + A[b-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+A[i]+1,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()))

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def main():
	n=int(input())
	A=list(map(int,input().split()))
	res=0

	for i in range(n):
		for j in range(i+1,n):
			if abs(i-j)==A[i]+A[j]:
				res+=1
	print(res)
	
if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

from itertools import combinations

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
cand=[True for i in range(n)]
ans=0
for i in range(n):
  if a[i]>i+1 and a[i]>n-i:
    cand[i]=False
for i in range(n):
  if cand[i]:
    for j in range(i+1,n):
      if abs(i-j)==a[i]+a[j]:
        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+1,n):
        if j-i == height[i]+height[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())

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

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

print(ans)