Problem:


Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0



Sample input:
2
1000000000 1000000000


Sample output:
1000000000000000000

Submission status: Accepted

Solution code:
n = int(input())
n_l = list(map(int, input().split()))

VORDER = 10 ** 18
ans = 1

if 0 in n_l:
    ans = 0
else:
    for i in n_l:
        ans = i * ans
        if ans > VORDER:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
def check() -> int:
    n = int(input())
    n_l = list(map(int, input().split()))

    VORDER = 10 ** 18
    ans = 1

    if 0 in n_l:
        ans = 0
    else:
        for i in n_l:
            ans = i * ans
            if ans > VORDER:
                ans = -1
                break
    return ans


if __name__ == '__main__':
    print(check())

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
MAX = 10**18
A.sort()
ans = 1
for i in range(len(A)):
    ans = ans * A[i]
    if ans > MAX:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
#A = list(reversed(sorted(list(map(int, input().split())))))
A = sorted(list(map(int, input().split())))
assert len(A) == N
mul = 1
for a in A:
  mul *= a
#  print(a, mul)
  if a == 0:
    print(0)
    break
  if mul > (10 ** 18):
    print(-1)
    break
else:
  print(mul)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
if a[0] == 0:
  print(0)
else:
  for i in range(len(a)):
    ans *= a[i]
    if ans > 10**18:
      print("-1")
      exit()
    elif i == len(a)-1:
      print(ans)

Submission status: Accepted

Solution code:
import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, *A = map(int, read().split())
 
U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1
 
if p > U:
    print(-1)
else:
    print(p)

Submission status: Accepted

Solution code:
N = int(input())
AS = [int(i) for i in input().split()]

m = 10 ** 18
acc = 1
if 0 in AS:
  print(0)
  import sys
  sys.exit()

for i in AS:
  acc *= i
  if acc > m:
    print('-1')
    import sys
    sys.exit()

print(acc)

Submission status: Accepted

Solution code:
# coding=utf-8
import sys

if __name__ == '__main__':
    N = int(input())
    li_A = list(map(int, input().split()))

    ans = li_A[0]

    if 0 in li_A:
        print('0')
        sys.exit()

    for i in range(1, N):
        if ans * li_A[i] > 1000000000000000000:
            print('-1')
            sys.exit()
        else:
            ans *= li_A[i]

    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
dota = 1
if 0 in set(a):
    dota = 0
else:
    for ai in a:
        dota *= ai
        if dota > 10**18:
            dota = -1
            break
print(dota)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
prod=1
for i in a:
    prod*=i
    if prod>10**18:
        break
if prod>10**18:
    print(-1)
else:
    print(prod)

Submission status: Accepted

Solution code:
input()
a = list(map(int, input().split()))
if 0 in a:
	print(0)
else:
	if 1 in a:
		a.sort(reverse=True)
		del a[-a.count(1):]
	product = 1
	limit = 10 ** 18
	for x in a:
		product *= x
		if product > limit:
			print(-1)
			break
	else:
		print(product)

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, input().split()))
LA = len(A)
ans = A[0]
for j in range(LA):
    if A[j] == 0:
        print('0')
        sys.exit()

for i in range(LA-1):
    ans = ans*A[i+1]
    if ans > 10**18:
        print('-1')
        sys.exit()
        
print(ans)

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    As = list(map(int, input().split()))
    ans = 1
    if 0 in As:
        print(0)
        return

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()
list1=list(map(int,input().split()))
if 0 in list1:
    print(0)
else:
    ans=1
    for i in list1:
        ans*=i
        if ans>1e18:
            ans=-1
            break
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
li=list(map(int,input().split()))
if 0 in li:
    print(0)
    exit()
ans=1

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

Submission status: Accepted

Solution code:
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 ()

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

n = int(input())

nums = sorted(list(map(int, input().split())))

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

    if ans == 0:
        print(0)
        exit()

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
l = list(map(int,input().split()))
if l.count(0) != 0 :
    print(0)
    exit()
for i in range(n) :
    ans *= l[i]
    if ans > 10**18 :
        print('-1')
        exit()
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
if 0 in a:
  print(0)
else:
  b=1
  for i in range(n):
    b*=a[i]
    if b>10**18:
      print(-1)
      exit()
  print(b)

Submission status: Accepted

Solution code:
def main():
    n = int(input())

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

    if 0 in n1:
        print(0)
        return

    sum = 1
    for i in n1:
        sum *= i
        if sum > 1000000000000000000:
            print(-1) 
            return 
    print(sum)

main()

Submission status: Accepted

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

ans=1

if A.count(0)>0:
    ans=0
