Problem:


Score: 500 points

Problem Statement

You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.

There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.

According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.

The absolute difference of their attendee numbers is equal to the sum of their heights.

There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?

P.S.: We cannot let you know the secret.

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the number of pairs satisfying the condition.

Sample Input 1

6
2 3 3 1 3 1

Sample Output 1

3

A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.

A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.

A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.

No other pair satisfies the condition, so you should print 3.

Sample Input 2

6
5 2 4 2 8 8

Sample Output 2

0

No pair satisfies the condition, so you should print 0.

Sample Input 3

32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Sample Output 3

22



Sample input:
6
2 3 3 1 3 1


Sample output:
3

Submission status: Time Limit Exceeded

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

checked = {}
cnt = 0

checked_me = [False] * N

# 最大200k
for i in range(N-1):
    for j in range(i + 1, N):
        if checked_me[j] == False:
            if (i, j) not in checked.keys() and (j, i) not in checked.keys():

                # 番号の差の絶対値が伸長の和に等しい
                if abs(i - j) == A[i] + A[j]:
                    cnt += 1
                checked.update({(i, j): True})
                checked.update({(j, i): True})

    checked_me[i] = True

# print(checked)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
participant = list(map(int, input().split()))
hashSet = collections.defaultdict(lambda:set())
for i,v in enumerate(participant):
  hashSet[v].add(i)
  
ans = 0
for i,v in enumerate(participant):
  for key, s in hashSet.items():
    if i+v+key in s:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun May  3 21:56:12 2020

