Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  if i - v > 1:
    c[i - v].append(i)
c = dict(c)
# print(f'{b=}')
# print(f'{c=}')

ans = 0
for v, L in c.items():
  for j in L:
    if v in b:
      for i in b[v]:
        if i < j:
          ans += 1
        else:
          break
print(ans)

Fixed submission:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  if 2 <= i - v <= 100000001:
    c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in b.items():
  for j in L:
    if v in c:
      ans += len(c[v])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in c.items():
  for j in L:
    if v in b:
      for i in b[v]:
        if i < j:
          ans += 1
        else:
          break
print(ans)

Fixed submission:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  if 2 <= i - v <= 100000001:
    c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in b.items():
  for j in L:
    if v in c:
      ans += len(c[v])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in b.items():
  for i in L:
    if v in c:
      for j in c[v]:
        if i < j:
          ans += 1
print(ans)

Fixed submission:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  if 2 <= i - v <= 100000001:
    c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in b.items():
  for j in L:
    if v in c:
      ans += len(c[v])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  c[i - v].append(i)

ans = 0
for v, L in b.items():
  for i in L:
    for j in c[v]:
      if i < j:
        ans += 1
print(ans)

Fixed submission:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  if 2 <= i - v <= 100000001:
    c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in b.items():
  for j in L:
    if v in c:
      ans += len(c[v])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import combinations
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(enumerate(map(int, readline().split()), 1))

ans = 0
for (i, b), (j, c) in combinations(a, 2):
  # print(f'{i=} {b=} {j=} {c=} {i-j=} {b+c=}')
  if abs(i - j) == abs(b + c):
    ans += 1

print(ans)

Fixed submission:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  if 2 <= i - v <= 100000001:
    c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in b.items():
  for j in L:
    if v in c:
      ans += len(c[v])
print(ans)