Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    max_A = max(A)
    num = tuple(range(1, N + 1))
    cand = 0
    for a in range(N):
        a_height = A[a]
        for b in range(min(a + 1 + a_height, N), N):
            diff_num = b - a
            sum_height = A[a] + A[b]
            if diff_num == sum_height:
                cand += 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    num = tuple(range(1, N + 1))
    cand = 0
    log = {}
    for i in range(0, N):
        if i + 1 - A[i] in log:
            cand += log[i + 1 - A[i]]
        if i + 1 + A[i] in log:
            log[i + 1 + A[i]] += 1
        else:
            log[i + 1 + A[i]] = 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    max_A = max(A)
    num = tuple(range(1, N + 1))
    cand = 0
    for a in range(N):
        a_height = A[a]
        possible_range = max_A + a_height
        for b in range(a + 1, min(a + 1 + possible_range, N)):
            diff_num = b - a
            sum_height = A[a] + A[b]
            if diff_num == sum_height:
                cand += 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    num = tuple(range(1, N + 1))
    cand = 0
    log = {}
    for i in range(0, N):
        if i + 1 - A[i] in log:
            cand += log[i + 1 - A[i]]
        if i + 1 + A[i] in log:
            log[i + 1 + A[i]] += 1
        else:
            log[i + 1 + A[i]] = 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    num = tuple(range(1, N + 1))
    cand = 0
    for a in range(N):
        for b in range(a + 1, N):
            diff_num = b - a
            sum_height = A[a] + A[b]
            if diff_num == sum_height:
                cand += 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    num = tuple(range(1, N + 1))
    cand = 0
    log = {}
    for i in range(0, N):
        if i + 1 - A[i] in log:
            cand += log[i + 1 - A[i]]
        if i + 1 + A[i] in log:
            log[i + 1 + A[i]] += 1
        else:
            log[i + 1 + A[i]] = 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()