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:
from sys import stdin
MAX = 10**18

def main():
    line_count = 0

    for line in stdin:
        line_count += 1
        factors_str = line.split()
        if line_count == 2:
            break

    factors = [int(factor) for factor in factors_str]
    
    if 0 in factors:
        print(0)
        return

    product = 1
    for factor in factors:
        product *= factor
        if product > MAX:
            print(-1)
            return

    print(product)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = [int(i) for i in input().split()]
ans = 1
if 0 in a:
    print(0)
    sys.exit()
for i in a:
    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()))
p = 10**18
a.sort()
#print(a)
if 0 in a:
    print(0)
    exit()

a.reverse()
#print(a)
ans = 1
for i in a:
    ans *= i
    #print(ans)
    if ans > p:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
 
N = int(input())
x_list = list(map(int, input().split()))
 
result = 1
if 0 in x_list:
  print(0)
  exit()
for x in x_list:
  result *= x
  if result > 1e18:
    print(-1)
    exit()
print(result)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    exit()
a = sorted(a, reverse=True)
res = a[0]
for ai in a[1:]:
    res *= ai
    if res > 10**18:
        print(-1)
        exit()
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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>10**18:
        ans=-1
        break 
for i in A_list:
    if i==0:
        ans=0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p=int(input())
ans=1
ar=list(map(int,input().split()))
if 0 in ar:ans=0
else:
    for i in range(p):
        if ans<1e18:ans*=ar[i]
        else:ans=-1;break
if ans>1e18:ans=-1
print(ans,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 i in a:
    ans *= i
    if ans > 10 ** 18:
        print("-1")
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

FLAG = True
if(min(A) == 0):
    prod = 0
else:
    prod = 1
    for a in A:
        prod *= a
        if(prod > 1000000000000000000):
            print(-1)
            FLAG = not FLAG
            break

if FLAG:
    print(prod)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
a = [int(i) for i in input().split()]
x = 1
if 0 in a:
    print(0)
    sys.exit()

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

Submission status: Accepted

Solution code:
n = input()
lista = list(map(int,input().split()))
r = 1

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

Submission status: Accepted

Solution code:
def main():
# スペース区切りの整数の入力
	N, *d = map(int, open(0).read().split())

	if 0 in d:
  		print(0)
  		return

	A = 1
	for O in d:
		A *= O
		#print(O)
		if A > 1000000000000000000:
			print(-1)
			return

	print(A)

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import functools
n = int(input())
arr = [int(a) for a in input().split()]
m = 10 ** 18

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

Submission status: Accepted

Solution code:
th = 10**18

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

res = 1

for v in A:
    res *= v
    if res > th:
        print(-1)
        quit()
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main ():
  count = int(input())
  c = list(map(int,input().split()))

  if 0 in c:
    print(0)
    return

  result = 1
  for a in c:
    result *= a
    if result > 1000000000000000000:
      print(-1)
      return

  print(result)

main()

Submission status: Accepted

Solution code:
def main():
  
	n = int(input())
	a = list(map(int,input().split()))
	uppest = pow(10 , 18)

	ans = 1

	if 0 in a:
  		print (0)
  		return

	for s in a:
	  	ans *= s
  		if ans > uppest:
    			print(-1)
    			return
  
	print(ans)

main()

Submission status: Accepted

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

ans = 1

import sys

if 0 in A:
  print(0)
  sys.exit()
  
for a in A:
  ans *= a
  if ans > pow(10, 18):
      print(-1)
      sys.exit()

print(ans)

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int, input().split()))
sum = 1
flag = 1
upper = pow(10, 18)
for num in nums:
  if flag == 1:
    sum = sum * num
    if sum > upper:
      flag = 2
  if num == 0:
    flag = 0
    break
if flag == 2:
  print(-1)
else:
  print(sum * flag)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int, input().split()))
sum = 1
flag = 1
upper = pow(10, 18)
for num in nums:
  if num == 0:
    sum = 0
    flag = 1
    break
  if flag == 1:
    sum = sum * num
    if sum > upper:
      flag = 2

if flag == 1:
  print(sum)
elif flag == 2:
  print(-1)

Submission status: Accepted

Solution code:
n = int(input())
lists = list(map(int, input().split()))
number = 1
if 0 in lists:
  number = 0
else:
  for j in lists:
    number = number * j
    if number > 10 ** 18:
      number = -1
      break
print(str(number))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def multiply(arr):
    ans = 1
    if 0 in arr:
        return 0
    for i in arr:
        ans *= i
        if ans > 1000000000000000000:
            return -1
    return ans
n = int(input())
nums = list(map(int, input().split(' ')))
print(multiply(nums))

Submission status: Accepted

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

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

Ans = 1
for i in range(0,len(A)):
    Ans *= A[i]
    if Ans > 10**18:
        print(-1)
        exit()
    else:
        continue
