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:
# coding: utf-8
import itertools

n = int(input())
alst = list(map(int, input().split()))
alst = [(ai,ni) for ni,ai in enumerate(alst, 1)]
alst.sort()

cnt = 0
for i in range(len(alst)):
    ai, ni = alst[i]
    if ai > n:
        #print('break 1')
        break

    for j in range(i + 1, len(alst)):
        aj, nj = alst[j]
        if ai + aj > n:
            #print('break2: ', ai, aj, n)
            break

        if ai + aj == abs(ni - nj):
            cnt += 1
            #print(ni, nj, ai, aj, ai + aj)

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

plus = [A[i] + i for i in range(N)]
minus = [j - A[j] for j in range(N)]

count = 0
for i in range(N):
	h = A[i]
	for j in range(i+h+1, N):
		if plus[i] == minus[j]:
			count += 1
print count

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    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 a[i]+a[j] == j-i:
                cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())

b = []
c = []
for i in range(n):
    b.append([i,a[i],i-a[i]])
    c.append(i-a[i])
# print(b)
# print(c)

ans = 0
for i in range(n):
    m = i + a[i]
    ans += c.count(m)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
def main():
    n=int(input())
    aa=list(map(int,input().split()))
    c=0
    for i,a in enumerate(aa):
        for j in range(i+a+1,n):
            if j-i==a+aa[j]:
                c+=1
    print(c)
main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
*A, = map(int, input().split())
t = [[A[i], i] for i in range(N)]
t.sort()

ta = [v for v, i in t]
ti = [i for v, i in t]

ans = 0
for i in range(N):
    r = N-1-ta[i]
    ri = bisect.bisect_right(ta, r)
    for j in range(i+1, ri):
        if (ta[i]+ta[j]) == abs(ti[i]-ti[j]):
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
count=0
for i1,r1 in enumerate(A):
    Q=A[i1+1:]
    for i2,r2 in enumerate(Q):
        if i2+1==r1+r2:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

if __name__ == "__main__":
    N = int(sys.stdin.readline().strip())
    A = [int(a) for a in sys.stdin.readline().strip().split(" ")]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
c = [0]*n
for i in range(n):
    b[i] = a[i]-i
for i in range(n):
    c[i] = a[i]+i
cb = Counter(b)
cc = Counter(c)
mb = cb.most_common()
mc = cc.most_common()
mb.sort(reverse = True)
mc.sort()
lb =len(mb)
lc =len(mc)
ans = 0
for i in range(lb):
    for j in range(lc):
        if mb[i][0]==mc[j][0]*(-1):
            ans += mb[i][1]*mc[j][1]
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(N):
  a = A[i]+(i+1)
  B.append(a)
i = N-1
t = 0
while i >=2 :
  a = i+1 - A[i]
  b = i+1 +A[i]
  K = B[0:i-1]
  if  a <=0:
    i =i- 1
  else:
    t += B.count(a)
    i =i-1
print(t)

Submission status: Time Limit Exceeded

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

num = int(input())

h = input().split(" ")

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

dic = defaultdict(list)
for i, a in enumerate(A):
    dic[a].append(i)
cnt = 0
for i in range(N):
    a = A[i]
    for k, l in dic.items():
        # k + a がimaのiとl[*]の差と等しくなればいい
        if i - (k + a) in l:
            # print("k", k, a)
            # print("l", l)
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
height_list = [0]  # 1始まりで合わせるため
height_list.extend(list(map(int, input().split())))

counta = 0
for i in range(1, num+1):
    for j in range(i, num+1):
        if abs(i-j) == height_list[i] + height_list[j]:
            counta += 1

print(counta)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0

for i in range(n):
    a_height = h_list[i]
    for k in range(i + 1 + a_height, n):
        b_height = h_list[k]
        if k - i == a_height + b_height:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
arr = list(map(int, input().split(" ")))

ret = 0
for i, j in combinations(list(range(1, len(arr)+1)),2):
    if j - i == arr[i-1] + arr[j-1]:
        ret +=1

print(ret)

Submission status: Time Limit Exceeded

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

count = 0

count_dict = collections.defaultdict(int)

for idx, a in enumerate(A):
    if idx+a+1 in count_dict:
        count += count_dict[idx+a+1]
        continue
    for i in range(idx+a+1, N):
        if a + A[i] == i - idx:
            count += 1
            count_dict[idx+a+1] += 1

print(count)

Submission status: Time Limit Exceeded

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

