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:
ans = 1
n = input()
a = list(map(int,input().split()))
if 0 in a:
	ans = 0
for i in a:
	ans = ans * i
	if ans > 10**18:
		ans = -1
		break
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, stdout
from collections import defaultdict

def main():
    n = int(stdin.readline())
    a = list(map(int,stdin.readline().split()))
    f = 1
    flag=0
    a = sorted(a)
    for i in range(n):
        f = f*a[i]
        if f>10**18:
            flag=1
            break
    if flag:
        print("-1")
    else:
        print(f)

main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
lim = 10**18
if A[-1] == 0:
    print("0")
    exit(0)
ans = 1
for a in A:
    ans *= a
    if (ans > lim):
        print("-1")
        exit(0)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def fun(A):
    for i in A:
        if i == 0:
            return 0
    ans = 1
    for i in A:
        ans = ans*i
        if(ans > 1000000000000000000):
            return -1
    return ans

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# このファイルはutf-8で書かれているため、日本語を書く場合は上の記述が必要

count_num = int( input())
text = input()

num_data = text.split(' ')

ans = 1
for i in num_data:
        if i == '0':
                ans = 0
                break

if ans == 1:
        for i in num_data:
                ans = ans * int(i)
                if ans > 1000000000000000000:
                        ans = -1
                        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
 
List = [int(i) for i in input().split()]
lst = sorted(List, reverse=True)
if lst[-1] == 0:
  print(0)
  exit()
total = 1
for i in lst:
  total = total*i
  if total > 1000000000000000000:
    print(-1)
    exit()
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
arr=input()
prod=1
k=1;
l=list(map(int,arr.split(' ')))
#l.sort()

for x in l:
    if(x==0):
        k=0
        break

if(k==0):
    print(0)
else:
    for x in l:
        prod*=x
        if(prod>1000000000000000000):
            prod=-1
            break
    print(prod)

Submission status: Accepted

Solution code:
import sys
N = int(input().strip())
array = list(map(int, input().strip().split()))
ans = 1
for i in array:
  if i == 0:
    print(0)
    sys.exit()
for i in array:
  ans *= i
  if ans > 1e18:
    print(-1)
    sys.exit()
if ans > 1e18:
  print(-1)
else :
  print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
z,flag=1,0
m=10**18
mi=min(l)
if mi==0:
  print(0)
else:
  for i in l:
    z*=i  
    if z>m:
      flag=1
      break
  if flag==1:
    print(-1)
  else:
    print(z)

Submission status: Accepted

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

ans = 1

flag = True
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        flag = False
        break

if flag:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
s=1
if 0 in a:
    print(0)
    exit()
for i in a:
    s*=i
    if  s > 1e18:
        print(-1)
        exit()
print(s)

Submission status: Accepted

Solution code:
how_many = input()
a = []
a = list(map(int, input().split()))
st = set(a)

c = 0
for i in a:
    p = str(i)
    c += len(p)
if (0 in st):
    print(0)
    quit()

max = 1
for i in a:
    max = max * i
    if(1000000000000000000 < max):
        print('-1')
        quit()
    
print(max)

Submission status: Accepted

Solution code:

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

  if result <= 10**18:
    print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

if 0 in A:
    print(0)
    sys.exit()
else:
    for i in A:
        mult *= i
        if mult > 10**18:
            print('-1')
            sys.exit()

print(mult)

Submission status: Accepted

Solution code:
import sys
n=int(input())
list=input().split(" ")
x=1

if "0" in list:
  print(0)
  sys.exit()
for i in list:
  x*=int(i)
  if x>1e18:
    print(-1)
    sys.exit()
print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
se = 1
c = True
for n in range(N):
  se *= A[n]
  if se >  10**18:
    c = False
    break
for n in range(N):
  if A[n] == 0:
    se = 0
    c = True
if c:
  print(se)
else:
  print("-1")

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from math import log10

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

mul = 1

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)
res = 1
flag0 = False
if 0 in a_list:
  res = 0
else:
  for i in range(n):
    res = a_list[i]*res
    if res > 1000000000000000000:
      res = -1
      break

print(res)

Submission status: Accepted

Solution code:
MAX = 10**18
def main():
    N = map(int,input())
    A = list(map(int,input().split(' ')))
    ans = 1
    if 0 in A:
        print(0)
        exit(0)
    for a in A:
        ans *= a
        if ans > MAX:
            print(-1)
            exit(0)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
max_number = 10 ** 18
len_number = int(input())
number_list = list(map(int, input().split()))

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

number_list.sort(reverse=True)

is_over_max = False
answer = 1
for n in number_list:
    answer *= n
    if max_number < answer:
        is_over_max = True
        break

