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

Submission status: Accepted

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

A.sort()

for i in A:
    if 0 <= (ans * i) and (ans * i) <= 1000000000000000000:
        ans *= i
        #print(ans)
    else:
        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(0)

for i in A:
    ans = ans * 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)

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()))
if min(a) != 0:
  ans = 1
  for i in range(n):
    ans = ans*a[i]
    if 10**18 < ans:
      print(-1)
      break
  if ans <= 10**18 and ans != 0:
      print(ans)
else:
  print(0)

Submission status: Accepted

Solution code:
def main():
  n=int(input())
  anums=list(map(int,input().split()))
  res=1
  if 0 in anums:
    return 0
  for anum in anums:
    res*=anum
    if res>10**18:
      return -1
  return res
print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:


n=int(input())
l=list(map(int,input().split()))
res=1
f=1
if(0 in l):
    print(0)
    f=0
if(f==1):
    
    for x in l:
        res=res*x
        if(res>1000000000000000000):
            print(-1)    
            f=0
            break
    
    if(f==1):
        print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input().split()))
if 0 in s:print(0);exit()
ans=1
for i in s:
  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()))

ans = 1

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

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

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

m = a[0]
over = False
limit = pow(10, 18)
for i in a[1:]:
    m *= i
    if m > limit:
        over = True
        break

if over:
    print("-1")
else:
    print(m)

Submission status: Accepted

Solution code:
import math
n = int(input())

val = pow(10,18)
p = 1
a = list(map(int,input().strip().split()))
	
a.sort()

for i in range(n):
	p = p*a[i]
	if (p>val):
		p = -1
		break

print (p)

Submission status: Accepted

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

if 0 in a:
    print('0')
else:
    for b in a:
        res *= b
        if res > 1e18:
            print('-1')
            break
    else:
        print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

##### 進数の変換 #####
# bin_str = bin(i)[2:]
# oct_str = oct(i)[2:]
# hex_str = hex(i)[2:]

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	ans = 0
	for i,vol in enumerate(A):
		if i == 0:
			ans = vol
			continue
		ans = ans * vol
	
		if ans > 1000000000000000000:
			if 0 in A:
				print(0)
				sys.exit()
			else:
				print(-1)
				sys.exit()

	print(ans)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索のリバース
def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索
# 存在しない場合: None 存在する場合: その値
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
if 0 in A:
    print(0)
    exit()
ans = A[0]

for i in A[1:]:
    ans *= i
    if ans > 10 ** 18:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
xs = [int(x) for x in input().split()]

if 0 in xs:
  print(0)
else:
  s = 1
  for x in xs:
    s *= x
    if s > 10 ** 18:
      print(-1)
      break
  else:
    print(s)

Submission status: Accepted

Solution code:
N=int(input())
n=list(map(int,input().split()))
A=n[0]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = 1
over = False
zero = False

for i in range(N):
    if A[i] == 0:
        zero = True
        break

if zero:
    print(0)
else:
    for i in range(N):
        s *= A[i]
        if s > 10**18:
            over = True
            break
    if over :
        print('-1')
    else:
        print(s)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    max_ans = 10 ** 18
    ans = 0
    if 0 in A:
        print(0)
        exit()

    for i, a in enumerate(A):
        if i == 0:
            ans = a
            continue

        ans = ans * a
        if ans > max_ans:
            print(-1)
            exit()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

an = 1

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

print(an)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
List = list(map(int,input().split()))
import math
def seki(L):
  num = 1
  for i in L:
    num *= i
  return num
