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())
aa = sorted(list(map(int, input().split())))
if aa[0] == 0:
    print(0)
else:
    ret = 1
    ff = False
    for a in reversed(aa):
        ret *= a
        if ret > 10**18:
            ff = True
            break
    if ff:
        print(-1)
    else:
        print(ret)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
mod=1000000000000000000
ans=1
p=1
if(l.count(0)>=1):
    ans=0
else:
    for i in range(0,n):
        x=l[i]
        p=p*x
        if(p>mod):
            ans=-1
            break
if(ans!=0 and ans!=-1):
    ans=p
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def solve(N, A):
  ans = A[0]
  exist_zero = False
  if A[-1] == 0:
    exist_zero = True

  if exist_zero:
    print(0)
    return

  for i in range(1, N):
    ans *= A[i]
    if ans > 10**18 and not exist_zero:
      print(-1)
      return

  print(ans)

solve(N, A)

Submission status: Accepted

Solution code:
n=input()
flag=0
flag1=0
a=list(map(int,input().split()))
sum=1
a.sort()
for i in a :
    sum*=i
    if(i==0):
        flag1=1
    if(sum>1e18) :
        flag=1
        break
if(flag==0 or flag1==1):
    print(sum)
else : print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1

for x in arr:
    if x == 0:
        ans = 0

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

Submission status: Accepted

Solution code:
s=input()
n=input().split(" ")
a=1
flag=False
for i in n:
  if int(i)==0:
    print(0)
    exit(0)
  if flag==False:
    a=a*int(i)
  if a>1000000000000000000:
    flag=True
if flag==True:
  print(-1)
else:
  print(a)

Submission status: Accepted

Solution code:
# import numpy as np
n = int(input())
a_lst = list(map(int, input().split()))
x = 10 ** 18

# ans = np.prod(a_lst)



ans = 1
if 0 in a_lst:
    # print("a")
    ans = 0
else:
    for i in range(n):
        ans *= a_lst[i]
        if ans > x:
            ans = -1
            break
        # elif ans == 0:
        #     break
    
# if ans > x:
#     print(-1)
# else:
#     print(ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
t.sort()
r = 1
for i in t:
    r *= i
    if(r > 1000000000000000000):
        r = -1
        break
print(r)

Submission status: Accepted

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

if 0 in A:
    print(0)
    finish = 1
else:
    for n in range(N):
        result = result*A[n]
        if result > 10**18:
            print(-1)
            finish = 1
            break

    if finish == 0:
        print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
List=list(map(int,input().split()))
List.sort(reverse=True)
if 0 in List:
    print(0)
    sys.exit()
ans=1
for i in List:
    if ans<=10**18:
        ans*=i
    else:
        print(-1)
        sys.exit()
if ans<=10**18:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
#coding:utf-8

N = int(input())

A = [int(i) for i in input().split()]

ans = 1
flag = True

for i in A:
    if i == 0:
        ans = 0
        flag = False

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

print("{}".format(ans))

Submission status: Accepted

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

X = 1
c = 0
for i in range(0,N):
    X = X * A[i]
    if X <= 10**18:
        c = c + 1
    else:
        break

if c == N:
    print(X)
else:
    print("-1")

Submission status: Accepted

Solution code:

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

def main():
  if(0 in A):
    print(0)
    return

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

main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# your code goes here
n = int(input())
ans = 1
MAX = 1e18
lst = input().split(' ')
for x in lst:
	ans = ans*int(x)
	if ans > MAX or ans < 0:
		ans = -1
		
print(ans)

Submission status: Accepted

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

ans = 1
a.sort()
for i in range(n):
    ans = ans * a[i]
    if ans == 0:
        ans = 0
        break
    if ans > pow(10,18):
        ans = -1
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
A = list(map(int, input().split()))
newA = sorted(A,reverse=True)
num = 1
if 0 in A:
  num = 0
else:
  for i in newA:
    if num > 1000000000000000000:
      break
    num = num*int(i)
if num > 1000000000000000000:
  print(-1)
else:
  print(num)

Submission status: Accepted

Solution code:
# python3.5

import sys

n = int(sys.stdin.readline())
ns = sys.stdin.readline().split()

for i in range(0, len(ns)): 
    ns[i] = int(ns[i]) 

ns.sort()

if ns[0] == 0:
	print(0)
else:
	res = 1
	for i in ns:
		res = res * i
		if res > 1000000000000000000:
			res = -1
			break
	print(res)

Submission status: Accepted

Solution code:
input()
a = input().rstrip().split()
a = [int(a_i) for a_i in a]

res = 1
if 0 in a:
    print(0)
