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:
def main():    
    t =  int(input())
    n = 1
    a = list(map(int,input().strip().split()))[:t]
    for i in range(t):
        if a[i]==0:
            return 0
    for i in range(t):
        n*=a[i]
        if n>1e18:
            return -1
    if n>1e18:
        return -1
    else:
        return n
        
if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

ans=1

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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:
s = [input() for i in range(2)] 
li = list(map(int, s[1].split()))
s0 = int(s[0])
f1 = 1
if 0 in li:
    print(0)
if 0 not in li:
    for i in range(s0):
        f1 = f1 * li[i]
        if f1 > 1000000000000000000:
            print(-1)
            break
    if f1 <= 1000000000000000000:
        print(f1)

Submission status: Accepted

Solution code:

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

MAX_A= 10**18
aa = 1

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
lst = list(map(int, input().split()))
flg = 0
if 0 in lst:
    print(0)
else:
    for _ in lst:
        ans *= _
        if ans > 10**18:
            print(-1)
            flg = 1
            break
    if not flg :
        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:
import math
import sys

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


ans = 1
num = 1000000000000000000

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

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

print(ans)

Submission status: Accepted

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

q = 1000000000000000000
b = 1
cek = True
zero = a.count(0)
if zero > 0 :
	print("0")
else :
	for i in range(n) :
		b = b*a[i]
		if b > q :
			cek = False
			break
	if cek :
		print(b)
	else :
		print("-1")

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

Submission status: Accepted

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

i = 1
result = a[0]
flag = False
if a[-1] == 0:
    result = 0
else:
    for i in range(len(a)-1):
        result = result * a[i+1]
        if result > 10 ** 18:
            flag = True
            break

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

Submission status: Accepted

Solution code:
n = int(input())
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)
            break
    else:
        print(ans)

Submission status: Accepted

Solution code:
n = int(input())
num = list(map(int,input().split()))
ans = 1
limit = 1000000000000000000
if 0 in num:
  print(0)
else:
  for item in num:
    ans *= item
    if ans>limit:
      ans = -1
      break

  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

# import numpy as np
# ret = np.prod(a)

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

    # if ret > 10**18 or ret < 0:
    #     print(-1)
    # else:
    #     print(ret)

Submission status: Accepted

Solution code:
#from collections import deque
def hanbun(L):
    N = len(L)
    flag = N % 2
    N = N // 2
    ans = []
    for i in range(N):
        ans.append(L[2 * i] * L[2 * i + 1])
    if flag == 1:
        ans.append(L[-1])
    return(ans)

N = int(input())
A = list(map(int, input().split()))
while len(A) > 1:
    A = hanbun(A)
ans = A[0]
if ans > 10 ** 18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A,reverse=True)
B = 1
if 0 in A:
    print(0)
    quit()
else:
    for i in A:
        B *= i
        if B> 10**18:  
            print(-1)
            quit()
print(B)

Submission status: Accepted

Solution code:
import sys
N = int(input())
data = [int(i) for i in input().split()]
sum = 1

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

for j in data:
    sum *= j
    if sum > 10 ** 18:
        print(-1)
        sys.exit()
        
else:
    print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

AA = set(Nums)

if '0' in AA:
  print(0)
else:
  A = 1
  for i in range(N):
    A*=int(Nums[i])
    if A > 10**18:
      A = -1
      break
  print(A)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split()
result = 1
line = pow(10,18)

if "0" in A:
  result = 0
else:
  for i in range(N):
    result *= int(A[i])
    if result > line:
      result = -1
      break

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
#print(A)
i = 10**18
ans = 1
if min(A) == 0:
    ans = 0
else:
    for a in A:
        ans *= a
        if ans > i:
            ans = -1
            break
print(ans)

Submission status: Accepted

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

A.sort(reverse=True)
out = 1
if A[-1] == 0:
  out = 0
else:
  for i in A:
    out *= i
    if out > 1e18:
      out = -1
      break
print(out)

Submission status: Accepted

Solution code:
# cook your dish here

num = int(input())
arr = list(map(int,input().split(" ")));

maxi = 1000000000000000000

val = 1;
arr.sort()

if arr[0]==0:
        print(0)

else:
        for i in arr:
                val = val*i;
                if val>maxi:
                        val = -1
                        break
        
        
        print(val)

Submission status: Accepted

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

result = 1
flag = 0
zero_flag = False
for x in range(N):
  if(i[x]==0):
    zero_flag = True
    result = 0

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

if(flag==1):
  print('-1')
else:
  print(result)

Submission status: Accepted

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

ans = int(A[N])

if 0 in A:
    ans = 0
else:
    while N > 0:
        ans = ans * A[N-1]
        N = N-1
        if ans > 10 ** 18:
            N = 0
        else:
            N = N

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

Submission status: Accepted

Solution code:
# coding: utf-8
a = int(input())
b = list(map(int, input().split()))
c = 1
if 0 in b:
    print(0)