def Seki(L):
  if len(L) <= int(math.sqrt(N)):
    return seki(L)
  else:
    return Seki(L[:len(L)//2]) * Seki(L[len(L)//2:])
if Seki(List) <= 10**18:
  print(Seki(List))
else:
  print(-1)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        return 0
    prod = 1
    for i in range(N):
        if 10**18//prod < A[i]:
            return -1
        prod *= A[i]
    return prod
print(solve())

Submission status: Accepted

Solution code:
def main ():
  input()
  result = 1
  for i in map(int, input().split()):
    if i == 0:
      result = 0
      break
    
    if result == -1:
      continue
      
    result = result * i
    if result > 10 ** 18:
      result = -1
  
  return result

print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
a = 1
i = 0
while a<= 10**18 and i <=n-1:
    a = a*lis[i]
    i = i + 1

if 0 in lis:
    print(0)
elif a > 10**18:
    print("-1")
else:
    print(a)

Submission status: Accepted

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

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

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

print(x)

Submission status: Accepted

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

a.sort()
ans = 1
above = False
for x in a:
	ans *= x
	if ans > 10**18:
		above = True
		break

if not above:
	print(ans)
else:
	print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=1
f=1
i=0
for i in range(n):
  if ans<=10**18:
    ans=ans*l[i]
  else:
  	f=0
if f==1 and ans<=10**18:
  print(ans)
else:
  print(-1)

Submission status: Accepted

Solution code:
input()
r = 1
for x in map(int, input().split()):
  if x == 0:
    r = 0
    break
  if r > 0:
    r *= x
    if r > 1e18:
      r = -1
print(r)

Submission status: Accepted

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

res = 1
from collections import Counter
count = Counter(al)
cc = count[0]

if cc >=1:
    print(0)
    exit()

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

else:        
    print(res)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1
if min(a) == 0:
    print('0')
    exit()
else:
    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=list(map(int, input().split()))

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

output = 1

if 0 in nums:
  print(0)
  sys.exit()
  
else:
  for x in nums:
    output *= x

    if output > 10**18:
      print(-1)
      sys.exit()

  print(output)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

answer = A[0]
overl = False

for i in range(N-1):
    answer *= A[i+1]
    if answer > 10**18:
        overl = True
        break

if overl:
    print("-1")
else:
    print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

LIMIT = 10**18

if 0 in set(As):
    print(0)
else:
    result = 1
    for a in As:
        result *= a
        if result > LIMIT:
            result = -1
            break
    
    print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

result = 1
for num in nums:
    result *= num

    if result > 10 ** 18:
        print(-1)
        exit()

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    A_list = [int(item) for item in input().split()]

    is_zero = False
    is_over = False
    res = 1

    for item in A_list:
        if item == 0:
            is_zero = True
            break

    if is_zero:
        print(0)
    else:
        for item in A_list:
            res *= item

            if res > 10 ** 18:
                is_over = True
                break
        else:
            print(res)

        if is_over:
            print(-1)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

results = A[0]
can = True
zero = False
for i in range(N):
    if A[i]==0:
        zero = True
        break

if zero:
    print(0)
else:
    for i in range(N):
        if i==0:
            continue
        results *= A[i]
        if results>10**18:
            can = False
            break

    if can:
        print(results)
    else:
        print(-1)

Submission status: Accepted

Solution code:
N = int(input())
input_list = [int(i) for i in input().split()]
max_num = 10 ** 18

sum_num = 1
if 0 in input_list:
    print('0')
else:
    for i in input_list:
        sum_num *= i
        if sum_num > max_num:
            sum_num = -1
            break
    print(sum_num)

Submission status: Accepted

Solution code:
n = int(input())
a = map(int, input().split())
sum = 1
for x in a:
  sum *= x
  if sum > 1e18:
    sum = -1
    break
if 0 in a:
  sum = 0
print(sum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

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

Submission status: Accepted

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

    if A.__contains__(0):
        print(0)
        return

    ans = A[0]
    for v in range(1, N):
        if ans > 10 ** 18:
            print(-1)
            return
        else:
            ans *= A[v]
    if ans > 10 ** 18:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for item in A:
    m *= item
    if m > 10 ** 18:
        print("-1")
        sys.exit()
print(m)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(input().split())
A = [int(i) for i in A]
if 0 in A:
    print(0)
    exit(0)

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

Submission status: Accepted

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n = int(input())
    a = [int(x) for x in 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)
                return
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
num_list = list(map(int, input().split()))
sum = 1
for i in range(len(num_list)):
	if num_list[i] == 0:
		print(0)
		sys.exit()

for i in range(len(num_list)):
	sum *= num_list[i]
	if sum > 1000000000000000000:
		print(-1)
		sys.exit()

print(sum)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    if 0 in A:
        ans = 0
    else:
        for a in A:
            ans *= a
            if ans > 1000000000000000000:
                ans = -1
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if 0 in a:
    print(0)

else:
    m=1

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

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

Submission status: Accepted

Solution code:
import math

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

flag_zero = 0
sum = 0
for i in range(n):
  if a[i]==0:
    flag_zero = 1
  else:
    sum += math.log10(a[i])

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

Submission status: Accepted

Solution code:

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


print(c)

Submission status: Accepted

Solution code:
# your code goes here
n = int(input())
a = input().split()
res = 1
zero = 0
for e in range(n):
	if int(a[e]) == 0:
		zero = 1
for e in range(n):
	res *= int(a[e])
	if res > 1000000000000000000:
		break
if zero == 1:
	print(0)
elif res > 1000000000000000000:
	print(-1)
else:
	print(res)

Submission status: Accepted

Solution code:
"""
~~ Author : Bhaskar
~~ Dated : 31~05~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 10**18
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")

def solve():
    n = int(sys.stdin.readline())
    a = list(map(int,sys.stdin.readline().split()))
    ans =  1
    flag = False
    for i in a:
        ans *= i
        # print(ans)
        if ans > mod:
            flag = True
            break
    if 0 in a:
        print(0)
    else:
        if not flag:
            print(ans)
        else:
            print(-1)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys

MAX = 10**18

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

if 0 in A:
    print("0")
else:
    res = 1
    for a in reversed(sorted(A)):
        if a == 1:
            break
        res *= a
        if res > MAX:
            print("-1")
            sys.exit()
    print(res)

Submission status: Accepted

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

b = 10 ** 18
cnt = 1

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

for i in range(N):
    a = A[i]
    if a > b:
        print(-1)
        exit(0)
    cnt *= a
    if cnt > b:
        print(-1)
        exit(0)
print(cnt)

Submission status: Accepted

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


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    limit = 10 ** 18

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

    ans = 1
    for i in a:
        ans *= i
        if ans > limit:
            ans = -1
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


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

Submission status: Accepted

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

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>1000000000000000000:
        print("-1")
        exit()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
*a, = map(int, input().split())
th = 10**18

if 0 in a:
    print(0)
    exit()
mul = 1
for i in range(n):
    mul *= a[i]
    if mul > th:
        print(-1)
        exit()
print(mul)

Submission status: Accepted

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

MAX=10**18
ans = 1
fover=False
fzero=False
for A in As:
    if A==0:
        fzero=True
        break
    if not fover:
        ans *= A
        if ans > MAX:
            fover=True

if fzero:
    print(0)
elif fover:
    print(-1)
else:
    print(ans)