Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
L1 = list()
L2 = list()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    L2.append(num2)    
    if num1 in L2:
        ret += 1
    if num2 in L1:
        ret += 1
ret = 0
retlist = dict()
for l in L1:
    if l not in retlist.keys():
        num = len([l2 for l2 in L2 if l2 == l]) 
        ret += num
    else:
        ret += retlist[l]
print(ret)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L1 = list()
D2 = dict()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    if num2 not in D2:
        D2[num2] = 1
    else:
        D2[num2] += 1
ret = 0
retlist = dict()
for l in L1:
    if l in D2.keys():
        ret += D2[l]
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
L1 = list()
L2 = list()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    L2.append(num2)    
    if num1 in L2:
        ret += 1
    if num2 in L1:
        ret += 1
ret = 0
for l in L1:
    ret += len([l2 for l2 in L2 if l2 == l]) 
print(ret)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L1 = list()
D2 = dict()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    if num2 not in D2:
        D2[num2] = 1
    else:
        D2[num2] += 1
ret = 0
retlist = dict()
for l in L1:
    if l in D2.keys():
        ret += D2[l]
print(ret)

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

max1 = max(A)
A_ = A.copy()
A_.remove(max1)
max2 = max(A_)
ln = max1 + max2
ret = 0
for i in range(len(A)-1):
    for j in range(i+1, min(i + ln + 1, len(A) )):
        if A[j] + A[i] == j - i:
            ret += 1
print(ret)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L1 = list()
D2 = dict()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    if num2 not in D2:
        D2[num2] = 1
    else:
        D2[num2] += 1
ret = 0
retlist = dict()
for l in L1:
    if l in D2.keys():
        ret += D2[l]
print(ret)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

max1 = max(A)
A_ = A.copy()
A_.remove(max1)
max2 = max(A_)
ln = max1 + max2
ret = 0
for i in range(len(A)-1):
    for j in range(i+1, i+ln + 1):
        if A[j] + A[i] == j - i:
            ret += 1
print(ret)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L1 = list()
D2 = dict()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    if num2 not in D2:
        D2[num2] = 1
    else:
        D2[num2] += 1
ret = 0
retlist = dict()
for l in L1:
    if l in D2.keys():
        ret += D2[l]
print(ret)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A_ = list(map(int, input().split()))
A = list()
for i in range(len(A_)):
    if A_[i] < N - 1:
        A.append([i + 1, A_[i]])
ret = 0
for i in range(len(A)-1, -1, -1):
    ind, val = A[i][0], A[i][1]
    B = [a for a in A if a[1] < N - 1 - val]
    for b in B:
        if abs(b[0] - ind) == val + b[1]:
            ret += 1
return ret

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L1 = list()
D2 = dict()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    if num2 not in D2:
        D2[num2] = 1
    else:
        D2[num2] += 1
ret = 0
retlist = dict()
for l in L1:
    if l in D2.keys():
        ret += D2[l]
print(ret)