if is_over_max:
    print(-1)
else:
    print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

ans=1

for i in range(N):
    if A[i]==0:
        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()))

s=1
if min(A) == 0:
    s = 0
    print(s)
elif max(A) > 10**18:
    s = -1
    print(s)
else:
    for i in range(N):
        s = s*A[i]
        if s > 10**18:
            s = -1
            print('-1')
            break
    if s != -1:
        print(s)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int, input().split()))
val=0
ans=1
num=10**18
if 0 in l:
    print(0)
else:
    for i in l:
        l1=len(list(str(ans)))
        l2=len(list(str(i)))
        if l1+l2>20:
            val=1
            break
        ans=ans*i
        if ans>num:
            val=1
            break
    if val==1:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))
b = 1
for i in range(N):
    if b > 0:
        b *= a[i]
    if a[i] == 0:
        b = 0
    if b > 10**18:
        b = -1

print(b, end='')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
alis=sorted(list(map(int,input().split())))
p=alis[0]
if p==0:
  print(0)
  exit()
bre=False
for i in range(1,n):
  p*=alis[i]
  
  
  if len(list(str(p)))>18:
    bre=True
    break


if bre:
  sa=list(map(int,list(str(p))))
  if sum(sa)!=1:print(-1)
  else:print(p)
else:print(p)

Submission status: Accepted

Solution code:
limit = 1E18
n = int(input())
total = 1
# A string
line = str(input())

if line.startswith("0 ") or " 0" in line:
    print(0)
    exit()

for i in line.split():
    x = int(i)
    total *= x
    if total > limit:
        print(-1)
        exit()

print(-1 if total > limit else total)

Submission status: Accepted

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

    ans = ans * i
    if ans == 0:
        break
    if ans > 1000000000000000000:
        ans = -1
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().strip().split()))
a.sort()
# print(a)
ans=1;
for i in a:
    ans*=i
    if(ans>1000000000000000000):
        break
if(ans>1000000000000000000):
    print(-1)
if(ans<=1000000000000000000):
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
A_list.sort(reverse=True)
n = 1
for i in A_list:
  if A_list[-1] == 0:
    print(0)
    break
  n = n * i
  if n > 1000000000000000000:
    print(-1)
    break
else:
  print(n)

Submission status: Accepted

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

Submission status: Accepted

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

limit = pow(10, 18)

ans = 1

if 0 in nums:
    ans = 0
else:
    for e in nums:
        if ans > limit / e:
            ans = -1
            break
        else:
            ans *= e

if ans > limit:
    ans = -1

print(int(ans))

Submission status: Accepted

Solution code:
import math
 
A = 1
N = int(input())
array = input().split()
flag = True
for i in range(N):
	A = (A * int(array[i]))
	if A > math.pow(10,18):
		flag = False
		break

if flag:
  print(A)
else:
  if '0' in array:
    print(0)
  else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i
        if ans >= LIMIT:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

sum0 = str_list[0]

for n in range(0,N):
    if str_list[n] == 0:
        sum0 = 0

for n in range(1,N):
    if sum0 == 0:
        break
    sum0 = sum0 * str_list[n]
    if sum0 > 10 ** 18:
        sum0 = -1
        break

print(sum0)

Submission status: Accepted

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

P = 1
flag = 0

for i in range(N):
    P = P * newA[i]
    if P == 0:
        print(P)
        flag = 1
        break
    elif P > 1e18:
        print(-1)
        flag = 1
        break
        
if flag == 0:
    print(P)

Submission status: Accepted

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

pro=1
List.sort()
for i in range(n):
    pro *=List[i]
    if pro > 10**18 :
        print("-1")
        exit()

print(pro)

Submission status: Accepted

Solution code:
n = int(input())
lt = [int(x) for x in input().split()]
ans =0
if 0 in lt:
    ans=0
else:
    ans = 1 
    for x in lt:
        ans*=x 
        if ans > 10**18:
            ans="-1"
            break 
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split(" ")

sum = 1
for i in a:
  sum = sum * int(i)
  if sum > 1000000000000000000:
    break

if "0" in a:
  print(0)
elif sum > 1000000000000000000:
  print(-1)
else:
  print(sum)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
A.sort(reverse=True)
result=1
if 0 in A:
    print(0)

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

Submission status: Accepted

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

y = 1
q = 1
z = 1
for i in range(0, n):
  if a[i] == 0:
    q = 0

for i in range(0, n):
  z = z * a[i]
  if z > 1000000000000000000:
    y = -1
    break
 
if q == 0:
  print(0)
elif z <= 1000000000000000000:
  print(z)
else:
  print("-1")

Submission status: Accepted

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

sum = 1
if 0 in nums:
    print(0)
