Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
setL=set(L)  
setR=set(R)
for i in range(N):
  if i in setL and i in setR:
    ans+=L.count(i)*R.count(i)
print(ans)    

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
setL=set(L)  
setR=set(R)
for i in R:
  if i in setL:
    ans+=L.count(i)
print(ans) 

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
setL=set(L)  
setR=set(R)
for i in range(N):
  if i in setL and i in setR:
    ans+=L.count(i)*R.count(i)
print(ans)    

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
setL=set(L)  
setR=set(R)
for i in R:
  if i in setL:
    ans+=L.count(i)
print(ans) 

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
index=[]
for i in range(N):
  index+=[[listA[i],i]]
index.sort()
for i in range(N):
  if index[i][0]<N:
    for k in range(i+1,N):
      if index[k][0]<N:
        if abs(index[k][1]-index[i][1])==index[k][0]+index[i][0]:
          ans+=1
      else:
        break
  else:
    break
print(ans)        

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
for i in range(N-1):
  if listA[i]<N-i:
    for k in range(i+2,N):
      if k-i==listA[i]+listA[k]:
        ans+=1
print(ans)        

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
for i in range(N-1):
  if listA[i]<N-i:
    for k in range(i+2,N):
      if k-i==listA[i]+listA[k]:
        ans+=1
print(ans)        

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
for i in range(N-1):
  if listA[i]<N-i:
    for k in range(i+1,N):
      if k-i==listA[i]+listA[k]:
        ans+=1
print(ans)        

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
for i in range(N-1):
  if listA[i]<N-i:
    for k in range(i+1,N):
      if k-i==listA[i]+listA[k]:
        ans+=1
print(ans)        

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
for i in range(N-1):
  if listA[i]<N-i:
    for k in range(i+1,N):
      if abs(k-i)==listA[i]+listA[k]:
        ans+=1
print(ans)        

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=list(map(int,input().split()))
ans=0
for i in range(N-1):
  if listA[i]<N:
    for k in range(i+1,N):
      if abs(k-i)==listA[i]+listA[k]:
        ans+=1
print(ans)        

Fixed submission:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)