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:

def main():
    N = int(input())
    
    An = list(map(int, input().split(' ')))
    
    c = 0
    for a in range(len(An)):
        for b in range(a, len(An)):
            if b - An[b] == a + An[a]:
                c += 1
    print(c)            
    
    
    


main()

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
x = int(input())
height = list(map(lambda x: int(x), input().split()))  
cands = []


results = []
for i in range(len(height)):
  tmp = []
  cands.append(tmp)
  
# j < k
def check(j, k):
  return k - j == height[j]+ height[k]

  
for i in range(len(height)):
  if i-height[i] >= 0:
    for j in cands[i-height[i]]:
      if check(j, i):
        results.append([j, i])
      
  if i+height[i] < len(height):
    cands[i+height[i]].append(i)

if len(results) > 1:
  #results = np.sort(results, axis=1)
  results = np.unique(results, axis=0)
print(len(results))

Submission status: Time Limit Exceeded

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

import itertools
A_conbi = itertools.combinations(range(1,N+1), 2)

same_cnt = 0
for (a, b) in A_conbi:
    #print(A)
    sss = A_list[a-1] + A_list[b-1]
    if abs(a-b) == sss:
        same_cnt = same_cnt + 1

print(same_cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())

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


l = [a[i] +i+1 for i in range(n)]
r = [i+1 -a[i] for i in range(n)]

L = collections.Counter(l)
R = collections.Counter(r)

c = 0

for i in range(max(max(l),max(r))+1):
    c += L.get(i, 0) * R.get(i, 0)

print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
from numba import jit
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N = int(input())
    H = np.array(input().split(), np.int64)
    A = np.arange(1,N+1)
    B = np.arange(1,N+1)
    A = A + H
    B = B - H
    ans = 0

    @jit(nopython=True)
    def aa(i):
        return N - i - np.count_nonzero(B[i:] - A[:-i])
    for i in range(1,N):
        ans += aa(i)
    print(ans)



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())))
B = np.array([i+1 for i in range(n)])
C,D = A+B,B-A
ans = 0
for i in C:
    ans += np.count_nonzero(D==i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
import numpy as np

N = int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A=list(map(int, input().split()))
B=sorted([A[i]+i+1 for i in range(n)])
x=B[0]
y=B[-1]
C=sorted([j+1-A[j] for j in range(n) if x<=j+1-A[j]<=y])
C2=set(C)

t=0
for i in range(n):
  if B[i] in C2:
    t+= C.count(B[i])
print(t)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
l_1 = []
l_2 = []

for i in range(N):
  if A[i] < (10**5)*2:
    l_1.append(A[i]+i)
    l_2.append(i-A[i])
  
for num in range(min(l_2), max(l_2)+1):
  ans += l_1.count(num)*l_2.count(num)
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
alist = list(map(int, input().split()))
count = 0
for a in range(1, n + 1):
    for b in range(a + 1, n + 1):
        #print(a, b, alist[a-1], alist[b-1], abs(a-b))
        if abs(a - b) == alist[a-1] + alist[b-1]:
            #print('!!!!!!!!')
            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):
    for j in range(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()))
mi = min(a)
ma = max(a)
c = 0
for i in range(1, n-2*mi+1):
    st = max(i+a[i-1], i+2*mi)
    for j in range(st, min(n+1, st+2*ma)):
        if j-i == a[i-1]+a[j-1]:
            c += 1
            
print(c)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


n = int(input().strip())
a = np.array(list(map(int, input().split())))
count = 0
for i in range(n-1):
    test_a = a.copy()
    target = a[i]
    sub_a = np.array([j - i for j in range(n)])
    add_a = np.array([a_h + target for a_h in a])
    cal_a = sub_a - add_a
    count += np.count_nonzero(cal_a == 0)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count = 0
