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

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

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

print(ans)

Submission status: Accepted

Solution code:
N=input()
S=input().split()
buf=-2
for n,i in enumerate(S):
  if i=="0":
    buf=0
if buf!=0:
  for n,i in enumerate(S):
    if n==0:
      buf=int(i)
    else:
      buf=buf*int(i)
    if buf>1000000000000000000:
      buf=-1
      break
print(buf)

Submission status: Accepted

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

for i in input_data:
	if i == 0:
		print(0)
		exit()

result = 1
for i in range(num):
	result = result * int(input_data[i])
	if pow(10, 18) < result:
		print(-1)
		exit()

print(result)

Submission status: Accepted

Solution code:
n = int(input())
result=1
a = list(map(int,input().split()))
    
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:
import sys

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

if 0 in A:
    print(0)
else:
    x = 1
    for i in range(N):
        x = x * A[i]
        if x>10**18:
            print(-1)
            sys.exit()
        
    print(x)

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in A:
  ans = 0
  
else:
  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()))
ans = 1

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve(n, a):
    for x in a:
        if x == 0:
            return 0
    ans = 1
    for x in a:
        ans *= x
        if ans > 10**18:
            return -1
    return ans
    
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()))
a.sort()
res = 1
flag = False
for i in range(n):
    res *= a[i]
    if res > 1000000000000000000:
        print(-1)
        flag = True
        break
if not flag:
    print(res)

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:
"""
from functools import reduce
from operator import mul

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

result = reduce(mul, A)
print(result if result <= 10**18 else -1)
"""
import sys

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

result = 1
for a in A:
    result *= a
    if result > 10**18:
        print(-1)
        sys.exit()
else:
    print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    print(ans)

Submission status: Accepted

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

r = 1

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

for x in a:
    r = r * x
    if(r > 10**18):
        print(-1)
        exit(0)
r = int(r)
print(r)

Submission status: Accepted

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

        if x>10**18:
            print(-1)
            c=1
            break        

        
    if c==0:
        print(x)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 1
INF = 10**18
*a, = map(int, input().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s = [input() for l in range(2)]
    N, A_dct, A = int(s[0]), {int(x): int(x) for x in s[1].split()}, [int(x) for x in s[1].split()]
    if 0 in A_dct:
        print(0)
    else:
        tmp = 1
        for k in A:
            tmp *= k
            if tmp > 10**18:
                tmp = -1
                break
        print(tmp)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = input().split()

list = [int(x) for x in input().split()]

list.sort()

answer = 1

for a in list:
    answer = answer*a
    if answer == 0:
        break
    if answer > 10**18:
        answer = -1
        break
    else:
        continue

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# ~oisín~ Python3 Template
#

import sys
import math
import statistics
import datetime
import collections

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 1
    e = False
    for x in a:
        if ans > 1000000000000000000:
            print("-1")
            e = True
            break
        ans *= x
    if ans > 1000000000000000000 and e == False:
        print("-1")
    elif e == False:
        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 a in A:
        ans *= a
        if ans > 1000000000000000000:
            print(-1)
            return

    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

a.sort(reverse=True)
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()))

if 0 in a:
    print(0)
else:
    a.sort(reverse=True)
    ans = 1
    for i in a:
        ans *= i
        if ans > 1000000000000000000:
            print("-1")
            break
    else:
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	A = [int(i) for i in input().split()]
	
	if 0 in A:
		print(0)
		return
	
	res = 1
	top = 10 ** 18
	for a in A:
		res *= a
		if res > top:
			print(-1)
			return
	print(res)

if __name__ == "__main__":
	main()

Submission status: Accepted

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


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n=II()
	A=LI()

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

	print(ans)


if __name__ == "__main__":
	main()

Submission status: Accepted

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

A = sorted(A, reverse=True)
#print(A)

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

s = 1

A = input().split()

if '0' in A:
  print(0)
else:
  for i in A:
    a = int(i)
    s *= a
    if s > 10**18:
      s = -1
      break
  print(s)

Submission status: Accepted

Solution code:
import sys
N=int(input())
A=list(map(int,input().split()))
if 0 in A:
    print(0)
    sys.exit()


