Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    for w in y:
      for ww in z:
        if w>ww:
          ans+=1
print(ans)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    ans+=len(z)*len(y)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x in dt:
    y=dr[x]
    z=dt[x]
    for w in y:
      for ww in z:
        if w>ww:
          ans+=1
print(ans)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    ans+=len(z)*len(y)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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)  

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    ans+=len(z)*len(y)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
l=np.array(list(map(int,input().split())))
r=list(np.arange(1,n)-l[1:])
rx=sorted(r)
for i in range(n-1):
  r[i]=[r[i],i]
r=sorted(r)
t=list(l+np.arange(n))
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
print(ans)  

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    ans+=len(z)*len(y)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
l=np.array(list(map(int,input().split())))
r=np.arange(1,n)-l[1:]
ans=0
for i in range(n):
  ans+=np.count_nonzero(r[i:]==l[i]+i)
print(ans)  

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    ans+=len(z)*len(y)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
l=np.array(list(map(int,input().split())))
r=np.arange(1,n)
ans=0
for i in range(n):
  ans+=np.count_nonzero(r[:n-i-1]-l[i+1:]==l[i])
print(ans)  

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    ans+=len(z)*len(y)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
l=np.array(list(map(int,input().split())))
r=np.arange(1,n)
ans=0
for i in range(n):
  x=l[i+1:]+np.full(n-i-1,l[i])-r[:n-i-1]
  ans+=np.count_nonzero(x)
print(n*(n-1)//2-ans)  

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    ans+=len(z)*len(y)
print(ans)