qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
def main():
    n, *a = map(int, read().split())

    if 0 in a:
        print(0)
    a = deque(a)
    s = 10 ** 18
    r = 1
    while a:
        r = r * a.popleft()
        if r > s:
            print(-1)
            sys.exit()
    print(r)

if __name__ == '__main__':
    main()


Fixed code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
def main():
    n, *a = map(int, read().split())

    if 0 in a:
        print(0)
        sys.exit()
    a = deque(a)
    s = 10 ** 18
    r = 1
    while a:
        r = r * a.popleft()
        if r > s:
            print(-1)
            sys.exit()
    print(r)

if __name__ == '__main__':
    main()
Buggy code:
import sys
n=int(input())
a=list(map(int,input().split()))
m=1
for i in range(n):
  m*=a[i]
  if m>10**18:
    print(-1)
    sys.exit()
print(m)

Fixed code:
import sys
n=int(input())
a=list(map(int,input().split()))
m=1
if 0 in a:
  print(0)
  sys.exit()
for i in range(n):
  m*=a[i]
  if m>10**18:
    print(-1)
    sys.exit()
print(m)
Buggy code:
n = int(input())
a = list(map(int, input().split()))

a.sort()

if a[0] == 0:
        print(0)
        exit(0)

ans = 1
for i in a:
        ans *= i
        print(i, ans)
        if (ans > 1e18):
                print(-1)
                exit(0)

print(ans)


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

a.sort()

if a[0] == 0:
        print(0)
        exit(0)

ans = 1
for i in a:
        ans *= i
        if (ans > 1e18):
                print(-1)
                exit(0)

print(ans)
Buggy code:
N = int(input())
a = list(map(int,input().strip().split()))

result = 1

if 0 in a:
  print(0)
  exit()
else:
  for i in range(N):
    result *= a[i]
    if result > 10**18:
      print(-1)
      exit()
    print(result)

Fixed code:
N = int(input())
a = list(map(int,input().strip().split()))

result = 1

if 0 in a:
  print(0)
  exit()
else:
  for i in range(N):
    result *= a[i]
    if result > 10**18:
      print(-1)
      exit()
  print(result)
Buggy code:
import math

N=int(input())
A=list(map(int, input().split()))
a=A[0]
for i in range(1,len(A)):
  a*=A[i]
  if pow(10,18)<a:
    print('-1')
    exit(0)
print(a)

Fixed code:
import math

N=int(input())
A=list(map(int, input().split()))
a=A[0]
if 0 in A:
  print(0)
  exit(0)  

for i in range(1,len(A)):
  a*=A[i]
  if pow(10,18)<a:
    print('-1')
    exit(0)
print(a)
Buggy code:
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

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

    for ai in a:
        ans *= ai

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

    print(ans)


if __name__ == '__main__':
    main()


Fixed code:
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

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

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

    for ai in a:
        ans *= ai

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

    print(ans)


if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
c = list(map(int, input().split()))
ans=1
max =10**18
for i in range(n):
    if ans< max:
        ans=ans*c[i]
        if ans >= max:
            ans =-1
            break
    else:
        ans = -1
        break
print(ans)

Fixed code:
n = int(input())
c = list(map(int, input().split()))
ans=1
max =10**18

if 0 in c:
    ans =0
else:
    for i in range(n):
        if ans< max:
            ans=ans*c[i]
            if ans > max:
                ans =-1
                break
        else:
            ans = -1
            break
print(ans)
Buggy code:
def finish(t):
    print(t)
    exit()

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

if 0 in a:
    finish(-1)

mod = pow(10, 18)
s = 1
for i in range(n):
    s *= a[i]
    if s > mod:
        finish(-1)
else:
    finish(s)

Fixed code:
def finish(t):
    print(t)
    exit()

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

if 0 in a:
    finish(0)

mod = pow(10, 18)
s = 1
for i in range(n):
    s *= a[i]
    if s > mod:
        finish(-1)
else:
    finish(s)
Buggy code:
a = int(input())
b = list(map(int, input().split()))
c = 1
for n in b:
    c = c*n
    if c > 10**18:
        print(-1)
        exit()

print(c)

Fixed code:
a = int(input())
b = list(map(int, input().split()))
c = 1

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

for n in b:
    c = c*n
    if c > 10**18:
        print(-1)
        exit()

