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 sys
def main():
  u = 1  
  n = int(input())
  a = list(map(int,(input().split())))
  
  if 0 in a:
    print(0)
    sys.exit()
	
  for i in a:
    u *=i
    if u > 1000000000000000000:
      print(-1)
      sys.exit()

  print(u)


main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
li = list(map(int, sys.stdin.readline().split()))
if 0 in li:
    print(0)
    exit()
res = 1
for i in range(n):
    res *= li[i]
    if res > 1000000000000000000:
        print(-1)
        exit(0)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC169 B-Multiplication2
class Calc():
  def multi(self,x,y):
    x, y, sign, rslt = str(x)+".", str(y)+".",1 ,""
    if x[0]=="-":
      sign*=-1
      x=x[1:]
    if y[0]=="-":
      sign*=-1
      y=y[1:]
    x,y=x.split("."),y.split(".")
    x2 = [int(x[1][-i-1]) for i in range(len(x[1]))] + [int(x[0][-i-1]) for i in range(len(x[0]))]
    y2 = [int(y[1][-i-1]) for i in range(len(y[1]))] + [int(y[0][-i-1]) for i in range(len(y[0]))]
    sum=[0]*(len(x2)+len(y2))
    for i, p in enumerate(y2):
      for j, q in enumerate(x2):
        K=i+j
        sum[K]+=p*q
        while sum[K]>9:
          sum[K+1], sum[K] = sum[K+1] + int(sum[K]/10) , sum[K]%10
          K+=1
    for i in range(len(sum)): rslt+=str(sum[-i-1])
    dclen=len(x[1])+len(y[1])
    if dclen>0: rslt=rslt[:len(rslt)-dclen]+"."+rslt[len(rslt)-dclen:len(rslt)]
    for i in range(len(rslt)):
      if rslt[i]=="0" and (rslt[i+1] if i<len(rslt)-1 else ".")!="." : continue
      else:
        rslt=rslt[max(i,0):]
        break
    return ("-" if sign==-1 else "")+rslt
  
  def max_2(self,x,y):
    X,Y=x,y
    x, y, rslt = str(x)+".", str(y)+".", ""
    if x[0]=="-" and y[0]!="-": return Y
    if x[0]!="-" and y[0]=="-": return X
    if x[0]=="-" and y[0]=="-": return #(略)
    x,y=x.split("."),y.split(".")
    size0,size1 = max(len(x[0]),len(y[0])), max(len(x[1]),len(y[1]))
    x[0],y[0] = "0"*( size0 - len(x[0]) ) + x[0] , "0"*( size0 - len(y[0]) ) + y[0]
    x[1],y[1] = x[1] + "0"*( size1 - len(x[1]) ) , y[1] + "0"*( size1 - len(y[1]) )
    for s in [0,1]:
      for i in range( size0 if s==0 else size1 ):
        p,q=int(x[s][i]),int(y[s][i])
        if p==q: continue
        elif p>q: return X
        elif p<q: return Y
    return X

N=int(input())
A=input().split()
R,lim="1","1"+"0"*17+"1"
if "0" in A: print(0)
else:
  for i in range(N): 
    R=Calc().multi(R,A[i])
    if Calc().max_2(lim,R)==R:
      print(-1)
      break
  else:
    print(R)

Submission status: Accepted

Solution code:
# we collect the input A1 upto An.
# limit cannot exceed 10**18
# if N = 0 then ans = 0
# in N is in range then compute ans * A[n]
# else if  ans is greater than limit then display 1
# finally if length equal 1 then display -1
N = int(input())
ans = 1
limit = 10 ** 18
length = 0

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

A0 = set(A)
if 0 in A0:
    ans = 0
else:
    pass

for n in range(N):
    ans = ans * A[n]
    if ans == 0:
        break
    elif ans > limit:
        length = 1
        break
    else:
        pass

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

Submission status: Accepted

Solution code:
# we collect the input A1 upto An.
# limit cannot exceed 10**18
# if N = 0 then ans = 0
# in N is in range then compute 1 * A[n]
N = int(input())
ans = 1
limit = 10 ** 18
length = 0

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

A0 = set(A)
if 0 in A0:
    ans = 0
else:
    pass

for n in range(N):
    ans = ans * A[n]
    if ans == 0:
        break
    elif ans > limit:
        length = 1
        break
    else:
        pass

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 1
lim = 10 ** 18
l = 0

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

A0 = set(A)
if 0 in A0:
  ans = 0
else:
  pass

for n in range(N):
  ans = ans * A[n]
  if ans == 0:
    break
  elif ans > lim:
    l = 1
    break
  else:
    pass

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

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 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()))

result = 1

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

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

Submission status: Accepted

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

    if 0 in A: 
        print(0)
        return

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

    print(prod)

main()

Submission status: Accepted

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

