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())
S=list(map(int,input().split()))
if S[0]==0:
  print(0)
else:
  X=S[0]
for i in range(1,N):
  if S[i]==0:
    X=0
    print(0)
    break
  else:
    if X>10**18:
      continue
    else:
      X=X*S[i]
if 0<X<=10**18:
  print(X)
else:
  if X!=0:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
i = 0
p = 1

if 0 in a:
    print("0")
else:
    while i < n:
        p *= a[i]
        if p > 10**18:
            break
        i += 1
    if p <= 10**18:
        print(p)
    else:
        print("-1")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

now = 1

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

print(now)

Submission status: Accepted

Solution code:
num = input()
a = input().split()

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

print(b)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys
def v():
    N=int(sys.stdin.readline())
    A=list(map(int,sys.stdin.readline().split()))
    if A.count(0)>0:return 0
    else:
        A=list(filter(lambda x:x>1,A))
        x=1
        for a in A:
            x*=a
            if x>10**18:
                x=-1
                break
        return x
def main():print(v())
if __name__=='__main__':main()

Submission status: Accepted

Solution code:
N = int(input())
vals = [int(v) for v in input().split()]

rslt = 1

if 0 in vals:
  rslt = 0

for v in vals:
  rslt = rslt * v
  
  if rslt > 10 ** 18:
    rslt = -1
    break

print(rslt)

Submission status: Accepted

Solution code:
import sys
N = int(input())

b = 1

a = sorted(list(map(int, input().split())), reverse=True)
if a[-1] == 0:
    print("0")
    sys.exit()
for i in a:
    b *= i
    if b > pow(10, 18):
        print("-1")
        sys.exit()
print(b)

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
a=1
for i in sorted(l):
  a*=i
  if a>10**18: a=-1; break
print(a)

Submission status: Accepted

Solution code:


N = int(input())
A_list = list(map(int, input().split()))
A_list.sort()
if A_list[0] == 0:
    print(0)
else:
    ans = 1

    for a in A_list:
        ans *= a

        if ans > 10 ** 18:
            ans = -1
            break

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
if A.count(0):
    print(0)
    exit()
A = sorted(A)
ans = 1
for i in range(n):
    if ans * A[i] > 10**18:
        print(-1)
        exit()
    ans *= A[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *
n = int(input())
a = [int(x) for x in input().split()]
ans = 1
ok = False
fail = False
for x in a:
  if (x == 0):
    ok = True
    break
for x in a:
  if (ans * x > 1000000000000000000):
    fail = True
    break
  ans *= x
if (ok):
  print(0)
else:
  if (fail):
    print("-1")
  else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

Submission status: Accepted

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

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

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

now = 1

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

print(now)

Submission status: Accepted

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

t = 1

for i in A:
    t *= i

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

print(t)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
totalNumbers = int(input())
array = list(map(int, input().split()))
answer = 1
if 0 in array:
    print(0)
else:
    for number in array:
        answer*=number
        if answer>10**18:
            answer=-1
            break
    print(answer)

Submission status: Accepted

Solution code:
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()

  #f_inf=float("inf")
  #MOD=10**9+7
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    n = 2
    A = [1000000000, 1000000000]

  else:
    ##INPUT 
    n = input()
    A = list(map(int, input().split()))

  ## SUBMITION CODES HERE
  if 0 in A:
    print(0)
    exit()
  
  ans = 1
  for a in A:
    ans *= a
    if ans > 10**18:
      ans = -1
      break
  
  print(ans)
    
main()

Submission status: Accepted

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

def solve():
    N = int(input())
    As = list(map(int, input().split()))
    MAX = 10**18

    if 0 in As:
        print(0)
        return

    ans = 1
    for a in As:
        ans *= a
        if ans > MAX:
            print(-1)
            return
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    n = int(readline().rstrip())
    aList = list(map(int, readline().rstrip().split()))
    ans = 1

    if 0 in aList:
        print(0)
        return

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if ans == 10**18+1:
    ans = -1

print(ans)

Submission status: Accepted

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

ans = 1
flag = True
flag_zero = False
for a in A:
    ans *= a
    if ans > 10 ** 18:
        flag = False
        break
    if a == 0:
        flag_zero = True
        break

if flag:
    if not flag_zero:
        print(ans)
    else:
        print(0)
else:
    print(-1)

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    if(0 in A):
        print(0)
        sys.exit()

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

    print(sum_l)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Accepted

Solution code:
#１文字をインプット
a=int(input())
#1行をint型でインプット
li = list(map(int,input().split()))

#初期値をセット
sum=1

#リストに入っている分だけ掛ける
if 0 in li:#もしリストに0が入っていたら合計を0にして、34行目へ
    sum = 0
else:
    for i in range(a):
        sum = sum*li[i]
        if sum > 10**18:
            break

if sum <= 10**18:#10の18乗以下の場合、答えを出力
    print(sum)
else:#10の18乗を超える場合、'-1'を出力
    print(-1)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(item) for item in input().split()]