else:
    for num in nums:
        sum *= num
        if sum > 10 ** 18:
            print(-1)
            break
    else:
        print(sum)

Submission status: Accepted

Solution code:
def multiplyList(myList) : 
      
    # Multiply elements one by one 
    result = 1
    for x in myList: 
        result = result * x
        if result == 0:
             return 0 
        if result > 10**18:
             return -1
    return result
 
n = int(input())
l = list(map(int, input().split()))
l.sort()
res = multiplyList(l)
print(res)

Submission status: Accepted

Solution code:
import sys

L = []
for l in sys.stdin:
  L.append(l) 
A = list(map(int, L[1].split()))

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

Submission status: Accepted

Solution code:
n=int(input())

a=input().split()
ans=1
if '0' in a:
    print(0)
else:   
    for i in range(n):
        k=int(a[i])
        if ans*k>1e18:
            print(-1)
            break
        ans*=k
        if i==n-1:
            print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
mod = 1000000007

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

ans = 1
flag = True
for i in range(len(a)):
    if a[i] == 0:
        print(0)
        exit()

for i in range(n):
    ans *= a[i]
    if ans > 1e+18:
        flag = False
        break;

if(flag):
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(ls):
    n = len(ls)
    p = 1
    for i in range(n):
        if ls[i] == 0:
            return 0
    for i in range(n):
        p *= ls[i]
        if p > 1000000000000000000:
            return -1
    return p


n = int(input())
ls = list(map(int, input().split()))
print(solve(ls))

Submission status: Accepted

Solution code:
N = int(input())
temp = input()
temp = temp.split(" ")
arr = []
prod=1
for i in range(N):
    arr.append(int(temp[i]))
arr.sort()
flag=0    
for i in range(N):
    prod = prod*arr[i]
    if prod>1000000000000000000:
        flag=1
        break
if flag==0:
    print(prod)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

if a == 1:
  print(0)
elif a == 2:
  print(-1)
else:
  b = 0
  ans = 1
  for i in range(N):
    ans = ans*A[i]
    if ans > 10**18:
      b = 1
      break

  if b == 0:
    print(ans)
  else:
    print(-1)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(str,input().split()))
ans = 1
b = Counter(a)
b0 = 0
b1 = 0

if '0' in a:
    b0 = b['0']
if '1' in a:
    b1 = b['1']
more2 = n-b0-b1
if b0 >0:
    print(0)
elif more2 >=60:
    print(-1)
else:
    for i in range(n):
        ans *= int(a[i])
    if ans > 10**18:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split(" ")]
res=1
xx=10**18
f=0
a.sort()
for i in a:
    res*=i
    if res>xx:
        f=1
        print(-1)
        break

if f==0:
    print(res)

Submission status: Accepted

Solution code:
import sys

INF = 10e17
N = int(input())
A = list(map(int, sys.stdin.readline().rstrip().split()))
ans = 1
for a in A:
    if a == 0:
        print(0)
        sys.exit()
for a in A:
    ans = ans*a
    if ans > INF:
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
import collections
import sys


def pow2(x, n):
    ret = 1
    while (n > 0):
        if (n & 1):
            ret *= x
        x *= x
        n = n >> 1
    return ret


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

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

c = collections.Counter(a)

l = sorted(list(c.keys()))

ans = 1
for num in l:
    ans *= pow2(num, c[num])
    if ans > 1000000000000000000:
        print(-1)
        sys.exit(0)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
if A[-1] == 0:
    print(0)
    exit()

ans = A[0]
lim = 10**18
for a in A[1:]:
    ans *= a
    if ans > lim:
        print('-1')
        exit()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(N):
    ans = ans * An[i]
    if ans > 10**18:
        flag = False
        break
    else:
        continue
    
if flag:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
import sys
n = int(input())
l = list(map(int,input().split()))
##print(n)
##print(l)
x = l[0]
if 0 in l:
  print(0)
  sys.exit()
for i in range(1,n):
  ##print(i)
  ##print(l[i])
  x *= l[i]
  if x >+ 1000000000000000000:
    ##print(i)
    ##print(x)
    print(-1)
    sys.exit()
print(x)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
intNum = int(input())
numList = [int(x) for x in input().split()]

total = 1
judgeNum = 10 ** 18

if 0 in numList:
    total = 0
else:
    for num in numList:
        total *= num

        if total > judgeNum:
            total = -1
            break

print(total)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().rstrip().rsplit()))
A_dict = {}

for val in A:
    A_dict[val] = A_dict.get(val, 0) + 1

limit = 10**18
ans = 1

if A_dict.get(0, 0) > 0:
    ans = 0
else:
    for val in A_dict:
        ans *= val ** A_dict[val]

        if ans > limit:
            ans = -1
            break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
