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 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+an[i], 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()))

B=[0]*N
for i in range(N):
    B[i]=A[i]+i
C=[]
for i in range(N):
    if i-A[i]>0:
        C.append(i-A[i])

ans=0
for i in B:
    ans+=C.count(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if h[i] > 10**5:
        continue
    num = min(n, i + h[i] + 1)
    s = np.array(h[num:])
    length = len(s)
    u = np.arange(length) + 1
    s -= u
    t = np.count_nonzero(s)
    ans += length - t
print(ans)

Submission status: Time Limit Exceeded

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

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) if val < N]
    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:
n=int(input())
ans=0
a=list(map(int,input().split()))
now=max(a)
noww=now
matc=list([] for i in range(n+2*now))
mat2=list([] for i in range(n+2*now))
for i in range(n):
  matc[now-a[i]].append(i)
  mat2[now+a[i]].append(i,)
  now+=1
#print(matc)
for j in range(n+2*noww):
  ans+=len(matc[j])*len(mat2[j])
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,j in combinations(range(n), 2):
        if j-i==aa[i]+aa[j]:
            c+=1
    print(c)
main()

Submission status: Time Limit Exceeded

Solution code:
N =int(input())
A = list(map(int,input().split()))
x=0
y=0
ans =0
while x <N:
    y =x+A[x]
    while y <N:
        t = A[x]+A[y]
        if t == y-x:
            ans +=1
        y+=1
    x+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import itertools
#K = int(input())
#N,K = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))
c=0
for i in range(N):
    s=i+A[i]+1
    if s>N:
        continue
    for j in range(s,N):
        if abs(i-j)==A[i]+A[j]:
            c+=1

print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n):
  for _ in range(min(i + a[i], n), n):
#    print(i, ' ', _, a[i] + a[_], ' ', _-i)
    if a[i] + a[_] == _-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):
    m=-a[i]
    for k in range(i+1,n):
        m+=1
        if a[k]==m:
            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(1,N):
    for j in range(N):
        if j+i > N-1:
            break
        else:
            if A[j]+A[j+i] == i:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

print(X)

Submission status: Time Limit Exceeded

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

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

import itertools
combs = list(itertools.combinations(items, 2))

ans = 0
for comb in combs:
  if ((comb[1][0]-comb[0][0])==(comb[0][1]+comb[1][1])):
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

s = 0

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

print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

pear = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

    d = defaultdict(int)
    C = []
    for i in range(N-1,-1,-1):
        d[B[i]] += 1
        C.append(d.copy())
    C.reverse()
    ans = 0
    for i in range(N-1):
        ans += C[i][A[i]]

    print(ans)

    


if __name__ == "__main__":
    main()

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

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


ans = 0
d = deque(A)
for i in range(N):
  a = d.popleft()
  c = d.count(-a - 2 * i)
  ans += c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

n_list = [i for i in range(n)]
comb = itertools.combinations(n_list, 2)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().rstrip().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:
# E - This Message Will Self-Destruct in 5s

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

if __name__ =='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(1000000)




def main():
    n = int(input())
    a_dic = {}
    i = 0
    count = 0
    for a in map(int, input().split()):
        a_dic[i] = a
        for j in range(i-1):
            if i - j == a + a_dic[j]:
                count += 1
        i += 1

    # for i in range(n):
    #     ai = a_dic[i]
    #     for j in range(i+1, n):
    #         # combi = (i,j)
    #         if j - i == ai + a_dic[j]:
    #             count += 1
    print(count)



main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
N = int(input())
A = list(map(int, input().split()))
count = 0
 
J = list(itertools.combinations([i for i in range(N)], 2))
 
for i in range(len(J)):
  if J[i][1]-J[i][0] == A[J[i][1]]+A[J[i][0]]:
    count += 1
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
M = list(range(1, N+1))
A = list(map(int, input().split()))