else:
    for a_i in a:
        a_i = int(a_i)
        res = res * a_i
        if res > 1000000000000000000:
            print(-1)
            break
    else:
        print(res)

Submission status: Accepted

Solution code:
ans = 1
flag = 0

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

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

Submission status: Accepted

Solution code:
n = int(input())
Sum = 1
Max = 1000000000000000000

l = list(map(int, input().split()))
f = 0
for i in range(n):
  if l[i]==0:
    f = 1
for i in range(n):
  Sum=Sum*l[i]
  if Sum>Max:
     break
if f == 1:
  print("0")
elif Sum<=Max:
  print("%d" % Sum)
else :
  print("%d" % -1)

Submission status: Accepted

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

check = True
zero = False

for i in range(0,n):
    if a[i]==0:
        zero = True
        break;




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

    if ans>1000000000000000000:
        check = False
        break;




if zero:
    print(0)
else:
    if check:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

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

sum = 1
if 0 in A:
  sum = 0
ans = 0
for x in A:
  sum *= x
  if sum > 1000000000000000000:
    ans = -1
    break
  if sum == 0:
    ans = 0
    break

if ans < 0:
  print(ans)
else:
  print(sum)

Submission status: Accepted

Solution code:
import sys
from decimal import Decimal
N = int(input())
A = list(map(int,input().split()))
A.sort()
cnt = Decimal('1')
for i in range(N):
  if cnt*Decimal(str(A[i]))>Decimal(10**18):
    print(-1)
    sys.exit()
  cnt = Decimal(cnt)*Decimal(A[i])


print(cnt)

Submission status: Accepted

Solution code:
import sys
N = int(input())
l = list(map(int,input().split()))

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

ans = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
         
if(0 in A):
  ans = 0 
else:
  ans = 1       
  for a in A:
    ans *= a
    if(ans > 10**18):
      ans = -1
      break
    if(len(str(ans))>=2):
     if(str(ans)[1] == 'e'):
      ans = -1
      break
         
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
ans = 1
for i in a_list:
  ans *= i
  if ans > 1000000000000000000:
    break

if ans > 1000000000000000000 and 0 not in a_list:
              print("-1")
elif 0 in a_list:
              print(0)
else:
              print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
a = 1
if 0 in A:
    a = 0
else:
    for i in range(N):
        a *= A[i]

        if a > 1000000000000000000:
            a = -1
            break
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 **18
N,*A = map(int, read().split())
if 0 in A:
  print(0)
  sys.exit()
ans = 1
for i in A:
  ans *= i
  if ans > INF:
    print(-1)
    sys.exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int, input().split()))
res = 1
if 0 in ls:
    print(0)
    quit()
for x in ls:
    res *= x
    if res > 10**18:
        print(-1)
        quit()
print(res)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import log10 as log10

n = int(input())

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

_max = 10 ** (18)

ans = a[0]
min_a = min(a)

for _a in a[1:]:
    if min_a == 0:
        break
    if ans > _max:
        break


    ans *= _a

if (ans > _max):
    print(-1)
elif min_a == 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

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

ans=1
flag0=0
flag1=0
inf=1000000000000000000

for a in A:
	if(a==0):
		flag0=1
		
if flag0==1:
	print(0)
	
else:
	for a in A:
		ans=ans*a
		if(ans>inf):
			flag1=1
			break

	if flag1==1:
		print(-1)
	else:
		print(ans)

Submission status: Accepted

Solution code:
n=int(input())
c=sorted(list(map(int,input().split())))[::-1]
if c[-1]==0:
	print(0)
else:
	tot=1
	flag=0
	for i in range(len(c)):
		tot*=c[i]
		if tot>1000000000000000000:
			print(-1)
			flag=1
			break
	if flag==0:
		print(tot)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split()
answer = 1
flag = 0
x = 10**18

if '0' in A:
  print(0)
  flag = 1
  


if flag == 0:
  for i in range(N):
    answer *= int(A[i])
    if answer > x:
      print(-1)
      flag = 1
      break

if flag == 0:    
  print(answer)

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
 
A = set(As)
 
if 0 in A:
  print(0)
  exit()

rlt = 1
for i in As:
  if i > 1e18:
    print(-1)
    exit()
  else:
    rlt *= i
    if rlt > 1e18:
      print(-1)
      exit()
      
print(rlt)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
tmp = 1
for num in A:
    tmp *= num
    if tmp > 1e18:
      break
  
if tmp <= 1e18:
    print(tmp)
elif 0 in A:
    print(0)
else:
    print(-1)

Submission status: Accepted

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

A.sort()