ans = 1
a.sort()
for a_i in a:
    ans *= a_i
    if ans > 1_000_000_000_000_000_000:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def Ii():return int(input())
def Mi():return map(int,input().split())
def Li():return list(map(int,input().split()))
n = Ii()
a = sorted(Li())

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
arr = [int(x) for x in input().split()]
res=1
arr.sort()
if arr[0] == 0 :
  print('0')
  exit(0)
for i in range(n):
  res = res*arr[i]
  if res>1e18:
    print(-1)
    exit(0)
print(res)

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))
if (0 in lst):
  print(0)
else:
  product = 1
  for i in lst: 
    product *= i

    if(product > 1000000000000000000):
      print(-1)
      break
  else:
    print(product)

Submission status: Accepted

Solution code:
import sys

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

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

Π = 1
for _ in A:
    Π *= _
    if(Π > 1000000000000000000):
        print(-1)
        sys.exit(0)

print(Π)

Submission status: Accepted

Solution code:
import sys
n = int(input())
limit = 10 ** 18
ans = 1
a = [int(x) for x in input().split() ]
if 0 in a:
    print(0)
    sys.exit()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = map(int, input().split())
ans = 1
for a in l:
    if ans * a > 1e18:
        ans = -1
    elif ans != -1 or a == 0:
        ans *= a

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:
def main():
    N = int(input())
    A = list(map(int,input().split()))

    if 0 in A:
        print(0)
        return

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

    print(prod)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- codinf: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
ans = 1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int, input().split()))
if 0 in l:
    print(0)
    exit()
mlt = 1
for x in l:
    mlt *= x
    if mlt > 10 ** 18:
        print('-1')
        exit()
print(mlt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int(): return int(input())

    def map_int_input(): return map(int, input())

    MII = map_int_input

    def MII_split(): return map(int, input().split())

    def MII_to_index(): return map(to_index, input())

    def MII_split_to_index(): return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs(): return list(map(int, input()))

    LII = list_int_inputs

    def LII_split(): return list(map(int, input().split()))

    # 2次元リスト化
    def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

    N = input_int()
    A_list = LII_split()

    if 0 in A_list:
        print(0)
        return

    ans = A_list[0]
    for A in A_list[1:]:
        ans *= A
        # print(ans)
        if ans > 1e18:
            ans = -1
            break
    print(ans)
    
resolve()

Submission status: Accepted

Solution code:
_ = input()
nums = list(map(int, input().split()))
ans = 1
 
for num in nums:
    if num==0 or ans <= 10 ** 18:
        ans *= num
    else:
        pass
 
print(ans if ans <= 10 ** 18 else -1)

Submission status: Accepted

Solution code:
_ = input()
nums = list(map(int, input().split()))
ans = 1

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
sorted(A)
result=1
if 0 in A:
    result=0
for i in A:
    if result==0:
        break
    result*=i
    if result>1000000000000000000:
        result=-1
        break

print(result)

Submission status: Accepted

Solution code:
#create date: 2020-06-30 09:30

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    ans = 1
    if min(a) == 0:
        print(0)
        quit()
    for ai in a:
        ans *= ai
        if ans > 10**18:
            print(-1)
            quit()
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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 a in A:
    ans *= a
    if ans > 1e18:
        print(-1)
        sys.exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
from collections import Counter,defaultdict

n=IN()
a=LI()
p=1
if 0 in a:
    print(0)
    exit()
for i in a:
    p*=i
    if p>pow(10,18):
        print(-1)
        exit()
print(p)

Submission status: Accepted

Solution code:
Max = 10**18
N = int(input())
array = list(map(int, input().split()))
for i in range(N):
	if array[i]==0:
		print(0)
		exit()

ans = 1
for i in range(N):
	ans *= array[i]
	if ans > Max:
		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 :
    for i in range(N):
        ans = ans * a[i]
        if ans > 10**18:
            ans = -1
            break
print(ans)

Submission status: Accepted

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

	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())
l = list(map(int, input().split()))

res = 1
check = 10**18
flag = 0 in l

for e in l:
    res *= e
    if res > check:
        if flag:
            res = 0
        else:
            res = -1
        break

print(res)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
M = int(1e18)
n = int(input())
s = list(map(int, input().split()))
res = 1
flag = False
if 0 in s: print('0')
else:
    for i in range(len(s)):
        res *= s[i]
        if res > M: flag = True; break
    print(-1 if flag else res)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = 1

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

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

print(b)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int,input().split()))
arr.sort(reverse=True)
ans = 1
limit = 10**18

if arr[-1] == 0:
  ans = 0
else:
  for i in arr:
    ans *= i
    if ans > limit:
      ans = -1
      break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

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

LIM= 10**18
ans=1
for e in a:
    ans*=e
    if ans > LIM or ans<-1:
        ans = -1

