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:
import math
import sys
N = int(input())
mylist = list(map(int, input().split()))
mylist.sort(reverse = True)
#print(mylist)
if mylist[-1] == 0:
    print(0)
    sys.exit()
else:
    myans = 1
    for m in mylist:
        myans *= m
        if myans > 10**18:
            print(-1)
            sys.exit()
    print(myans)

Submission status: Accepted

Solution code:
import sys

n= int(input())
a = list(map(int,input().split()))
ans = a[0]
ans_max = 10 ** 18

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

for i in range(1, n):
    ans *= a[i]
    if ans > ans_max:
        print("-1")
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
ans = 1;
flg = True
A.sort()
for i in range(N):
    ans*=A[i]
    if(ans>1000000000000000000):
        flg = False
        break
if(flg):
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
#import numpy as np
n = int(input())
a = list(map(int,input().split()))

thre = 10**18

a.sort(reverse=True)
#print(a)

flag = 0
tm = a[n-1]
if(tm==0):
  print(0)
else:
  tmp=a[0]
  for i in range(1,n):
    tmp*= a[i]
    if(tmp > thre):
      flag = 1
      break
  if(flag == 1):
    print(-1)
  else:
    print(tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

if any([i == 0 for i in a]):
    print('0')
else:
    for i in range(n):
        x = a[i]
        t = t * x
        if x == 0:
            break
        if t > 10**18:
            break

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

Submission status: Accepted

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

re = 1


for a in inp:
    re = re * a
    if re > (10**18):
        of = True
        re = -1
        break


for a in inp:
    if a == 0:
        re = 0


print(re)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(input())
A = list(map(int, stdin.readline().split()))
if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans = ans*a
        if ans > 10**18:
            break
    """from functools import reduce
    ans = reduce(lambda x,y:x*y,A)"""
    """import numpy as np
    A = np.array(A)
    ans = np.prod(A)"""
    if ans >10**18:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
li = sorted(list(map(int,input().split())), reverse = True)

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

Submission status: Accepted

Solution code:
num = int(input())
str2 = input().split(" ")
nums = [int(s) for s in str2]
nums.sort()

ans = 1

for i in range(len(nums)):
    ans = ans * nums[i]
    if(ans > 1000000000000000000):
        print(-1)
        quit()
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
INF = 10 **18
N= int(input())
# ans =1
A= list(map(int,input().split()))
# if 0 in A:
#     print(0)
# else:
def calc(A):
    if 0 in A:
        return 0
    ans = A.pop()
    for a in A:


        ans *= a
        if ans > INF:
            # print(-1)
            return -1
    return ans

# ans = np.prod(A)
# ans = -1 if ans > INF else ans
# hoge =[1]*(10 **5)
# hoge.append(10**18 +1)
# print(calc(hoge))
print(calc(A))

Submission status: Accepted

Solution code:
a = int(input())
b = input().split()
c = 1
for i in range(a):
    if int(b[i]) == 0:
        c = 0

if c == 1:
    for i in range(a):
        c = c*int(b[i])
        if c > 1000000000000000000:
            break

if c > 1000000000000000000:
    print(-1)
else:
    print(c)

Submission status: Accepted

Solution code:
A=input()
list1=input().split()
A=int(A)
Ans=1
#---------------------------

if "0" in list1:
    print("0")
    
else:
    for i in range(0,A):
        Ans=Ans*int(list1[i])    
        if Ans >10**18:
                print(-1)
                break
    if Ans <=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):
    ans *= A[i]
    if ans > 10**18:
      ans = -1
      break
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(_) for _ in input().split()]

if 0 in A:
    print(0)
else:
    now=1
    ok=True
    for a in A:
        now*=a;
        if now>1e18:
            ok=False
            break
    if ok:
        print(now)
    else:
        print(-1)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
INF = 10**18
ans = 1
if 0 in A:
    print(0)
    exit()

for a in A:
    ans *= a
    if ans > INF:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

for x in a:
  i *= x
  if i > 10 ** 18:
    break


if i > 10 ** 18:
  i = -1