res = 1
for a in A:
    res *= a
    if res > 10 ** 18:
        res = -1
        break

print(res)

Submission status: Accepted

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

multi = 1
if min(a) == 0:
    print(0)
else:
    for i in range(n):
        multi = multi * a[i]
        if multi > 1000000000000000000:
            print(-1)
            break
    if multi <= 1000000000000000000:
        print(multi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 1
for i in l:
    count= count*i
    if count == 0:
        print("0")
        sys.exit()
    elif count > 10**18:
        print("-1")
        sys.exit()
if count > 10**18:
    print("-1")
    sys.exit()
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

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

cum = 1
over = False
for x in a:
    if x == 0:
        cum = 0
        break

if cum == 0:
    print(0)
else:
    for x in a:
        cum *= x
        if (cum > 1e18):
            over = True
            break
    print(-1) if over else print(cum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
A = [int(i) for i in input().split()]
total = 1
for i in A:
    if total != -1:
        total *= i
        if total > 10**18:
            total = -1
    else:
        if i==0:
            total = 0
            break
print(total)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
if a[-1] == 0:
    print(0)
else:
    for i in range(1, n):
        ans *= 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()))
b=0 in a
c=1
d=0
for i in range(n):
    c=c*a[i]
    if c>1000000000000000000:
        d=1
        break
    
if c<=1000000000000000000:
    print(c)
if d==1:
    if b==True:
        print("0")
    else:
        print("-1")

Submission status: Accepted

Solution code:
n=int(input())
l = list(map(int,input().strip().split()))[:n] 
rs= 1
l.sort()
if l[0]==0 :
    rs=0
else:
    for i in range(n):
        if(10**18 // rs < l[i]):
            rs = -1
            break
        rs=l[i]*rs
print(rs)

Submission status: Accepted

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

if 0 in listA:
    print(0)
    exit()
result = 1
maxA = 10 ** 18
for a in listA:
    result *= a
    if result > maxA:
        result = -1
        break
print(result)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A_list = list(map(int, input().split()))

    if 0 in set(A_list):
        print(0)
        exit()

    ans = 1
    for i in A_list:
        ans *= i
        if 1000000000000000000 < ans:
            print('-1')
            exit()
    else:
        print(ans)


main()

Submission status: Accepted

Solution code:
mul,f = 1, 0
input()
l = list(map(int, input().split()))
if l.__contains__(0):
    print(0)
    f = 1
else:
    for i in l:
        mul = mul * i
        if mul>1000000000000000000:
            print(-1); break;
    else:
        print( mul)

Submission status: Accepted

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

for i in range(N):
    if(A[i]==0):
        flag=1

if flag==0:        
    if(N%2==0):
        for i in range(int(N/2)):
            ans *= (A[i]*A[N-1-i])
            if(ans>1000000000000000000):
              break
    else:
        for i in range(int(N/2)):
            ans *= A[i]*A[N-1-i]
            if(ans>1000000000000000000):
                break
        ans*=A[int((N-1)/2)]

if flag==1:
    print(0)
elif(ans>1000000000000000000):
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())

a = [int(x) for x in input().split(" ")]
ans = 1
fail = False
zero = False
for i in range(N):
	if(not fail):
		ans*=a[i]
	if(not fail and ans>1000000000000000000 or ans<0) :
		fail = True
	elif(a[i]==0) :
		zero = True
		ans=0
		break

if(fail and not zero) :
	print("-1")
else:
	print(ans)

Submission status: Accepted

Solution code:
import sys

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

ans=1
if 0 in m:
  print(0)
  sys.exit()

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

if ans<=pow(10,18):
  print(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-1,-1,-1):
		ans *= a[i]
		if(ans>10**18):
			break
if(ans>10**18):
	print(-1)
else:
	print(ans)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().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)

Submission status: Accepted

Solution code:
ans = 1
n = input()
n = int(n)
nums = input().split()
for i in range(n):
    mul = int(nums[i])
    if mul == 0:
        print(0)
        exit()


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

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

exit()

Submission status: Accepted

Solution code:
n = int(input())
a= input().split()
level = pow(10, 18)
product = 1

if "0" in a:
  print(0)
else:
  for num in range(n):
    product *= int(a[num])
    if product > level:
      print("-1")
      break
  if product <= level:
    print(product)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
b=A[0]

if(A.count(0)!=0):
    print('0')
    exit()

for i in range(1,len(A)):
    b=b*A[i]
    if(10**18<b):

        print('-1')
        exit()
        
print(b)

Submission status: Accepted

Solution code:
n = int(input())
List = list(map(int, input().split()))
res = 1
if 0 in List:
    print(0)
    quit()