ans=1
for elem in A:
    ans*=elem
    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

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

    print(S)

main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 1;
tem = 0
ok = 1
s = input().split()
for i in s:
    if(int(i) == 0):
        tem = 1
        break
    if(ok == 1):
        ans *= int(i) 
        if(ans > 10**18):
            ok = 0
if(tem):
    print(0)
elif(ok):
    print(ans)
else:
    print("-1")

Submission status: Accepted

Solution code:
import sys
 
N=int(input())
#print(N)
A=input().split()
A_int = [int(s) for s in A]
#print(A_int)
if 0 in A_int:
  print(0)
  sys.exit()


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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())


ans = 1

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

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

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


print(ans)

Submission status: Accepted

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

def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    lim = int(1e18)
    ans = 1
    for a in A:
        ans *= a
        if ans > lim:
            ans = -1
            break
        elif ans == 0:
            break
    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
  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())
numlist = list(map(int, input().split()))
if 0 in numlist:
    print(0)
else:
    ans = 1
    for i in numlist:
        ans *= i
        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
    ans = 1
    for cal in a:
        ans *= cal
        if ans > 1e18:
            print(-1)
            return
    print(ans)

main()

Submission status: Accepted

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


def f(list):
    a = 1
    for i in list:
        a = a*i
    return a


def main():

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


main()
# log_prod_a = sum(map(math.log10, a))
# if log_prod_a < 18.0:
#     print(f(a))
# else:
#     print(-1)

Submission status: Accepted

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

# B - Multiplication 2
n = int(input())
a = list(map(int, input().split()))

ans = 1
upper = 10 ** 18

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

	print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ary = list(map(int,input().split()))
import cmath
if 0 in ary:
    print(0)
else:
    multiple = 1
    while ary:
        multiple *= ary.pop()
        if multiple > 10**18:
            multiple = -1
            break
    print(multiple)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

main ()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()
A.sort()
ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        ans = -1
        break

print(ans)

Submission status: Accepted

Solution code:
#intの場合
N = int(input()) #ここで標準入力

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

# multiple = 1
# for i in range(N):
#     multiple *= A[i]



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

def main():
    if 0 in A:
        print(0)
        return

    output = 1
    for a in A:
        output *= a

        if output > (10 ** 18):
            print(-1)
            return

    print(output)

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 1
for i in a_list:
    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()))

mx = 1e18
pr = 1
done = True
zero = False

for i in a:
	if i == 0:
		zero = True

if zero == False:
	for i in a:
		pr = pr*i
		if pr > mx:
			break
else:
	pr = 0
if zero or pr <= mx:
	print(pr)
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()))
if 0 in A:
  print(0)
  exit()

ans = 1
for i in range(n):
  ans = 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()))

if 0 in A:
    print(0)
    exit()
ans = 1
for a in A:
    ans = ans * a
    if ans > pow(10, 18):
        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 a in A:
    ans = ans * a
    if ans > pow(10, 18):
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
times= int(input())
nums= list(map(int, input().split()))
a= 1
if 0 in nums:
  print(0)
  exit()
for i in nums:
  a*= i
  if a > 10**18:
    print('-1')
    exit()
else:
  print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ps = [int(x) for x in input().split()]
    ps.sort()
    a = 1
    for p in ps:
        a *= p
        if a == 0:
            print(0)
            return
        if a > 10 ** 18:
            print(-1)
            return
        
    print(a)

    
main()

Submission status: Accepted

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

import numpy as np

def main():
    n = int(input())
    l = list(map(int,input().split()))
    if 0 in l:
        print(0)
        exit()
    pro=1
    for num in l:
        pro = pro*num
        if pro > 10**18:
            print(-1)
            exit()
    else:
        print(pro)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a1 = int(input())
b2 = input().split(" ")

def check(a , b):
  score = 1
  if '0' in b:
    return 0
  else:
    for i in range(a):
      score *= int(b[i])
      if score > 10 ** 18:
        return -1
    
    return score

print(check(a1 , b2))

Submission status: Accepted

Solution code:
def ans(a):
    limit = 10**18
    acm=1
    if 0 in a:
        return 0

    for i in a:
        acm *= i
        if acm > limit:
            return -1
    return acm
    