print(Ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
if(A[-1] == 0):
  print(0)
else:
  p = 1
  for An in A:
    p *= An
    if(p > 10 ** 18):
      print(-1)
      sys.exit()
  print(p)

Submission status: Accepted

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

Submission status: Accepted

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

P = 1
c = 0

for c in range(N):
  if P * A[c] <= 10**18:
    P *= A[c]
  else:
    P = -1
    break
print(P)

Submission status: Accepted

Solution code:
import sys
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
n=ii1()
arr=iia()
max=10**18
res,flag=1,0
if 0 in arr:
    print(0)
else:
    for i in range(n):
        res*=arr[i]
        if res>max:
            flag=1
            break
    if flag==1:
        print(-1)
    else:
        print(res)

Submission status: Accepted

Solution code:
N=int(input())

A=sorted([int(x) for x in input().split()],reverse=True)
if A[-1]==0:
  print(0)
else:
  m=1
  for a in A:
    m*=a
    if m>10**18:
      break
  print(m if m<=10**18 else -1)

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return

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

    print(prod)

main()

Submission status: Accepted

Solution code:
N = int(input())
num = sorted([int(e) for e in input().split(" ")])
ans = 1
for a in num:
    ans *= a
    if(ans > 10 ** 18):
        print(-1)
        break
    elif(ans == 0):
        print(0)
        break
else:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
num = sorted([int(e) for e in input().split(" ")])
lim = 10 ** 18
i = -1
ans = 1
for a in num:
    ans *= a
    if(ans > lim):
        print(-1)
        break
    elif(ans == 0):
        print(0)
        break
else:
    print(ans)

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()
prod = 1
for i in range(n):
  prod *= a[i]
  if prod > 10 ** 18:
    print(-1)
    exit()
print(prod)

Submission status: Accepted

Solution code:
# coding: utf-8

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

if 0 in numlist:
    ans = 0
else:
    for i in numlist:
        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()))

num = 1
if 0 in a:
  num = 0
  
else:
  for k in range(n):
      num *= a[k]
      if num > 10**18:
        num = "-1"
        break

print(num)

Submission status: Accepted

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

if 0 in x: ans=0

for i in x:
    ans*=i
    if ans > 1000000000000000000:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(len(a)):
    c = c * a[i]
    if c > pow(10,18):
        print(-1)
        exit(0)

print(c)

Submission status: Accepted

Solution code:
N = int(input())

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

out_range = 10**18

ans=1
if  0 in P:
    print(0)
    exit()

for i in range(N):
    tmp = P[i]
    ans *= tmp
    if  ans > out_range:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(A):
    if 0 in A:
        return 0

    product = 1

    for a in A:
        product *= a

        if product > 10 ** 18:
            return -1

    return product


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

print(solve(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
int_list = list(map(int, input().split()))
max_num = 10**18
ans = 1

if 0 in int_list:
   print(0)
   exit()
 
for i in int_list:
   ans *= i
   if ans > max_num:
       print(-1)
       break
else:
   print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split(" ")))
ans=1
POW=pow(10,18)
check=False
answer=1
for i in range(n):
  ans*=A[i]
  if ans>POW:
    ans=0
    check=True
    answer=-1
  if A[i]==0:
    answer=0
if answer<1:
  print(answer)
else:
  print(ans)

Submission status: Accepted

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

	if 0 in A:
		print(0)
		return 

	prod = 1
	for x in A:
		prod = prod*x
		if prod > 1000000000000000000:
			print(-1)
			return
	print(prod)

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
t = int(input())
list_v = list(map(int,input().split()))
 
res = 1
if 0 in list_v:
  res = 0
else:
  for v in list_v:
    res *= v
    if res > 10**18:
      res = -1
      break
print(res)

Submission status: Accepted

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

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

a.sort(reverse=True)
ans = 1

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 = list(map(int,input().split()))
a.sort()
ans = 1

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 = list(map(int,input().split()))
mult = 1
 
if 0 in A:
  mult = 0
  
for i in range(N):
  mult *= A[i]
  if mult > 1e18:
    print(-1)
    break

if mult <= 1e18:
  print(mult)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(kotae)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np
 
n = int(input())
numlist = list(map(int, input().split()))
ans = 1;

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

Submission status: Accepted

Solution code:
N=int(input())
numlist=list(map(int,input().split()))
result=1
if 0 in numlist:
    print(0)
else:
    for x in numlist:
        result=result*x
        if result>10**18:
            break
    if result<=10**18:
        print(result)
    else:
        print(-1)

Submission status: Accepted

Solution code:
tenzyou=10**18
input()
A=[int(i) for i in input().split()]
if 0 in A:
  print(0)
  exit()
sortedA=sorted(A)[::-1]
multi = 1
for a in A:
  multi *= a
  if multi > tenzyou:
    print(-1)
    exit()