print(c)
Buggy code:
INF=10**18
n=int(input())
a=list(map(int,input().split()))
ans=1
for val in a:
	if val==0:
		print(0)
		exit()
	if ans>INF:
		print(-1)
		exit()		
	ans*=val
else:print(ans)

Fixed code:
INF=10**18
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
for val in a:
	ans*=val
	if val==0:
		print(0)
		exit()
	if ans>INF:
		print(-1)
		exit()
else:
	print(ans)
Buggy code:
n = input()
a = map(int, input().split())
ans = 1
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    exit()
print(ans)

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

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

ans = 1
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    exit()
print(ans)
Buggy code:
N = int(input())
arr = sorted(map(int, input().split()))
INF = 10 ** 18
ans = 1
for num in arr:
    if ans > INF:
        ans = -1
        break
    elif ans == 0:
        break

print(ans)


Fixed code:
N = int(input())
arr = sorted(map(int, input().split()))
INF = 10 ** 18
ans = 1
for num in arr:
    ans *= num
    if num > 0 and ans > INF:
        ans = -1
        break
    elif ans == 0:
        break

print(ans)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
res = 1

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

for x in range(N) :
    res = res*A[x]
    if res > 10E+17
        print(-1)
        break

print(res)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
ans = 1

if 0 in A :
    ans = 0

for x in range(N) :
    ans *= A[x]
    if ans > 10E+17 :
        ans = -1
        break

print(ans)
Buggy code:
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    ans=1
    a.sort()
    
    for i in a:
        ans*=i
        if(ans>=1000000000000000000):
            print("-1")
            return
    
    print(ans)

solve()

Fixed code:
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    ans=1
    a.sort()
    
    for i in a:
        ans*=i
        if(ans>1000000000000000000):
            print(-1)
            return
    
    print(ans)

solve()
Buggy code:
N = int(input())
A = [int(x) for x in input().split()]
if 0 in A:
	print("-1")
	exit(0)
ans = 1
lim = 10**18
for a in A:
	ans *= a
    if ans > lim:
      print("-1")
      exit(0)
print(ans)

Fixed code:
N = int(input())
A = [int(x) for x in input().split()]
if 0 in A:
  print("0")
  exit(0)
ans = 1
lim = 10**18
for a in A:
  ans *= a
  if ans > lim:
    print("-1")
    exit(0)
print(ans)
Buggy code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(0)
prod = 1
for i in range(n):
  prod *= a[i]
  if prod >= 10 ** 18:
    print(-1)
  	exit()
print(prod)

Fixed code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(0)
  exit()
prod = 1
for i in range(n):
  prod *= a[i]
  if prod > 10 ** 18:
    print(-1)
    exit()
print(prod)
Buggy code:
n = int(input())
a = list(map(int, input().split(' ')))
lim = int(1e18)
mult = 1
for v in a:
	if mult > lim:
		break
	else:
		mult *= v
if mult > lim:
	print("-1")
else:
	print(mult)

Fixed code:
n = int(input())
a = list(map(int, input().split(' ')))
if a.count(0) > 0:
	print("0")
else:
	lim = int(1e18)
	mult = 1
	for v in a:
		if mult > lim:
			break
		else:
			mult *= v
	if mult > lim:
		print("-1")
	else:
		print(mult)
Buggy code:
import numpy as np


def main(A):
    ans = 1
    for i in A:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
    return ans


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


Fixed code:
import numpy as np


def main(A):
    ans = 1
    for i in A:
        if i == 0:
            return 0
    for i in A:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
    return ans


N = int(input())
A = list(map(int, input().split()))
print(main(A))
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]

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


Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()

ans = 1
for i in range(n):
	ans *= a[i]
	if ans == 0:
		break
	if ans > 10**18:	
		print(-1)
		exit()
print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
temp = 1
for i in a:
  temp *= i
  if temp > 10**18:
    temp = -1
    break
print(temp)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
temp = 1
if 0 in a:
  print(0)
else:
  for i in a:
    temp *= i
    if temp > 10**18:
      temp = -1
      break
  print(temp)
Buggy code:
lines = []
for i in range(2):
    lines.append(input())
num = int(lines[0])

out = 1
split = lines[1].split()
for i in range(num):
    out = int(split[i]) * out 
    if out > 1000000000000000000:
        out = - 1
        break