for i in range(N):
    ans*=A[i]
    if ans>10**18:
        ans=-1
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(v) for v in input().split()]
limit = 1000000000000000000
if 0 in a:
    print (0)
else:
    ans = 1
    num = 1
    for i in a:
        num *= i
        if num > limit:
            num = -1
            break
    ans = num
    print(ans)

Submission status: Accepted

Solution code:
def main() -> None:
    n = int(input())
    a_tuple = tuple(map(int, input().split()))

    if 0 in a_tuple:
        print(0)
        return
    boader = 10 ** 18
    answer = 1
    for a in a_tuple:
        answer *= a
        if answer > boader:
            print(-1)
            return
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

sum=1

if 0 in A:
    print(0)
else:
    for i in range(N):
        sum *= A[i]  
        if sum >= int(1e18):
            break
    print(sum if sum<= int(1e18) else -1)

Submission status: Accepted

Solution code:
N=int(input())
As=list(map(int,input().split()))
ans=1

if 0 in As:
    print(0)
else:
    for i in range(N):
        ans*=As[i]
        if ans>int(1e18):
            break
    print(ans if ans<=int(1e18) else -1)

Submission status: Accepted

Solution code:
N = int(input())
line = [int(i) for i in input().split()]
sum = 1
line.sort(reverse=True)
if line[len(line) -1]== 0:
  print(0)
  exit()
for num in line:
  sum = sum * num
  if sum > 10 ** 18:
    print(-1)
    exit()
print(sum)

Submission status: Accepted

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

if 0 in A:
    print(0)
else:
    ans = 1
    a = sorted(A, reverse=True)
    for i in a:
        ans *= i
        if ans > 10 ** 18:
            print(-1)
            break
    else:
        print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] == 0:
    print(0)
else:
    p = 1;
    for i in range(N):
        p *= A[i];
        if p > 10**18:
            p = -1;
            break;
    print(p)

Submission status: Accepted

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

ans = 1

for i in a:
    if i == 0:
        ans = 0

if ans != 0:
    for i in a:
        ans *= i
        if ans > 10**18:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = map(int,input().split())
ans = 1
for x in A:
	ans *= x
	if ans > 10**18:
		ans = 10**18+1
print(-1 if ans > 10**18 else ans)

Submission status: Accepted

Solution 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 *= a[i]
        if ans > 10**18:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

lst = input().split()

ans = 1

if '0' in lst:
   ans = 0
else:
   for i in range(N):
      ans = ans * int(lst[i])
      if 10**18 < ans:
         ans = -1
         break

print(ans)

Submission status: Accepted

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

ans = 1
for i in A:
    ans *= i
    if ans > pow(10, 18):
        ans = -1
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = list(map(int,input().split()))
product = 1
if 0 in A:
    print(0)
    sys.exit()
for i in range(N):
    product *= A[i]
    if product > 10 ** 18:
        product = -1
        break
print(product)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
a = list(map(int,input().split()))
ans = 1
t = False

for i in a:
  if i == 0:
    ans = 0
    t = True

if t != True:
  for i in a:
    ans *=i
    if ans>10**18:
      ans = -1
      break
    
print(ans)

Submission status: Accepted

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

mul=1
if 0 in A:print("0")
else:
    for i in range(N):
        mul*=A[i]
        if mul>pow(10,18):
            print("-1")
            break
        elif i==N-1:print(mul)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
wa = 1
ka = 0
if(a.count(0)>=1):
  print(0)
  ka +=1
else:
  for i in range(n):
    wa = wa*a[i]
    if(wa>10**18):
      print("-1")
      ka +=1
      break
if(ka==0):
  print(wa)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 1

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

Submission status: Accepted

Solution code:
n = int(input())
L = list(map(int,input().split()))
ans = 1
if 0 in L:
  print(0)
else:
  for l in L:
    ans *= l
    if ans > 10**18:
      print(-1)
      exit()
  print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
X=1
if 0 in A:
    print(0)
else:
    for idx in range(N):
        X=X*A[idx]
        if X >10**18:
            print(-1)
            break
    else:
        print(X)

Submission status: Accepted

Solution code:
N =int(input())

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

B = 1
C = 10 ** 18

for i in range(N):
    B = B * A[i]
    if B == 0:
        break
    elif B > C:
        B = -1
        break

print(B)

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int, input().split()))

ans = 1
if al.count(0) > 0:
    print(0)
else:
    for a in al:
        ans *= a
        if ans > 10**18:
            print(-1)
            break
    else:
        print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    if 0 in A:
        print(0)
        return

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

        if mul > 1e18:
            print(-1)
            return

    print(mul)


main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    for a in A:
        if a == 0:
            print(0)
            return

    mul = 1
    for a in A:
        mul *= a
        if mul > 10 ** 18:
            print(-1)
            return

    print(mul)

