Problem:


Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0



Sample input:
2
1000000000 1000000000


Sample output:
1000000000000000000

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import functools

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

def foldMulti(acc, x):
    return acc*x

if 0 in xs:
    print(0)
elif len([x for x in xs if x > 1]) >= 60:
    print(-1)
else:
    res = functools.reduce(foldMulti, xs, 1)

    if res > 1e18:
        print(-1)
    else:
        print(res)

Submission status: Accepted

Solution code:
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n = int(input())
da = NextIntList()
da = sorted(da)
ans = 1
for i in range(n):
    ans *= da[i]
    if ans > 10**18:
        ans = -1
    elif ans < 0:
        ans = -1

if ans < 0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def prod(n, A):
    if 0 in A:
        return 0
    p = 1
    for a in A:
        if p * a <= 10**18:
            p *= a
        else:
            return -1
    return p

n = int(input())
A = [int(i) for i in input().split()]
print(prod(n, A))

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)
        break
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IS(): return str(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")


def solve(N,A):
    ans = 1
    if 0 in A:
        print(0)
        return
    
    for i in A:
        ans *= i
        if ans > pow(10,18):
            print(-1)
            return
    print(ans)

def main():
    N = II()
    A = LI()
    solve(N,A)

#main
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#B
N=int(input())
ans=1
flag=True
A=[]
for x in input().split():
    A.append(int(x))
    if int(x)==0:
        ans=0

for i in range(N):
    x=A[i]
    ans*=x
    if ans>pow(10,18):
        flag=False
        break

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

Submission status: Accepted

Solution code:
N = input()
A_list = [int(e) for e in input().split()]

LIMIT = pow(10, 18)
total = 1

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

for a in A_list:
    total = total * a
    if total > LIMIT:
        print('-1')
        exit()
print(total)

Submission status: Accepted

Solution code:
import sys
n=input()
n=int(n)
a=input().split()
ans=1
v=[]
for m in a:
    m=int(m)
    if(m==0):
        print(0)
        sys.exit()
    else:
        v.append(m)
for m in v:
    if(ans>1e18):
        print(-1)
        sys.exit()
    else:
        ans*=m
if(ans>1e18):
    print(-1)
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 a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_=input()
val=1
t=10**18
*a,=sorted(map(int,input().split()))

for i in a:
  if i==0:
    val*=i
    break
  val*=i
  if val>t:
    print(-1)
    exit()

print(val)

Submission status: Accepted

Solution code:
import math

def main(*, int=int, input=input):
    N = int(input())

    # スペース区切りでの入力(定数個)
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return
    else:
        Alog = [math.log10(x) for x in A]

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


if __name__ == "__main__":
    import io, sys
    if "_INPUT" in locals():
        sys.stdin = io.StringIO(_INPUT)
    main()

Submission status: Accepted

Solution code:
N = int(input())
MX = 10**18
a = list(map(int, input().split()))
if 0 in a:
    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:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
ans=1
c=a.count(0)
if c>0:
    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:
import sys
def input():
    return sys.stdin.readline().strip()

def main():
    n = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    x = 1
    for i in A:
        x *= i
        if x > pow(10,18):
            print(-1)
            return
    print(x)

main()

Submission status: Accepted

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


if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

def input():
    return sys.stdin.readline()[:-1]
n = int(input())
l = list(map(int, input().split(" ")))
output = 1

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

for i in range(n):
    output = output * l[i]
    if output > 10 ** 18:
        output = -1
        break
print(output)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc169/submissions/13893064

def main():
    from itertools import zip_longest

    LIMIT = 10 ** 18

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

    while len(A) > 1:
        A = [x * y for x, y in zip_longest(A[::2], A[1::2], fillvalue=1)]

    if A[0] > LIMIT:
        print(-1)
    else:
        print(A[0])


if __name__ == '__main__':
    main()

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()
A = list(map(int, input().split()))
A.sort()
if A[0] == 0:
    print(0)
else:
    isOverflow = False
    product = 1
    A.sort(reverse=True)
    for number in A:
        product = product * number
        if product > 10 ** 18:
            print(-1)
            isOverflow = True
            break
    if not isOverflow:
        print(product)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
MX=10**18
prod=1
for q in sorted(a):
  prod*=q
  if prod>MX:
    print(-1)
    exit()
print(prod)

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

if 0 in multi:
    result = 0
    print(0)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    # 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 > 10 ** 18:
                ans = -1
                break

    print(f'{ans}')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    max_val = pow(10, 18)
    if 0 in a:
        print(0)
    else:
        answer = 1
        for aa in a:
            answer *= aa
            if max_val < answer:
                print(-1)
                break
        else:
            print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from heapq import heappop, heappush, heapify

    LIMIT = 10 ** 18

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

    heapify(A)

    if A[0] is 0:
        print(0)
        return

    while len(A) > 1:
        x = heappop(A)
        y = heappop(A)
        heappush(A, x * y)

    ans = heappop(A)
    print(ans if ans <= LIMIT else -1)


if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 1
A = [int(i) for i in input().split()]
if 0 in A:
  print(0)
  exit()
for a in A:
  ans *= a
  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()))

