Problem:


Score : 200 points

Problem Statement

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

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

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

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

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

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

Sample Input 3

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

Sample Output 3

0



Sample input:
2
1000000000 1000000000


Sample output:
1000000000000000000

Submission status: Accepted

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

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

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

print(r)

Submission status: Accepted

Solution code:
x = input()
y = [int(a) for a in input().split(" ")]
if 0 in y:
  print(0)
  exit(0)
res = 1
for i in y:
  res *= i
  if res > int(1e+18):
    print(-1)
    exit(0)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        ans = 0
    else:
        ans = 1
        for x in A:
            ans *= x
            if ans > 10**18:
                ans = -1
                break
    print(ans)

 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

Submission status: Accepted

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

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

for i in range(n):
    if re > 1000000000000000000:
        break
    re = re * li[i]
if 0 in li:
    print(0)
elif re > 1000000000000000000:
    print(-1)
else:
    print(re)

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)
import operator as op



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    ans = 1
    if any(map(lambda x: x==0, L)):
        print(0)
    else:
        for i in range(n):
            ans = ans * L[i]
            if ans > 10**18:
                print(-1)
                exit()
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


class Solution:
    def main(self):
        n = int(input())
        a = list(map(int, input().split()))

        a.sort()

        ans = 1
        for v in a:
            ans *= v;
            if ans > 10 ** 18:
                print(-1)
                return
        print(ans)

# Run main
if __name__ == '__main__':
    Solution().main()

Submission status: Accepted

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

Submission status: Accepted

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

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

    else:
        print(ans)

Submission status: Accepted

Solution code:
n = int(input())
goukei = 1
ok = 0
arr = [int(x) for x in input().split()]
if 0 in arr:
    print(0)
else:
    for i in arr:
        goukei *= int(i)
        if goukei > 1000000000000000000:
            print(-1)
            ok = 1
            break
    if ok == 0:
        print(goukei)

Submission status: Accepted

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

A = sorted(A, reverse= True)

if A[-1] == 0:
    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:
N=int(input())
A = list(map(int,input().split()))
#print(A[0])
if 0 in A:
  print('0')
  exit()

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

Submission status: Accepted

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

if 0 in A:
    ans = 0
else:
    for num in A:
        ans *= num
        if ans > 1e18:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input("").split()))
ans=1
A.sort()
for i in A:
    ans*=i
    if ans==0:
        break
    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:
    ans = 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())
L=list(map(int,input().split()))
L.sort()
if L[0]==0:
    print(0)
else:
    ans=1
    for i in range(n-1,-1,-1):
        ans=ans*L[i]
        if ans >1e18:
            print(-1)
            break
    else:
        print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()
res = 1
if 0 in A:
  res = 0
else:
  for i in range(N):
    res *= A[i]
    if res > 10**18:
      res = -1
      break

print(res)

Submission status: Accepted

Solution code:

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *
from heapq import *

def mi():
    return map(int, input().split())
def ii():
    return int(input())
def li():
    return list(mi())
def gcd(a,b):return a if(not b) else gcd(b,a%b)
def qw(a,b,p):
    '''quick pow'''
    ans = 1
    while b:
        if b & 1:
            ans = ans * a % p
        a = a * a % p
        b >>= 1
    return ans
def is_prime(x):
    if(x < 2): return 0
    for i in range(2,int(sqrt(x)+1)):
        if(x % i == 0) : return 0
    return 1

n = ii()
a = li()
ans = 1
ok = 1
a.sort()
for i in range(0,n):
    ans = ans * a[i]
    if(ans > 1000000000000000000):
        ok = 0
        break
# print(ans)
if(ok == 0):print(-1)
else: print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
Alist=list(map(int,input().split()))
multi=Alist[0]
ibreak=0
if(Alist.count(0)>0):
    print(0)
else:
    for i in range (N-1):
        multi*=Alist[i+1]
        if(multi>1e18):
            print(-1)
            ibreak=1
            break;
    if(ibreak==0):
        print(multi)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A = LI()
ans = A[0]
if 0 in A:
    ans = 0
else:
    for i in range(1, N):
        if ans > 10**18:
            ans = -1
            break
        else:
            ans = ans*A[i]
if ans > 10**18:
    ans = -1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N = read_a_int()
A = read_ints()
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:
N = int(input())
A = list(map(int, input().split()))
A.sort()
answer = 1
for i in A:
    answer *= i
    if answer > 10 ** 18:
        break

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

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
if 0 in As:
    print(0)
