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 numpy as np
n=int(input())
ans=1
a=input().split()
#print(a)
if '0' in a:
    ans=0
    print(ans)
else:
    for i in a:
        ans=ans*int(i)
        if ans>10**18:
            ans=-1
            break
    print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(input())

An = [int(_) for _ in input().split()]
An.sort()

ans = 1

for val in An:
    # 0がきたらすぐに抜ける
    if(int(val) == 0):
        print(0)
        sys.exit()
    ans *= val
    # ansが10^18を超えた時点で-1にする
    if(ans > 10 **18):
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
ans=1
a=input().split()
#print(a)
if '0' in a:
    ans=0
    print(ans)
if ans!=0:
    for i in a:
        ans=ans*int(i)
        if ans>10**18:
            ans=-1
            break
    print(ans)

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
from heapq import *
heapify(l)
while len(l)>1:
  heappush(l,heappop(l)*heappop(l))
print([l[0],-1][l[0]>10**18])

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    ans=1
    
    for i in range(N):
        ans=ans*A[i]
        if ans>pow(10,18):
            ans=-1
            break
        
    if 0 in A:
        ans=0
        
    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INF = 10 ** 18

n = int(input())
a = [int(i) for i in input().split()]

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

ans = 1
for i in range(len(a)):

    ans = ans * a[i]
    if ans > INF:
        print("-1")
        exit()

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    ans = 1
    if 0 in a: return 0
    for i in a:
        ans *= i
        if ans > int(1e18): return -1
    
    
    return ans
    

print(solve())

Submission status: Accepted

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

def main():

    if 0 in a:
        print(0)
        return
    
    val = 1
    for each in a:
        val *= each
        if val > 1e+18:
            print(-1)
            return
    print(val)

main()

Submission status: Accepted

Solution code:
def demon():
  N = int(input())
  A = list(map(int,input().split()))
  A.sort()
  if A[0] == 0:
    print(0)
    return

  X = 1
  for i in A:
    X *= i
    if X > 10 ** 18:
      print("-1")
      return

  print(X)

demon()

Submission status: Accepted

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

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

ans = 1
s = 10**18

for i in nums:
  ans = ans * i
  if(ans > s):
    print('-1')
    break


if(ans <= s):
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
multi3 = [int(x.strip()) for x in input().split()]
ans=1
flag=True
for i in multi3:
    if ans*i>10**18:
        flag=False
    elif i==0:
        flag=True
        ans=0
        break
    else:
        ans*=i
if(flag):
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

judge=10**18
ans = 1

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans=1

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

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


print(ans)

Submission status: Accepted

Solution code:
N = int(input())
#A = [int(a) for a in input().split()]
#A = input().split()
A = list(map(int,input().split()))

ans = 1

if 0 in A:
	print(0)
else:
	for a in range(N):
		ans = ans * A[a]

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

Submission status: Accepted

Solution code:
def main(): 
  N = int(input())
  str_num = input().split()

  num_list = []
  for i in str_num:
    num_list.append(int(i))

  num_list.sort(reverse=True)

  ans = num_list[0]

  LIMIT_NUM = 10**18

  if 0 in num_list:
    print(0)
    return

  for i in range(1,N):
    ans *= num_list[i]
    if ans > LIMIT_NUM:
      print(-1)
      return

  print(ans)


main()

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
count = int(input())
nums = []
nums = input().split(" ")

total = 1

for i in range(count):
    if int(nums[i]) == 0:
        total = 0
        break


for i in range(count):
    total = int(nums[i]) * total
    if total > 10**18:
        total = -1
        break
print(total)

Submission status: Accepted

Solution code:
p=1
mx=1000000000000000000
n=int(input())
num=input().split()
z=num.count('0')
if(z!=0):
    print('0')
else:    
    for i in num:
        p*=int(i)
        if(p>mx):
            p=-1
            break
    print(p)

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
for i in range(N):
    if A[i] == 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()))
if 0 in A:
    print('0')
else:
    threshold = 10**18
    res = 1
    for x in A:
        res *= x
        if res > threshold:
            res = -1
            break
    print(res)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = input()
seq = sorted((int(x) for x in input().split()))
if seq[0] == 0:
    ans = 0
else:
    ans = 1
    for val in seq:
        ans *= val
        if ans > 10**18:
            ans = -1
            break