for x in List:
    res *= x
    if res > 10**18:
        print(-1)
        quit()
print(res)

Submission status: Accepted

Solution code:
import sys
n = int(input())
a =[ [int(c) for c in l.split()] for l in sys.stdin]
a =a[0]
m = 1

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

print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
check = 0
for i in a:
  if i == 0 :
    check = 1

if check == 1:
  print(0)
else :
  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()))
b = [i for i in a if i != 1]
ans = 1
if len(b) < 100:
    for i in range(len(b)):
        ans *= b[i]
else:
    ans = 10**18+1
if 0 in b:
    ans = 0
print(ans if ans <= 10**18 else '-1')

Submission status: Accepted

Solution code:
input_line1 = input()
N = int(input_line1)
input_line2 = input()
numbers = input_line2.split()
num_sum = 1
 
if '0' in numbers:
    print(0)

else:
    for i in range(N):
        num_sum *= int(numbers[i])
        if num_sum > 10 ** 18:
            num_sum = -1
            break
 
    print(num_sum)

Submission status: Accepted

Solution 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 > 1000000000000000000):
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

N = int(input())
cNum = collections.Counter(list(map(int, input().split())))
ans = 1
if cNum[0] != 0:
  print("0")
  exit()
for n in cNum.keys():
  ans *= n**cNum[n]
  if ans > 10**18:
    ans = -1
    break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
over = 10**18

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

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

Submission status: Accepted

Solution code:
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
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 10**18 < ans :
            ans = -1
            break
print(ans)

Submission status: Accepted

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

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

    if ans > 10 ** 18:
        break
ans = 0 if 0 in A else ans
ans = ans if ans <= 10 ** 18 else -1
print(ans)

Submission status: Accepted

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

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

    print(-1 if M > 1000000000000000000 else M)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 1
keta = 0
if 0 in A:
  print(0)
  exit()

for x in A:
  ans *= x
  keta += len(str(x))
  if ans > 1000000000000000000:
    print(-1)
    exit()

print(ans)

Submission status: Accepted

Solution code:
def product(list):
    num = 1

    if any([i == 0 for i in num_list]):
        print(0)
        return
     
    for i in num_list:
        num *= i
        if num > 1000000000000000000:
            num = -1
            break

    print(num)


N = int(input())

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

product(num_list)

Submission status: Accepted

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

if 0 in A:
  ans = 0
  N = 0
  
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 = list(map(int, input().strip().split()))[:n]
mx = 1000000000000000000
if 0 in lst:
    print(0)
else:
    cur = lst[0]
    for x in lst[1:]:
        cur = cur * x
        if cur > mx:
            cur = -1
            break
    print(cur)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ls = list(map(int, input().split()))
    ans = 1
    if 0 in ls:
        print(0)
        return
    for l in ls:
        ans *= l
        if (ans > 1000000000000000000):
            print(-1)
            return
    print(ans)
    return
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n = int(input())
num_list = list(map(int, input().split()))
num_list.sort()
a = 1;
for i in range(n) :
  a *= num_list[i]
  if a > 1000000000000000000 :
    print("-1")
    sys.exit()
    
print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())

i = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる

ans = 1
flg = 1

for a in i:
  if(a == 0):
    print(0)
    flg = 0

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

if(flg==1):
  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

    maks = 10**18
    mnozenje = 1
    for i in a:
        mnozenje *= i

        if mnozenje > maks:
            print(-1)
            return

    print(mnozenje)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import *
n = stdin.readline()
things = list(map(int, stdin.readline().split()))

if min(things) == 0:
    print(0)
    exit()
hue = things[0]
for i in range(1, len(things)):
    hue *= things[i]
    if hue > 10**18:
        print(-1)
        exit()
print(hue)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush


def solve():
    n = II()
    A = LI()
    th = 1_000_000_000_000_000_000
    ans = 1
    if 0 in A:
        print(0)
        return

    for a in A:
        ans *= a
        # print(a, ans)
        if ans > th:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

count=0
if 0 in s:
  print(0)
  count=1
else:
  a=1
  for i in s:
    a*=i
    if a>10**18:
      print(-1)
      break
if a<=10**18 and count!=1:
  print(a)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A =list(map(int, input().split(" ")))

if 0 in A:
    print(0)
    exit(0)
    
ret = 1
for a in A:
    ret *= a
    if len(str(ret)) >= 19 and ret != 10 ** 18:
        print(-1)
        exit(0)
    

if len(str(ret)) >= 19 and ret != 10**18:
    print(-1)
else:
    print(ret)

Submission status: Accepted

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

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

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

print(a)