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:
import math

def main():
    N = int(input())
    Al = [int(x) for x in input().split()]
    center = int(N/2)
    cnt = 0
    for i in range(N):
        for j in range(i,N):
            if i+Al[i] == j-Al[j]:
                cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

count = 0
I = [0]*N
J = [0]*N
for i in range(N):
  I[i] = i+A[i]
  J[i] = i-A[i]
for j in range(N):
  count += J.count(I[j])

print(count)

Submission status: Time Limit Exceeded

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

count = 0
I = [0]*N
J = [0]*N

for i in range(N):
  I[i] = i+A[i]
  J[i] = i-A[i]
for j in range(N):
  count += J.count(I[j])

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
height = [int(x) for x in input().split()]
cnt =0

for i_index, i in enumerate(height[:-1]):
    if i+i_index >= n:
        continue

    for j_index, j in enumerate(height[i_index+i+1:]):
        if j+i == j_index+i+1:
            cnt += 1
            # print(i,j,j_index)
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
height = [int(x) for x in input().split()]
cnt =0

for i_index, i in enumerate(height[:-1]):
    if i+i_index >= n:
        continue

    for j_index, j in enumerate(height[i_index+i:]):
        if j+i == j_index+i:
            cnt += 1
            # print(i,j,j_index)
            
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
height = [int(x) for x in input().split()]
cnt =0

for i_index, i in enumerate(height[:-1]):
    if i+i_index >= n:
        continue

    for j_index, j in enumerate(height[i_index+i:]):
        if j+i == j_index+i:
            cnt += 1
            
            

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

n=int(input())
A=list(map(int, input().split()))
B=[0]*n
c=0

for i,a in enumerate(A):
  B[i]=i-A[i]
  A[i]=i+A[i]
  
for i in range(n):
  a=A.count(i)
  b=B.count(i)
  c+=a*b
  
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
height = [int(x) for x in input().split()]
cnt =0
i_index = 0
j_index = 0
for i in height[:n-1]:
    i_index += 1
    j_index = i_index
    for j in height[i_index:]:
        j_index+=1
        if j+i == abs(i_index - j_index):
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
aL = list(map(int, input().split(" ")))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

from collections import defaultdict
n=n0()
a=[0]
a.extend(n1())

m1=[i+a[i] for i in range(n+1)]
m2=[j-a[j] for j in range(n+1)]

d1=defaultdict(list)
d2=defaultdict(list)
for i in range(1,n+1):
    d1[m1[i]].append(i)
    d2[m2[i]].append(i)

ans=0
for i in d1:
    if len(d2[i])>0:
        for k in d1[i]:
            ans+=len([h for h in d2[i] if h>k])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 愚直な方法: O(n^2)
import numpy as np

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

Submission status: Time Limit Exceeded

Solution code:
# 各要素に身長同士の和を保持する行列を利用する方法
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
s = np.array([])
for i in a:
    s = np.append(s, i+a)
s = s.reshape(len(a), -1)
for i in range(len(a)):
    s[i, i] = -1
b = np.arange(1, n+1)
t = np.array([])
for i in b:
    t = np.append(t, abs(b-i))
t = t.reshape(len(b), -1)
print(int(np.count_nonzero(s == t)/2))

Submission status: Time Limit Exceeded

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
lisA = list(map(int,input().split()))
# arrA = np.array(input().split(),dtype=np.int64)

ans = 0
for i in range(1,N):
    for j in range(0,N-i):
        if lisA[j]+lisA[j+i]==i:
            ans += 1
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Time Limit Exceeded

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

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

for k in range(n-1):
    for j in range(k,n): #nC2通りを再現
        if (j+1)-a[j] == a[k]+k+1:
            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-1):
    for j in range(i,n): #nC2通りを再現
        if abs(i+1-(j+1)) == a[i] + a[j]: #0スタートであることに注意
            count += 1
            
print(count)

Submission status: Time Limit Exceeded

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

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

    print(counter)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

ListL = [i+1+List[i] for i in range(N)]
ListR = [i+1-List[i] for i in range(N)]