@author: riichi
"""
import numpy as np

N = int(input())
A = list(map(int,input().split()))
a = np.array([],dtype = int)
b = np.array([],dtype = int)

A = np.array(A)
ans = 0
for i in range(N-1):
    a = np.append(a,1-A[i])
    a = a + 1
    
a = a-1

for i in range(N):
    b = np.append(b,A[i])
    b = b + 1

b = b - 1
a = np.sort(a)
b = np.sort(b)

for i in b:
    ans += np.count_nonzero(a==i)


print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N-1):
  first = A[i]
  count = first-1
  for j in range(min(N,i+first),N):
    count += 1
    final = A[j]
    if first + final == count:
      ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
A_list_diff = sorted([i - a for a, i in zip(A_list, range(1, N  +1))])

ans = 0

for i, a in enumerate(A_list):
    d = a + i + 1
    for o in A_list_diff:
        if d == o:
            ans += 1
        elif d < o:
            break
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
a = list(map(int,input().split()))
a = [(i+1,a[i]) for i in range(N) if a[i]-i<2*1e5]
ans=0
for i in itertools.combinations(a,2):
  if abs(i[0][0]-i[1][0])==i[0][1]+i[1][1]:
    #print(i[0],i[1])
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
m = max(li) #最大値
mi = min(li) #最小値
ans = 0

for i in range(n):
    li[i] = [i+1, li[i]]

for i in range(n-mi*2):
    for j in range(i+mi*2, min(n, i+1+m*2)):
        x = li[j][0]-li[i][0]
        y = li[j][1]+li[i][1]
        if x == y:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
p = []
for i in range(N):
    p.append([i,A[i]])

for v in itertools.combinations(p,2):
    if abs(v[0][0]-v[1][0]) == v[0][1] + v[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-1):
    for j in range(i,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 i in range(N):
    for j in range(i,N):
        if(A[i]+A[j]==abs(i-j)):
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:

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

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 countPairs(arr, n): 
	mp = dict() 
	for i in range(n): 
		mp[arr[i] - i] = mp.get(arr[i] - i, 0) + 1
	res = 0
	for x in mp: 
		cnt = mp[x] 
		res += ((cnt * (cnt - 1)) // 2) 

	return res 


def main():
    n = I()
    a = LI()
    c=0
    d= dict()
    for i in range(n):
        for j in range(i+1,n):
            x = abs(i-j)
            s = a[i]+a[j]
            if x==s:
                if (i,j) not in d:
                    d[(i,j)]=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()))[::-1]

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
index = np.array(list(range(1, N+1)))
A = np.array(list(map(int, input().split())))
a = index + A
d = list((index - A))
ans= 0
c = 0
for num in a:
  ans += (d[c:]).count(num)
  c += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
n = int(input())
A = list(map(int, input().split()))
A_p = np.array([a + (i+1) for i, a in enumerate(A)])
A_m = np.array([a - (i+1) for i, a in enumerate(A)])
# print(A_p)
# print(A_m)
count = 0
for i in range(1, n+1):
    tmp = A_p[:i] + A_m[n-i:n]
    # print(tmp)
    # print(np.count_nonzero(tmp))
    tmp2 = A_p[n-i:n] + A_m[:i]
    count += len(tmp) - np.count_nonzero(tmp)
    count += len(tmp2) - np.count_nonzero(tmp2)

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
H = list(map(int, input().split()))
H = [0] + H
count = 0

for a in range(1, n+1):
    for b in range(1, n+1):
        if a >= b :
            continue
        if abs(a - b) == H[a] + H[b]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
new=[]
def diff(a,b):
    if a>b:
        return(a-b)
    else:
        return(b-a)
for i in range(0,len(l)):
    if l[i]>2*10**5:
        pass
    else:
        new.append((l[i],i+1))

new.sort()
for i in range(0,len(new)):
    for j in range(i+1,len(new)):
        if new[i][0]+new[j][0]>2*10**5:
            break
        if diff(new[i][1],new[j][1])==new[i][0]+new[j][0]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(map(int,input().split()))
a = np.array([],dtype = int)
b = np.array([],dtype = int)

A = np.array(A)
ans = 0
for i in range(N-1):
    a = np.append(a,1-A[i])
    a = a + 1
    
a = a-1

for i in range(N):
    b = np.append(b,A[i])
    b = b + 1

b = b - 1


for i in b:
    ans += np.count_nonzero(a==i)


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

name_list=np.arange(1,n+1)

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sa = input().split(" ")
a = []
for s in sa:
    a.append(int(s))

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:
import bisect
n=int(input())
a=list(map(int,input().split()))
B=[]
for i in range(n):
  B.append(i+1-a[i])
cnt=0
for i in range(n-1):
  b=B[i+1:]
  b.sort()
  x=i+1+a[i]
  cnt+=bisect.bisect_left(b,x+1)-bisect.bisect_left(b,x)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
AJ = [a - i for i, a in enumerate(A)]

count = 0
for i in range(0, N-1):
    ai = A[i]
    count += list(map(lambda x: x + ai + i, AJ[i+ai:])).count(0)

print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve(n, xs):

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

    return ans
if __name__ == "__main__":
    n = int(input())
    xs = [int(i) for i in input().split()]
    print(solve(n, xs))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


N = readint()
A = np.array(list(readnums()))

ans = 0
for i in range(N):
    r = np.arange(N - i)
    a = A[i:]
    ans += np.count_nonzero((a - r) == -A[i])

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def main():
    N = int(input())
    lst = list(map(int, input().split()))
    A = np.array([l + i for i, l in enumerate(lst)])
    B = np.array([i - l for i, l in enumerate(lst)])
    setA = set(A)
    setB = set(B)
    seki = setA & setB
    ans = 0
    for s in seki:
        numa = np.count_nonzero(A == s)
        numb = np.count_nonzero(B == s)
        ans += numa*numb
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

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

main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
PA=[A[i-1]+i for i in range(1,n+1)]
MA=[i-A[i-1] for i in range(1,n+1)]
c=0
for p in PA:
     c+=MA.count(p)
print(c)

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
for i in range(1,n):
  r[i-1]=i-l[i]
for i in range(n):
  t[i]=i+l[i]
rx=sorted(r)
for i in range(n-1):
  r[i]=[r[i],i]
r.sort()
ans=0
import bisect
for i in range(n):
  le=bisect.bisect_left(rx,t[i])
  ri=bisect.bisect_right(rx,t[i])
  for j in range(ri-le):
    if i<r[le+j][1]:
      ans+=1
    else:break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
hlist = list(map(int, input().split())) 
from collections import Counter
newlist =[0]*n
res = 0
for i in range(0,n):
    newlist[i] = i+1-hlist[i]

for j in range(0,n):
    count = Counter(newlist[j:])
    temp  = count[hlist[j]+1+j]
    res = res + temp

print(res)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A=list(map(int, input().split()))
B=[A[i]+i+1 for i in range(n)]
x=min(B)
y=max(B)
C=[j+1-A[j] for j in range(n) if x<=j+1-A[j]<=y]
C2=set(C)

t=0
for i in range(n):
  if B[i] in C2:
    t+= C.count(B[i])
print(t)

Submission status: Time Limit Exceeded

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

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

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

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

number = range(1, N+1)
numhei = [0] * N
for n in range(N):
    numhei[n] = number[n] + A[n]

count = 0
for n in number:
    count += Counter(numhei)[n - A[n-1]]

print(count)

Submission status: Time Limit Exceeded

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

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    n = 0
    x_list = list(range(N-1))
    y_list = list(range(N-1))
    product = itertools.product(x_list, y_list)

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

    print(n)

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 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()))
R = [[] for _ in range(N)]
res = 0

for i, a in enumerate(A):
    if i != 0:
        R[i] += list(map(lambda x: x+1, R[i-1]))

    if i+a+1 < N:
        R[i+a+1].append(1)
    res += R[i].count(a)

print(res)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())  # 文字列または整数(一変数)
    A = list(map(int, input().split()))  # 整数のリスト

    answer = 0

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

    print(answer)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
from bisect import bisect_left,bisect
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=np.array(nl())
A2=A-np.array([i for i in range(N)])
A2.sort()
cost=[1]*N
c=0
A2=A2-cost
for i in range(N-1):
    A2=A2+cost
    p=bisect_left(A2,-A[i])
    tmp=-A[i]
    tmp=A2[p]
    while(tmp==-A[i]):
        c=c+1
        p=p+1
        tmp=A2[p]

print(c)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[0]*n
a[:]=map(int,input().split())
import numpy as np
r=0
for ii in range(n):
  for jj in np.arange(n-1,ii,-1):#(ii+1,n):
    if a[ii]>jj-ii:
        break
    if a[ii]+a[jj]==jj-ii:
      r+=1
print(r)

Submission status: Time Limit Exceeded

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

for i in range(len(a)):
  for j in range(i+1,len(a)):
    if abs(i-j) <= a[i]:
      continue
    if abs(i-j) == a[i]+a[j]:
      ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
d_i = defaultdict(list)
d_j = defaultdict(list)

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

for i in range(N):
    d_i[i-A[i]].append(i)
    d_j[i+A[i]].append(i)

cnt = 0
for key in d_j.keys():
    arr_i = d_i[key]
    arr_j = d_j[key]
    for i in arr_i:
        for j in arr_j:
            if i > j:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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


b=[]
for i in range(1,n):
  b.append(a[i]+a[0])

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

b=np.array(b)
c=np.array(c)
c=c[1:]

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

  d=b-c
  ans+=np.count_nonzero(d==0)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
goukei = 0

N = int(input()) * (-1)
Ai = list(map(int, input().split()))
array_Ai = np.array(Ai)
number = np.array([j for j in range(0, N, -1)])
new_ai = number + array_Ai
for i in range(len(Ai)):
    goukei += np.count_nonzero(new_ai == (-Ai[i] - i))
print(goukei)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []
ans = 0
for i in range(N):
  if A[i] < 200000:
    B.append(i)
for b in B:
  for c in B:
    if b != c and max(b,c) - min(b,c) == A[b] + A[c]:
      ans += 1
print(int(ans/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,N):
            # print(i,j,abs(i-j),A[i] + A[j])
            if A[i] + A[j] == abs(i-j):
                ans += 1
 
    print(ans)
 
 
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
a=input().split(" ")
for i in range(num):
  a[i]=int(a[i])
count=0
for i in range(num-2):
  for j in range(i+2,num):
    id=j-i
    x=a[j]+a[i]
    if x==id:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
lim = min(10**9, n)
i = 0
di = 1
while True:
    if i+di >= n:
        i = 0
        di += 1
        if di == lim+1:
            break
    elif a[i+di] + a[i] == di:
        cnt += 1
        i += 1
    else:
        i += 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(N-i-1):
    if A[i] + A[i+j+1] == j + 1:
      ans += 1
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list((i, j) for i, j in enumerate(map(int, input().split())))
un = sorted(A, reverse=True)

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n=ii()
    a=lmis()
    m=max(a)
    cnt=0
    ss=2*10**5-1
    for i in range(n-2):
        dis=i+1+a[i]
        if a[i]>=ss: continue
        for j in range(dis,min(m+dis,n)):
            if j-i==a[i]+a[j]: cnt+=1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(_) for _ in input().split(" ")]

ans=0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

count = 0

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

Submission status: Time Limit Exceeded

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

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()
#print(alst)

cnt = 0
for i in range(len(alst)):
    ai, ni = alst[i]
    if ai * 2 > 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:
import math

n = int(input())

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


listi = [a[i] +i+1 for i in range(n)]
listj = [i+1 -a[i] for i in range(n)]

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

Submission status: Time Limit Exceeded

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

ans = 0
p = []
for i in range(N):
    p.append([i,A[i]])

for v in itertools.permutations(p,2):
    if abs(v[0][0]-v[1][0]) == v[0][1] + v[1][1]:
        ans += 1
print(ans//2)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
c_list = a_list.copy()
for i in range(n):
  a_list[i] -= i + 1
count = 0
for i in range(n-1):
  target = a_list[i+1:]
  count += target.count(-(c_list[i] + i + 1))
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = []
for j in range(0,n):
  k = ["a"]*(j+1)+[i-a[j] for i in range(1,n-j)]
  l.append(k)
l1 = list(map(list,(zip(*l))))
#print(l)
s = 0
for i in range(n):
  q = a[i]
  z = l1[i]
  s += z.count(q)
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = [int(i) for i in input().split()]
pair = 0
for x in itertools.combinations(range(n), 2):
    i, j = x
    if abs(i - j) == a[i] + a[j]:
        pair += 1
print(pair)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = np.array(read().split(), dtype=np.int64)

    ans = 0
    for i in range(1,N):
        ans += np.count_nonzero(A[:i] + A[i] == np.arange(i,0,-1))
        
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

name_list=np.arange(1,n+1)

count = 0

for i in range(n-1):
    for j in range(i+1,n):
        sa = abs(name_list[i]-name_list[j])
        if sa == a_list[i] + a_list[j]:
            count +=1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(1,n):
    ru.append(a[0] + a[i])
#print(ru)

tmp =  [j for j in range(len(ru))  if j+1 == ru[j]]
ans = ans + len(tmp)

for i in range(1,n-1):
    ru.pop(0)
    ru = [x- a[i-1] +a[i] for x in ru]
    #print(ru)
    tmp =  [j for j in range(len(ru)) if j+1 == ru[j]]
    ans = ans + len(tmp)


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
x = int(input())
height = list(map(lambda x: int(x), input().split()))  
cands = []

for i in range(len(height)):
  tmp = []
  cands.append(tmp)
  
for i in range(len(height)):
  if i-height[i] >= 0:
    cands[i-height[i]].append(i)
  if i+height[i] < len(height):
    cands[i+height[i]].append(i)

#print(cands)
results = []
for i in range(len(height)):
  #print(cands[i])
  if len(cands[i]) > 1:
    tmp = cands[i]
    for j in range(len(tmp)):
      for k in range(len(tmp)):
        if tmp[j] != tmp[k] and (tmp[j] - tmp[k] == height[tmp[j]]+ height[tmp[k]] or tmp[k]-tmp[j] == height[tmp[j]]+ height[tmp[k]]):
          #print([tmp[j], tmp[k]])
          results.append([tmp[j], tmp[k]])

if len(results) > 1:
  results = np.sort(results, axis=1)
  results = np.unique(results, axis=0)
print(len(results))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = [int(x) for x in input().split()]
n = 0
x_list = list(range(N-1))
y_list = list(range(N-1))
product = itertools.product(x_list, y_list)

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

print(n)

Submission status: Time Limit Exceeded

Solution code:
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

f=[]
for i in range(0,n):
    for j in range(0,n):
        #if abs(b[i]-b[j])==abs(a[i]+a[j]):
        #d.append(abs(b[i]-b[j]))
        #e.append(abs(a[i]+a[j]))
        f.append(a[i]+a[j]-abs(b[i]-b[j]))
        


for i in range(0,len(f)):
    if f[i]==0:
        count+=1
print(count//2)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline

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

ans = 0
for i in range(2, n):
    a = np.array(an)
    a = a[i:] - (i - a[:-i])
    ans += len(a[a == 0])

print(ans)