alexjercan/bugnet huggingface dataset:
Problem p02644 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys
from collections import deque


input = iter(sys.stdin.readlines()).__next__

R, C, K = [int(x) for x in input().split()]
X1, Y1, X2, Y2 = [int(x) - 1 for x in input().split()]  # 0 indexed

grid = [input().rstrip() for r in range(R)]

source = (X1, Y1)
q = deque([source])
dist = {source: 0}


def getNbr(node, currDist):
    r, c = node
    ret = []
    for dr, dc in [(0, 0), (-1, 0), (0, -1), (0, 1), (1, 0)]:
        for k in range(1, K + 1):
            nr = r + dr * k
            nc = c + dc * k
            if not (0 <= nr < R and 0 <= nc < C):
                break
            if grid[nr][nc] == "@" or ((nr, nc) in dist and dist[(nr, nc)] <= d):
                break
            ret.append((nr, nc))
    return ret


while q:
    node = q.popleft()
    d = dist[node]
    for nbr in getNbr(node, d):
        if nbr not in dist:
            q.append(nbr)
            dist[nbr] = d + 1


if False:
    for row in grid:
        print(row)
    print()
    for r in range(R):
        for c in range(C):
            print(dist.get((r, c), "?"), end=" ")
        print()


if (X2, Y2) in dist:
    print(dist[(X2, Y2)])
else:
    print(-1)


Error: TLE

Fixed submission:

import sys
from collections import deque


input = iter(sys.stdin.readlines()).__next__

R, C, K = [int(x) for x in input().split()]
X1, Y1, X2, Y2 = [int(x) - 1 for x in input().split()]  # 0 indexed

grid = [input().rstrip() for r in range(R)]

source = (X1, Y1)
q = deque([source])
dist = {source: 0}


def getNbr(node):
    r, c = node
    ret = []
    for dr, dc in [(0, 0), (-1, 0), (0, -1), (0, 1), (1, 0)]:
        for k in range(1, K + 1):
            nr = r + dr * k
            nc = c + dc * k
            if not (0 <= nr < R and 0 <= nc < C):
                break
            if grid[nr][nc] == "@":
                break
            ret.append((nr, nc))
    return ret


while q:
    node = q.popleft()
    d = dist[node]
    for nbr in getNbr(node):
        if nbr not in dist:
            q.append(nbr)
            dist[nbr] = d + 1


if False:
    for row in grid:
        print(row)
    print()
    for r in range(R):
        for c in range(C):
            print(dist.get((r, c), "?"), end=" ")
        print()


if (X2, Y2) in dist:
    print(dist[(X2, Y2)])
else:
    print(-1)
Problem p02645 (Python) — buggy submission, verdict: Runtime Error

s = input()
print(s[:3])


Error: WA

Fixed submission:

s = input()
print(s[3])
Problem p02645 (Python) — buggy submission, verdict: Runtime Error

print(input()[:3])


Error: ValueError: '0' is not in list
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02645/Python/s112750711.py", line 1, in <module>
    print(input().split().index("0") + 1)
ValueError: '0' is not in list


Fixed submission:

print(input().split().index("0") + 1)
Problem p02647 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8[:](i8,i8,i8[:])", cache=True)
def solve(N, K, A):
    for _ in range(min(41, K)):
        A_cumsum = np.zeros(shape=N, dtype=np.int64)
        for i in range(N):
            A_cumsum[max(0, i - A[i])] += 1
            b = i + A[i] + 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = np.cumsum(A_cumsum)
    return A


def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)

    ans = solve(N, K, A)

    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

import sys
from itertools import accumulate

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for _ in range(min(41, K)):
        A_cumsum = [0] * N
        for i in range(N):
            a = i - A[i]
            b = i + A[i] + 1
            if a < 0:
                A_cumsum[0] += 1
            else:
                A_cumsum[a] += 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = list(accumulate(A_cumsum))

    print(" ".join(map(str, A)))


if __name__ == "__main__":
    main()
Problem p02647 (Python) — buggy submission, verdict: Time Limit Exceeded

