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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
from bisect import bisect_left as bl,bisect_right as br
a=list(map(int,input().split()))
l=[-a[0]]
ans=0
for i in range(1,n):
    ans+=br(l,a[i]-i)-bl(l,a[i]-i)
    l.append(-i-a[i])
    l.sort()
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

# total = N * (N-1) // 2

combi = list(itertools.combinations(range(N), 2))

count = 0
for i, j in combi:
    if A[i] + A[j] == abs(i-j):
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())

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

B = A - id
C = -A - id

count = 0
while(True):
  d = B[0]
  d_in_B = np.count_nonzero(B==d)
  d_in_C = np.count_nonzero(C==d)
  count += d_in_B * d_in_C
  B = B[B != d]

  if len(B) == 0:
    break
print(int(count))

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from itertools import combinations
n = int(input())
arr = list(map(int , input().split()))
dic = defaultdict(int)
s = [i for i in range(2,n+2)]
#print(s)
ans = 0
for i in s:
	if 1 <= i <= n-1:
		for j in range(i+1,n+1):
			#print( j , j - i , i)
			if abs(arr[j-1] + arr[j-i-1]) == i:
				ans+=1
print(ans)

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
    for c in list(combinations(range(1,N+1),2)):
        # 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(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

N = int(input())
A = sys.stdin.readlines()
#改行コード削除
A = [b.strip() for b in A][0].split()
#print(A)

count = 0

for i in range(len(A)):
  data = A[i]
  for j in range(i, len(A)):
    if i == j:
      continue

    if abs(j-i) == (int(A[i])+int(A[j])):
      count += 1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    As = list(map(int,input().split(" ")))

    dp = [0]*(n+1)
    for i in range(1,n):
        temp = 0
        for j in range(i):
            if i-j == As[j]+As[i]:
                temp+=1
        dp[i] = dp[i-1]+temp
    print(dp[n-1])
main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
P = [i + A[i] for i in range(N)]
Q = [j - A[j] for j in range(N) if j - A[j] >= 1]
R = list(set(Q))
ans = 0
for r in R:
  ans = ans + P.count(r) * Q.count(r)
print(ans)

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


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

main()

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

    ans += np.count_nonzero(c == 0)

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

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 = x_dic[i]
        for j in range(i+1, n):
            # combi = (i,j)
            if ai == y_dic[j]:
                count += 1
    print(count)



main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    ans = 0
    for i, a in enumerate(A[:-1]):
        if a > N:
            continue
        api = a + i
        for j in range(a-1, N):
            if api + A[j] == 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()))

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


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

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(1,n):
    for j in range(i,n+1):
        if 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(N-1):
    height_A = A[i]
    start = i + height_A
    if start < N - 1:
        for j in range(start,N):
            height_B = A[j]
            if j - i == height_A + height_B:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
from itertools import combinations
def run():
    N = int(input())
    A = list(map(int, sysread().split()))
    A = [(idx, val) for idx, val in enumerate(A, 1)]
    ret = 0
    for (i,Ai), (j,Aj) in combinations(A, 2):
        if abs(i-j) == Ai+Aj:
            ret += 1

    print(ret)

if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
def solve(n, elements):
    count = 0

    for i in range(n):
        for j in range(i+1, n):
            diff = abs(i - j)
            value = elements[i] + elements[j]
            if diff == value:
                count += 1

    return count


if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    result = solve(n, arr)
    print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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+A[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()))
check = []
ans = 0


for i, v in enumerate(A):
    if v in check:
        ans += check.count(v)
    check.append(-v)
    check = list(map(lambda x: x+1, check))

print(ans)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(p)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
ans = 0
li = list(map(int, input().split())) #list
comb = itertools.combinations(range(1, n+1), 2)
for i, j in comb:
    if li[i-1] + li[j-1] == abs(i-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(0,n):
  if i+a[i]+1 >= n:
    continue
  for j in range(i+a[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()))
P = [i + A[i] for i in range(N)]
Q = [j - A[j] for j in range(N) if j - A[j] >= 1]
ans = 0
for q in Q:
  ans = ans + P.count(q)
print(ans)

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):
    minus=a[i]+i
    mask = np.arange(n-minus)==a[minus:]
    ans+=np.count_nonzero(mask)