cnt = 0
for a, b in list(combinations(M, 2)):
    if abs(a-b) == A[a-1]+A[b-1]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N):
  for j in range(i+A[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 = input().split()
for i in range(n):
    a[i] = int(a[i])
result = 0
for i in range(n):
    j = i
    #print("i", i)
    j = j + a[i]
    while True:
        #print(j)
        if j >= n:
            break
        if j-i == a[j] + a[i]:
            result += 1
        j += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
As = np.array(list(map(int, input().split())))\

max_A = max(As)

ans = 0
for n in range(N):
    h = As[n]
    co = As.copy()
    co = co + h - np.array([abs(n-i) for i in range(N)])
    ans += np.sum(co==0)
print(ans//2)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())

A_list = []
inp_list = list(map(int, input().split(" ")))
for i in range(N):
	A_list.append([i+1, inp_list[i]])
answer = 0
for v in itertools.combinations(A_list, 2):
	if abs(v[0][0] - v[1][0]) == (v[0][1] + v[1][1]):
		answer += 1
print(answer)

Submission status: Time Limit Exceeded

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

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        target_ind = j
        target_h = a_ls[target_ind]
        diff = abs(target_ind - i)
        Sum = target_h + a_ls[i]
        if diff == Sum:
            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+A[i],N):
      if j - i == A[i] + A[j]:
        spy += 1
      
print(spy)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = [(int(index),int(i)) for index,i in enumerate(input().split(" "))]

def combinations(iterable, r):
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    yield tuple(pool[i] for i in indices)
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        yield tuple(pool[i] for i in indices)

        
count = 0
c = combinations(As, 2)
for a in c:
    p1 = a[0]
    p2 = a[1]
    if abs(p1[0]-p2[0]) == (p1[1]+p2[1]):
        count+=1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
# input
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 abs_val <= a_ls[j]: continue
		if a_ls[j] + a_ls[j+abs_val] == abs_val: cnt += 1

# result
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

x = input().split(' ')
a_s = []

for x_ in x:
  a_s.append(int(x_))
  
count = 0
for i in range(n):
  low_bound = a_s[i] + i 
  if low_bound >= n:
    continue
  
  for j in range(max([low_bound, i+1]), n):
    if j - i == a_s[i] + a_s[j] and i != j:
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
N=int(input())
# N,M=map(int,input().split())
# S=[[]for i in range(N)]
# # for i in range(Q):
A=list(map(int,input().split()))
# #     S[i]=a
ans=0
# # print()
for i in range(N):
    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:
test_case=int(input())
b=[int(b) for b in input().split()][:test_case]
count=0
for i in range(test_case):
    for j in range(i+1,test_case):
        if j-i ==(b[j]+b[i]):
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(_) for _ in input().split()]
ans=0
for i in range(n):
    t=a[i]
    for j in range(i+t,n):
        ans+=a[j]==j-i-t
print(ans)

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**5:
        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:
N = int(raw_input())
A = map(int, raw_input().split())

count = 0
for i in range(N):
	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:
N = int(input())
A = list(map(int, input().split()))
S = [0]*N
D = [0]*N

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

ans = 0
for l in range(N-1):
    ans += D[l+1:].count(S[l])

print(ans)

Submission status: Time Limit Exceeded

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

A1 = [0]*N
A2 = [0]*N

for i in range(N):
    A1[i] = A[i] + (i+1)

for j in range(N):
    A2[j] = (j+1) - A[j]

cnt = 0
for i in range(N):
    cnt += A2[i:].count(A1[i])

print(cnt)

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+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:
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    increased = [elm + i for i, elm in enumerate(L)]
    decreased = [(elm - i, i) for i, elm in enumerate(L)]
    decreased.sort(key=lambda x: x[0])
    decreased_stripped = [elm[0] for elm in decreased]
    # print(increased)
    # print(decreased_stripped)
    cnt = 0
    for i, num in enumerate(increased):
        res = - num
        # print(res)
        left = bisect_left(decreased_stripped, res)
        right = bisect_right(decreased_stripped, res)
        # print(f"{left} {right}")
        for x in range(left, right):
            j = decreased[x][1]
            # print(decreased[x][1])
            if i < j:
                cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in range(1, N+1):
  p = i + A_list[i-1]
  for j in range(i+1, N + 1):
    if j - A_list[j-1] == p:
      x = x + 1
print(x)

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

cnt = 0
for i in range(N-1):
    cnt += Q[i+1:].count(P[i])

print(cnt)

Submission status: Time Limit Exceeded

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

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

print(count)

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

index_list = np.arange(N)

count = 0
for i in filter(lambda i: heights[i] + i <= N, range(N)):
    h = heights[i]
    min = h + i
    count += np.count_nonzero((heights + i + h)[i+1:] == index_list[i+1:])

print(f"{count}")

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  N = int(input())
  sanka_l = list(map(int, input().split()))
  count = 0
  min_num = min(sanka_l)
  for i in range(N):
    if sanka_l[i] > N-(i+1)-min_num:
      continue
    for j in range(i, N):
      if sanka_l[i] + sanka_l[j] == j - i:
        count += 1
  print(count)
      
main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

comb = {}
result = 0

def add_comb(a, b, c, boolean):
    if a <= b:
        comb[(a, b, c,)] = boolean
    else:
        comb[(b, a, c,)] = boolean

def get_comb(a, b, c):
    if a <= b:
        return comb.get((a, b, c,))
    return comb.get((b, a, c,))

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

        # data = comb.get((A[i],A[j],(i + 1) - (j + 1)))
        data = get_comb(A[i], A[j], (i + 1) - (j + 1))

        if data is None:
            if abs((i + 1) - (j + 1)) == A[i] + A[j]:
                add_comb(A[i], A[j], (i + 1) - (j + 1), True)
                # comb[(A[i],A[j],(i + 1) - (j + 1),)] = True
                data = True
            else:
                add_comb(A[i], A[j], (i + 1) - (j + 1), False)
                # comb[(A[i],A[j],(i + 1) - (j + 1),)] = False
                data = False

        if data is True:
            result += 1

print(result)

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(n):
    num = a_list[i]
    if i + num < n:
        for j in range(i + num, n):
            if a_list[i] + a_list[j] == j - i:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import sys
input=sys.stdin.readline
N = int(input().rstrip('\n'))
As=[int(x) for x in input().rstrip('\n').split()]
comb = [x for x in combinations(range(N),2)]
res = [As[i[0]] + As[i[1]] - abs(i[1]-i[0]) for i in comb]
print(res.count(0))

Submission status: Time Limit Exceeded

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

counts = 0

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

print(counts//2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) #2<=N<=2*(10**5)
A = list(map(int, input().split())) #1<=Ai<=10**9
ans = 0
dummy = 0
for i in range(N-1):
  if(A[i] >= 2*(10**5)):
    dummy += 1
  else:
    for j in range(i+A[i],N):
      #print(i+1,j+1,A[i],A[j], "=", j-i, A[i]+A[j])
      if(j-i == A[i]+A[j]):
        ans += 1
        #print("+")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
dic={}
ans=0
for i in range(n):
    a=i-l[i]
    if a in dic.keys():
       dic[a].add(i)
    else:
       dic[a]={i}
for i in range(n):
  a=i+l[i]
  if a in dic.keys():
    s=dic[a]
  else:
    continue
  k=0
  for j in s:
    if i<j:
      break
    k+=1
  ans+=len(s)-k
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
num = int(input())

s = list(map(int, input().split(" ")))

ans = 0
for i in range(num) :
    x = s[i]
    for j in range(num-i-1) :
        y = s[i+j+1]
        if (j+1) == int(abs(y+x)):
            ans = ans + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
idx = [i+1 for i in range(N)]

# A_dict = dict(zip(idx, A))
# A_dict = sorted(A_dict.items(), key=lambda x: x[1])
# print(A_dict)

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

count = 0
for i in range(N):
    start = i + A[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())
a = list(map(int, input().split()))

fromLeft = [-1]*n

for i in range(n):
    fromLeft[i] = a[i] - i

ans = 0

for i in range(n):
    ans += fromLeft[i:].count(-1*a[i]-i)

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

Submission status: Time Limit Exceeded

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

pairs = list(itertools.combinations(range(n), 2))
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:
#E
from itertools import combinations_with_replacement
n = int(input())
a = list(map(int, input().split()))
ans=0
for i in combinations_with_replacement(range(1, n + 1), 2):
    if abs(i[0] - i[1]) == a[i[0]-1] + a[i[1]-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(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()]
s=sorted(list(set(a)))
r=0
for i in range(len(a)-1):
    for _a in s:
        index=a[i]+_a+i
        if index<len(a):
            if a[index]==_a:
                r+=1
        else:
            break
print(r)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
later_max = [0]*(n+1)
a.insert(0, 0)
for i in range(1, n):
    later_max[i] = i + a[i] + max(a[i+1:])
    if later_max[i] > n:
        later_max[i] = n

# print(a)
# print(later_max)
count = 0
for i in range(1, n):
    j = i + a[i] + 1
    # print(f"start:{i} {j}")
    while j <= later_max[i]:
        if a[i] + a[j] == j - i:
            # print(i, j)
            count += 1
        j += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


n = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    num = min(n, i + h[i] + 1)
    s = np.array(h[num:])
    diff = h[i]
    u = np.arange(len(s)) + 1
    s -= u
    t = np.count_nonzero(s)
    ans += len(s) - t
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:
# coding: utf-8
import itertools

n = int(input())
alst = enumerate(map(int, input().split()), 1)

cnt = 0
for pair in itertools.combinations(alst, 2):
    (n1, a1), (n2, a2) = pair
    if abs(n1 - n2) == a1 + a2:
        #print (pair)
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = [(int(index),int(i)) for index,i in enumerate(input().split(" "))]

def combinations(iterable, r):
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    yield tuple(pool[i] for i in indices)
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        yield tuple(pool[i] for i in indices)

        
count = 0
for a in combinations(As, 2):
    p1 = a[0]
    p2 = a[1]
    if abs(p1[0]-p2[0]) == (p1[1]+p2[1]):
        count+=1
        
print(count)