if a[n-1] == 0:
    print("0")
    exit()
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()))
if 0 in A:
    print(0)
else:
    bound = 10 ** 18
    ans = 1
    for a in A:
        ans = ans * a
        if ans > bound:
            ans = -1
            break
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if A.count(0) > 0:
    print(0)
    exit()

ans = 1
for a in A:
    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()))
ans = 1
if 0 in a:
    ans = 0
else:
    a.sort(reverse=True)
    for i in a:
        if(i==0):
            ans = 0;break
        if ans>(10**18):
            ans = -1;break
        ans = ans*i
print(-1 if ans>(10**18) else ans)

Submission status: Accepted

Solution code:
n = int(input())

s =list(map(int, input().split()))
s.sort()
a = 1
for i in range(n):
    a = a * s[i]
    if a > 1000000000000000000:
        print('-1')
        exit()
    else:
        if a == 0:
            print('0')
            exit()

print(a)

Submission status: Accepted

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

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

ans = 1000000000000000000
prod = 1
f = 0
f2 = 0

for i in range(n):
    if a[i] == 0:
        f = 1
        break

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

    if prod > ans:
        f2 = 1
        break

if f == 1:
    print(0)

else:
    if f2 == 1:
        print(-1)
    else:
        print(prod)

Submission status: Accepted

Solution code:
n=int(input())
mx=10**18
z=1

a=[int(i) for i in input().split()]
for i in a:
    if i==0:
        print(0)
        quit()

for i in a:
    z*=i
    if z>mx:    z=-1
    if z==-1:   break

if z>mx or z<0   : z=-1
print(z)

Submission status: Accepted

Solution code:
n = int(input())

MAX_NUM = 10 ** 18

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

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

ans = 1
for num in nums:
  ans *= num
  if ans > MAX_NUM:
    print(-1)
    exit()

print(ans)

Submission status: Accepted

Solution code:
num = int(input())
h = input().split()
hi = sorted(h)
#print(hi)

#print(num)
#print(h)
ans = 0
 
for i in range(num):
    if i == 0:
        ans = ans + int(hi[i])
    else:
        ans = ans * int(hi[i])
        if ans > 10**18 or ans == 0:
            break
if ans <= 10**18:
    print(ans)
else:
    print("-1")

Submission status: Accepted

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

print(s)

Submission status: Accepted

Solution code:

n = int(input())
l = list(map(int, input().split()))
res = 1
flag = 0
for i in l:
	res *= i
	if i == 0:
		flag = 0
		res = 0
	if(res > 1000000000000000000):
		flag = 1
		break
for i in l:
	if (i == 0):
		flag = 0
		res = 0
if flag == 1:
	print('-1')
else : print(res)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def multiple(nums):
    result_log = 0
    result = 1
    if (np.any(np.array(a) == 0)): return 0

    for a_ in a:
        result_log += np.log10(a_)
        if (result_log > 18.0):
            return -1
        result *= a_
        if (result > 10**18):
            return -1
    return result

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_s = sorted(a)
    res = 1
    for i in a_s:
        res *= i
        if res == 0:
            print(0)
            break
        if res > 10 ** 18:
            print(-1)
            break
    if res > 0 and res <= 10 ** 18:
        print(res)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())


n = I()
a = LI()
ans = a[0]
if 0 in a:
    print(0)
    sys.exit()

for ai in a[1:]:
    ans *= ai
    if ans > 10 ** 18:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

prod = 1
frg_overflow = False

if 0 in a:
  print(0)
else:
  for i in range(n):
    if prod <= 10**18:
      prod = prod * a[i]
    else:
      frg_overflow = True
  if frg_overflow == True:
    print(-1)
  elif prod > 10**18:
    print(-1)
  else:
    print(prod)

Submission status: Accepted

Solution code:
def main(n, a):
  a = list(a)
  for x in a:
    if(x == 0):
      print(0)
      return
   
  ans = a[0]
  for i in range(1, n):
    ans = ans * a[i]
    if(ans > 1000000000000000000):
      print(-1)
      return
  print(ans)
 
if(__name__ == '__main__'):
  n = int(input())
  a = map(int, input().split())
  main(n, a)

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
    n = int(input())
    a = list(map(int, input().split()))

    if 0 in a: return 0
    l = Counter(a)
    ans = 1
    for i,j in l.items():
        ans *= i**j
        if ans > int(1e18):
            return -1

    return ans
    

print(solve())

Submission status: Accepted

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

ans = 1

for a in li:
  if a == 0:
    print(0)
    exit()

for a in li:
  ans = ans * a
  if ans > 1000000000000000000:
    print(-1)
    exit()
  
print(ans)