print(i)

Submission status: Accepted

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

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 a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
res = 1
ls = input().split(' ')
list.sort(ls)
if int(ls[0]) == 0:
    print(0)
    exit()
for a in ls:
    res = res * int(a)
    if res > 1000000000000000000:
        print(-1)
        exit()
print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
if a[0] == 0:
  print(0)
  exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
v = input().split(' ')

prod = 1

v.sort()

for i in v:
  prod *= int(i)
  if int(prod) > int(1e18):
    prod = -1
    break
print(prod)

Submission status: Accepted

Solution code:
N = int(input())
A = []
A  = list(map(int,input().split()))	
if A.count(0)!=0:
    print("0")
    exit()
ans = 1
for i in A:
    ans = ans*i
    if ans > 1000000000000000000:
        print("-1")
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import functools
import operator

n=int(input())
a=list(map(int,input().split()))
b=0
r=1
if min(a)==0:
  print(0)
  exit()
for i in a:
  r*=i
  if r>10**18:
    print(-1)
    exit()
print(r)

Submission status: Accepted

Solution code:
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a = cino()
    l = cina()
    check = True
    suma = 1
    l.sort()
    if l[0]==0:
        print(0)
    else:
        for i in l:
            suma = suma*i
            if suma>1000000000000000000:
                check = False
                break
        if check:
            print(suma)
        else:
            print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

multi = 1

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
b = np.sqrt(a)

lim = 10**9
lim_1 = 10**18
ans_1 = np.prod(b)
ans = np.prod(a)

if ans_1 > lim:
  ans = -1
elif ans_1 < 0:
  ans = -1
    
if ans > lim_1:
  ans = -1
elif ans < 0:
  ans = -1
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input().split(' ')
s_i = [int(val) for val in s]
s_i.sort()
ans = 1
x = 1000000000000000000

for val in s_i:
    ans *= val
    if ans > x:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

lim = math.pow(10,18)

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]

    if x > 1000000000000000000:
        break

if x > 1000000000000000000:
    x = -1

if 0 in r:
    x = 0

print(math.floor(x))

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 = ans*i
		if ans > 1000000000000000000:
			break

if ans <= 1000000000000000000:
	print(ans)
else:
  	print(-1)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int,input().split()))
limit = 10**18
res = 1
i = 0
if 0 in nums:
    print(0)
    exit()
while i<n:
    res *= nums[i]
    i += 1
    if res > limit:
        res = -1
        break
print(res)

Submission status: Accepted

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

pro = 1

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

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

Submission status: Accepted

Solution code:
p=int(input())
k=list(map(int,input().split()))
if 0 in k:
    print(0)
else:
    t=k[0]
    for e in range(1,len(k)):
        t = t * k[e]
        if t > 10**18:
          break
    if t > 10**18:
        print(-1)
    else:
        print(t)

Submission status: Accepted

Solution code:
n = int(input())
A = map(int,input().split())
 
ans = 1
for num in A:
    ans*=num
    if (ans > 10**18):
        ans = -1
        break
if (0 in A):
    ans = 0;
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

i = 0
x = 1
while i < n:
    x = x * a[i]
    i += 1
    if x > 1000000000000000000:
        print(-1)
        exit()

print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# %%time
from numba import njit
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))


@njit
def f(A):
    ans = 1
    limit = 10**18
    if np.sum(A == 0) > 0:
        return 0
    elif np.sum(np.log10(A)) > 18:
        return -1
    for i in A:
        ans = ans*i
    return ans if ans<=limit else -1



print(int(f(A)))

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(len(A)):
        ans = ans * A[i]
        if ans > 10 ** 18:
            error = str(ans)
            ans = '-1'
            break
print(ans)

Submission status: Accepted

Solution code:
a=[input() for i in range(2)]

a_num=a[1]
a_num=a_num.split()
a_list=[int(n) for n in a_num]

a_mul=1

if 0 in a_list:
	print(0)

else:
	for i in a_list:
		a_mul*=i

		if a_mul>10**18:
			a_mul=-1
			break

	print(a_mul)

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
result = 1
if 0 in a_list:
  print(0)