if ans <0:
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
# cook your dish here
n=int(input())
a=[int(x) for x in input().split()]
ans=1  
mod=int(1e18)
for i in range(n):
    if a[i]==0:
        ans=0 
        break 
for i in range(n):
    ans*=a[i]
    if ans>mod:
        ans=-1 
        break 
    if ans==0:
        break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from functools import reduce
def f(acc, a):
  if acc == 0 or a == 0:
    return 0
  elif acc == -1:
    return -1
  elif acc * a > 10 ** 18:
    return -1
  else:
    return acc * a

n = int(input())
a_list = list(map(int, input().split()))
print(reduce(f, a_list, 1))

Submission status: Accepted

Solution code:
import math  # noqa: F401
from typing import Dict, List, Optional, Tuple, Union  # noqa: F401


def main(N: int, A: List[int]):
    A = sorted(A, reverse=True)
    if A[-1] == 0:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10 ** 18:
            ans = -1
            break
    print(ans)


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    main(N, A)

Submission status: Accepted

Solution code:
#169B
#Multiplication2

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
output = 1
flug = 0

if 0 in A_list:
    print(0)
    flug = 1
if flug != 1:
    for i in range(N):
        output *= A_list[i]
        
        if (output > 10 ** 18):
            print(-1)
            flug = 1
            break
if(flug != 1):
    print(output)

Submission status: Accepted

Solution code:
from sys import stdin
data = stdin.readlines()

a = int(data[0])
b = [int(s) for s in data[1].split()]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split(' ')))
if a.count(0) > 0:
	print("0")
else:
	lim = int(1e18)
	mult = 1
	for v in a:
		if mult > lim:
			break
		else:
			mult *= v
	if mult > lim:
		print("-1")
	else:
		print(mult)

Submission status: Accepted

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

def main():
    n = int(input())
    a = list(map(int, input().strip().split()))
    
    if 0 in a:
        print(0)
        return
    ans = 1
    for ai in a:
        ans *= ai
        if(ans > 10**18):
            print(-1)
            return
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    for i in A:
        if i == '0':
            print(0)
            return

    X = 1
    for i in A:
        X *= int(i)
        if X > 1000000000000000000:
            print(-1)
            return
    print(X)
main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        return 0

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

    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())

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

res = 1
overflow = False

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

i = 0
while i < len(A) and res <= 10**18:
  res *= A[i]
  i += 1


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

Submission status: Accepted

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

k = 0
ans = 1
for k in range(n):
    ans *= A[k]
    k += 1
    if ans > 10**18:
        ans = -1
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = 1
for i in range(n):
    ans *= a[i]
    if (ans > 1e18):
        break
print(ans if ans <= 1e18 else -1)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    in_list = list(map(int,input().split()))
    result = 1
    if in_list.count(0)>0:
        print(0)
        return

    for i in range(n):
        result = result*in_list[i]
        if result > 10**18:
            print(-1)
            return
    print(result)

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
a = sorted(a,reverse=True)
if(0 in a):
	print(0)
	exit()
for i in a:
	if(len(str(i)) + len(str(ans)) > 20):
		print(-1)
		exit()
	ans *=i

print(ans if(ans<=pow(10,18)) else -1)

Submission status: Accepted

Solution code:
def main():
    num = int(input())
    num_list = list(map(int, input().split()))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from decimal import Decimal

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

product = 1
max_product = 10**18

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


for a in A_list:
    check = Decimal(str(max_product)) / Decimal(str(product))

    if a <= check:
        product *= a
    else:
        print(-1)
        sys.exit()

print(product)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():

    ma = 10**18
    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 >ma:
            print(-1)
            exit()

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




if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

t = 1
limit = pow(10, 18)

if 0 in set(a):
    print(0)
else:
    for i in a:
        t *= i
        if t > limit:
            print(-1)
            break
    else:
        print(t)

Submission status: Accepted

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

P = 0
if not(0 in A):
    P = 1
    for i in A:
        P *= i
        if P > 10**18:
            P = -1
            break

print(P)

Submission status: Accepted

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

MultipliedNum=1
index=0

if min(Alist)==0:
    print(0)
    index=1

else:
    for i in Alist:
        MultipliedNum*=i

        if MultipliedNum>10**18:
            print(-1)
            index=1
            break
            
if index==0:
    print(MultipliedNum)

Submission status: Accepted

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

sum_A = 1

for i in range(0,len(A)):
  if(A[i] == 0):
        print(0)
        exit()

for i in range(0,len(A)):
  if(sum_A > 1000000000000000000):
        break
  sum_A *= A[i]
if(sum_A > 1000000000000000000):
        print("-1")
        exit()
print(sum_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 a in A:
    ans *= a
    if ans > 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:
import sys

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

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

res = 1
for a in A:
    res *= a
    if 1e18 < res:
        print(-1)
        sys.exit()

print(res)