from copy import deepcopy

n, k = map(int, input().split())
As = list(map(int, input().split()))

for _ in range(k):
    if sum(As) == n * n:
        break
    Bs = [0] * n
    for i in range(n):
        l = max(0, i - As[i])
        r = min(n - 1, i + As[i])
        Bs[l] += 1
        if r + 1 < n:
            Bs[r + 1] -= 1
    for i in range(1, n):
        Bs[i] += Bs[i - 1]
    As = Bs

print(" ".join(map(str, As)))


Error: TLE

Fixed submission:

from copy import deepcopy

n, k = map(int, input().split())
As = list(map(int, input().split()))

for _ in range(k):
    if sum(As) == n * n:
        break
    As_next = [0] * n
    for i in range(n):
        for j in range(max(0, i - As[i]), min(n, i + As[i] + 1)):
            As_next[j] += 1
    As = deepcopy(As_next)

print(" ".join(map(str, As)))
Problem p02647 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    b = [0] * (n + 2)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n + 1, i + a[i] + 1)] -= 1
    a[0] = b[0]
    cnt = a[0]
    for i in range(1, n):
        a[i] = a[i - 1] + b[i]
        cnt += a[i]

    # print(*a)
    if cnt == n**2:
        break

print(*a)


Error: TLE

Fixed submission:

n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    b = [0] * (n + 2)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n + 1, i + a[i] + 1)] -= 1
    a[0] = b[0]
    cnt = 1 if a[0] == n else 0
    for i in range(1, n):
        a[i] = a[i - 1] + b[i]
        if a[i] == n:
            cnt += 1

    if cnt == n:
        break

print(*a)
Problem p02647 (Python) — buggy submission, verdict: Time Limit Exceeded

# 問題文の意味がわからんコンテスト
# 0の場合も自分自身を照らす、っての気づくところからやっと読解
# Kを5000兆回やったあとはすべての要素がNになっとる この収束はわりと早いらしい
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(min(k, 100)):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]
    a = b[:n]
print(" ".join(list(map(str, a))))


Error: TLE

Fixed submission:

# 問題文の意味がわからんコンテスト
# 0の場合も自分自身を照らす、っての気づくところからやっと読解
# Kを5000兆回やったあとはすべての要素がNになっとる この収束はわりと早いらしい
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]
    a = b[:n]
    if b[-1] == n:
        break
print(" ".join(list(map(str, a))))
Problem p02647 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
A = list(map(int, input().split()))


def query(lamps):
    start_list = []
    end_list = []
    for idx, power in enumerate(lamps):
        start, end = idx - power, idx + power
        start_list.append(start)
        end_list.append(end)

    start_list.sort(reverse=True)
    end_list.sort(reverse=True)

    now = 0
    for idx in range(n):
        while start_list and start_list[-1] <= idx:
            start_list.pop()
            now += 1

        while end_list and end_list[-1] < idx:
            end_list.pop()
            now -= 1

        lamps[idx] = now


def full_check(counts, full):
    for count in counts:
        if count == full:
            continue
        else:
            return False

    return True


for _ in range(k):
    query(A)
    if full_check(A, n):
        break

print(*A)


Error: TLE

Fixed submission:

n, k = map(int, input().split())
A = list(map(int, input().split()))


def query(lamps):
    start_list = []
    end_list = []
    for idx, power in enumerate(lamps):
        start, end = idx - power, idx + power
        start_list.append(start)
        end_list.append(end)

    counts = [0] * n
    start_list.sort(reverse=True)
    end_list.sort(reverse=True)

    now = 0
    for idx in range(n):
        while start_list and start_list[-1] <= idx:
            start_list.pop()
            now += 1

        while end_list and end_list[-1] < idx:
            end_list.pop()
            now -= 1

        counts[idx] = now

    return counts


def full_check(counts, full):
    for count in counts:
        if count == full:
            continue
        else:
            return False

    return True


for _ in range(k):
    A = query(A)
    if full_check(A, n):
        break

print(*A)
Problem p02651 (Python) — buggy submission, verdict: Runtime Error