else:
  for a in a_list:
    result = result *a
    if len(str(result)) >= 19:
      if result == 10**18:
        continue
      else:
        result = -1
        break
        
  print(result)

Submission status: Accepted

Solution code:
n = int(input())
list = [int(i) for i in input().split()]

ans = 1
flag = True
for i in range(n):
    ans *= list[i]
    if ans>10**18:
        flag = False
        ans = ans%(10**18)
    if list[i]==0:
        flag = True
        break

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

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
ans = 1
if '0' in a:
    ans = 0
else:
    for i in a:
        ans = ans*int(i)
        if ans > 1000000000000000000:
            print(-1)
            exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input_number = int(input())
int_list = list(map(int, input().split()))

check = 10 ** 18
ans = int_list[0]
for i in int_list[1:]:
    ans = ans * i

    if ans > check:
        ans = -1
        break

for i in int_list:
    if i == 0:
        ans = 0
        break

print(ans)

Submission status: Accepted

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

if min(As) == 0:
    print(0)
else:
    ans = 1
    for i in As:
        ans *= 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()))
lim = 10**18

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

  
ans = 1
A.sort(reverse = True)
for i in range(len(A)):
  ans = ans * A[i] 
  if ans > lim:
    print(-1)
    exit()

if ans > lim:
  print(-1)
else:
  print(ans)

Submission status: Accepted

Solution code:
n=int(input())
list=[int(i) for i in input().split()]
k=1
list.sort()
x=list[0]
while k<n:
  y=x*list[k]
  x=y
  if y<=1000000000000000000:
    k=k+1
  else:
    k=n+1
    y=-1
print(y)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
N, *A = map(int, open(0).read().split())