print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
paramN = int(input())
params1 = list(map(lambda x: int(x), input().split(' ')))

counter = 0

for i0 in range(paramN):
    if i0 < paramN - 1:
        for i1 in range(i0 + 1, paramN):
            if (i1 - i0) == (params1[i0] + params1[i1]):
                counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
idList = [i for i in range(1,n+1)]

com = list(itertools.combinations(idList, 2))

num = len(com)
ans = 0
for i in range(num):
    aa = com[i]
    # print(aa)
    idA = aa[0]
    idB = aa[1]
    dif = abs(idA - idB)
    height = a[idA - 1] + a[idB - 1]

    if (height == dif):
        ans += 1

print(ans)

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+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())
li = list(map(int,input().split()))
a=0
for i in range(1,n+1):
  for j in range(1,n+1):
    if (li[i-1]+li[j-1])==abs(i-j):
      a+=1
print(a//2)

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(len(a_list) - 1):
    for j in range(i+1, len(a_list)):
        if j - i == a_list[j] + a_list[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):
    Ai = A[i]
    if Ai >= 2*10**5:
        pass
    else:
        for j in range(i+A[i],N):
            if j-i == Ai+A[j]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

pear = 0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import sys

N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(1, N+1):
    for k in range(i+1, N+1):
        if i != k and A[i-1] < N and A[k-1] < N:
            if abs(i-k) == A[i-1]+A[k-1]:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n]]

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = list(map(int,input().split()))
N_comb = list(itertools.combinations([n for n in range(1,N+1)],2))
cnt = 0

for i in range(len(N_comb)):
    x = N_comb[i][0]
    y = N_comb[i][1]
    if abs(x-y)==A[x-1]+A[y-1]:
        cnt = cnt + 1
del N_comb
print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools
import heapq
#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    n=int(input())
    a=list(map(int,input().split()))
#    b=[[i for i in range(n-1)]]
    total=0
    for i in range(n-1):
        for j in range(i+1,n):
            if a[i]+a[j]==j-i:
                total+=1
    print(total)






if __name__ == "__main__":

    main()

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
#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:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()

ans = 0
for i in range(N):
    h_i = A[i]
    for j in range(h_i + i, N):
        if h_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()))
count=0
for i in range(n):
  for h in range(n):
    d=i-h
    g=a[i]+a[h]
    if d==g:
      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):
    h = a[i]
    for j in range(i+h+1, n):
        if j - i == a[j] + h:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():
  N = int(input())
  ans = 0
  A = tuple(map(int,input().split()))
  for k in range(1,N):
    for i in range(0,N-k):
      if A[i]+A[i+k]==k:
        ans += 1
  print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

score = {}

for i, a in enumerate(A):
  if i ==0:
    continue
  
  s = i-a
  if s not in score:
    score[s] = []
  score[s].append(i)

from bisect import bisect_left
ans = 0
for i, a in enumerate(A):
  if i+a in score:
    index = bisect_left(score[i+a], i)
    ans += len(score[i+a]) - index
    score[i+a] = score[i+a][index:]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())

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

b = [A[0] + 1]

ans = 0

for i, a in enumerate(A[1:], 2):
    ans += bisect.bisect_right(b, i - a) - bisect.bisect_left(b, i - a)
    bisect.insort_right(b, i + a)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
attendees = int(input())

heights = list(map(int, input().split(' ')))
res_count = 0
for i in range(len(heights)):
    for j in range(len(heights)):
        if abs(i - j) == (heights[i] + heights[j]):
            res_count += 1