else:
    As = sorted(As, reverse=True)
    ans = 1
    break_flag = 0
    for n in range(N):
        ans *= As[n]
        if ans > 1e18:
            print(-1)
            break_flag = 1
            break
    if break_flag == 0:
        print(ans)

Submission status: Accepted

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

ans = 1
for a in A:
    ans *= a
    if  ans > 1000000000000000000:
        break

if 0 in A:
    print(0)
elif ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
i = 0
while i<=n-1 and ans<= 10**18:
    ans *= a[i]
    i += 1
if 0 in a:
    print('0')
elif ans <= 10**18:
    print(ans)
else:
    print('-1')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
m = 1000000000000000000
num_list = [ int(v) for v in input().split() ]
ans = 1
s = 0
if 0 in num_list:
	ans = 0
for i in num_list:
	ans *= i
	if ans > m:
		s = 1
		break
if s == 0:
	print(ans)
else:
  	print(-1)

Submission status: Accepted

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

print(b)

Submission status: Accepted

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

    ans = 1
    th = 1000000000000000000

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
S = list(map(int,input().split()))
if 0 in S:
    print(0)
else:
    i = 0
    m = 1
    while i < n:
        m = m*S[i]
        if m > 1000000000000000000:
            print(-1)
            break
        i += 1
    else:
        print(m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
result = 1
if 0 in A:
	result = 0
else:
	for i in range(N):
		result = result*A[i]

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
p = 1
c = 0
a.sort()
for i in range(n):
	p = a[i]*p
	if p > pow(10,18):
		break
	c += 1

if c == n:
	print(p)
else:
	print(-1)

Submission status: Accepted

Solution code:
n=int(input())

a=[]

import sys

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


c=1
if a.count(0)>=1:
    print(0)
    sys.exit()

for k in range(n):

    c*=int(a[k])

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


print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MAX_VAL = 10 ** 18

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

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

ans = 1
for i, a in enumerate(A):
    if i == 0:
        ans = a
    else:
        ans *= a

    if ans > MAX_VAL:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
if a[0] == 0:
    print(0)
else:
    s = 1
    for aa in a:
        s *= aa
        if s > 1e18:
            print("-1")
            break
    if s <= 1e18:
        print(s)

Submission status: Accepted

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

rev_A = sorted(A, reverse=True)

if 0 in rev_A:
    print(0)
    exit()
else:
    limit = 10 ** 18
    current = 1

    for x in range(N):
        current *= rev_A[x]

        if current > limit:
            print(-1)
            exit()
    print(current)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = LMI()
ans = 1
th = 10 ** 18
if 0 in A:
    print(0)
    exit()
for a in A:
    ans *= a
    if ans > th:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([int(n) for n in input().split()], reverse=True)
M = 10**18
ans = A[0]
for i in range(1, len(A)):
    if A[-1] == 0:
        ans = 0
        break
    ans *= A[i]
    if M < ans:
        ans = -1
        break 
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
prod = 1
maxx = 10**18
found = 2
arr = list(map(int,input().split()))
if(0 in arr):
    found = 1
if(found==2):
    for i in arr:
        if(prod*i>maxx):
            found = 0
            break
        else:
            prod*=i
if(found==2):
    print(prod)
elif(found==1):
    print(0)
else:
    print(-1)

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=ans*L[i]
    if ans > 10**18:
        print("-1")
        exit()
print(ans)

Submission status: Accepted

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

ans = 1
c=0
for i in range(N):
  a = List[i]
  ans *= a
  if ans > 10**18:
    c=1
    break
d =0
for i in range(N):
  a = List[i]
  if a == 0:
    d = 1
    
if d == 1:
  print(0)
elif c ==1:
  print(-1)
else:
  print(int(ans))

Submission status: Accepted

Solution code:
import sys

n = int(input())
a = [num for num in map(int, input().split())]

if min(a) == 0:
  print(0)
  sys.exit(0)

ans = 1
m = 10 ** 18

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

print(ans)

Submission status: Accepted

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

for i in range(n):
    x=a[i]
    if x==0:
        print(0)
        exit()
    if not check==-1:
        sum*=x
        if sum>10**18:
            check=-1
if check==-1:
        print(-1) 
        exit()  
print(sum)

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(result)

Submission status: Accepted

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    A = kwargs["A"]
    res = 1

    for i in range(n):
        res *= A[i]

        if res > 10 ** 18:
            res = -1

            if min(A) == 0:
                res = 0

            break

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]

    cin = input().split()
    kwargs["A"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Submission status: Accepted

Solution code:
from sys import stdin,stdout
n = int(stdin.readline())
v = list(map(int, stdin.readline().split()))
flag = True
if 0 in v:
	print(0)
else:
	ans = 1
	for i in v:
		ans *= i
		if ans > 10 ** 18:
			flag = False
			break
	if flag == False:
		ans = -1
	stdout.write(str(ans) + '\n')

Submission status: Accepted

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

if(min(hoge)==0):
  print(0)
  flag=False
else:
  for i in range(n):
    ans=ans*hoge[i]
    if(ans>10**18):
      print(-1)
      flag=False
      break
if(flag):
  print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


def main():
    if A[0] == 0:
        print(0)
        return

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

    print(ans)



main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
# import numpy as np

def resolve():
    # s = input()
    n = int(input())
    a = list(map(int, input().split()))
    # l = [list(map(int, input().split())) for _ in range(n)]

    thr = 10 ** 18
    a.sort(reverse=True)
    ans = 1

    if 0 in a:
        ans = 0
    else:
        for a_i in a:
            ans *= a_i

            if ans > thr:
                ans = -1
                break

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1000000000 1000000000"""
        output = """1000000000000000000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
101 9901 999999000001"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """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"""
        output = """0"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
MAX = 10**18

ans = 1
for i in range(N):
    ans = ans*A[i]
    if ans > MAX:
        for j in range(i,N):
            if A[j]==0:
                ans = 0
                break
        if ans != 0:
            ans = -1
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)