print(out)

Fixed code:
lines = []
for i in range(2):
    lines.append(input())
num = int(lines[0])

out = 1
split = lines[1].split()
if "0" in split:
    out = 0
for i in range(num):
    out = int(split[i]) * out 
    if out > 1000000000000000000:
        out = - 1    
        break
print(out)
Buggy code:
n = int(input())
lst = list(map(int, input().split()))
ans = 1
for i in range(n):
  ans = ans*lst[i]
  if ans > 10**18:
    print(-1)
    exit()
print(ans)

Fixed code:
n = int(input())
lst = list(map(int, input().split()))
ans = 1
for i in range(n):
  if lst[i] == 0:
    print(0)
    exit()
for i in range(n):
  ans = ans*lst[i]
  if ans > 10**18:
    print(-1)
    exit()
print(ans)
Buggy code:
a = int(input())
b = [int(i) for i in input().split()]
last = 1
if 0 not in b:
  for i in b:
      last*=i
      if last > 10**18:
      	last = -1
        break

else:
  last = 0
    
print(last)

Fixed code:
input()
b = [int(i) for i in input().split()]

if 0 not in b:
  last = 1
  for i in b:
      last*=i
      if last > 10**18:
        last = -1
        break
    
else:
  last = 0
    
print(last)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

ans = 1
if 0 in a:
    ans = 0
    print(ans)
    exit()
else:
    for i in a:
        ans *= i
        if ans > 10**18:
            print(-1)
            exit()


Fixed code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

ans = 1
if 0 in a:
    ans = 0
    print(ans)
    exit()
else:
    for i in a:
        ans *= i
        if ans > 10**18:
            print(-1)
            exit()
print(ans)
Buggy code:
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)
        exit()
print(ans)

Fixed code:
N = int(input())
A = list(map(int,input().split()))
ans = 1
if 0 in A:
    print(0)
    exit()
for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Buggy code:
n = int(input())
a = input().split()
b = 0
too_big = False
for i in a:
    if int(i) > 10 ** 18:
        print(-1)
        too_big = True
        break
if too_big:
    pass
else:
    for i in range(n):
        if b > 10 ** 18:
            break
        if i == 0:
            b = int(a[i])
        else:
            b = b * int(a[i])
    if b > 10 ** 18:
        print(-1)
    else:
        print(int(b))

Fixed code:
n = int(input())
a = input().split()
b = 0
is_include_zero = False
too_big = False
for i in a:
    if int(i) > 10 ** 18:
        print(-1)
        too_big = True
    if int(i) == 0:
        is_include_zero = True
if too_big:
    pass
elif is_include_zero:
    print(0)
else:
    for i in range(n):
        if b > 10 ** 18:
            break
        if i == 0:
            b = int(a[i])
        else:
            b = b * int(a[i])
    if b > 10 ** 18:
        print(-1)
    else:
        print(int(b))
Buggy code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
for x in a:
    ans *= x
    if ans >= 10 ** 18:
        print(-1)
        exit()
print(ans)

Fixed code:
n = int(input())
A = list(map(int, input().split()))

ans = 1

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

for a in A:
  ans *= a
  if ans > 10 ** 18:
    print(-1)
    exit()
print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))

threshold = 10**18
ans = 1
for val in a:
    ans *= val
    if ans > threshold:
        ans = -1
        break
print(ans)

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

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

Fixed code:
n=int(input())
l=list(map(int,input().split()))
if 0 in l:
  print(0)
else:
  a=1
  for i in l:
    a=a*i
    if a>10**18:
      print(-1)
      exit()
  print(a)
Buggy code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    ans = 1
    for i in a:
        ans *= i
        if ans > 10**18:
            print(-1)
            return
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Fixed code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    if 0 in a:
        print(0)
        return
    ans = 1
    for i in a:
        ans *= i
        if ans > 10**18:
            print(-1)
            return
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
Buggy code:
n= int(input())
l =list(map(int,input().split()))
ans= 1

if 0 in l:
    print("0")
else:
    for i in range(n):
        ans*= l[i]
        if ans>= 10**18:
            break
    if ans>= 10**18:
        print("-1")
    else:
        print(ans)

Fixed code:
n= int(input())
l =list(map(int,input().split()))
ans= 1