ans = 0
for i in range(2*10**5):
  ans += ListL.count(i)*ListR.count(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    aa=list(map(int,input().split()))
    ll={}
    for i,a in enumerate(aa,1):
        x=i-a
        if x < 1:
            continue
        if x not in ll:
            ll[x]=[i]
        else:
            ll[x].append(i)
    c=0
    for i,a in enumerate(aa,1):
        x=i+a
        if x not in ll:
            continue
        c+=sum(j>i for j in ll[x])
    print(c)
main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = list(map(int,input().split()))
c = 0
Bn = []
Cn = []
for k in range(N):    
    Bn.append(An[k]+k)
    Cn.append(k-An[k])
Bn_Cn = set(Bn) & set(Cn)
for i in Bn_Cn:
    c+= Bn.count(i) * Cn.count(i)
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = list(map(int,input().split()))
c = 0
Bn = []
Cn = []
for k in range(N):    
    Bn.append(An[k]+k+1)
    Cn.append(k+1-An[k])
Bn_and_Cn = set(Bn) & set(Cn)
for i in Bn_and_Cn:
    c += Bn.count(i) * Cn.count(i)
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = list(map(int,input().split()))
c = 0
Bn = []
Cn = []
Bn = Bn + An
Cn = Cn + An
for k in range(N):    
    Bn[k] = Bn[k] + k + 1
    Cn[k] = k + 1 - Cn[k]
Bn_and_Cn = set(Bn) & set(Cn)
for i in Bn_and_Cn:
    c += Bn.count(i) * Cn.count(i)
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = list(map(int,input().split()))
c = 0
Bn = []
Cn = []
Bn = Bn + An
Cn = Cn + An
for k in range(N):    
    Bn[k] = Bn[k] + k + 1
    Cn[k] = k + 1 - Cn[k]
for X in range(1,N):
    if X in Bn and X in Cn:
        c = c + Bn.count(X) * Cn.count(X)
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = input().split()
c = 0
for i in range(N):
    An[i] = int(An[i])
Bn = []
Cn = []
Bn = Bn + An
Cn = Cn + An
for k in range(N):    
    Bn[k] = Bn[k] + k + 1
    Cn[k] = k + 1 - Cn[k]
for X in range(1,N):
    if X in Bn and X in Cn:
        c = c + Bn.count(X) * Cn.count(X)
print(c)

Submission status: Time Limit Exceeded

Solution code:
def E():
    n = int(input())
    a = list(map(int, input().split()))
    former = []
    later = []
    for i in range(n):
        former.append(i - a[i])
        later.append(a[i] + i)
    res = 0
    for i in former:
        res += later.count(i)
    print(res)
E()

Submission status: Time Limit Exceeded

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


##Miss 1
# from itertools import combinations

# comb = list(combinations([i for i in range(N)],2))

# cnt=0
# for i in comb:
#     if Agents[i[0]] + Agents[i[1]] == abs(i[0] - i[1]):
#         print(i[0],i[1])
#         cnt+=1

# print(cnt)

# Miss 2
# for i in range(0,N):
#     k=Agents[i]-(i+1)
#     if k<i:
#         k=i+1
#     for j in range(k,N):
#         if Agents[i]+Agents[j]==abs(i-j):
#             # print(i,j,Agents[i],Agents[j])
#             cnt+=1


L={}
for i in range(N):
    L['{}'.format(i+1)]=i+1 + Agents[i]
R={}
for j in range(N):
    R['{}'.format(j+1)]=j+1 - Agents[j]
cnt=0

for key,value in L.items():
    for key2,value2 in R.items():
        if int(key) < int(key2) and value == value2:
            cnt+=1


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# E
# 2020/05/04  18:30-
n = int(input())
a = list(map(int, input().split()))

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
Hs = list(map(int, input().split()))
As = np.array([Hs for _ in range(N)])
h = As.T.copy()
idxs = np.tile([i for i in range(N)], (N, 1))
tidxs = idxs.T.copy()
co = As + h - np.abs(idxs-tidxs)
ans = N**2-np.count_nonzero(co)
print(ans//2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
L=[]
R=[]
ans=0
for i in range(N):
    L.append(i+1+A[i])
    R.append(i+1-A[i])
L.sort()
R.sort()
l=0
for i in range(N):
    if i>=1:
        if L[i]==L[i-1]:
            ans=ans+count
            continue
    count=0
    for j in range(l,N):
        if L[i]==R[j]:
            count=count+1
        if L[i]<R[j]:
            l=j
            break
    ans=ans+count
print(ans)

Submission status: Time Limit Exceeded

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

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

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

for i in range(n-1):
    cnt=0
    h=sa[i]
    for j in range(i+1,n):
        if sb[j]==h:
            cnt+=1
    ans+=cnt

print(ans)

Submission status: Time Limit Exceeded

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

spy_dict = {}
for i in range(0,N):
    spy_dict[i+1] = height_list[i]

L_dict = {}
R_dict = {}
for i in spy_dict:
    L = i + spy_dict[i]
    L_dict[i] = L
    R = i - spy_dict[i]
    R_dict[i] = R

counter = 0
for i in range(1,N):
    for j in range(i+1,N+1):
        if L_dict[i] == R_dict[j]:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  n=int(input())
  heights=list(map(int,input().split()))
  assert len(heights)==n
  i=0
  count=0

  while i<n:
    j=i+1
    while j<n:
        if heights[i]+heights[j]==(j-i):
            count+=1
        j+=1
    i+=1
  print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
#n,m = map(int,input().split())
#h = list(map(int,input().split()))

#ab = [map(int,input().split()) for _ in range(m)]
#a,b = [list(i) for i in zip(*ab)]

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

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

"""

R=[0]*n
L=[0]*n

for i in range(n):
    R[i]=a[i]+i+1
    L[i]=i+1-a[i]

for i in range(n):
    cnt+=L.count(R[i])

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

l = []
r = []
for i, ai in enumerate(a):
   l.append(i+ai)
   r.append(i-ai)

ans = 0
for i in l:
   ans += r.count(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = list(map(int,input().split()))
resultDict = {}
resultDict['diff'] = []
resultDict['sum'] = []
for num in range(1,N+1):
    resultDict['diff'].append(int(num - An[num-1]))
    resultDict['sum'].append(int(num + An[num-1]))
countN = 0
for i, name in enumerate(resultDict['diff']):        
    countN = countN + resultDict['sum'].count(name)
    if name == resultDict['sum'][i]:
        countN = countN - 1
print(countN)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#n,m = map(int,input().split())
#h = list(map(int,input().split()))

#ab = [map(int,input().split()) for _ in range(m)]
#a,b = [list(i) for i in zip(*ab)]

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

cnt=0

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

Submission status: Time Limit Exceeded

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

count=0

for i, h in enumerate(height):
    
    nokori_height=height[i+1:]
    
    for j, nh in enumerate(nokori_height):
        
        if h+nh==j+1:
            count+=1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n,*a=map(int,open(0).read().split())
l=[0]*n
r=[0]*n
for i,c in enumerate(a):
  l[i]+=c+i+1
  r[i]+=i+1-c
L=Counter(l)
R=Counter(r)
ans=0
for i in range(1,n+max(a)):
  ans+=L[i]*R[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
X=sum([L[i]+(i+1)==(j+1)-L[j] for i in range(N-1) for j in range(i+1,N)])
print(X)

Submission status: Time Limit Exceeded

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

i = 0
ans = 0
while i < n-1:
    j = a[i] + 1
    t = j - i
    while j<n:
        if t == a[i] + a[j]:
            ans += 1
        j += 1
        t += 1
    i += 1

print(ans)

Submission status: Time Limit Exceeded

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

i = 0
ans = 0
while i < n-1:
    j = a[i] + 1
    while j<n:
        t = j - i
        if t == a[i] + a[j]:
            ans += 1
        j += 1
    i += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
import math
N = int(input())
An = list(map(int,input().split()))
#組み合わせ nC2
numList = list(itertools.combinations(range(1,N+1), 2))
count = 0
for pair in numList:
    #　数字のdiff (絶対値) float型
    numDiff = int(math.fabs(pair[1] - pair[0]))
    # 身長の和
    sumHeight = An[pair[0]-1] + An[pair[1]-1]
    if numDiff == sumHeight:
        count = count + 1
print(count)

Submission status: Time Limit Exceeded

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

i = 0
ans = 0
while i < n-1:
    j = i+1
    while j<n:
        t = j - i
        if t == a[i] + a[j]:
            ans += 1
        j += 1
    i += 1

print(ans)

Submission status: Time Limit Exceeded

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

count=0

for i in range(len(height)):
    nokori_height=height[i+1:]
    
    for j in range(len(nokori_height)):     
        if height[i]+nokori_height[j]==abs(j+1):
            count+=1
            
            
            
print(count)

Submission status: Time Limit Exceeded

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

i = 0
ans = 0
while i < n-1:
    j = i+1
    while j<n:
        t = i - j
        if t < 0:
            t = -t
        if t == a[i] + a[j]:
            ans += 1
        j += 1
    i += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
 
cnt=0
cnt= cnt + sum([(L[i+x]+L[i])==x for i in range(N) for x in range(N-i)  if (L[i+x]+L[i])<=x ])
    
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = input().split()
c = 0
for i in range(N):
    An[i] = int(An[i])
for i in range(N):
    for k in range(1,N-i):
        if An[0] + An[k] == k :
            c = c + 1
    del An[0]
print(c)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
 
cnt=0
for i in range(N):
    cnt= cnt + sum([(L[i+x]+L[i])==x for x in range(N-i) if (L[i+x]+L[i])<=x])
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
LL=list(set([i for i in L if i<N]))

LL=list(set([x+y for x in LL for y in LL]))


cnt=0
for i in range(N):
    X=[(L[i]+L[i+j]==j) for j in LL if j<(N-i)]
    cnt=cnt+sum(X)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ls=[int(s) for s in input().split()]
lsA=[i+ls[i] for i in range(N)]
lsB=[i-ls[i] for i in range(N)]
ans=0
for i in range(N):
  for j in range(i,N):
    if lsA[i]==lsB[j]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

cnt=0
for i in range(N):
    cnt= cnt + sum([(L[i:][x]+L[i])==x for x in range(N-i) if (L[i:][x]+L[i])<=x])
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ls=[int(s) for s in input().split()]
ls2=[[i,ls[i]]for i in range(N)]
ls2=sorted(ls2,key=lambda x:-x[1])
ans=0
for a,b in ls2:
  M=2*b
  for i in range(max([0, a-M]),min([N,a+M])):
    if abs(i-a)==b+ls[i]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=int(input())
a=list(map(int,input().split()))
d=deque()
for i in range(1,n):
  d.append((i+1)-a[i])
cnt=0
for i in range(n-1):
  cnt+=d.count(a[i]+(i+1))
  d.popleft()
print(cnt)

Submission status: Time Limit Exceeded

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

cnt=0
for i in range(N):
    cnt= cnt + sum([(L[i:][x]+L[i])==x for x in range(N-i)])
    
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    num_person = int(input())
    height_list = list(map(int, input().split()))
    height_list = [0] + height_list # var[0] is dummy
    count = 0
    for i in range(1, len(height_list)):
        h_i = height_list[i]
        #if h_i > num_person:
        #    continue
        for j in range(i + 1, len(height_list)):
            #print(i, j) # debug
            h_j = height_list[j]
            if j - i == h_j + h_i:
                count += 1
    #print('count') # debug
    #print(count) # debug
    print(count)

    #print('\33[32m' + 'end' + '\033[0m') # debug

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# なんか身長順でソートすればいいんじゃない？
# 身長差でありえるのは1〜Nなので，身長差が1になるエージェントの組み合わせをだして，それぞれの身長差について調べる
# でも結局全探索になるか？やっぱり配列を作ると同時に答えが独立してうまく求まるようなのがいいよね
# j-i = Aj+Ai となるのが求めるもの，これを変換してiとjの式のみに分離すると，うまく配列を作るだけでうまくいくようになる
# j-Aj = Ai+i となる．こうすると独立しているので,X=i-Ai,Y=Ai+iを作り，setもしくはdictで探索すればすぐです！
# i==jのときはi-i == Ai+Ai が絶対に成立しないので問題ない

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

X=[i+1-A[i] for i in range(N)]
Y=[i+1+A[i] for i in range(N)]
#Y=set(Y) # set使うと同じ要素が減るのでだめ！！！
dicY=dict()
for y in Y:
    if not y in dicY:
        dicY[y]=1
    else:
        dicY[y]+=1
count=0
for x in X:
    if x in Y:
        count+=dicY[x]
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())

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

x = {}
y = {}

ans = 0

# print(x)
# print(y)

for i in range(n):
  x.setdefault((i+a[i]), []).append(i) 
  y.setdefault((i-a[i]), []).append(i)

z = list(set(x.keys()) & set(y.keys()))

# print(x)
# print(y)
# print(z)

for i in z:
  for j in range(len(x[i])):
    # print(x[i])
    # print(x[i][j])
    # print(y[i])
    # print(sum(x[i][j] < y[i][0]))
    ans += sum(1 for k in y[i] if x[i][j] < k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = 0
l_array = []
r_array = []
for i, X in enumerate(A):
    l_array.append(i + X)
    r_array.append(i - X)

for x in l_array:
    count += r_array.count(x)
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
L1 = list()
L2 = list()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    L2.append(num2)    
    if num1 in L2:
        ret += 1
    if num2 in L1:
        ret += 1
ret = 0
retlist = dict()
for l in L1:
    if l not in retlist.keys():
        num = len([l2 for l2 in L2 if l2 == l]) 
        ret += num
    else:
        ret += retlist[l]
print(ret)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
L1 = list()
L2 = list()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    L2.append(num2)    
    if num1 in L2:
        ret += 1
    if num2 in L1:
        ret += 1
ret = 0
for l in L1:
    ret += len([l2 for l2 in L2 if l2 == l]) 
print(ret)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
input = sys.stdin.readline

start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if Asum[i] == Adif[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
# input = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if Asum[i] == Adif[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = []
Adif = []
for i, j in enumerate(A):
    Asum.append(i+j)
    Adif.append(i-j)

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if Asum[i] == Adif[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

    l = []
    r = []
    
    for i in range(n):
        l.append((i + 1) + a[i])
        r.append((i + 1) - a[i])
        
    cnt = 0
    for i in l:
        for j in r:
            if i == j:
                cnt += 1



    
    return cnt




print(solve())

Submission status: Time Limit Exceeded

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

    cnt = 0
    for i in range(n):
        l = (i + 1) + a[i]
        for j in range(n):
            r = (j + 1) - a[j]
            if l == r:
                cnt += 1
        



    
    return cnt




print(solve())

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N=int(input())
A=list()
for i,a in enumerate(input().split(),1):
  A.append((int(a),i))
A.sort()

t=0
k=[a[0] for a in A]
for i in range(0,bisect_left(k,N)):
  for j in range(0,bisect_left(k,N-A[i][0])):
    if A[i][0]+A[j][0]==abs(A[i][1]-A[j][1]):
      t+=1
print(t//2)

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ai = list(map(int,input().split()))
pl = []
mi = []
for i in range(n):
    pl.append(i+ai[i])
    mi.append(i-ai[i])
cnt = 0 
for i in range(n):
    cnt += mi.count(pl[i])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=0
L=[i for i in range(N)]
A=list(map(int,input().split()))
dic1={i:i+a for i,a in zip(L,A)}
dic2={i:i-a for i,a in zip(L,A)}
for p in range(N):
    z=[k for k,v in dic1.items() if v==p ]
    w=[k for k,v in dic2.items() if v==p ]
    s+=len(z)*len(w)
print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=[]
r=[]
for i in range(n):
  l.append(i+a[i]+1)
  r.append(i-a[i]+1)
ans=0
for x in l:
  ans=ans+r.count(x)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def intlist(x):
    y = []
    for i in range(len(x)):
        y.append(int(x[i]))
    return y

N = int(input())
height = intlist(input().split())

count = 0
for i in range(N):
    for k in range(i+1,N):
        #if i == k:
         #   continue
        if height[i] + height[k] == abs((i+1)-(k+1)):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a1=[]
a2=[]
for i in range(n):
  a1.append(i-a[i])
for i in range(n):
  a2.append(i+a[i])
count=0
p=0
q=1
for k in range(int(n*(n-1)/2)):
  if a1[q]==a2[p]:
    count+=1
  p+=1
  if p==q:
    p=0
    q+=1
print(count)