l.sort()
product = 1
flag=0
for i in l:
	product *= i
	if product > int(10**18):
		print("-1")
		flag=1
		break
 
if flag == 0:
	print(product)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = [int(item) for item in input().split()]
l.sort()
product = 1
flag=0
for i in l:
	product *= i
	if product > int(10**18):
		print("-1")
		flag=1
		break

if flag == 0:
	print(product)

Submission status: Accepted

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

Submission status: Accepted

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

main ()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
for i in A:
    ans*=i
    if ans>1e18:
        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:
  print(0)
  exit()

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

print(result)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
if A.count(0) != 0:
  ans = 0
else:
  ans = 1
  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()))
a.sort()

if a[0] == 0:
    print(0)
    exit(0)

lim = 10 ** 18
ans = 1

for x in a:
    ans *= x
    if ans > lim:
        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:
    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())
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)

Submission status: Accepted

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

res = 1

for a in A:
  res *= a
  
  if res > 10**18:
    res = -1
    break

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
m = 1
for n in input().split():
  i = int(n)
  m = m * i
  if m > 10 ** 18 or m < 0:
    m = -1
print(m)

Submission status: Accepted

Solution code:
def main():
    lim = 1e18
    n = int(input())
    nums = list(map(int,str(input()).split(" ")))
    if 0 in nums:
        print(0)
        return
    ans = 1
    for num in nums:
        ans *= num
        if ans > lim:
            print(-1)
            return
    print(ans)
    return

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(str(ans))

Submission status: Accepted

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

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

print(str(ans))

Submission status: Accepted

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

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

ans = 1

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = map(int, sorted(input().split()))
count = 1

for i in A:
    count *= i

    if i == 0:
        print(0)
        sys.exit()
    elif count > 10 ** 18:
        print(-1)
        sys.exit()
    else:
        pass

print(count)

Submission status: Accepted

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

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

j = 1
ans = l[0]
while j < n:
    ans = ans * l[j]
    j += 1
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(n, a):
  if 0 in a:
    return 0
  else:
    p = 1
    x = 10**18
    for i in a:
      if p<=x:
      	p*=i
      else:
        break
    if p>x:
      p = -1
    return p

n = int(input())
a = [int(x) for x in input().split()]
print(solve(n, a))

Submission status: Accepted

Solution code:
L = 1000000000000000000
r = 1
n = input()
A = list(map(int, input().split()))
A = sorted(A)
if A[0] == 0:
    print(0)
else:
    p = True
    while len(A) > 0:
        b = A.pop()
        r *= b
        if r > L:
            print(-1)
            p = False
            break
    if p: print(r)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
res=1
z=10**18
for i in a:
    if(i==0):
        res=0
        break
i=n-1
while(i>=0):
    if(a[i]==0):
        res=0
        break
    if(res>z/a[i]):
        res=z+1
        break
    res*=a[i]
    if(a[i]>z):
        break
    i-=1
if(res>z):
    res=-1
print(res)

Submission status: Accepted