else:
  while c < 10 ** 18 and len(b) != 0:
    c = c * b[0]
    del b[0]
  if c > 10 ** 18:
    print(-1)
  else:
    print(c)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
import numpy as np
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

n = int(input())

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

ans = 1
for i in range(n):
  if (A[i] == 0):
    print(0)
    exit()
    
for i in range(n):
    ans *= A[i]
   
    if ans > 1000000000000000000:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

if 0 in numbers:
  print("0")
else:
 result=1
 for n in numbers:
    result *= n
    if result > 10**18:
      result = -1
      break
 print(result)

Submission status: Accepted

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

if 0 in A:
    print(0)
else:

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

Submission status: Accepted

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

Submission status: Accepted

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

result = As[0]
if 0 in As:
    print(0)
else:
    for i in range(n-1):
        result = result*As[i+1]
        if result > 10**18 :
            print(-1)
            break
        else:
            continue
    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 set(A):
  print("0")
  sys.exit()  

ans = 1
for i in A :
  ans *= i
  if ans > 1000000000000000000 :
    print("-1")
    sys.exit()

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = [int(x) for x in input().split()]

ans = 1
c=0

A.sort()

for x in A:
    ans = ans * x
    if ans == 0:
        print(0)
        c=1
        break
    elif ans > 10**(18):
        print(-1)
        c=1
        break

if c==0:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
b = 0
is_include_zero = False
too_big = False
for i in a:
    if int(i) > 10 ** 18:
        print(-1)
        too_big = True
    if int(i) == 0:
        is_include_zero = True
if too_big:
    pass
elif is_include_zero:
    print(0)
else:
    for i in range(n):
        if b > 10 ** 18:
            break
        if i == 0:
            b = int(a[i])
        else:
            b = b * int(a[i])
    if b > 10 ** 18:
        print(-1)
    else:
        print(int(b))

Submission status: Accepted

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

n = int(input())
num_list = list(map(int, input().split()))
sum=1

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

for i in num_list:
    
    if i==0:
        print(0)
        exit()
    i=str(i)
    sum=str(sum)
    
    if len(i)+len(sum)>21:
        print(-1)
        exit()
    i=int(i)
    sum=int(sum)
    sum=sum*i
    if sum>10**18:
        print(-1)
        exit()
print(sum)

Submission status: Accepted

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

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

ans = 1
for ni in A:
  ans = ans * ni
  if ans > 1000000000000000000:
    print(-1)
    exit()
    
print(ans)

Submission status: Accepted

Solution code:
import math
import sys
import functools
import operator

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


ans = 1
INF = 1000000000000000000

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

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

print(ans)

Submission status: Accepted

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

ans = 1

A = sorted(A, reverse=True)

if 0 not in A:
    for i in A:
        ans *= i
        if ans > 10 ** 18:
            break
else:
    ans = 0

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

#標準出力からの読み込み

n = int(input())
a = [int(s) for s in input().split(" ")]
output = 1

if a.count(0) >= 1:
    output = 0
else:
    number = 1
    for i in a:
        number = number*i
        output = number
        if number > 1000000000000000000:
            output = -1
            break;
        
print(output)

Submission status: Accepted

Solution code:
N = int(input())
numList = list(map(int, input().split()))
product = 1
toPrint = True
isZero = False
for j in numList:
    if j == 0:
        isZero = True
if not isZero:
    for i in numList:
        product = product * i
        if product > 10**18:
            toPrint = False
            break
if isZero:
    print(0)
else:
    if toPrint:
        print(product)
    else:
        print(-1)

Submission status: Accepted

Solution code:

import sys
N = int(input())
A = list(map(int, input().split()))
A.sort()
tar = 1
for i in A:
    tar *= i
    if tar > 10 ** 18:
        print('-1')
        sys.exit()

print(tar)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

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

result=1
for i in X:
  result*=i
  if result>10**18:
    result=-1
    break
for i in X:
  if i==0:result=0

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n = int(input())
m = 10**18
l = [int(x) for x in input().split()]
l.sort();
prod = 1
for i in l:
	prod *= i
	if prod > m:
		prod = -1
		break
	elif prod == 0:
		break
print(prod)

Submission status: Accepted

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

ans = A[0]
isOver = False

if 0 in A:
    print(0)
else:
    for i in range(1, N):
        ans *= A[i]
        ans_size = int(math.log10(ans) + 1)
        if ans_size >= 19 and ans - (10**18) >= 1:
            isOver = True
            break

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N=ii()
    A=lmis()
    A.sort()
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)





main()

Submission status: Accepted

Solution code:
n = int(input())

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

res = 1

if 0 in a:
    print(0)
else:
    for i in range(n):
        res *= a[i]

        if a[i] == 0:
            break
        if res > 10**18:
            print(-1)
            break


    if res > 10**18:
        pass
    else:
        print(res)

Submission status: Accepted

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