total = 1
a.sort()
if a[0] == 0:
	print(0)
	sys.exit()
for i in range(n):
	total *= a[i]
	if total > 10**18:
		print('-1')
		sys.exit()
print(total)

Submission status: Accepted

Solution code:
def Judge(x,y):
    sum=1
    for i in range(y):
        if x[i]==0:
            return 0
    for i in range(y):
        sum*=x[i]
        #print(sum)
        if sum>10**18:
            return -1
    return sum

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

c=Judge(a,n)
print(c)

Submission status: Accepted

Solution code:
"""
隣り合う2要素を掛けていく

ref. https://atcoder.jp/contests/abc169/submissions/13893064
"""
n = int(input())
A = list(map(int,input().split()))

MX = 1e18

while len(A)>1:
    if len(A)%2 == 1: # 要素数が奇数のときは[1]を加えて偶数にしておく
        A += [1]
    A = [A[2*i]*A[2*i+1] for i in range(len(A)//2)]

if A[0] > MX:
    print(-1)
else:
    print(A[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

def input():
    return sys.stdin.readline()[:-1]
n = int(input())
l = list(map(int, input().split(" ")))
output = 1

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

for i in range(n):
    output = output * int(l[i])
    if output > 10 ** 18:
        output = -1
        break
print(output)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] == 0:
  print(0)
  sys.exit()
  
ans = 1
LIMIT = 10**18

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

Submission status: Accepted

Solution code:

import sys
import math
import itertools
import collections

# H1,M1,H2,M2,K = map(int,input().split())
# H2 -= K//60
# M2 -= K % 60

# print((H2 - H1) * 60 + (M2 - M1))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = map(int, input())
data = list(map(int, input().split()))
 
ans = 1
flag = 1
flag2 = 0
 
for d in data:
  if d == 0:
    flag2 = 1
 
for d in data:
  ans = ans * d
  if ans > 1e18:
    flag = 0
    break
 
if(flag2):
  print(0)
elif(flag):
  print(ans)
else:
  print(-1)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = list(map(int,input().split()))

count =data[0]
data.remove(data[0])

if 0 in data:
    print(0)

else:
    for _ in data:
        if count ==0:
            break
        elif count <= 10**18:
            count *= _

    if count <= 10**18:
        print(count)
    else:
        print(-1)

Submission status: Accepted

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

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:
from functools import reduce
t = int(input())
A = [int(s) for s in input().split(" ")]
if 0 in A:
    print(0)
else:
    ans = 1
    for k in A:
        ans *= k
        if ans > 10**18:
            ans = -1
            break
    print(ans)

Submission status: Accepted

Solution code:
import sys

_ = 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 > 1e18:
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
#!/bin/python3

import sys
input = sys.stdin.readline

def main():
  n = int(input().strip())
  a = list(map(int, input().strip().split()))
  result = 1
  LIMIT = 10**18
  if 0 in a:
    print(0)
    sys.exit()
  for i in a:
    result *= i
    if result > LIMIT:
      print(-1)
      sys.exit()
  print(result)

main()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
A=sorted(A)#小さい順に計算することで処理時間短縮
f=A[0]
for i in range(1,N):
    f*=A[i]
    if f>10**18:
        print(-1)
        exit()
            
print(f)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

if 0 in a:
    print(0)
else:
    cur = 1
    for x in a:
        cur *= x
        if cur > 10 ** 18:
            print(-1)
            sys.exit()
    print(cur)

Submission status: Accepted

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

ans =1
b = sorted(b)
for I in b:
  ans = ans*I
  if b[0] == 0:
      ans = 0
      print(0)
      break
  elif ans > 10**18:
    print('-1')
    ans = -1
    break
if ans >=1:
    print(ans)

Submission status: Accepted

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

main()

Submission status: Accepted

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

limit = 1000000000000000000

result = 1
if 0 not in A:
  for i in A:
    result = result * i
    if result > limit:
      result = -1
      break
else:
  result = 0

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

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

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

print(ans)

Submission status: Accepted

Solution code:
N, *a = map(int, open(0).read().split())

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve(N, A):
    ret = 1
    upper = 10**18
    if 0 in A:
      return 0
    for i in A:
        ret *= i
        if upper < ret:
          return -1
    return ret
 
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))

Submission status: Accepted

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

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

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

    print(ans)


main()

Submission status: Accepted

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

ans = 1
inf = 10**18 + 1
for i in a:
    ans *= i
    ans = min(ans, inf)
    
if ans == inf:
    ans = -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
for a in As:
    ans *= a
    ans = min(ans, 10**18 + 1)

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

Submission status: Accepted

Solution code:
#from operator import mul
#from functools import reduce
#cnt = 1000000000000000000
ans =1
N = int(input())
nums = list(map(int, input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(number)

Submission status: Accepted

Solution code:
#A,B,C=(int(x) for x in input().split())
N=int(input())
A=list(map(int, input().split()))


if 0 in A:
  t=0
else:
  t=A[0]
  i=1
  for k in range(N-1):
    t=t*A[i]
    if t>10**18:
      break
    i+=1

if t<=10**18:
  print(t)
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())
a = list(map(int, input().split()))

limit = 10**18
total = 1

for i in a:
    if (i == 0):
        total = 0

if (total != 0):
    for i in a:
        total *= i
        if (total > limit):
            total = -1
            break

print(total)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

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 i in A:
        ans *= i
        if(ans > 1000000000000000000):
            print(-1)
            return
    print(ans)


main()

Submission status: Accepted

Solution code:
def f(n, a):
  if 0 in a:
    return 0
  p = 1
  for x in a:
    p *= x
    if p > 10**18:
      return -1
  return p
 
n = int(input())
a = list(map(int, input().split()))
print(f(n, a))

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
list_input = list(map(int, sys.stdin.readline().strip().split()))

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

a = 1
for i in list_input:
    a *= i
    if a > pow(10, 18):
        break


if a > pow(10, 18):
    print(-1)
else:
    print(a)

Submission status: Accepted

Solution code:
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_np =np.array(A,dtype=np.int64)
ans =np.prod(A_np) #累積積
if 0 in A:
    print(0)
elif 0 < ans <=10**18:
    print(ans)
else:
    print(-1)

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

Submission status: Accepted

Solution code:
def funct(a):
  c = 1
  if(0 in a):	return 0
  for i in range(len(a)):
    c *= a[i]
    if(c > 10 ** 18):
      return -1
  return c
n = input()
a = [int(x) for x in input().split()]
print(funct(a))

Submission status: Accepted

Solution code:
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    f=1
    if 0 in a:
        f=0
    for i in a:
        f*=i
        if f>1000000000000000000:
            print(-1)
            return 
    print(f)
solve()

Submission status: Accepted

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

ans = 1
INF = 1000000000000000000

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:
def solve(N, A):
    ret = 1
    upper = 10**18
    if 0 in A:
      return 0
    for a in A:
        ret *= a
        if upper < ret:
          return -1
    return ret
 
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
_, *A = map(int, open(0).read().split())
ans = 1

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

Submission status: Accepted

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





if __name__ == '__main__':
    N = int(input())
    main(N)

Submission status: Accepted

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

x = 1
flag = False
INF = 10**18
if 0 in a:
    print(0)
else:
    for i in range(n):
        if flag == False:
            x *= a[i]
        if x > INF:
            flag = True
    
    if flag:
        print(-1)
    else:
        print(x)

Submission status: Accepted

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

Submission status: Accepted

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

res = 1
if 0 in a_list:
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

product = 1

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

print(product)

Submission status: Accepted

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