if 0 in l:
    print("0")
else:
    for i in range(n):
        ans*= l[i]
        if ans> 10**18:
            break
    if ans> 10**18:
        print("-1")
    else:
        print(ans)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(N):
  ans *= A[i]
  if ans > 10**18:
    ans = -1
    break
print(ans)    

Fixed code:
N = int(input())
A = list(map(int,input().split()))
if 0 in A:
  ans = 0
else:
  ans = 1
  for i in range(N):
    ans *= A[i]
    if ans > 10**18:
      ans = -1  
      break
print(ans)
Buggy code:
import sys
n = int(input())
a = list(map(int,input().split()))
ans = 1
for k in a:
	ans *= k
	if ans > 1000000000000000000:
		print(-1)
		sys.exit()
print(ans)

Fixed code:
import sys
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
for k in a:
	ans *= k
	if ans > 1000000000000000000:
		print(-1)
		sys.exit()
	if k == 0:
		print(0)
		sys.exit()
print(ans)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
count=1
if 0 in a:
  print(0)
  exit(0)
for i in a:
    count*=i
	if count>10**18:
    	print(-1)
        exit(0)
print(count)


Fixed code:
n = int(input())
a = list(map(int,input().split()))
count = 1
if 0 in a:
  print(0)
  exit()
for num in a:
  count *= num
  if count > 10**18:
    print(-1)
    exit()
print(count)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
p=1
for i in range(0,n):
    p=p*a[i]
if p>=10**18:
    print('-1')
else:
    print(p)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
p = a[0]
if 0 in a:
    p = 0
for i in range(1, n):
    p *= a[i]
    if p > int(10**18):
        p = -1
        break

print(p)
Buggy code:
n = int(input())
a_lst = list(map(int,input().split()))

ans = 1
for a in a_lst:
    ans *= a
    if ans > 10**18:
        ans = -1
        break
print(ans)

Fixed code:
n = int(input())
a_lst = list(map(int,input().split()))

ans = 1
if 0 in a_lst:
    print(0)
else:
    for a in a_lst:
        ans *= a
        if ans > 10**18:
            ans = -1
            break
    print(ans)
Buggy code:
n = int(input())

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

ans = 1

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

Fixed code:
n = int(input())

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

ans = 1

if 0 in a:
  ans = 0
else:
  for i in range(n):
    ans = ans * a[i]
    if ans > (10 ** 18): 
      break
      
if ans > (10 ** 18):
  print("-1") 
else:
  print(ans)
Buggy code:
from math import log10
from functools import reduce
from operator import mul

N = int(input())

nums = [int(s) for s in input().rstrip().split()]

def product(nums):
  limit = 10**18
  result = 1
  for n in nums:
    if n == 0:
      return 0
    else:
      result *= n
    if result > limit:
      return -1
  return result
    
print(product(nums))

Fixed code:
from math import log10
from functools import reduce
from operator import mul

N = int(input())

nums = [int(s) for s in input().rstrip().split()]

def product(nums):
  limit = 10**18
  result = 1
  if 0 in nums:
    return 0
  for n in nums:
    result *= n
    if result > limit:
      return -1
  return result
    
print(product(nums))
Buggy code:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def product_many(N):
    if 0 in N: return 0
    ans = 1
    for x in N:
        ans *= x
        if ans > 10 ^ 18: return -1
    return ans

def main():
    _ = input()
    N = list(map(int, input().split()))
    print(product_many(N))

if __name__ == "__main__":
    main()


Fixed code:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def product_many(N):
    if 0 in N: return 0
    ans = 1
    for x in N:
        if (10 ** 18 / ans) < x: return -1
        ans *= x
        if ans > 10 ** 18: return -1
    return ans

def main():
    _ = input()
    N = list(map(int, input().split()))
    print(product_many(N))

if __name__ == "__main__":
    main()
Buggy code:
import sys
n = input()
a = list(map(int, input().split()))

if 0 in a:
  pirnt(0)
  sys.exit(0)

s = 1
for x in a:
  s *= x
  if s > 1000000000000000000:
    break
if s > 1000000000000000000:
  print(-1)
else:
  print(s)


Fixed code:
import sys

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

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

s = 1
for x in a:
  s *= x
  if s > 1000000000000000000:
    break
if s > 1000000000000000000:
  print(-1)