main()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 1
A = sorted(A)
for i in range(n):
  ans *= A[i]
  if ans > 10**(18):
    print('-1')
    exit()
print(ans)

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    ans = 1
    if 0 in A:
        ans = 0
    else:
        for a in A:
            ans *= a
            if (10**18 < ans):
                ans = -1
                break
        if (10**18 < ans):
            ans = -1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

x = 1

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

print(x)

Submission status: Accepted

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

Submission status: Accepted

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

if min(A) == 0:
    print(0)
    exit()

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = 1
if 0 in a:
    x = 0
else:
    for i in range(n):
        if x != -1:
            x = x * a[i]
        if x > 10 ** 18:
            x = -1
print(x)

Submission status: Accepted

Solution code:
n = int(input())
lst = sorted(list(map(int, input().split())))
mult = 1

for i in lst:
    mult *= i
    if 10**18 < mult:
        print(-1)
        exit()
else:
    print(mult)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    if 0 in A:
        print(0)
    else:
        s = 1
        for a in A:
            s *= a
            if 10**18 < s:
                s = -1
                break
        if 10 ** 18 < s:
            s = 1
        print(s)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
L=list(map(int,input().split()))
A=1
if 0 in L:
  print(0)
  exit()
for i in range(N):
  A=A*L[i]
  if 10**18<A:
    print(-1)
    exit()
if 10**18<A:
  print(-1)
else:
  print(A)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split()

ans = 1
zero_count = A.count("0")

if zero_count != 0:
    print(0)
else:
    for i in range(N):
        ans *= int(A[i])
        if ans > 10**18:
            ans = -1
            break

    print(ans)

Submission status: Accepted

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

if 0 in A:
  ans = 0
else:
  ans = 1
  max_limit = 10 ** 18
  for i in range(N):
    if ans * A[i] > max_limit:
      ans = -1
      break
    else:
      ans *= A[i]

print(str(ans))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 1
max_limit = 10 ** 18
for i in range(N):
  ans *= A[i]
  if ans > max_limit:
    ans = -1
    break

if ans > max_limit:
  print(str(-1))
else:
  print(str(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	INF = 10**18
	
	n = int(input())
	A = list(map(int,input().split()))

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

	ans = 1
	flg = False

	for i in range(n):
		ans = ans * A[i]
		if ans > INF:
			ans = -1
			break

	print(ans)

Submission status: Accepted

Solution code:
N=int(input())

A=list(map(int,input().split()))
ans=A[0]

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

for cnt in range(N-1):
    ans = ans * A[cnt+1]
    if ans > 1000000000000000000:
        break
    elif ans == 0:
        break
if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
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 10**18 < ans:
      print(-1)
      exit()
  print(ans)

Submission status: Accepted

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

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

    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
alist = list(map(int, input().split()))
k = 1
if 0 in alist:
    print(0)
else:
    for i in range(0,N):
        k = k*alist[i]
        if k > 1000000000000000000:
            k= -1
            break
    print(k)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  a = list(map(int, input().split()))
  ans = 1
  if 0 in a:
    print(0)
    return
  else:
    flag = True
    for i in a:
      ans *= i
      if ans > (10 ** 18):
        print(-1)
        return
    print(ans)
  
main()

Submission status: Accepted

Solution code:
def main():
  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):
      print(-1)
      return
  print(ans)
  
main()

Submission status: Accepted

Solution code:
import sys

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

if min(A) == 0:
    print(0)
    sys.exit()

else:
    for i in range(N):
        A_sum = A_sum * A[i]
        
        if A_sum > 1e18:
            print(-1)
            sys.exit()


print(A_sum)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 1

for item in A:
    ans *= item

    ans = min(ans, 10**18 + 1)

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

print(ans)

Submission status: Accepted

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

ans=1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
prod = 1

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

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

print(prod)

Submission status: Accepted

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

Submission status: Accepted

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

AA=sorted(A)
B=1
for i in range(N):
    B=B*AA[i]
    if B>10**18:
      B=-1
      break

print(B)

Submission status: Accepted

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

res = 1
for a in A:
    res = min(res*a, 10**18 + 1)
if res == 10**18 + 1: print(-1)
else: print(res)

Submission status: Accepted

Solution code:
# 169 B
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 1
for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys

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

U = 10**18
ret = 1

for x in A:
  ret *= x
  if ret > U:
    ret = U+1
    
if ret > U:
  ret = -1

print(ret)

Submission status: Accepted

Solution code:
input();a=sorted(map(int,input().split()));z=1
for i in a:
 z*=i
 if z>1e18:z=-1;break
print(z)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split());z=1
for i in a:
 if i>1e18//z:z=-1;break
 z*=i