for i, a in enumerate(A_list):
    for o in range(i + 1, N):
        if abs(o - i) == A_list[o] + a:
            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:

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res

n = readInt()
a = readInts()

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

Submission status: Time Limit Exceeded

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

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:
import sys
input = sys.stdin.readline

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
num_pairs = 0
# find ai+aj = j-i
for i in range(N):
    ai = A[i]
    _j = ai+i
    for j in range(_j, N):
        if _j+A[j] == j:
            num_pairs += 1
print(num_pairs)

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

print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    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()))
count=0
for i1,r1 in enumerate(A):
    Q=A[i1+1:]
    for i2,r2 in enumerate(Q):
        if abs(i2+1)==r1+r2:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ea = list(map(int, input().split(" ")))
c = 0
for ia in range(n - 1):
    eaia = ea[ia]
    ac = eaia + ia
    if eaia < n:
        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:
cnt = int(input())
heights = [int(x) for x in input().split(' ')]

output = 0
for i in range(cnt - 1):
    h_1 = heights[i]
    for j in range(i + 1, cnt):
        if h_1 + heights[j] == j - i:
            output += 1

print(output)

Submission status: Time Limit Exceeded

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

d = dict(sorted(d.items(),key=lambda x: x[1]))

cnt = 0
for i in range(1,n+1):
    now = d[i]
    for key,val in d.items():
        if key == i:
            continue
        total = val + now
        if total < n:
            if total == abs(i-key):
                cnt += 1
        else:
            continue
    d.pop(i)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#import itertools

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

temp=0

#for i,j in itertools.combinations(l, 2):

for i in range(N-2):
  if i+A_values[i]<N:
    temp_min=max(i+A_values[i],i+2)
    #temp_max=min(i-A_values[i],N)
    for j in range(temp_min,N):
      #print(i,j)
      if j-i==A_values[i]+A_values[j]:
        temp+=1
print(temp)

Submission status: Time Limit Exceeded

Solution code:
def calc(N, A):
    answer = 0
    for i in range(N):
        if(N-(i + 1) < A[i]):
            continue
        for j in range(i+A[i], 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()))
sorted_a = sorted(a, reverse = True)
max_a = sorted_a[0]
cnt = 0
ans = 0
for i in range(n - 1):
    if a[i] == max_a:
        cnt += 1
        max_a = sorted_a[cnt]
    for j in range(a[i] + i + 1, min(n, a[i] + i + max_a + 1)):
        if a[i] + a[j] == j - i:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
A = [int(height) for height in input().split()]

res = 0

for i in range(N - 1):
    a1_height = A[i]
    j = a1_height + i + 1
    for a2_height in A[j:]:
        if abs((i + 1) - (j + 1)) == (a1_height + a2_height):
            res += 1
        j += 1

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
D = dict()
for idx, a in enumerate(A):
    D[idx+1] = a

D_sort = sorted(D.items(), key=lambda x: x[1])
cnt = 0
for i in range(len(D_sort)):
    if D_sort[i][1] > N:
        break
    for j in range(i+1, len(D_sort)):
        if abs(D_sort[j][0] - D_sort[i][0]) == abs(D_sort[j][1] + D_sort[i][1]):
            cnt += 1

        if (D_sort[j][1] + D_sort[i][1]) > N:
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
ans = 0
p = 0
nextj = 0
while True:
    if j == n:
        i += 1
        j = min(n-1,i+a[i]+1)

    
    if a[i] + a[j] == j-i:
        ans += 1

    j += 1
    
    if i == n-1:
        print(ans)
        exit()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools 
n = int(input())
a = list(map(int, input().split()))
a_list = [[j, i] for i, j in enumerate(a)]
#a_list.sort(reverse=True)
pairs = list(itertools.combinations(a_list, 2))
#print(pairs)
ans = 0
for pair in pairs:
    if pair[0][0] + pair[1][0] >= n:
        continue
    elif pair[0][1] == pair[1][1]:
        continue
    elif abs(pair[0][1]-pair[1][1]) == (pair[0][0]+pair[1][0]):
        ans += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
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)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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


sumer = 0
for i in range(1, n):
    for j in range(len(a)):
        if j + i < n:
            if a[j] + a[j + i] == i:
                sumer += 1
        if j - i >= 0:
            if a[j] + a[j - i] == i:
                sumer += 1

