Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    dd = defaultdict(list)
    count = 0
    for i in range(N - 1):
        ai = A[i]
        iai = i + ai
        if dd[iai] == []:
            for j in range(i + 1, N):
                if j - A[j] == iai:
                    dd[iai].append(j)
                    count += 1
        else:
            for j in dd[iai]:
                if j > i:
                    count += 1
    print(count)
    
if __name__ == '__main__':
    main()


Fixed submission:
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    b = [0] * (10 ** 6)
    ans = 0
    for i in range(n):
        if i - a[i] > 0:
            ans += b[i - a[i]]
        if i + a[i] < 10 ** 6:
            b[i + a[i]] += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    dd = defaultdict(list)
    count = 0
    for i in range(N - 1):
        ai = A[i]
        iai = i + ai
        if dd[iai] == []:
            for j in range(i + 1, N):
                if j - A[j] == iai:
                    dd[iai].append(j)
                    count += 1
        else:
            for j in dd[iai]:
                if j > i:
                    count += 1
    print(count)
    
if __name__ == '__main__':
    main()

Fixed submission:
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    b = [0] * (10 ** 6)
    ans = 0
    for i in range(n):
        if i - a[i] > 0:
            ans += b[i - a[i]]
        if i + a[i] < 10 ** 6:
            b[i + a[i]] += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dd = defaultdict(list)
count = 0
for i in range(N - 1):
    ai = A[i]
    iai = i + ai
    if dd[iai] == []:
        for j in range(i + 1, N):
            if j - A[j] == iai:
                dd[iai].append(j)
                count += 1
    else:
        for j in dd[iai]:
            if j > i:
                count += 1
print(count)

Fixed submission:
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    b = [0] * (10 ** 6)
    ans = 0
    for i in range(n):
        if i - a[i] > 0:
            ans += b[i - a[i]]
        if i + a[i] < 10 ** 6:
            b[i + a[i]] += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dd = defaultdict(list)
count = 0
for i in range(N - 1):
    if dd[i + A[i]] == []:
        for j in range(i + 1, N):
            if j - A[j] == i + A[i]:
                dd[i + A[i]].append(j)
                count += 1
    else:
        for j in dd[i + A[i]]:
            if j > i:
                count += 1
print(count)

Fixed submission:
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    b = [0] * (10 ** 6)
    ans = 0
    for i in range(n):
        if i - a[i] > 0:
            ans += b[i - a[i]]
        if i + a[i] < 10 ** 6:
            b[i + a[i]] += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n):
    if i + a[i] + 1 < n:
        for j in range(i + a[i] + 1, n):
            if j - i == a[i] + a[j]:
                count += 1
print(count)

Fixed submission:
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    b = [0] * (10 ** 6)
    ans = 0
    for i in range(n):
        if i - a[i] > 0:
            ans += b[i - a[i]]
        if i + a[i] < 10 ** 6:
            b[i + a[i]] += 1
    print(ans)


if __name__ == "__main__":
    main()