Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

count = 0
for k in range(0, max(AI)):
    ci = AI.count(k)
    cj = AJ.count(k)
    count += ci * cj
print(count)

Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

cai = {}
caj = {}
vali = set()
valj = set()
for ai, aj in zip(AI, AJ):
    if not ai in cai:
        cai[ai] = 0
    if not aj in caj:
        caj[aj] = 0

    cai[ai] += 1
    vali.add(ai)

    caj[aj] += 1
    valj.add(aj)

count = 0
for val in vali & valj:
    count += cai[val] * caj[val]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(int, input().split()))
AI = [i + a for i, a in enumerate(A)]
AJ = [i - a for i, a in enumerate(A)]

count = 0
for k in range(0, max(A)+2*10**5):
    ci = AI.count(k)
    cj = AJ.count(k)
    count += ci * cj
print(count)

Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

cai = {}
caj = {}
vali = set()
valj = set()
for ai, aj in zip(AI, AJ):
    if not ai in cai:
        cai[ai] = 0
    if not aj in caj:
        caj[aj] = 0

    cai[ai] += 1
    vali.add(ai)

    caj[aj] += 1
    valj.add(aj)

count = 0
for val in vali & valj:
    count += cai[val] * caj[val]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
AJ = [a - i for i, a in enumerate(A)]

count = 0
for i in range(0, N-1):
    ai = A[i]
    count += list(map(lambda x: x + ai + i, AJ[i+ai:])).count(0)

print(count)

Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

cai = {}
caj = {}
vali = set()
valj = set()
for ai, aj in zip(AI, AJ):
    if not ai in cai:
        cai[ai] = 0
    if not aj in caj:
        caj[aj] = 0

    cai[ai] += 1
    vali.add(ai)

    caj[aj] += 1
    valj.add(aj)

count = 0
for val in vali & valj:
    count += cai[val] * caj[val]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(int, input().split()))

count = 0
for i in range(0, N-1):
    iai  = i + A[i]
    for j in range(iai+1, N):
        if iai == j - A[j]:
            count += 1

print(count)

Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

cai = {}
caj = {}
vali = set()
valj = set()
for ai, aj in zip(AI, AJ):
    if not ai in cai:
        cai[ai] = 0
    if not aj in caj:
        caj[aj] = 0

    cai[ai] += 1
    vali.add(ai)

    caj[aj] += 1
    valj.add(aj)

count = 0
for val in vali & valj:
    count += cai[val] * caj[val]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(int, input().split()))

count = 0
for i in range(0, N):
    for j in range(i + A[i], N):
        if abs(i - j) == A[i] + A[j]:
            count += 1

print(count)

Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

cai = {}
caj = {}
vali = set()
valj = set()
for ai, aj in zip(AI, AJ):
    if not ai in cai:
        cai[ai] = 0
    if not aj in caj:
        caj[aj] = 0

    cai[ai] += 1
    vali.add(ai)

    caj[aj] += 1
    valj.add(aj)

count = 0
for val in vali & valj:
    count += cai[val] * caj[val]

print(count)