print(ans)

Submission status: Accepted

Solution code:
def intMap(): return map(int,input().split())
def intList(): return list(map(int, input().split())) #横並びの場合
n = int(input())
a = intList()

#MAX_NUM = 1000000 * 1000000 * 1000000
MAX_NUM = 10**18

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

if 0 in A:
    print(0)
elif sum(map(math.log, A)) > math.log(10**18*1.1):
    print(-1)
else:
    temp = 1
    for a in A:
        temp *= a
    if temp > 10 ** 18:
        print(-1)
    else:
        print(temp)

Submission status: Accepted

Solution code:
from sys import stdin

def main():
  read = stdin.readline
  N = int(read())
  data = list(map(int,read().split(" ")))
  ans = 1
  flg = False
  if 0 in data:
    print("0")
    flg = True
    exit()
  for i in data:
    
    if ans*i > 10**18:
      print("-1")
      flg = True
      break
    else:
      ans *= i
      
  if not flg:  
    print(ans)
  
  
if __name__ == "__main__":
  main()

Submission status: Accepted

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

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

ans = 1

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

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
ans = 1
a.sort()
for val in a:
	ans = ans * val
	if ans > 10 ** 18:
		ans = -1
		break
print ans

Submission status: Accepted

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

  if 0 in v:
    print(0)
    return
  
  prod = 1
  for i in v:
    prod *= i
    if(prod > 1000000000000000000):
      print(-1)
      return
  print(prod)

main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in 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:
def main():
    n = int(input())

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

    if 0 in a:
        print(0)
        return

    ans = 1
    for tmp in a:
        ans *= tmp
        if (ans > 1e18) :
            print(-1)
            return

    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if 0 in A:
    multiple = 0
else:
    multiple = 1
    for i in range(N):
        multiple = multiple * A[i]
        if multiple > 1000000000000000000:
            multiple = -1
            break

print(multiple)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def fun(a,n):
    if 0 in a:
        return 0
    z = 1
    for i in a:
        z=z*i 
        if(z>1000000000000000000):
            return -1
    return z

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

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = 1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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
  p=1
  for a in A:
    p*=a
    if p>1000000000000000000:
      print(-1)
      return
  print(p)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = 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())
L=list(map(int,input().split()))
if 0 in L:
	print(0)
	exit()
sum=1
for i in range(N):
	sum=sum*L[i]
	if sum > 10**18:
		print(-1)
		exit()
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
lista = [int(e) for e in input().split()]

if 0 in lista:
    ans = 0
else:
    ans = 1
    for i in lista:
        ans *= i
        if ans>10**18:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 1
A = list(map(int, input().split()))
A.sort(reverse=True)
if A[N-1] == 0:
  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 = [int(x) for x in input().split() ]
sum = a[0]

if 0 in a:
        sum = 0
else:
    for i in range(1,len(a)):
        sum = sum * a[i]
        if sum > 10**18:
            break
        


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

Submission status: Accepted

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

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

    print(res)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = 1

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

print(ans)

Submission status: Accepted

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

for i in A:
    if i==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()))
import sys
limit = 10 ** 18
if 0 in a:
    print(0)
    sys.exit()
else:
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > limit:
            print(-1)
            sys.exit()
    print(ans)

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return

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

    print(ans)

main()

Submission status: Accepted

Solution code:

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

    if 0 in A:
        print(0)
        return

    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return

    print(prod)
    return

main ()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    if min(a) == 0:
        return 0
    r = 1
    for c in a:
        r *= c
        if r > 10**18:
            return -1

    return r

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

Submission status: Accepted

Solution code:
import sys

#1
#a,b=map(int,input().split())
#print(a*b)

#2
n=input()
s=list(map(int,input().split())) 
count=0

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

print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=input().split()
answer=1
for i in range(N):
  if int(A[i])==0:
    answer=0
for i in range(N):
  answer=answer*int(A[i])
  if answer>1*10**18:
    answer=-1
    break
print(answer)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def multiply2(A):
    res = 1
    if 0 in A:
        return 0
    for item in A:
        res *= item
        if res > 10**18:
            return -1
    return res

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(multiply2(A))

Submission status: Accepted