def solve(n, a_list, s):

    for i in range(n - 1, -1, -1):
        if s[i] == "0":
            if a_list[i] == 0:
                continue
            r = 2 ** (a_list[i].bit_length() - 1)
            for j in range(i):
                if a_list[j] & r > 0:
                    a_list[j] = a_list[i] ^ a_list[j]
        else:
            if a_list[i] > 0:
                return 1
    return 0


def main():
    t = int(input())
    res_list = []
    for _ in range(t):
        n = int(input())
        a_list = list(map(int, input().split()))
        s = input()
        res = solve(n, a_list, s)
        res_list.append(res)
    for res in res_list:
        print(res)


def test():
    assert solve(2, [1, 2], "10") == 1
    assert solve(2, [1, 1], "10") == 0
    assert solve(6, [2, 3, 4, 5, 6, 7], "111000") == 0


if __name__ == "__main__":
    test()
    main()


Error: 0

Fixed submission:

def solve(n, a_list, s):

    for i in range(n - 1, -1, -1):
        if s[i] == "0":
            r = 2 ** (a_list[i].bit_length() - 1)
            for j in range(i):
                if a_list[j] & r > 0:
                    a_list[j] = a_list[i] ^ a_list[j]
        else:
            if a_list[i] > 0:
                return 1
    return 0


def main():
    t = int(input())
    res_list = []
    for _ in range(t):
        n = int(input())
        a_list = list(map(int, input().split()))
        s = input()
        res = solve(n, a_list, s)
        res_list.append(res)
    for res in res_list:
        print(res)


def test():
    assert solve(2, [1, 2], "10") == 1
    assert solve(2, [1, 1], "10") == 0
    assert solve(6, [2, 3, 4, 5, 6, 7], "111000") == 0


if __name__ == "__main__":
    test()
    main()
Problem p02657 (Python) — buggy submission, verdict: Runtime Error

a, b = map(int, input().split())
print(a * b)


Error: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s298903403.py", line 1, in <module>
    a, b = int(input().split())
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'


Fixed submission:

a, b = int(input().split())
print(a * b)
Problem p02657 (Python) — buggy submission, verdict: Runtime Error

a, b = [*map(int, input().split(" "))]
print(a * b)


Error: TypeError: 'type' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s795495503.py", line 1, in <module>
    a, b = [*map(input().split(" "), int)]
TypeError: 'type' object is not iterable


Fixed submission:

a, b = [*map(input().split(" "), int)]
print(a * b)
Problem p02657 (Python) — buggy submission, verdict: Runtime Error

val1, val2 = (int(x) for x in input().split())

print(int(val1) * int(val2))


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s139420322.py", line 2, in <module>
    val2 = input()
EOFError: EOF when reading a line


Fixed submission:

val1 = input()
val2 = input()

print(int(val1) * int(val2))
Problem p02657 (Python) — buggy submission, verdict: Runtime Error

x, y = map(int, input().split())
print(x * y)


Error: TypeError: can't multiply sequence by non-int of type 'str'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s474601082.py", line 2, in <module>
    print(x * y)
TypeError: can't multiply sequence by non-int of type 'str'


Fixed submission:

x, y = input().split()
print(x * y)
Problem p02657 (Python) — buggy submission, verdict: Runtime Error

nums = input().split()

A = int(nums[0])
B = int(nums[1])

val = A * B

print(val)


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s123530671.py", line 2, in <module>
    b = input()
EOFError: EOF when reading a line


Fixed submission:

a = input()
b = input()

A = int(a)
B = int(b)

val = A * B

print(val)
Problem p02657 (Python) — buggy submission, verdict: Runtime Error

a, t = map(int, input().split())
print(a * t)


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s987059931.py", line 3, in <module>
    a, t = map(int, input().split())
EOFError: EOF when reading a line


Fixed submission:

a, t = map(int, input().split())
print(a * t)
a, t = map(int, input().split())
print(a * t)
Problem p02657 (Python) — buggy submission, verdict: Runtime Error