ml = list(map(int, input().split()))
for i in range(n):
    for j in range(i,n):
        if (abs(i-j) == (ml[i] + ml[j])) and (i != 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, a in enumerate(A):
    ans += np.sum(A[i+a+1:] == np.arange(1, N-i-a))
    """
    for j, b in enumerate(A[i+a+1:]):
        if j + 1 == b:
            ans += 1
    """
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
d = 2*10**5
r = [[] for i in range(5*(10**3))]
for i in range(N):
    p = A[i]//d
    r[p].append([i,A[i]])


def s(p,q,ans):
    t = p+q
    for k in range(len(t)-1):
        for l in range(k+1,len(t)):
            if abs(t[k][0]-t[l][0]) == t[k][1] + t[l][1]:
                ans += 1
    return ans

for i in range(len(r)-1):
    ans = s(r[i],r[i+1],ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations
inputs = open(0).readlines()
n = int(inputs[0])
*A, = (map(int, inputs[1].split()))
B = [a+i for i, a in enumerate(A, 1)]
C = [i-a for i, a in enumerate(A, 1)]
ans = 0
for k1, v1 in Counter(B).items():
    for k2, v2 in Counter(C).items():
        if k1 == k2:
            ans += v1*v2
print(ans)

Submission status: Time Limit Exceeded

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

def main():
    res = 0
    N = int(input())
    a = list(map(int, input().split()))
    for n, k in enumerate(a):
        t = k + n
        if N < t:
            continue
        for m, j in enumerate(a[t:]):
            if abs(n - m - t) == k + j:
                res += 1

    print(res)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    A = np.array(list(map(int, args[1].split())))

    ret = 0
    for i in range(1, n):
        ret += n-i-np.count_nonzero(A[i:]+A[:-i]-i)

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
from itertools import combinations

def file_input():
    f = open('../Beginner_Contest_166/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    N=int(input())  #人数
    A=list(map(int, input().split()))   #身長

    ans=0
    A_set=set(A)
    sum=set()
    tmp=[x*2 for x in set(A) if A.count(x) > 1]
    sum=sum|set(tmp)
    # print(type(tmp))
    for c in list(combinations(A_set,2)):
        sum.add(c[0]+c[1])
        # print(c)
        # print(str(c[0]-1)+str(c[1]-1)+" : "+str(A[c[0]-1])+str(A[c[1]-1]))
        # print(str(abs(A[c[0]-1]-A[c[1]-1]))+" : "+str(abs(c[0]-1-(c[1]-1))))
        # if abs(A[c[0]-1]+A[c[1]-1])==abs(c[0]-1-(c[1]-1)):
        #     ans+=1
    # print(sum)
    for s in sum:
        # print("sum : "+str(s))
        for i in range(N-s):
            if A[i]+A[i+s]==s:
                # print("h : "+str(i)+","+str(i+s))
                ans+=1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_plus_i = [i + A[i] for i in range(N)]
A_minus_i = [A[i] - i for i in range(N)]
keys = [-x for x in A_minus_i if x < 0]
ans = 0
for key in keys:
    ans += A_plus_i.count(key)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N = int(input())
    H = np.array(input().split(), np.int64)
    A = np.arange(1,N+1)
    B = np.arange(1,N+1)
    A = A + H
    B = B - H
    ans = 0
    for i in range(1,N):
        ans += N - i - np.count_nonzero(B[i:] - A[:-i])
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#import itertools
from operator import sub

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

for i in range(n):
    aa = list(map(sub, l, a[i+a[i]:]))
    c += aa.count(0)


#    for j in a[i+a[i]:]:
#        if j == jc:
#            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:
import numpy as np

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

intersection = setAi.intersection(setAj)
for x in intersection:
  for i in range(N):
    if Ai[i] == x:
      count += np.sum(Aj[i+1:]==x)
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
aa = np.array(list(map(int, input().split())))
cnt = 0
pl = aa + np.array(range(n))
ms = -aa + np.array(range(n))
common = set(pl).intersection(set(ms))
for v in common:
    cnt += (pl==v).sum() * (ms==v).sum()
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

n = int(input())

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

count = 0

for n1 in range(n-1):
    for n2 in range(n1,n):
        a1 = A[n1]
        a2 = A[n2]
        if abs(n1 - n2) == a1 + a2:
            count += 1

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

Submission status: Time Limit Exceeded

Solution code:
# == E ==
import itertools
count = 0
N = int(input()) # パーティーの参加者
A = list(map(int, input().split())) # 参加者_iの身長
for i,j in itertools.combinations(range(N), 2):
	X = abs(i-j)
	Y = A[i] + A[j]
	if X == Y:
		# print(i+1, j+1)
		count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
h = [int(x) for x in input().split()]
mini = sorted(h)[0] + sorted(h)[1]
count = 0
for i in range(n):
    for k in range(i+mini,n):
        height = np.abs(h[i] + h[k])
        if k - i == height:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

list_ = list((itertools.combinations(range(1, n + 1), 2)))

ans = 0;
for i,j in list_:
  if A[i - 1] + A[j - 1] == max(i - j, j - i):
    ans += 1;
  
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
members = list(map(int, input().split()))
pairs = 0

for index1, member1 in enumerate(members, 1):
    for index2, member2 in enumerate(members[index1:], index1+1):
        if member1 + member2 == index2 - index1:
            pairs += 1
    
print(pairs)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())

a = list(map(int, input().split()))
a_array = np.array(a)
base_array = np.array(range(n))+1

ans = 0

# print(a_array)
# print(base_array)

for i in range(n-1):
  sum_array = a_array[i+1:] + a_array[i]
  # print(sum_array)
  sum_array = sum_array - base_array[:-(i+1)]
  res = np.count_nonzero(sum_array == 0)
  ans += res
#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())
a = list(map(int,input().split()))
count=0
for i in range(1,n):
    for j in range(0,n-i):
        if a[j]+a[j+i]==i:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    A_arr_ext = [A_arr[i] for i in range(len(A_arr)) if A_arr[i]<N-1]
    A_arr_ext_sort = sorted(A_arr_ext)
    height_range = [sum(A_arr_ext_sort[:2]),min(sum(A_arr_ext_sort[-2:]),N-1)]
    A_arr_ext = {}
    for i,a in enumerate(A_arr):
        if a<N-1:
            A_arr_ext[i] = a
    cnt = 0
    for height in range(height_range[0],height_range[1]+1):
        for i in range(N-height):
            if i in A_arr_ext:
                j = i+height
                if j in A_arr_ext:
                    if A_arr[j]+A_arr[i]==j-i:
                        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+1, n):
        if abs(j-i) == a[i] + a[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

na = []

for i in range(n):
    na.append((a[i], i))

na.sort()

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
#import itertools
from operator import sub

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

for i in range(n):
    aa = list(map(sub, list(range(n)), a[i+a[i]:]))
    c += aa.count(0)


#    for j in a[i+a[i]:]:
#        if j == jc:
#            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:
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))

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

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

