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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
q = 0
p = []*10
m = []*10
for i in range(10):
    p.append([])
    m.append([])
for i in range(n):
    x = i+1-a[i]
    if(x > 0):
        if(x in p[x%10]):
            m[x%10][p[x%10].index(x)][0] += 1
        else:
            m[x%10].append([1,0])
            p[x%10].append(x)
    x = i+1+a[i]
    if(x in p[x%10]):
        m[x%10][p[x%10].index(x)][1] += 1
    else:
        m[x%10].append([0,1])
        p[x%10].append(x)
    
for i in range(10):
    for j in range(len(m[i])):
        q += m[i][j][0]*m[i][j][1]
print(q)

Submission status: Time Limit Exceeded

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

s = 0

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
#E問題
import itertools
N = int(input())
A = input().split()
A_i =[int(s) for s in A]
number = []
count = 0
for i in range(1, N+1):
    number.append(i)
combination_list = list(itertools.combinations(A_i, 2))
number_list = list(itertools.combinations(number, 2))
for i in range(len(combination_list)):
    if(abs(number_list[i][0] - number_list[i][1]) == combination_list[i][0] + combination_list[i][1]):
        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+1,n):
        if a[i]+a[j] == j-i:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    for i in range(N-1):
        for j in range(i+1,N):
            if abs(A_arr[j]+A_arr[i])==j-i:
                cnt += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Time Limit Exceeded

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

cnt=0
for i in range(n):
    a1 = alist[i]
    for j in range(i):
        a2 = alist[j]
        if abs(i-j) == a1+a2:
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

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

li = []
for i in range(N):
    li.append(A[i] + i)

li.sort()

cnt = 0
for j in range(N):
    cnt += li.count(j - A[j])

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

Submission status: Time Limit Exceeded

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

    else:
        temp += 1

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

num = len(com)
ans = 0
for i in range(num):
    aa = com[i]
    # print(aa)
    idA = aa[0]
    idB = aa[1]
    dif = abs(idA - idB)
    indexA = idList.index(idA)
    indexB = idList.index(idB)

    height = a[indexA] + a[indexB]

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A= list(map(int, input().split()))
a=[]
for i,v in enumerate(A):
    if v<n:
        a.append([i+1,v])
a.sort(key=lambda x: x[1])
ans=0
for i,v in enumerate(a):
    for j in range(i+1,len(a)):
        tmp=a[j][1]+v[1]
        if tmp>=n:
            break
        if tmp==abs(v[0]-a[j][0]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

N = int(input())

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

total = 0
for i,height_a in enumerate(heights):
    if height_a <= (N-i-2):
        for j in range(i+height_a+1,N):
            if abs(i-j) == height_a + heights[j]:
                total += 1

print(total)

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)):
    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]) > 2 * 10 ** 5:
            break
print(cnt)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import Counter
n=int(input())
l=[int(x) for x in input().split()]
f1=[]
f2=[]
for i in range(1,len(l)+1):
	f1.append(i-l[i-1])
	f2.append(l[i-1]+i)

c=0
for i in range(len(l)):
	c+=f1.count(f2[i])
print(c)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
b = np.array([i for i in range(1, n+1)])

ans = 0
for i in range(n-1):
  ans += ((a[i+1:] + a[i]) == b[:n-1-i]).sum()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

import itertools
import numpy as np

# --- fetch input ---
inputs: list = []
while True:
    try:
        inputs.append(input().strip('\n'))
    except EOFError:
        break

# --- write code below ---
n = int(inputs[0])
candidate_info = {n+1: int(height) for n, height in enumerate(inputs[1].split())}

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

counter = 0

for a, b in pair_list:
    if np.abs(a - b) == candidate_info[a] + candidate_info[b]:
        counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

cnt = 0
dist = [a[0]-1]
for ai in a[1:]:
    cnt += dist.count(-ai)
    dist.append(ai)
    dist = list(map(lambda x: x-1, dist))

print(cnt)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

S1=(np.array(a)+np.arange(n)).tolist()
s1=set(S1)
S2=(np.arange(n)-np.array(a)).tolist()
s2=set(S2)

check=0
commons=list(s1&s2)

for l in commons:
    check+=S1.count(l)*S2.count(l)