Solution code:
import sys
n=int(input())
List=list(map(int,input().split()))
List.sort(reverse=True)
if List[-1]==0:
    print(0)
    sys.exit()
ans=1
for i in List:
    if ans<=10**18:
        ans*=i
    else:
        print(-1)
        sys.exit()
if ans<=10**18:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

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

limit = 10 ** 18
A = sorted(A)

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

for a in A[1:]:
    total *= a
    if total > limit:
        print(-1)
        exit()
print(total)

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

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

A = sorted(A)

total = A[0]
limit = 10 ** 18

for a in A[1:]:
    total *= a
    if total > limit:
        print(-1)
        exit()
print(total)

Submission status: Accepted

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

if sorted(a)[0]==0:
    print(0)
else:
    import math
    b = [math.log10(i) for i in a if i!=0]    
    if sum(b)>18:
        print(-1)
    else:
        z = 1
        for i in a:
            z*=i
        if z>10**18:
            print(-1)
        else:
            print(z)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
 
N = int(input())
l = [int(x) for x in input().split()]
if 0 in l:
  print(0)
  sys.exit()
ans = 1
for i in range(N):
  if ans > pow(10, 18):
    ans = -1
    break
  else:
    ans *= l[i]
if ans > pow(10, 18):
  print(-1)
else:
  print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(input())
l = [int(x) for x in input().split()]
if 0 in l:
  print(0)
  sys.exit()
ans = 1
for i in range(N):
  if ans > pow(10, 18):
    ans = -1
    break
  else:
    ans *= l[i]
if ans > pow(10, 18):
  print(-1)
else:
  print(ans)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(N):
    T*=A[i]
    if T>K:
        print(-1)
        exit()


print(T)

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
    s *= i
    if s > INF:
        s = -1
        break

print(s)

Submission status: Accepted

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

inf = 10**18
ans = 1

sorted(a, reverse=True)
if 0 in a:
    print(0)
    exit()
else:
    for i in a:
        ans *= i
        if ans > inf:
            print(-1)
            exit()

print(ans)

Submission status: Accepted

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

MAX = 10**18
ans = 1

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if 0 in l:
    print(0)
    exit()
else:
    ans = 1

for a in l:
    ans *= a
    if ans > pow(10, 18):
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cumul = 1
if 0 in nums:
    print(0)
else:
    for i in range(N):
        cumul *= nums[i]
        if cumul > 10 ** 18:
            print(-1)
            break
    if cumul <= 10 ** 18: print(cumul)

Submission status: Accepted

Solution code:
# Import
from collections import deque

# I/O
def read(): return input()
def read_int(): return int(input())
def read_array(type=int): return list(map(type, input().split()))
def read_tupple(type=None):
    tmp = input().split()
    if type is None: return map(int, tmp)
    assert len(tmp) == len(type)
    return [type[i](tmp[i]) for i in range(len(tmp))]

# Implementation
N = read_int()
A = read_array()
A.sort()
ans = 1
for i in range(N):
    ans *= A[i]
    if ans > int(1e18):
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = map(int, readline().split())

ans = 1
ng = False
for x in a:
    ans *= x
    if x == 0:
        print(0)
        exit()
    if ans > 10**18:
        ng = True
        ans = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
ls=[int(s) for s in input().split(" ")]

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

  print(num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
ls=[int(s) for s in input().split(" ")]

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

  print(num)

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)
            break
    else:
        print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

if 0 in x:
  print(0)
else:
  res = 1
  ok = False
  for i in x:
    res = res * i
    if res > int(1e18):
      print(-1)
      ok = True
      break
  if not ok :
    print(res)

Submission status: Accepted

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

Submission status: Accepted

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

pro = 1
a.sort()
for i in a:
    pro *= i
    if pro > 10**18:
        pro = -1
        break

if a[0] == 0:
    print(0)
else :
    print(pro)

Submission status: Accepted

Solution code:
from collections import Counter

N = input()
A_str = input().split()

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

c = Counter(sorted(A_str))
res = 1
for i, v in c.items():
    res *= int(i) ** v

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

print(res)

Submission status: Accepted

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

a.sort()
tmp = a[0]
f = True
for i in range(1, n):
    tmp *= a[i]

    if tmp > 10 ** 18:
        f = False
        break

if f:
    print(tmp)
else:
    print(-1)