print(sumer//2)

Submission status: Time Limit Exceeded

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

def main():
    N = int(input())
    height_list = list(map(int,input().split()))
    # print(height_list)

    match_count = 0
    for a_i, a_height in enumerate(height_list) :
        for b_i, b_height in enumerate(height_list[a_i+1:], a_i+1) :
            # print(a_i,b_i, b_height)
            # b_height = height_list[b_i]
            height_sum = a_height + b_height
            no_diff = b_i - a_i
            if (height_sum == no_diff) :
                match_count += 1
    
    print(match_count)

if __name__ == '__main__':
    main()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

num = []

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

ans = 0
for i in range(n):
    scan = (i+1) + a[i]
    ans += num.count(scan)

print(ans)

Submission status: Time Limit Exceeded

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

def main():
    n = int(input())
    lis = list(map(int, input().split()))
    ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
Asort = sorted(A)
Amin = sum(Asort[:2])
Amax = min(sum(Asort[-2:]), N - 1)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

count = 0
for split_n, a in enumerate(a_list):
    split_a_list = np.array(a_list[split_n+1:])
    com_list = np.array([i-a for i in range(1, (n - split_n))])
    count += np.count_nonzero(split_a_list == com_list)

print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces


def main():
    n = ni()
    hs = na()
    maxh = [0 for i in range(n-1)] + [hs[-1]]
    for i in range(n-2, -1, -1):
        maxh[i] = max(maxh[i+1], hs[i])
    ans = 0
    for i in range(n-1):
        cnt = -1*hs[i] + 1
        for j in range(i+1,n):
            if cnt > maxh[j]:
                break
            if cnt == hs[j]:
                ans += 1
            cnt += 1
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
input()
a = [int(s) for s in input().split()]
print(len([0 for i, ai in enumerate(a) for j, aj in enumerate(a) if i != j and abs((i+1)-(j+1)) == ai + aj]) // 2)

Submission status: Time Limit Exceeded

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

B = []
for j in range(n):
    B.append(j - A[j])

count = 0

for i in range(n):
    b = i + A[i]
    count += B[(i+1):].count(b)

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

Submission status: Time Limit Exceeded

Solution code:
# E - This Message Will Self-Destruct in 5s
n = (int)(input())

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

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

print(sum)

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = [int(x) for x in input().split()]
index = list(range(N))

from itertools import combinations

count = 0

for i,j in combinations(index,2):
    if A[i] + A[j] == abs(i - j):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
A = list(map(int, input().split()))
index = list(range(N))
ans = 0
for combination in combinations(index, 2):
    if A[combination[0]]+A[combination[1]] == combination[1] - combination[0]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

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

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

print(res)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_dict = {}
ans = 0

for i in range(len(A)):
    if (i+1) <=2 * 10**4:
        A_dict[i+1] = A[i]

for k_1, v_1 in A_dict.items():
    for k_2, v_2 in A_dict.items():
        if abs(k_2 - k_1) == v_1 + v_2:
            ans += 1

print(ans // 2)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
N = int(input())
M = list(map(int, input().split()))
result = 0
for i in range(N):
  x = M[i]
  #print(i, x)
  result += len([1 for m,n in enumerate(range(i+x+1, N)) if m+1 == M[n]])
print(result)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
import numpy as np
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N = int(readline())
h = list(map(int, readline().split()))
A = np.array(list(itertools.combinations(range(1, N+1), 2)))
cnt = 0
for i in range(len(A)):
  a = A[i][0]
  b = A[i][1]
  if abs(a-b) == h[a-1]+h[b-1]:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
a = list(map(int, input().split()))
d = []
count = 0

for i, v in enumerate(a):
  d.append([i+1, v])

for v in itertools.combinations(d, 2):
    if v[1][0] - v[0][0] == v[1][1]+v[0][1]:
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    N = int(readline())
    A = np.array(readline().split(), dtype=np.int)
    
    ans = 0
    for i in range(N-1):
        a = A[i]
        tmp = np.arange(1-a, N-i-a)
        c = A[i+1:] - tmp
        ans += len(np.where(c==0)[0])

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
cnt = 0
A_max = max(A)
A_min = min(A)
#print("min", A_min)
for i in range(N):
  i_upper = A[i] + A_min
  if i_upper < i:
    i_upper = i
  if i_upper <= N:
    for j in range(i_upper, N):
      #print(i,j)
      if abs(i - j) == (A[i] + A[j]):
        cnt = cnt + 1
        #print("cnt")
print(cnt)

Submission status: Time Limit Exceeded

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