print(multi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n=int(input())
a=[int(x) for x in input().split()]
a_log=[]
if 0 not in a:
  for i in a:
    i_log=math.log10(i)
    a_log.append(i_log)
  
  if sum(a_log)>18:
    print("-1")
  else:
    for i in range(n-1):
  	  a[i+1]*=a[i]
    if a[n-1]>10**18:
      print("-1")
    else:
      print(a[n-1])
else:
  print("0")

Submission status: Accepted

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

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

main()

Submission status: Accepted

Solution code:
a=int(input())
x=list(map(int, input().split()))
ans=1
x.sort()
for i in range(a):

	if x[i]!=1 and x[i]!=0:
		ans=ans*x[i]
	if ans>10**18:
		break
	if x[i]==0:
		ans=0
		break
if ans>10**18:
	print(-1)
else:
	print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1

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

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

Submission status: Accepted

Solution code:
n = input()
l = map(int, raw_input().split())
ans = 1
for i in l:
    if i == 0:
        ans = 0
if (ans != 0):
    for i in l:
        if (ans * i) <= 1e18:
            ans = ans * i
        else:
            ans = -1
            break
print(ans)

Submission status: Accepted

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

res = 1

l.sort()

for i in l:
    res *= i
    if res > 10**18:
        res = -1
        break

print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = 1
max = pow(10, 18)

if 0 in a:
    c = 0
else:
    for i in a:
        c = c * i
        if max < c:
            c = -1
            break
print(c)

Submission status: Accepted

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


def main():
  if 0 in n:
    print(0)
    return
  p = 1
  for v in range(t):
    p *= n[v]
    if (p > 10 **18):
      print("-1")
      return
  print(p)

main()

Submission status: Accepted

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

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

print(num)

Submission status: Accepted

Solution code:
def main():
    N = input()
    str_num = input()
    num_list = str_num.split()
    
    if '0' in num_list:
        print(0)
        return
    
    answer = 1
    for num in num_list:
        answer *=int(num)
        if answer > 10**18:
            answer = -1
            break

    print(answer)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
inp = int(input())
lst = list(map(int,input().split()))
sum = 1
if 0 in lst:
    print(0)
    sys.exit(0)
else:
    num = 1;
    for i in range(inp):
        num *= lst[i]
        if num > 10 ** 18:
            print("-1")
            sys.exit()
    print(num)

Submission status: Accepted

Solution code:
# coding: utf-8
import string

n = int(input())
a = list(map(int,input().split()))
res = 1
for i in range(n):
    res *= a[i]
    if(res>pow(10,18)):
      	break

if(res<=pow(10,18)):
    print(res)
elif(0 in a):
    print(0)
else:
    print(-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

import sys
import copy

THREASHHOLD = 10 ** 18


def main():
    # 1行目を得る
    line = sys.stdin.readline()
    n = int(line.rstrip())

    # 2行目を得る
    line = sys.stdin.readline()
    list_a1_an = list(map(lambda x: int(x), line.rstrip().split(' ')))

    if 0 in list_a1_an:
        result = 0
    else:
        result = list_a1_an[0]
        for index in range(1, len(list_a1_an)):
            result = result * list_a1_an[index]
            if result > THREASHHOLD:
                result = -1
                break
    print(result)

    #for line in sys.stdin:
    #    print(line)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools

n = int(input())
a=1
ll = [int(i) for i in input().split()] 
ll.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
flag=1
n=int(input())
l=list(map(int,input().split()))
c=10**18
ans=1
l.sort()
for i in l:
    ans=ans*i
    if ans>c:
        flag=0
        break
if flag:
    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)
else:
  for i in A:
    S=S*i
    if S>10**18:
      print(-1)
      exit()
  print(S)

Submission status: Accepted

Solution code:
import sys
O = pow(10, 18)
N = int(input())
L = list(map(int, input().split()))
M = 1

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

for i in range(N):
    M = M * L[i]
    if O < M:
        print(-1)
        sys.exit()
    else:
        continue
print(M)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 1


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

for i in range(n):
    if x[i] == 0:
        ans = 0
        break


print(ans)

Submission status: Accepted

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

flag = 0

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

Submission status: Accepted

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

    
main ()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

n = int(input())

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

ans = 1

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
limit = 10 ** 18
res = 1

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

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

print(res)

Submission status: Accepted

Solution code:
c = int(input())
n_list = list(map(int, input().split()))

if min(n_list) == 0:
    print(0)
else:
    i = 1
    ERR = 10 ** 18
    flag = False
    for n in n_list:
        i = i * n
        if i > ERR:
            flag = True
            break

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

Submission status: Accepted

Solution code:
N = int(input())
max_value = 10**18
answer = 1
over = False
a = list(map(int, input().split()))


for i in range(N):
    answer *= a[i]
    if answer > max_value:
        over = True
        break

if 0 in a:
    print(0)
else:
    if not over:
        print(answer)
    else:
        print(-1)

Submission status: Accepted

Solution code:
import math
 
n=int(input())
arr=list(map(int,input().split()))
if 0 in arr:
  print("0")
  exit()
ans=1
for i in range(n):
  ans *= arr[i]
  if math.log10(ans) >= 18 and ans!=1000000000000000000:
    print("-1")
    exit()
print(ans)

Submission status: Accepted

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

if 0 not in b:
  last = 1
  for i in b:
      last*=i
      if last > 10**18:
        last = -1
        break
    
else:
  last = 0
    
print(last)