while len(A) > 1:
  n = len(A)
  if n & 1:
    A.append(1)
    n += 1
  L, R = A[:n//2], A[n//2:]
  A = [x * y for x, y in zip(L, R)]
x = A[0]
if x > 10 ** 18:
  x = -1
print(x)

Submission status: Accepted

Solution code:
LIMIT = 1000000000000000000

def main():
    N = int(input())  # 文字列または整数(一変数)
    a = list(map(int, input().split()))  # 整数のリスト
    answer = 1

    for i in range(N):
        answer *= a[i]
        if answer > LIMIT:
            if 0 in a[i:]:
                print(0)
                return
            else:
                print(-1)
            return

    print(answer)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
p=list(map(int, input().split()))
i=0
ans=1
flag=0
k=1e18
while(n>i):
	if(p[i]==0):
		flag=1
	i+=1
if(flag==1):
	print(0)
else:
	flag=0
	i=0			
	while(n>i):
		ans*=p[i]
		if(ans>k):
			flag=1
			break
		i+=1		
	if( flag==1):
		print(-1)
	else:
		print(ans)

Submission status: Accepted

Solution code:
n = int(input())
num = input()
num = num.split()
if '0' in num:
    print(0)
    exit()
ans = 1
MAXX = 1000000000000000000
for item in num:
    ans = ans * int(item)
    if ans > MAXX:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = input()
a = input()
a = a.split()
x = 0;
mul = 1;

for num in a:
    if(int(num) == 0):
    	mul = 0;
    	break;
    	
for num in a:
	mul *= int(num)
	if(mul > 1000000000000000000):
		mul = -1;
		break;
    
print(mul);

Submission status: Accepted

Solution code:
n = int(input())
arr = []
p = 1
c = 0
l = 0
a = list(map(int,input().strip().split()))[:n] 

for i in range(n):
    if a[i]==0:
        c = 1
    if p > 1000000000000000000:  
        l = 1
    else:    
        p *= a[i]
if c == 1:
    print(0)
elif l == 1 or p > 1000000000000000000 :
    print(-1)
else:
    print(p)

Submission status: Accepted

Solution code:
import sys

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

for val in a:
    if val == 0:
        print("0")
        exit(0)

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

print(ans)

Submission status: Accepted

Solution code:
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n= ii()
a= li()

ans=1
a.sort()
a.reverse()

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

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

Submission status: Accepted

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

    answer = 1
    maxNum = 10 ** 18

    if(0 in listCulcNum):
        print(0)
        return

    for culcNum in listCulcNum:
        answer = answer * culcNum

        if(answer > maxNum):
            answer = -1
            break

    print(answer)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math
import functools
import operator
N=int(input())
A = list(map(int, input().split()))
#AA=A.sort()
if A.count(0)>0:
    ans=0
elif N>30 and A.count(1)<10:
    ans=-1
    
else:
    ans=functools.reduce(operator.mul, A)
if ans>10**18 :
    ans=-1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from sys import stdin
    input = stdin.readline
    n = int(input())
    inlis = list(map(int, input().split()))
    if 0 in inlis:
        ans = 0
    else:
        ans = 1
        for i in inlis:
            ans *= i
            #print(ans)
            if ans > 10 ** 18:
                ans = -1
                break
    print(ans)
    
 
 
 
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
a=1
for i in sorted(l):
  a*=i
  if a>10**18: a=-1; break
print(a)

Submission status: Accepted

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

ans = 1
if 0 in A_list:
    ans = 0
else:
    for l in A_list:

        if ans > (10**18):
            ans = -1
            break
        else:
            ans *= l

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
sum = 1
keta = 0

numbers = input().split()
if not ("0" in numbers):
    for num in numbers:
        keta += len(num) - 1
        if keta > 19:
            print(-1)
            exit()
        sum *= int(num)
        if len(str(sum)) > 19:
            print(-1)
            exit()
        
    if len(str(sum)) == 19:
        if str(sum).count("1") == 1 and str(sum).count("0") == 18:
            pass
        else:
            print(-1)
            exit()
else:
    print(0)
    exit()
print(sum)

Submission status: Accepted

Solution code:

import sys
n = int(input())
aa = input()
a = aa.split()

for i in range(n):
    if(int(a[i]) == 0):
        print(0)
        sys.exit()

result = 1
for i in range(n):
    result *= int(a[i])
    if(result > 1000000000000000000):
        print(-1)
        sys.exit()

print(result)

Submission status: Accepted

Solution code:
n = int(input())
temparr = input()
temparr = temparr.split()
flag = 0 

arr = []
first = 0 
totallen = 0 
arr =[]
arr1 = []
for i in temparr:
    arr1.append(int(i))
arr1 = sorted(arr1)
for i in arr1:
    if i == 0 :
        flag = 1 
        break 
    if i == 1 :
        continue 
    
    if first == 0 :
        totallen += len(str(i))
        first = 1 
    else:
        totallen += len(str(i)) - 1 
    if totallen > 19:
        flag = 2
        break
    arr.append(i)
    
    
if flag == 2:
    print("-1")
elif flag == 1 :
    print("0")
else:
    ans = 1
    arr = sorted(arr)
    arr = arr[::-1]
    for i in arr:
        ans *= i 
        if ans > 1000000000000000000:
            flag = 1 
            break 
    if flag == 0 :
        print(ans)
    else:
        print(-1)

Submission status: Accepted

Solution code:
n=int(input())

a = list(input().split())
a = [int(i) for i in a]
ans=1


if 0 in a:
  pass

elif len(a) % 2 == 1: 
  for i in range(1, int(len(a)/2)+2):
    #print(ans)
    if ans > 10**18 or ans == 0:
      break
    if i == int(len(a)/2) + 1:
      ans = ans*a[i-1]
    else:
      ans = ans*a[i-1]*a[-1*i]
    
else:
  for i in range(0, int(len(a)/2)):
    if ans > 10**18 or ans == 0:
      break
    ans = ans*a[i]*a[-1 - i]
    

if ans > 10**18:
  print('-1')
elif 0 in a:
  print(0)
else:
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from decimal import *
 
n = int(input())
a = list(map(Decimal, input().split()))
b = np.array(a)
temp = 1
 
if a.count(0) >0:
  print(0)
  exit()
 
for i in range(n):
  temp = b[i] * temp
  if temp > 10**18 or temp < 0:
    print('-1')
    exit()
 
print(temp)

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 > 1000000000000000000:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
import collections
import sys

N=int(input())
A=list(map(int, input().split()))
A_dict=collections.Counter(A)
ANS=1
if 0 in A_dict.keys():
    print("0")
    sys.exit()
    
for key, value in A_dict.items():
    ANS=ANS*(key**value)
    if ANS>10**18:
        print(-1)
        sys.exit()

print(ANS)

Submission status: Accepted

Solution code:
import sys
def main():
    N = int(input())
    A_list = [int(_) for _ in input().split()]
    ans = 1
    
    if 0 in A_list:
        out = 0
        print(out)
        sys.exit()
    
    for i in range(N):
        ans = ans * A_list[i]
        
        if ans>1000000000000000000:
            ans = -1
            break
    out = ans
    print(out)

main()

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
target = 1
List = list(map(int,input().split()))
if 0 in List:
  print(0)
  exit()
for i in range(len(List)):
  target*=List[i]
  if target>10**18 :
    print(-1)
    exit()
print(target)

Submission status: Accepted

Solution code:
n=int(input())
a=list(input().split())
ans=1
f=0
i=0
while(i<n):
    if f==0:
        ans=ans*int(a[i])
    if f==0 and ans>1000000000000000000:
        f=1
    if int(a[i])==0:
        print(0)
        exit()
    i+=1
if f==1:
    print(-1)
    exit()
print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
ans = 1
flag = True
if 0 in a:
    print(0)
    sys.exit()

for i in a:
    ans *= i
    if ans > 1000000000000000000:
        flag = False
        break

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

Submission status: Accepted

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

A.sort()
ans = 1
flag=False
for a in A:
  ans *= a
  if ans > 1e18:
    flag=True
    break
if flag:
  print(-1)
else:
  print(ans)

Submission status: Accepted

Solution code:

import math
def num():
    return map(int , input().split())
def nu():
    return int(input())
def li():
    return input().split()
def sli():
    return list(map(str, input().split()))
def lli ():
    return list (map(int, input ().split ()))
def fli():
    return [float(x) for x in input().split()]

n = nu()
a = lli()

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

Submission status: Accepted

Solution code:
import math
N=int(input())
risuto=list(map(int,input().split()))
ans=1
kari=0
if 0 in risuto:
    print(0)
else:
    for j in range(N):
        kari+=math.log10(risuto[j])

    if kari<18:
        for i in range(N):
            ans*=risuto[i]
        print(ans) 
    elif kari==18:
        for i in range(N):
            ans*=risuto[i]
        if ans>10**18:
            print(-1)
        else:
            print(ans)
    else:
        print(-1)

Submission status: Accepted

Solution code:
n = input()
a = list(map(int,input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
for ai in a:
    ans = ans * ai
    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:
    print (0)
else:
    for i in a:
        ans *= i
        if 1000000000000000000 < ans:
            ans = -1
            break
    print (ans)

Submission status: Accepted

Solution code:
import sys
N=int(sys.stdin.readline())
values = []
res = 1
values=sys.stdin.readline().split()
for v in values:
    if int(v) == 0:
        print(0)
        exit(0)

for v in values:
    res *= int(v)
    if res > 1000000000000000000:
        print(-1)
        exit(0)
print(res)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
n = input()
tmp = input().split(" ")
l = sorted([int(e) for e in tmp])
def solve():
    res = 1
    for e in l:
        res = e*res
        if res > 1e+18:
            print("-1")
            return
    print(res)
solve()

Submission status: Accepted

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

import sys
if l.count(0) > 0:
    print(0)
    sys.exit()

ans = 1
for x in l:

    ans = ans * x

    if ans > 1000000000000000000:
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = list(map(str,input().split()))
for i in range(N):
    if A[i] == '0':
        print('0')
        sys.exit()

ans = 1
for i in range(N):
    ans *= int(A[i])
    if ans > 1000000000000000000:
        print(-1)
        sys.exit()

print(ans)