N = int(readline())

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

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

    print(res)

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = [int(x) for x in input().split(" ")]
if 0 in set(A):
    print(0)
    sys.exit(0)

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


print(product)

Submission status: Accepted

Solution code:
n=int(input(''))
s=input('')
s=s.split(' ')
p=1
f=0
t=0

for a in range(n):
    s[a]=int(s[a])

for b in s:
    if b==0:
        t=1

if t==1:
    print(0)
else:
    for a in range(n):
        p=p*s[a]

        if p>10**18:
            f=1
            break


    if f==1:
        print(-1)
    else:
        print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce


def input():
    return sys.stdin.readline()[:-1]


def mm(a, b):
	ans = a*b
	if ans > 10**18:
		return 0
	else:
		return a*b

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

if 0 in A:
	print(0)
else:
	ans = reduce(mm, A)
	
	if ans == 0:
		print(-1)
	else:
		print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
ans = 1
flag = False
zeros = False
over = pow(10,18)
for i in a:
    if flag == False:
        ans *= i
    if (ans > over):
        flag = True
    if i == 0:
        zeros = True

if (flag):
    ans = -1
if (zeros):
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    ans = 0
else:
    for ai in a:
        ans = ans * ai
        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
su=0
count=0
for j in a:
    if j==0:
        su+=1
        break
if su>0:
    print(0)
else:
    for i in a:
        ans*=i
        if ans>1000000000000000000:
            print(-1)
            count+=1
            break
    if count!=1:
        if ans>1000000000000000000:
            print(-1)
        else:
            print(ans)

Submission status: Accepted

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

if 0 in A:
    print(0)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
  print(0)
elif sum(A) // N > 2 and N > 60:
  print(-1)
else:
  ans = 1
  for i in A:
    ans *= i
  print(ans if ans <= 10 ** 18 else -1)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
ans=1
if 0 in a:
  ans=0
else:
  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())
Ai = [0] * N
Ai = list(map(int,input().split()))
Ai.sort()
Ans = 1

for i in range(N):
  if Ai[i] == 0:
    Ans = 0
    break
    
  Ans = Ans * Ai[i]

  if Ans > 10 ** 18:
    Ans = -1
    break
  
if Ans <= 10**18:
  print(Ans)
else:
  print('-1')

Submission status: Accepted

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

def solve():
    maxv = 10 ** 18
    p = 1
    for x in A:
        p *= x
        if p > maxv:
            p = -1
            break
    print(p)

zero = False
for a in A[:]:
    if a == 0:
        zero = True
if zero:
    print(0)
else:
    solve()

Submission status: Accepted

Solution code:
def quick_sort(list):
    stand=list[0]
    over=[]
    same=[]
    under=[]
    for i in list:
        if(i>stand):
            over.append(i)
        elif(i<stand):
            under.append(i)
        else:
            same.append(i)
    if(len(over)>1):
        over=quick_sort(over)
    else:
        pass
    if(len(under)>1):
        under=quick_sort(under)
    else:
        pass

    return under+same+over

N=int(input())
A=list(map(int,input().split()))
A=quick_sort(A)
ans=1
way=0
for i in A:
    ans*=i
    way=str(ans-1)
    if(len(way)>=19):
        ans=-1
        break
    else:
        pass
print(ans)