a, b = map(int, input().split())
print(a * b)


Error: AttributeError: 'str' object has no attribute 'ssplit'. Did you mean: 'rsplit'?
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s218726646.py", line 1, in <module>
    a, b = map(int, input().ssplit())
AttributeError: 'str' object has no attribute 'ssplit'. Did you mean: 'rsplit'?


Fixed submission:

a, b = map(int, input().ssplit())
print(a * b)
Problem p02657 (Python) — buggy submission, verdict: Runtime Error

a, b = map(int, input().split())

print(a * b)


Error: ValueError: invalid literal for int() with base 10: '2 5'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s768625073.py", line 1, in <module>
    A = int(input())
ValueError: invalid literal for int() with base 10: '2 5'


Fixed submission:

A = int(input())
B = int(input())

print(A * B)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    m = 0
else:
    for i in a:
        m *= i
        if m > 10**18:
            m = -1
            break
print(m)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    m = 0
else:
    for i in a:
        m *= i
        if m > 10**18:
            m = -1
print(m)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
A = list(map(int, input().split()))
ans = 1

if 0 in A:
    ans = 0
else:
    for i in A:
        ans *= i
        if ans > 10**18:
            ans = -1
            break

print(ans)


Error: TLE

Fixed submission:

n = int(input())
A = list(map(int, input().split()))
ans = 1

for i in A:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))

ans = 1

if 0 in A:
    print(0)
else:
    for a in A:
        ans *= a
        if ans > 1000000000000000000:
            print(-1)
            break
    else:
        print(ans)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))

ans = 1

for a in A:
    ans *= a
    if a == 0:
        print(0)
        break

else:
    if ans > 1000000000000000000:
        print(-1)
    else:
        print(ans)
Problem p02658 (Python) — buggy submission, verdict: Runtime Error

import sys

N = int(input().rstrip())

limit = pow(10, 18)

nums = list(input().split())

for num in nums:
    num = int(num)
    if num == 0:
        print(0)
        sys.exit(0)

accum = 1
for num in nums:
    num = int(num)
    try:
        accum *= num
    except Exception:
        accum = -1
        break

    if accum > limit:
        accum = -1
        break

print(accum)


Error: 0

Fixed submission:

import sys

N = int(input().rstrip())

limit = pow(10, 18)

nums = []

nums = input().rsplit()

# for i in range(0, N - 1):
#     a = input()
#     if a == 0:
#         print(0)
#         sys.exit(1)
#     nums.append(a)

accum = 1
for num in nums:
    num = int(num)
    try:
        accum *= num
    except OverflowError:
        print(-1)
        sys.exit(1)

    if accum > limit:
        print(-1)
        sys.exit(1)

print(accum)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)


main()


Error: TLE

Fixed submission:

import operator
from functools import reduce


n = int(input())
a = list(map(int, input().split()))
ans = reduce(operator.mul, a)
print(-1 if ans > 10**18 else ans)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

N = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)
    sys.exit()

res = 1
for a in A:
    res *= a
    if 1e18 < res:
        print(-1)
        sys.exit()

print(res)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))

res = 1
for a in A:
    res *= a

if 1e18 < res:
    print(-1)
else:
    print(res)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return

    anser = 1
    for a in A:
        anser *= a
        if anser > 1000000000000000000:
            print(-1)
            return

    print(anser)


main()


Error: TLE

Fixed submission:

N = int(input())
anser = 1
for a in input().split(" "):
    anser = anser * int(a)

if anser > 1000000000000000000:
    print(-1)
else:
    print(anser)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
else:
    ans = 1
    for i in a:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
    print(ans)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    ans *= i
print(ans if not ans > 10**18 else -1)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

input = sys.stdin.readline


def main():
    n = int(input())
    a = sorted(map(int, input().split()))
    ans = 1
    for x in a:
        ans *= x
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)


main()


Error: TLE

Fixed submission:

n = int(input())
a = map(int, input().split())
ans = 1
for x in a:
    ans *= x

if ans > 10**18:
    print(-1)
else:
    print(ans)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

