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:
from itertools import combinations

N = int(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):
    a1_h = A[a1_id]
    a2_h = A[a2_id]
    if abs(a1_id - a2_id) == (a1_h + a2_h):
        res += 1

print(res)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = int(input())
    a = input_to_int_tuple()

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

    return ret


if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

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

# Condition of A, B
# abs(idxA -idxB) == A + B
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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

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

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

# ###########################################
 
N=II()
A=LI()
for i in range(N):
    A[i] = [A[i],i+1]


kumi = itertools.combinations(A, 2)
ans=0
for z in kumi:
    if z[0][0] + z[1][0] == abs(z[0][1] - z[1][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):
    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:
def solve(n, elements):
    count = 0

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

    return count // 2


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

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

Submission status: Time Limit Exceeded

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

ans = 0
cnt = 0

for i in range(n-1):
    for j in range(cnt+1, n):
        # ans.append(a[j]+a[i])
        #ans.append(abs(j-i))
        if abs(j-i) == a[j]+a[i]:
            ans += 1
    cnt += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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

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

a.insert(0, 0)
b = [1 + a[1]]
cnt = 0

for x in range(2, n + 1):
    cnt += b.count(x - a[x])
    b.append(a[x] + x)

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0
pair_list = list(itertools.combinations(range(1, n + 1), 2))
for pair in pair_list:
    if a[pair[0] - 1] + a[pair[1] - 1] == abs(pair[0] - pair[1]):
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

wa = [0]*n
for i in range(n-1):
    wa[i+1] = wa[i] + (a[i+1] - a[i])

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
data = [int(i) for i in input().split()]
count = 0

for i in range(N):
    for j in range(N):
        if (i == j):
            continue
        else:
            h_order = i + 1
            o_order = j + 1
            x = abs(h_order - o_order)
            y = data[i] + data[j]
            if (x == y):
                count += 1
            else:
                continue

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(1,n):
        if a[i]+a[j]==j-i:
            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(1,len(a)+1):
    if abs(i-j)==a[i-1]+a[j-1]:
      y=y+1
    else:
      y=y
print(int(y/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(n-i-1):
        if a[i+j+1] + a[i] == j+1 or a[i+j+1] + a[i] == -j-1:
            ans +=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

import numpy as np

ans = 0
b = np.array(a[0])

for i in range(1,n):
    b-=1
    ans += np.count_nonzero(b == -a[i])
    b = np.append(b, a[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
S=0
for i in range(N-1):
    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:
n=int(input())
a=list(map(int, input().split()))


count=0

for i in range(n):
  for h in range(n):
    diff=abs(i-h)
    gokei=a[i]+a[h]
    if diff==gokei:
      count+=1
print(count//2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

cnt = 0
for i, a in enu(A):
    if i+a+1<=N-1:
        for j, b in enu(A[i+a+1:]):
            if abs(j+a+1) == a + b:
                cnt += 1
                # print(i, i+a+1+j)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import 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 copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        if abs(i-j)==arr[i]+arr[j]:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

A_sort = sorted(A)
_max = A_sort[-1] + A_sort[-2]

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

print(count)

Submission status: Time Limit Exceeded

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

num = 0

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

print(num)

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
h = list(map(lambda x: int(x), input().split(' ')))

r = list(combinations(range(0, n), 2))

count = 0

for i in r:
  a, b = i
  if abs(a - b) == h[a] + h[b]:
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    num = min(n, i + h[i] + 1)
    height_1 = h[i]
    for j in range(num, n):
        height_2 = h[j]
        if height_1 + height_2 == (j - i):
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

sum_cnt = [1 for num_1 in range(n) for num_2 in range(num_1+1, n) if a_list[num_1]+a_list[num_2] == abs(num_1-num_2) ]
print(sum(sum_cnt))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
height = list(map(int, input().split()))
ans = 0
m_height = max(height)
for i in range(n):
    for j in range(i+height[i], min(n, i+height[i] + 2 * m_height)):
        if(j-i == height[j] + height[i]):
            ans += 1
print(ans)

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

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#E
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 abs(i-j) == a[i]+a[j]:
            c += 1
print(c)

Submission status: Time Limit Exceeded

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())
answer = 0
for i, a in enumerate(A):
    B = np.arange(1, N-i) - a
    add = (A[i+1:] == B).sum()
    answer += add

print(answer)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n - 1):
    h = a[i]
    j = 0
    while j < n:
        if j-i == a[i] + a[j]:
            count += 1
        j += 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+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 = [int(i) for i in input().split()]
a_i = [i - aa for i, aa in enumerate(a)]
a_j = [j + aa for j, aa in enumerate(a)]
ans = 0
for i in a_i:
    ans += a_j.count(i)    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

d = {}
for i in range(N):
    if A[i] < N:
        d[i] = A[i]

result = 0
for a, b in combinations(d, 2):
    if abs(a - b) == A[a] + A[b]:
        result += 1
print(result)

Submission status: Time Limit Exceeded

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

E()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = int(input())
    a = input_to_int_tuple()

    import itertools

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

    return ret


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

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline())
li = list(map(int, sys.stdin.readline().split()))
cnt = 0
i = 0
l = len(li)
while i < l-1:
  k = i+1
  while k < l:
    if li[i] + li[k] == k-i:
      cnt += 1
    k += 1
  i += 1
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(N-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:
import itertools

N = int(input())
A = list(map(int, input().split()))
array = list(itertools.combinations(range(N), 2))
count = 0

for x in array:
    if (A[x[1]] + A[x[0]]) == (x[1] - x[0]):
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import numpy as np


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

count = 0
for i in range(N):
    for j in range(i, N):
        if heights[i] + heights[j] == j-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):
    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(N):
    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:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        c = a[i]
        for j,e in enumerate(a[:i]):
            if e + c == abs(j-i):
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
#N, K = (int(i) for i in input().split())
#B = [int(x) for x in stdin.readline().rstrip().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
for i in range(1, N+1):
    for j in range(i+1, N+1):
        # print(A)
        if abs(j-i) == A[i-1]+A[j-1]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

input = sys.stdin.readline
MOD = 1000000007

N = int(input())

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

dic = {}

b = []
for i in range(len(A)):
    dic[i+1] = A[i]
    b.append(i+1)

dic_sorted = sorted(dic.items(),key=lambda x:x[1])



c = list(itertools.combinations(b,2))

res = 0
for i in c:
    if (dic[i[1]] + dic[i[0]]) == abs(i[0] - i[1]):
        res+=1

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

dp = [[] for i in range(n)]
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
b=[A[i] - (i+1) for i in range(n)]
c=[A[i] + (i+1) for i in range(n)]
ans=0
for i in range(n):
    ans += (c[i+1:].count(-c[i]))
    ans += (b[i+1:].count(-c[i]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

Submission status: Time Limit Exceeded

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

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

result = 0
ai = [0]*n
aj = [0]*n

for i in range(n):
    ai[i] = a[i]+i+1
    aj[i] = i+1-a[i]
    
for i in range(n-1):
    result += aj[i+1:].count(ai[i])
print(result)

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 sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

dp = [[] for i in range(n)]

for i in range(n):
    b = i+a[i]
    if b < n:
        for j in range(b,n):
            dp[j].append(j-b)
ans = 0
for i in range(n):
    ans += dp[i].count(a[i])

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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)