Submission status: Time Limit Exceeded

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

resolve()

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

Submission status: Time Limit Exceeded

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

a1_list = []
a2_list = []
for i in range(n):
    a1_list.append(a_list[i]+i+1)
    a2_list.append(-a_list[i]+i+1)
a1_list.sort()
a2_list.sort()
tmp = 0
cnt = 0
for a1_idx in range(n):
    a2_idx = tmp
    a1 = a1_list[a1_idx]
    if tmp == n:
        break
    if a1 < a2_list[tmp]:
        break
    while a2_idx <= n-1 and  a1 >= a2_list[a2_idx]:
        if a1 == a2_list[a2_idx]:
            cnt += 1
        else:
            tmp = a2_idx
            if tmp == n:
                tmp = tmp-1
        a2_idx += 1
        
        
print(cnt)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split(" ")
compte = 0
B=[0]*N
C=[0]*N
for i in range(N):
  A[i] = int(A[i])
  B[i] = [A[i]+i,i]
  C[i] = [-A[i]+i,i]
B.sort()
C.sort()
for j in range(N):
  k = 0
  while B[k][0]<=C[j][0]:
    if B[k][0]==C[j][0]: 
    	if B[k][1]<C[j][1]:
      		compte+=1
      		k+=1
    else:
      B.remove(B[k])
print(compte)

Submission status: Time Limit Exceeded

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

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

print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
members = list(map(int, input().split()))
pairs = 0

for index1, member1 in enumerate(members, 1):
    for index2, member2 in enumerate(members[index1:], index1+1):
        if member1 + member2 == abs(index1 - index2):
            pairs += 1
    
print(pairs)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N = int(input().strip())
A = [a for a in enumerate([int(x) for x in input().strip().split(" ")])]

pair = 0
for a, b in product(A, A):
    if a[0] == b[0]:
        continue
    ids = abs(a[0] - b[0])
    if ids == a[1] + b[1]:
        pair += 1
print(pair // 2)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())  # 文字列または整数(一変数)
    A = list(map(int, input().split()))  # 整数のリスト

    answer = 0

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

    print(answer)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
n=int(input())
a=list(map(int,input().split()))
B=[]
for i in range(n):
  B.append(i+1-a[i])
cnt=0
B.sort()
for i in range(n-1):
  b=B[i+1:]
  x=i+1+a[i]
  cnt+=bisect.bisect_left(b,x+1)-bisect.bisect_left(b,x)
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):
    j = 0
    for a in A[i+A[i]:]:
        if a == j:
            ans += 1
        j += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