print(check)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = map(int, input().split())
A = list(map(int, input().split()))
res = 0
d = defaultdict(int)
for i, num in enumerate(A):
    res += d[num]
    new_d = defaultdict(int)
    for k, v in d.items():
        new_d[k+1] = v
    new_d[1 - num] += 1
    d = new_d
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 j in range(A[i]+i,N):
    if j-i==A[i]+A[j]:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
input = raw_input

n = int(input())
As = map(int, input().split(" "))

out = 0
d = 1
while True:
    if d >= n:
        break
    i0 = 0
    i1 = d
    while True:
        if As[i0] + As[i1] == d:
            out += 1

        i0 += 1 
        i1 += 1 
        if i1 >= n:
            break
    
    d += 1

print(out)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = list(map(int,input().split()))
g = max(a)
num = []
ans = 0
for i in range(n):
    value = a[i]
    if value >= n - (i+1):
        continue
    cnt = 1
    for j in range((i+value+1),n):
        if cnt == a[j] :
            ans += 1
        elif cnt > g:
            break
        cnt += 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 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() ) )

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

for p in itertools.permutations(A, 2):
  if abs(p[0][0]-p[1][0]) == p[0][1]+p[1][1]:
    #print(p)
    cnt += 1

print(int(cnt/2))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

mem =[]
count =0

for i in range(N-1,-1,-1):
    count += bisect.bisect_right(mem,A[i]+i)-bisect.bisect_left(mem,A[i]+i)
    bisect.insort(mem,i-A[i])

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    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)


main()

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

Submission status: Time Limit Exceeded

Solution code:
#import collections
# c = collections.Counter()
#import itertools as it
#import math
#import numpy as np
#import sys 
#sys.exit()
 
#  = input()
n  = int(input())
#a, b  = map(int, input().split())

a = list(map(int, input().split()))
b=[]
for i in range(1,n+1):
    b.append(i)
'''
n = input()
a = [int(input()) for i in range(n)]
'''
'''
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
'''
#print(n,a,b)
#-------------------------------#
count=0
for i in range(0,n):
    for j in range(0,n):
        if abs(b[i]-b[j])==abs(a[i]+a[j]):
        #print(abs(b[i]-b[j]))
        #print(abs(a[i]+a[j]))
            count+=1
print(count//2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
heights = [int(ch) for ch in input().split()]
ans = 0
for i in range(len(heights)):
    h = heights[i]
    for j in range(i+h+1,len(heights)):
        interval = j-i
        sum = h+heights[j]
        if sum == interval:
            ans+=1
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] > n - i - 1:
        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:
import sys
input=sys.stdin.readline

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

ans = 0

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

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(0 for i in range(n+2*now))
mat2=list(0 for i in range(n+2*now))
for i in range(n):
  matc[now-a[i]]+=1
  mat2[now+a[i]]+=1
  now+=1
#print(matc)
for j in range(n+2*noww):
  ans+=matc[j]*mat2[j]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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

ans=0
for i in range(N-1):
	ans+=len(list(filter(lambda x:x-A[x]==i+A[i],range(i+1,N))))
print(ans)

Submission status: Time Limit Exceeded

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

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

for s in range(1, n+1):
    for t in range(s+A[s-1]+1, n+1):
        if A[s-1] + A[t-1] == t-s:
            pn += 1

print(pn)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

N = int(input())

A = [
  int(j) - i  for i, j in enumerate(input().split())
]


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import Counter

N = int(input())
A = np.array(list(map(int, input().split())))
B = np.arange(N) + 1

s = A + B
m = B - A

s_ct = Counter(s)
m_ct = Counter(m)

ans = 0
for i in s_ct:
    for j in m_ct:
        if i == j:
            ans += m_ct[j] * s_ct[i] 

print(ans)

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

Submission status: Time Limit Exceeded

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

lis3 = list(set(lis1) & set(lis2))
for i in lis3:
    cnt += lis1.count(i) * lis2.count(i)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n = I()
    a = LI()
    c=0
    d= dict()
    for i in range(n):
        for j in range(n):
            if i!=j:
                x = abs(i-j)
                s = a[i]+a[j]
                if x==s:
                    ls = [i,j]
                    ls.sort()
                    if tuple(ls) not in d:
                        d[tuple(ls)]=1
                        c+=1
    print(c)


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

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from itertools import product
# from itertools import combinations


