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

Fixed submission:
import numpy as np

n = int(input())

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

x = {}
y = {}

ans = 0

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:
  if x[i][len(x[i])-1] < y[i][0]:
    n = len(y[i]) * len(x[i])
    ans += n
    # print(x[i])
    # print(y[i])
    # print(n)
    # print(ans)

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())

a = list(map(int, input().split()))
a_array = np.array(a)
base_array = np.array(range(n))+1

ans = 0

# print(a_array)
# print(base_array)

for i in range(n-1):
  sum_array = a_array[i+1:] + a_array[i]
  # print(sum_array)
  sum_array = sum_array - base_array[:-(i+1)]
  res = np.count_nonzero(sum_array == 0)
  ans += res
#for i in range(n-1):
#  for j in range(i+a[i]+1, n):
#    if j-i == a[i] + a[j]:
#      ans += 1

print(ans)

Fixed submission:
import numpy as np

n = int(input())

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

x = {}
y = {}

ans = 0

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:
  if x[i][len(x[i])-1] < y[i][0]:
    n = len(y[i]) * len(x[i])
    ans += n
    # print(x[i])
    # print(y[i])
    # print(n)
    # print(ans)

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())

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

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

print(ans)

Fixed submission:
import numpy as np

n = int(input())

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

x = {}
y = {}

ans = 0

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:
  if x[i][len(x[i])-1] < y[i][0]:
    n = len(y[i]) * len(x[i])
    ans += n
    # print(x[i])
    # print(y[i])
    # print(n)
    # print(ans)

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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 j-i == a[i] + a[j]:
      ans += 1

print(ans)

Fixed submission:
import numpy as np

n = int(input())

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

x = {}
y = {}

ans = 0

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:
  if x[i][len(x[i])-1] < y[i][0]:
    n = len(y[i]) * len(x[i])
    ans += n
    # print(x[i])
    # print(y[i])
    # print(n)
    # print(ans)

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

print(ans)