M = np.asarray(input().split(), dtype=int)
C = np.arange(1,N+1)
print(np.sum([np.sum(M[i+M[i]+1:]==C[:N-i-M[i]-1]) for i in range(N)]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

sintyo = list(map(int, input().split(' ')))
result = 0
for i in range(N):
  for j in range(i, N):
    if sintyo[i] + sintyo[j] == abs(i - j):
      result += 1
      #print(i, j, )
print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

# print(A)
ans = 0

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


print(int(ans / 2))

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline


n = int(input())
a = np.array(readline().split(), dtype=np.int64)

ans = 0

while len(a):
    l = a[0]
    np.delete(a, 0)
    ans += np.count_nonzero(a+l-1 == np.arange(len(a)))

print(ans)

Submission status: Time Limit Exceeded

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

n = int(input())
tall = list(map(int,input().split()))
number = [i+1 for i in range(n)]
small_number = [i for i in number if tall[i-1] <= n-1-min(tall)]
small_tall = [i for i in tall if i <= n-1-min(tall)]

pair = 0
for i in range(len(small_number)):
    for j in range(i+1, len(small_number)):
        if abs(small_number[i]-small_number[j]) == small_tall[i] + small_tall[j]:
            pair += 1

print(pair)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_in = input()
a = [int(comp) for comp in a_in.split()]
count = 0
for i in range(len(a) - 2):
    for j in range(i + 1 + a[i], len(a)):
        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()))
count=0
b=[]

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

dct=dict()
for i,j in enumerate(lst, start=1):
    dct[i]=j
import itertools
a = list(itertools.combinations(dct.items(),2))
cnt = 0
for i in a:
    if abs((i[0][0]-i[1][0])) == (i[0][1]+i[1][1]):
        cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ea = list(map(int, input().split(" ")))
c = 0
for ia in range(n - 1):
    eaia = ea[ia]
    ac = eaia + ia
    if n + eaia > ia:
        for ib in range(ia + 1, n):
            eaib = ea[ib]
            if eaib < n and ac == ib - eaib:
                c += 1
print(c)

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 h in range(i+1, n):
    if a[i]>n-1 or a[h]>n-1:
      continue
    else:
      d=h-i
      g=a[i]+a[h]
      if d==g:
        count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    ok = 0
    for p in range(N):
        for q in range(p+1, N):
            if abs(p-q) == A[p] + A[q]:
                ok += 1
    print(ok)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()

ans=0
for i in range(n):
    h=a[i]
    B=list(range(-i,-i+n))
    C=[0]*n
    for j in range(n):
        C[j]=abs(B[j])-a[j]-h
    ans+=C.count(0)
print(ans//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 abs((i+1)-(j+1))==a[i]+a[j]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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


def main():
    N = int(input())
    A = [i for i in map(int, input().split())]
    #print (N, A)
    gsize = 1000
    numg = (N - 1) // gsize + 1
    maxg = [0] * numg
    ming = [0] * numg
    size = len(A)
    for g in range(0, numg):
        gA = A[gsize*g:min(gsize*(g+1), size)]
        maxg[g] = max(gA)
        ming[g] = min(gA)

    count = 0
    for g1 in range(0, numg):
        for g2 in range(g1, numg):
            #print('checking group', g1, g2)
            gd = abs(g1 - g2)
            if maxg[g1] + maxg[g2] < gsize * (gd - 1):
                continue
            if ming[g1] + ming[g2] > gsize * (gd + 1):
                continue
            for g1i in range(gsize*g1, min(gsize*(g1+1), size)):
                for g2i in range(max(g1i+1, gsize*g2), min(gsize*(g2+1), size)):
                    d = abs(g1i - g2i)
                    if A[g1i] + A[g2i] == d:
                        count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
h = input().split()
count = 0
for n in range(N):
  if int(h[n]) <= 2*(10**5):
    for k in range(N):
      if n != k:
        sum = int(h[n]) + int(h[k])
        diff = max(n,k) - min(n,k)
        if sum == diff:
          count += 1
print(int(count/2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
for i in range(N):
    B[i] = A[i]-i-1

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