print(res_count//2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

ans = [(i,A[i-1]) for i in range(1,N+1)]
ans2 = list()
for tmp in ans:
    if tmp[1] < N:
        ans2.append(tmp)

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = 0
for i in range(N):
    tmp_A = A + A[i]
    tmp_B = np.concatenate([np.zeros(i),np.arange(N-i)])
    C = tmp_B - tmp_A
    ans += np.count_nonzero(C == 0)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

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

print(sum)

Submission status: Time Limit Exceeded

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

comb = {}
result = 0

for i in range(len(A)):
    for j in range(i + 1, len(A)):

        if abs((i + 1) - (j + 1)) == A[i] + A[j]:
            result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dic = {}
lis = list(map(int,input().split()))
cnt = 0
for i,j in zip(range(1,n+1),lis):
    dic[i] = j
for i in range(1,n):
    for j in range(i+1,n+1):
        if j - i == dic[j] + dic[i]:
            cnt += 1
print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
def cal():

    num = int(input())
    str1 = input()
    height = []
    height.extend(str1.split(" "))
    for i in range(len(height)):
        height[i] = int(height[i])

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


cal()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

count = 0

for i in range(n):
  a = al[i]
  l = i - a
  r = i + a
  if l >= 1:
    left_l = al[:l]
    length = len(left_l)
    ll = list(reversed(range(1, length+1)))
    for j in range(length):
      if ll[j] == left_l[j]:
        count += 1
      
  if r < n - 1:
    right_l = al[r+1:]
    length = len(right_l)
    ll = list(range(1, length+1))
    for j in range(length):
      if ll[j] == right_l[j]:
        count += 1
print(count // 2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

count = 0

sum_ = [0]

for i in range(2, n + 1):
    a.append(a[-1] + i)

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

print(count)

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy

# 入力
N = int(input())
height_num = list(map(int, input().split()))

# 作業リスト
work_l = [i+1 for i in range(N)]

cnt = 0
for i in range(N):
	# 先頭の作業インデックス
	tmp_f_num = work_l.pop(0)
	# 残りをコピー
	tmp_list = copy.deepcopy(work_l)
	len_tmp_list = len(tmp_list)

	for j in range(len_tmp_list):
		# 比較の作業インデックス
		tmp_num = tmp_list.pop(0)

		# 番号の絶対値
		abs_num = abs(tmp_f_num - tmp_num)
		# 身長の絶対値
		abs_height = height_num[tmp_f_num-1] + height_num[tmp_num-1]

		if(abs_num == abs_height):
			cnt += 1

print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = list(map(int,input().split()))
N_comb = list(itertools.combinations([n for n in range(1,N+1)],2))
cnt = 0

for i in range(len(N_comb)):
    x = N_comb[i][0]
    y = N_comb[i][1]
    if abs(x-y)==A[x-1]+A[y-1]:
        cnt = 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(1, n - i):
    if A[i] + A[i + j] == j:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
ap = defaultdict(list)
for i in range(n):
    ap[i - a[i]].append(i)

ans = 0
for i in range(n):
    for aj in ap[a[i] + i]:
        if max(i + 1, a[i] + 1) <= aj < n:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

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

s = set()
for idx, height in enumerate(l):
    id = idx + 1
    for in_idx, in_height in enumerate(l):
        if idx == in_idx:
            continue
        in_id = in_idx + 1
        if id - in_id == height + in_height:
            if id > in_id:
                s.add((in_id, id))
            else:
                s.add((id, in_id))

s = list(s)
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(x) for x in 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 = list(map(int, input().split()))

ans = 0

for i in range(n-1):
  index = a[i] + i
  if index >= n:
    continue
  else:
    for j in range(index+1, n):
      if j == index + a[j]:
        ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
import itertools
a_list = list(map(int,input().split()))
cand_list = list(itertools.combinations([i for i in range(n)],2))
count = 0
for cand in cand_list:
  if abs(cand[1] - cand[0]) == a_list[cand[0]] + a_list[cand[1]]:
    count += 1
    
print(count)