Solution code:
def main ():
  N = int(input())
  A = list(map(int,input().split()))
  prod = 1 
  A.sort()
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  
  print(prod) 
 
main()

Submission status: Accepted

Solution code:
N = int(input())

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

if A.count(0):
    ans = 0
else:
    ans = A[0]
    for ai in A[1:]:
        ans *= ai
        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()))
    if 0 in a:
        print(0)
        exit(0)
    ans = 1
    MAX = 10**18
    for ai in a:
        ans *= ai
        if ans > MAX:
            print(-1)
            exit(0)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def q_b():
    k = int(input())
    a = map(int, input().split())
    a = list(a)

    is_finished = False
    for i in a:
        if i == 0:
            print(0)
            is_finished = True
            break

    if is_finished:
        return

    answer = 1
    for i in a:
        answer *= i
        if answer > 10 ** 18:
            print(-1)
            is_finished = True
            break

    if is_finished is False:
        print(answer)


if __name__ == '__main__':
    q_b()

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n = iinput()
a = iarr()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

a = list(int(i) for i in input().split(" "))

prod = 1

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


print(prod)

Submission status: Accepted

Solution code:
import sys

n= int(input())
a = list(map(int,input().split()))
a.sort()
ans_max = 10 ** 18

ans = a[0]
for i in range(1, n):
    ans *= a[i]
    if ans > ans_max:
        print("-1")
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
import sys

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

zero_search = 0 in a_list
ans = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

number = list(map(int,input().split()))
ans = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = solve(n, a)
    print(ans)

def solve(n, a):
    if 0 in a:
        return 0
    lim = 10 ** 18
    ans = 1
    for i in a:
        ans *= i
        #print(f'{ans:}')
        if ans > lim:
            return -1
    return ans

if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = sorted(a)

ans = 1

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

print(ans)

Submission status: Accepted

Solution code:
n = input()
s = 1

int_list = [int(s) for s in input().split()]
if 0 in int_list:
  print(0)
else:
  for i in int_list:
    s = s * int(i)
    if s > 1e+18:
      s = -1
      break
  print(s)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

flag = True
if 0 in A:
    prod = 0
else:
    prod = 1
    for i in range(N):
        prod *= A[i]
        if prod > 10**18:
            flag = False
            break

if flag == True:
    print(prod)
else:
    print(-1)

Submission status: Accepted

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


def main():
    import sys
    input = sys.stdin.readline

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

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

    for ai in a:
        ans *= ai

        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
if 0 in A:
    print(0)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] == 0:
    print(0)
    sys.exit()
    
ans = 1
cond = 0
for a in A:
    ans *= a
    if ans > 10**18:
        cond = 1
        break

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

Submission status: Accepted

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

num.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc(num_list) -> int:
    result = 1
    max = 10**18

    if 0 in num_list:
        return 0

    for num in num_list:
        result *= num
        if result > max:
            return -1
    return result

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

print(str(calc(num_list)))

Submission status: Accepted

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

ans = 1
ng = False
max = 10**18
for A in Aj:
	if A == 0:
		ans = 0
		break
	if ng or ans*A > max:
		ans = -1
		ng = True
	else:
		ans *= A
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
L = list(map(int,input().split()))
if(0 in L):
    print(0)
    sys.exit()
    
sum_l = 1
for x in L:
    sum_l *= x
    if(sum_l > 10 **18):
        print(-1)
        sys.exit()

print(sum_l)

Submission status: Accepted

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

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

else:
    for i in range(1, N):
        ans = ans * A[i]
        if ans > 1E+18:
            ans = -1
            break
        else:
            continue
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def multiplication2(n,a):
    #acc = functools.reduce(lambda x,y:x*y, a)
    acc = 1
    a_sorted = sorted(a)
    if a_sorted[0] == 0:
        return 0
    
    for s in a_sorted:

        acc = acc*s
        if 10**18 < acc:
            acc = -1
            break
    return acc

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    print(multiplication2(n,a))

Submission status: Accepted

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