else:
  print(s)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
count = 1

for A in a:
    count  = count * A
    if count >= 10**18:
      print('-1')
      exit()
print(count)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
count = 1
 
if 0 in a:
  print(0)
  exit()
  
for A in a:
  count *= A
  if count > 10**18:
    print(-1)
    exit()
print(count)
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
ans = 1
for i in a:
   ans *= i
   if ans > 10**18:
      ans = -1
      break
print(ans)

Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
ans = 1
if 0 in a:
   print(0)
   quit()
for i in a:
   ans *= i
   if ans > 10**18:
      ans = -1
      break
print(ans)
Buggy code:
N,*A = map(int,open(0).read().split())
ans = 1
for i in A:
    ans *= i
print(-1 if ans>=10**18 else ans)  


Fixed code:
N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
if 0 in A:
    print(0)
    
else:
    for i in A:
        ans *= i
        if ans > a:
            print(-1)
            exit()
    print(ans)
Buggy code:
import sys
n=int(input())
a=input()
a0=a.split()
l=list()
b=1
q= "0" in l
if q=="True":
    print(-1)
    sys.exit()
for i in range (n):
    a1=int(a0[i])
    b=b*a1
    if b>10**18:
        print(-1)
        sys.exit()
print(b)

Fixed code:
import sys
n=int(input())
a=input()
a0=a.split()
l=list()
b=1
q= "0" in a0
if q==True:
    print(0)
    sys.exit()
for i in range (n):
    a1=int(a0[i])
    b=b*a1
    if b>10**18:
        print(-1)
        sys.exit()
print(b)
Buggy code:
n=int(input())
lis=list(map(int,input().split()))
ans=1
for i in lis:
    ans*=i
    if ans>1000000000000000000:
    ans=-1
    break
else:
    print(ans)

Fixed code:
n=int(input())
lis=list(map(int,input().split()))
ans=1
for i in lis:
    ans*=i
    if ans>1000000000000000000:
        ans=-1
        break
if 0 in lis:
    ans=0

print(ans)
Buggy code:
import sys
input()
a = list(map(int, input().split()))
ans = 1
flag = False
for i in a:
    ans *= i
    if(ans>1000000000000000001):
        sys.exit()
if ans<1000000000000000001:
    print(ans)
else:
    print(-1)


Fixed code:
import sys
input()
a = list(map(int, input().split()))
ans = 1
flag = False
for i in a:
    if i==0:
        print(0)
        sys.exit()
for i in a:
    ans *= i
    if ans>1000000000000000001:
        print(-1)
        sys.exit()
if ans<1000000000000000001:
    print(ans)
else:
    print(-1)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
import math
b = [math.log10(i) for i in a]    
if sum(b)>18:
    print(-1)
else:
    z = 1
    for i in a:
        z*=i
    if z>10**18:
        print(-1)
    else:
        print(z)

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

if sorted(a)[0]==0:
    print(0)
else:
    import math
    b = [math.log10(i) for i in a if i!=0]    
    if sum(b)>18:
        print(-1)
    else:
        z = 1
        for i in a:
            z*=i
        if z>10**18:
            print(-1)
        else:
            print(z)
Buggy code:
n = int(input())
a = list(map(int,input().split()))

if 0 in a:
    print(0)
    return
ans = 1
for i in a:
    ans *= i
    if ans > 10**18:
        ans = -1
        break
print(ans)


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

if 0 in a:
    print(0)
    exit()
ans = 1
for i in a:
    ans *= i
    if ans > 10**18:
        ans = -1
        break
print(ans)
Buggy code:
N = int(input())
A = list(map(int,input().split()))

if 0 in A:
  print(0)
else:
  result=1
  for i in A:
    result*=i
    print(result)

    if result>10**18:
      print(-1)
      break

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

if 0 in A:
  print(0)
else:
  result=1
  for i in A:
    result*=i
    if result>10**18:
      result=-1
      break
  print(result)
Buggy code:
n=int(input())
k=list(map(int,input().split()))
res=1
for x in k:
  res*=x
  if(res>10**18):
    print(-1)
    break
else:
  print(res)

Fixed code:
n=int(input())
k=list(map(int,input().split()))
res=1
k.sort()
for x in k:
  res*=x
  if(res>10**18):
    print(-1)
    break
else:
  print(res)