n = int(input())
a = input()
a = list(map(int,a.split()))

print(ans(a))

Submission status: Accepted

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

product = 1

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

print(product)

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  A = [int(i) for i in input().split()]
  
  if 0 in A:
    print(0)
    return
  
  c = 1
  for i in A:
    c *= i
    
    if c > 10**18:
      print(-1)
      return
  print(c)
  
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 > 10**18:
            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 = map(int, input().split())
ans = 1
for num in sorted(a):
    ans *= num
    if ans > 10**18:
        print("-1")
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
lst = sorted([int(x) for x in input().split() if x != "1"], reverse=True)

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

ret = 1
for x in lst:
    ret *= x
    if ret > 10 ** 18:
        print(-1)
        exit()

print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
    if i=='0':
        print("0")
        quit()
ans=1
p = 1000000000000000000 / ans
for i in a:
    #print(ans," ",p)
    if(int(ans)<=p):
        ans=ans*int(i)
        if(int(ans)>p):
            print("-1")
            quit()
    else:
        print("-1")
        quit()
print(ans)

Submission status: Accepted

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

res = 1

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

Submission status: Accepted

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

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

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

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

print(prod)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
if a[0] == 0:
    print(0)
    sys.exit()
b = 1
for i in a:
    b *= i
    if b > 10**18:
        print(-1)
        sys.exit()
print(b)

Submission status: Accepted

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

while len(arr) > 1:
    m = len(arr)
    if m & 1:
        arr.append(1)
        m += 1

    left, right = arr[:m // 2], arr[m // 2:]
    arr = [x * y for x, y in zip(left, right)]

x = arr[0]
if x > 10 ** 18:
    print(-1)
else:
    print(x)

Submission status: Accepted

Solution code:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort()
    ans = 1
    for aa in a:
        ans *= aa
        if ans > 10 ** 18:
            print(-1)
            break
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# Problem B - Multiplication 2

# input
N = int(input())
a_nums = list(map(int, input().split()))

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

Submission status: Accepted

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

if min(a) ==0:
    ans =0
else:
    order =0
    for i in a:
        order = order+len(str(i))-1

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
a = list(map(str, input().split()))
total = 1

if '0' in a:
    print('0')
    sys.exit()
for i in a:
    total *= int(i)
    if total > 10**18:
        print('-1')
        sys.exit()
print(total)

Submission status: Accepted

Solution code:

N = int(input())
A = [int(a) for a in 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:
n = int(input())
a = list(map(int, input().split()))

x =1

if min(a) ==0:
    ans =0
else:
    order =0
    for i in a:
        order = order+len(str(i))-1

    if order >18:
        ans = -1
    else:
        ans =1
        for i in a:
                ans = ans*i
        if ans >10**18:
            ans=-1
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:
from sys import stdin
input = stdin.readline

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

Submission status: Accepted

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

def ans():
    global N,A
    for i in range(N):
        if A[i]==0:
            return 0
    tmp = 1
    for i in range(N):
        tmp *= A[i]
        if tmp>10**18:
            return -1
    return tmp

print(ans())

Submission status: Accepted

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

# a = [0, 10, 10, 10, 10]

a.sort()
r = 1
t = 10 ** 18
for x in a:
  r *= x
  if r > t:
    break
if r <= t:
  print(r)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
max_value = 10 ** 18


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

if 0 in A:
    result = 0
else:
    result = A.pop(0)
    for i in A:
        result = result * i
        if result > max_value:
            result = -1
            break

print(result)

Submission status: Accepted

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

if Nlist.count(0)>=1:
    total = 0
    print(total)
    sys.exit()


for i in range(N):
    total = total*Nlist[i]
    if total > 1000000000000000000:
        total = -1
        break

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ar = list(map(int,input().split()))
ans = 1
z = 0
p = 0
for i in ar:
    if ans != -1:
        ans *= i
    if i == 0:
        z+=1
    if ans > 1e18:
        ans = -1
if z:
    ans = 0
print(ans)

Submission status: Accepted

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

now = 1
for a in A:
    now *= a
    if now > int(1e18):
        print(-1)
        exit()

print(now)