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

n = int(input())
h = np.array(list(map(int, input().split())))
ans = 0
loc = 0
for i in range(n-1):
    if h[i] > n - i - 1:
        continue
    diff = h[i]
    num = min(n, i + h[i] + 1)
    length = n - num
    t = np.count_nonzero((np.array(h[num:]) - np.arange(n - num) - 1))
    ans += length - t
print(ans)

Fixed submission:
from collections import Counter

n = int(input())
h = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(i + h[i])
    b.append(i - h[i])

x = Counter(a)
y = Counter(b)

z = set(a)
ans = 0
for i in z:
    ans += x[i] * y[i]

print(ans)

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

n = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if h[i] > n - i - 1:
        continue
    num = min(n, i + h[i] + 1)
    s = np.array(h[num:])
    length = len(s)
    u = np.arange(length) + 1
    s -= u
    t = np.count_nonzero(s)
    ans += length - t
print(ans)


Fixed submission:
from collections import Counter

n = int(input())
h = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(i + h[i])
    b.append(i - h[i])

x = Counter(a)
y = Counter(b)

z = set(a)
ans = 0
for i in z:
    ans += x[i] * y[i]

print(ans)

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

n = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if h[i] > 10**5:
        continue
    num = min(n, i + h[i] + 1)
    s = np.array(h[num:])
    length = len(s)
    u = np.arange(length) + 1
    s -= u
    t = np.count_nonzero(s)
    ans += length - t
print(ans)


Fixed submission:
from collections import Counter

n = int(input())
h = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(i + h[i])
    b.append(i - h[i])

x = Counter(a)
y = Counter(b)

z = set(a)
ans = 0
for i in z:
    ans += x[i] * y[i]

print(ans)

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


n = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    num = min(n, i + h[i] + 1)
    s = np.array(h[num:])
    diff = h[i]
    u = np.arange(len(s)) + 1
    s -= u
    t = np.count_nonzero(s)
    ans += len(s) - t
print(ans)


Fixed submission:
from collections import Counter

n = int(input())
h = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(i + h[i])
    b.append(i - h[i])

x = Counter(a)
y = Counter(b)

z = set(a)
ans = 0
for i in z:
    ans += x[i] * y[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    num = min(n, i + h[i] + 1)
    height_1 = h[i]
    for j in range(num, n):
        height_2 = h[j]
        if height_1 + height_2 == (j - i):
            ans += 1

print(ans)

Fixed submission:
from collections import Counter

n = int(input())
h = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(i + h[i])
    b.append(i - h[i])

x = Counter(a)
y = Counter(b)

z = set(a)
ans = 0
for i in z:
    ans += x[i] * y[i]

print(ans)