print(0 if 0in a else z)

Submission status: Accepted

Solution code:
a=int(input())
b=list(map(int,input().split()))
c=1
b.sort()
if b[0]==0:
  print(0)
else:
  for i in range(a):
    c=c*b[-i]
    if c>1000000000000000000:
      break
  if c>1000000000000000000:
    print(-1)
  else:
    print(c)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = a[0]

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

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

print(ans)

Submission status: Accepted

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

A.sort()
if A[0] == 0:
    ANS = 0
else:
    A.sort(reverse=True)
    ANS = 1
    for a in A:
        ANS = ANS * a
        if ANS > 10 ** 18:
            ANS = -1
            break

print(ANS)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline())
A = list(map(int, stdin.readline().split()))

ans = 1

if 0 in A:
    ans = 0

if ans:
    for a in A:
        ans *= a
        if ans > pow(10, 18):
            ans = -1
            break

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

def check():
  ans = 1
  for i in range(n):
    ans *= a[i]
    if ans == 0:
      return 0
    if ans > 10 ** 18:
      return -1
  return ans
p = check()
print(p)

Submission status: Accepted

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

ans = 1

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int,input().split()))
t = 10**18
ans = 1

if 0 in S:
  print(0)
  exit(0)
  
for n in S:
  ans *= n
  if ans > t:
    print(-1)
    exit(0)
  
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    ans = 1
    if 0 in A:
        print(0)
        sys.exit()
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            break
    else:
        print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int, input().split()))

def f():
    if 0 in S:
        return 0
    elif 10 ** 18 in S:
        return -1
    else:
        ans = 1
        for s in S:
            ans *= s
            if ans > 10 ** 18:
                return -1
        return ans

print(f())

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 1
P = 10**18

for i in range(N):
    ans *= A[i]
    if ans > P:
        ans = -1
        break

ans = 0 if any([a==0 for a in A]) else ans
print(ans)

Submission status: Accepted

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

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

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

print(acc)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
count = 1
if 0 in a:
  print(0)
else:
  for i in range(N):
    count *= a[i]
    if count > 10 ** 18:
      print(-1)
      break
  else:
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    a = list(map(int, input().split(" ")))
    lim = 1e18
    ans = 1
    if 0 in a:
        print(0)
        return
    for i in a:
        ans *= i
        if ans >lim:
            print(-1)
            return
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
N = input()
num = [int(x) for x in input().split()]
multiply = 1

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

for i in num:
    multiply *= i
    if (multiply > 10**18):
        print(-1)
        sys.exit()
if (0 < multiply and multiply <= 10**18):
    print(multiply)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
x=1
A.sort()
if 0 in A:
  print(0)
  exit()

for i in range(n):
  x*=A[n-i-1]
  if x>10**18:
    print(-1)
    exit()
  else:
    continue

print(x)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    
    if 0 in a:
        print(0)
        return
    
    prod = 1
    for i in a:
        prod *= i
        if prod > 10 ** 18:
            print(-1)
            return
    
    print(prod)
    
    return

main()

Submission status: Accepted

Solution code:
num = int(input())

k = input().split()

for i in range(len(k)):
    k[i] = int(k[i])

k.sort()

mul = 1

for i in range(num):
    mul *= int(k[i])
    if mul > 10**18:
        break

if mul > 10**18:
    print(-1)

else:
    print(mul)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(w) for w in input().split()]
x = sorted(x)
ans = 1
f = False
for i in range(n):
    ans *= x[i]
    if ans > 10**18:
        f = True
        break
    
if ans > 10**18:
    f = True
    
if(f):
    print(-1)
    
else:
    print(ans)

Submission status: Accepted

Solution code:
def main(X, A):
    ans = 1
    if 0 in A:
        return 0
    for a in A:
        ans *= a
        if ans > 1e18:
            return -1
    return ans

if __name__ == '__main__':
    X = int(input())
    A = list(map(int, input().split()))
    ans = main(X, A)
    print(ans)

Submission status: Accepted

Solution code:
# ABC169
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)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,(input().split())))
l=1
a=sorted(a)
for i in range(n):
    l*=a[i]
    if l>10**18:
        print('-1')
        exit()
print(l)

Submission status: Accepted

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

if 0 in a:
    print(0)
else:

    ans = 1
    i = 0
    while (i <= n - 1):
        if ans <= 10 ** 18:
            ans *= a[i]
            i += 1
        else:
            break

    #print(i)
    if ans <= 10 ** 18:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))

ans = 1
dotira = False
s = 10**18

if 0 in p :
  print(0)

else:
  
  for x in p:
    ans = ans * x
    if ans > s:
      dotira = True
      break
  if dotira:
    print(-1)
  else:
    print(ans)