# import numpy as np
N = int(input())
A = list(map(int, input().split()))
# A = np.array(A)
t = A[0]
for i in range(1, N):
    t *= A[i]
    if int(t) > 1e18:
        for j in range(i, N):
            if A[j] == 0:
                t = 0
        break
if int(t) <= 1e18:
    print(int(t))
else:
    print(-1)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))
t = A[0]
i = 1
while i < N:
    t *= A[i]
    i += 1
if t <= 1e18:
    print(t)
else:
    print(-1)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-
# 整数の入力
# a = int(input())
# スペース区切りの整数の入力
# b, c = map(int, input().split())
# 文字列の入力
# s = input()
# 出力
# print("{} {}".format(a+b+c, s))
import sys

N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    if A[i] == 0:
        print(0)
        sys.exit(0)
answer = 1
for i in range(N):
    answer *= A[i]
    if answer > 1000000000000000000:
        print(-1)
        sys.exit(0)

print(answer)


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-
# 整数の入力
# a = int(input())
# スペース区切りの整数の入力
# b, c = map(int, input().split())
# 文字列の入力
# s = input()
# 出力
# print("{} {}".format(a+b+c, s))

N = int(input())
A = list(map(int, input().split()))
answer = 1
for i in range(N):
    answer *= A[i]

if answer > 1000000000000000000:
    print(-1)
else:
    print(answer)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))

if A.count(0):
    print(0)
    import sys

    sys.exit()

ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        import sys

        sys.exit()

print(ans)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))

ans = 1
for a in A:
    ans *= a
if ans > 10**18:
    ans = -1
print(ans)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys


n = int(input())
a = list(map(int, input().split()))

ans = 1

for i in a:
    if i == 0:
        print(0)
        sys.exit(0)

for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        sys.exit(0)

if ans > 10**18:
    print(-1)
else:
    print(ans)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))

ans = 1

for i in range(n):
    ans *= a[i]

if ans > 10**18:
    print(-1)
else:
    print(ans)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
li = list(map(int, input().split()))
x = 1
if 0 in li:
    print(0)
else:
    for i in li:
        x = x * i
        if x > 10**18:
            print(-1)
            exit()
    print(x)


Error: TLE

Fixed submission:

n = int(input())
li = list(map(int, input().split()))
x = 1
if 0 in li:
    print(0)
else:
    for i in li:
        x = x * i
    if x > 10**18:
        print(-1)
    else:
        print(x)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
re = 1

li = list(map(int, input().split()))

for i in range(n):
    if re > 1000000000000000000:
        break
    re = re * li[i]
if 0 in li:
    print(0)
elif re > 1000000000000000000:
    print(-1)
else:
    print(re)


Error: TLE

Fixed submission:

n = int(input())
re = 1

li = list(map(int, input().split()))

for i in range(n):
    re = re * li[i]
if re > 1000000000000000000:
    print(-1)
else:
    print(re)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
aa = list(map(int, input().split()))

if 0 in aa:
    print("0")
    exit(0)

result = 1
for a in aa:
    result *= a
    if result > pow(10, 18):
        print("-1")
        exit(0)

print(result)


Error: TLE

Fixed submission:

n = int(input())
aa = list(map(int, input().split()))

if 0 in aa:
    print("0")
else:
    result = 1
    for a in aa:
        result *= a

    if result > pow(10, 18):
        result = -1

    print(result)
Problem p02658 (Python) — buggy submission, verdict: Time Limit Exceeded

import numpy as np

N = int(input())
A = [int(a) for a in input().split()]
ans = A[0]

if 0 in A:
    print(0)
    exit()

for i in range(1, len(A)):
    if A[i] != 1:
        ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)


Error: TLE

Fixed submission:

N = int(input())
A = [int(a) for a in input().split()]
ans = A[0]

if 0 in A:
    print(0)
    exit()

for i in range(1, len(A)):
    ans *= A[i]
    if A[i] > 10**18:
        print(-1)
        exit()

if ans > 10**18:
    print(-1)
else:
    print(ans)