def solve(N, A):
    bg = []
    sm = []
    # cl = set()
    for i in range(N):
        if A[i] <= i - 1:
            bg.append(i)
            # cl.add(i)
        if A[i] >= 1 - i:
            sm.append(i)
            # cl.add(i)
    # L = list(combinations(cl, 2))
    L = list(product(bg, sm))
    ct = 0
    for l in L:
        if l[0] > l[1]:
            if abs(l[0] - l[1]) == A[l[0]] + A[l[1]]:
                ct += 1
    print(ct)
    # L = list(combinations(range(N), 2))
    # ct = 0
    # for l in L:
    #     if abs(l[0] - l[1]) == A[l[0]] + A[l[1]]:
    #         ct += 1
    # print(ct)
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
            for line in sys.stdin:
                for word in line.split():
                    yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    A = [int(next(tokens)) for _ in range(N)]
    solve(N, A)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations as com
n = int(input())
a = list(map(int, input().split()))
q = list(range(1, n+1))
cnt = 0
for i, j in com(q, 2):
    if abs(i-j) == a[i-1]+a[j-1]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

import itertools
comb = list(itertools.combinations(range(N), 2))

cnt = 0
for co in comb:
    a,b = co
    a,b = a,b
    h_a = A[a]
    h_b = A[b]

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import numpy as np
import itertools

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

p = 0
for x,y in list(itertools.combinations(range(0,N),2)):
  if abs(x-y) == A[x]+A[y]:
    p += 1
#
print(p)

Submission status: Time Limit Exceeded

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

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

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, n):
        b_height = h_list[k]
        if k - i == a_height + b_height:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# import numpy as np
# from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# N, K = [int(x) for x in input().split()]

from itertools import *

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

number = list(combinations(range(1, N+1), 2))
height = list(combinations(A, 2))

count = 0

for n, h in zip(number, height):
    if n[1]-n[0] == sum(h):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_lst = [int(elem) for elem in input().split()]

lst = []
for i in range(n):
    lst.append(i - a_lst[i])

lst2 = []
for j in range(n):
    lst2.append(j + a_lst[j])

cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        if lst2[i] == lst[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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)
    A2[i] = (i+1) - A[i]

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

print(cnt)

Submission status: Time Limit Exceeded

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

count = 0
for k in range(n):
    # j - i == k となる組み合わせは？
    for i in range(n - k):
        j = i + k
        if as_[i] + as_[j] == k:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n-2):
    h = a[i]
    for j in range(i+h, min(n, i+max+h+1)):
        if abs(i-j) == h+a[j]:
            ans += 1

print(ans)

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(i + 1, 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(count)

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
attendees = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
L = list(range(1,N+1))

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()

arr = [[a[i], i + 1] for i in range(n)]
arr.sort()

ans = 0
for i in range(n - 1): #低い方
    if arr[i][0] + arr[i + 1][0] > n:
        continue
    for j in range(i + 1, n): #高い方
        if arr[i][0] + arr[j][0] == abs(arr[i][1] - arr[j][1]):
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations as com
n = int(input())
a = list(map(int, input().split()))
q = [i for i in range(1, n+1)]
cnt = 0
for i, j in com(q, 2):
    if abs(i-j) == a[i-1]+a[j-1]:
        cnt += 1
print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


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

R = [None] * (N + 1)
R[N] = Counter()
L = [None] * (N + 1)
L[0] = Counter()

# n < i
# for i in range(N):
#     c = Counter()
#     c[A[i] + i] = 1
#     L[i + 1] = L[i] | c

# n >= i
c = Counter()
for n in range(N - 1, -1, -1):
    R[n] = R[n + 1] | c
    R[n][(n + 1) - A[n]] += 1

ans = 0
for i, Ai in enumerate(A):
    # n < a
    # c0 = i - a
    # l = L[i][c0]

    # n >= a
    c1 = Ai + (i + 1)
    r = R[i + 1][c1]

    ans += r

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

    total_pass = 0
    for i, i_A in enumerate(A_list):
        for j in range(i+i_A, N):
            if (j - i) == i_A + A_list[j]:
                total_pass += 1

    print(total_pass)

    return

if __name__ == '__main__':
    main()
    sys.exit(0)