MAX = 1000000000000000000
ans = 1

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
if 1 in a:
    a.remove(1)
ans = 1

if 0 in a:
    print(0)
else:
    for i in range(len(a)):
        if ans <= 10 ** 18:
            ans *= a[i]
    if ans <= 10 ** 18:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
n = stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]
tmp = 1
ok = 1
for i in a:
    if i == 0:
        print(0)
        sys.exit(0)
    if ok == 1:
        tmp *= i
        if tmp > 1000000000000000000:
            ok = 0
if ok == 0:
    print(-1)
else :
    print(tmp)

Submission status: Accepted

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

ch1 = 0
for i in a:
	if(i == 0):
		print(0)
		ch1 = 1
		break

if(not ch1):
	ans = 1
	ch2 = 0
	for i in a:
		ans*=i
		if(ans > int(1e18)):
			print(-1)
			ch2 = 1
			break
	if(not ch2):
		print(ans)

Submission status: Accepted

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


# N = 3
# ARR = [1000000000, 0, 9]
#
# N = 31
# ARR =  [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]

def calculate(n, arr):
    res = 1
    for i in range(n):
        if arr[i] == 0:
            res = 0
            break

        if res == -1:
            continue

        res = res * arr[i]
        if res > 1000000000000000000:
            res = -1

    return res


print(calculate(N, ARR))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
#print(n)
prod = 1
overflow = False

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

for aa in a:
  if prod * aa > 1000000 * 1000000 * 1000000:
    overflow = True
  else:
    prod = prod * aa

for aa in a:
  if aa == 0:
    overflow = False

if overflow:
  print(-1)
else:
  print(prod)

Submission status: Accepted

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

maxval = 10 ** 18
ans = 1


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

Submission status: Accepted

Solution code:
n = int(input())
ans = 1

nums = list(map(lambda x : int(x),input().split()))

for i in range(n):
    if nums[i] == 0:
        ans = 0
        break
        
for k in range(n):
    ans *= nums[k]
    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()))
    temp = 1
    if 0 in a:
        temp = 0

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ass.sort(reverse=True)

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

ans = 1
for i in range(n):
	ans *= ass[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 num, val in enumerate(a):
        ans *= val
        if ans > 10**18:
            print(-1)
            break 
    else:
        print(ans)

Submission status: Accepted

Solution code:
def Multiplication_2():
    N = int(input())
    An = list(map(int,input().split()))

    if 0 in An:
        return 0
    
    over = 10 ** 18

    ans = 1
    
    for i in An:
        ans *= i
        if ans > over:
            return -1
        #print(ans)
    
    return ans

print(Multiplication_2())

Submission status: Accepted

Solution code:
n = int(input())
ls = [int(x) for x in input().split()]
if 0 in ls:
    print(0)
    exit()
res = 1
for x in ls:
    if res <= 1000000000000000000:
        res *= x
    else:
        break

print(res if res <= 1000000000000000000 else -1)

Submission status: Accepted

Solution code:
import sys

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

num = 1

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

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

print(num)

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1

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

  print(ans)

else:
  print(0)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from sys import stdin
input = stdin.readline



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

ans = 1
ng = False
for i in range(n):
    if l[i] == 0:
        print(0)
        quit()
    if not ng:
        ans *= l[i]
        if ans > 10**18:
            ng = True

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*n
a = input().split()
n0 = a.count('0')
sum = int(a[0])
if n0 == 0:
  for k in range(len(a)-1):
    sum =sum*int(a[k+1])
    if sum >1000000000000000000:
      print(-1)
      break
  if sum <=1000000000000000000:
    print(sum)
else:
  print(0)

Submission status: Accepted

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

ans = 1

over=False
zero=False

if 0 in data:
    zero=True

for num in data:
    ans*=num
    if(ans>1000000000000000000):
        over=True
        break

if ans>1000000000000000000:
    over=True

if zero:
    print("0")
elif over:
    print("-1")
else:
    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 a:
    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()))
if 0 in a:
  print(0)
else :
  prod = 1
  for x in a:
    prod *= x
    if prod:
      if prod > 10**18:
        print(-1)
        break
    else :
      print(0)
      break
  else :
    print(prod)

Submission status: Accepted

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

if 0 in As:
    print("0")
    exit()

pi = 1
for A in As:
  pi*=A
  if pi>1000000000000000000:
    print("-1")
    exit()

print(str(pi))

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

Submission status: Accepted

Solution code:
import sys
a = int(input())
c = list(map(int, input().split()))

if 0 in c:
  print('0')
  sys.exit()

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

Submission status: Accepted

Solution code:
def main():
    import sys
    n = int(input())
    a = list(map(int, input().split()))

    try:
        if a.index(0):
            print(0)
            sys.exit()
    except ValueError:
        pass

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math,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 = ans*A[i]
    if ans > pow(10,18):
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

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

if __name__=='__main__':
    main()