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:
A = int(input())
li = list(map(int,input().split()))

ans = 1
for i in range(len(li)):
    if li[i] == 0:
        ans = 0

if ans == 0:
    print(ans)
else:
    possible = True
    for i in range(len(li)):
        if int(li[i]) * ans > 1000000000000000000:
            possible = False
            break
        else:
            ans *= li[i]
    if (possible):
        print(ans)
    else:
        print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
s = 1
if 0 in A:
    print(0)
    exit(0)
for i in A:
    s *= i
    if s > 10**(18):
        print(-1)
        exit(0)
print(s)

Submission status: Accepted

Solution code:
import numpy as np

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

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

ans=1
P.sort(reverse=True)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul
import sys
input = sys.stdin.readline

count = int(input())
list = list(map(int, input().split()))
sum = list[0]
if 0 in list:
    print(0)
    exit()
else:
    for i in range(count - 1):
        sum = sum * list[i + 1]
        if sum > 1000000000000000000:
            print(-1)
            exit()


    print(sum)

Submission status: Accepted

Solution code:
def ans(a):
    ans = 1
    if 0 in a:
        return 0
    for i in A:
        ans *= i
        if 10 ** 18 < ans:
            ans = -1
            return ans
    return ans


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

print(ans(A))

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=1
if A.count(0) >= 1:
  print(0)
else:
  B=[i for i in A if i != 1]
  if len(B) >= 100:
    print("-1")
  else:
    for k in range(len(B)):
      ans=ans*B[k]
    if ans > 1000000000000000000:
      print("-1")
    else:
      print(ans)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
num = int(input())
line = input().split()

if "0" in line:
  x = 0
else:
  x = 1
  for i in range(num):
    x = x * int(line[i])
    
    if x > 10 ** 18:
      x = -1
      break
  
print(x)

Submission status: Accepted

Solution code:
N = int(input())
S = input().split()
S.sort()
ans = 1
#float
for i in range(N):
    A = int(S[i])
    if(A==0):
        ans = 0
        break
    else:
        ans *= A
    if ans>1000000000000000000:
        ans = -1
        break
print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

ans = 1
flag = 0

if i.count(0) > 0:
    print(0)
    flag = 1

if flag == 0:
    for x in range(len(i)):
        ans = ans * i[x]
        if ans > 1000000000000000000:
            flag = 1
            break

    if flag == 1:
        print(-1)
    elif flag == 2:
        print(0)
    else:
        print(ans)

Submission status: Accepted

Solution code:
def main():
    _ = input()
    a = sorted(list(map(int, input().split())), reverse=True)
    if a[-1] == 0:
        print(0)
        return
    x = 1
    m = 10 ** 18
    for i in a:
        if i < 2:
            continue
        x *= i
        if x > m:
            print(-1)
            return
    print(-1 if x > 10 ** 18 else x)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
#H1,M1,H2,M2,K= map(int,input().split())
A = list(map(int,input().split()))
#B = list(map(int,input().split()))
#S= str(input())
#prod = functools.partial(functools.reduce, operator.mul)
#c=np.array(A)
#p=np.prod(A)
c=1
if 0 in A:
    print(0)
    exit()
for i in A:
    c=c*i
    if c>10**18:
        print(-1)
        exit()
print(c)

Submission status: Accepted

Solution code:

n = int(input())
a = list(input().split(' '))
# print(n, a)
def doit(n,a):
  m = 1
  for i in range(n):
    m = m*int(a[i])
    if m > 1000000000000000000:
        for y in range(i+1, n):
            if a[y] == '0':
                return 0
        return -1
    elif m==0:
        return 0

#   if m > 1000000000000000000:
#     return -1
  return m
 
print(doit(n,a))

Submission status: Accepted

Solution code:
import array


n = int(input())
a=[]
a=input().split(" ")
f=0
f1=0
b=0
for i in a:
    if int(i) == 0:
        print("0")
        f1=1
        break
        

sum =1
if f1==0:
    for i in a:
        sum=sum*int(i)
        if sum>1e18:
            f=1
            print("-1")
            break
    


if f==0 and f1==0:
    print(sum)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
B = len(A)
ans = 1
a = 0
for a in range(B) :
    ans = ans*A[a] 
    if ans > 10**18 :
        if 0 in A :
            ans = 0
        else :
            ans = -1 
        break
    else :
        a += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    limit = 10 ** 18
    #print(A)

    if A[-1] == 0:
        print(0)
    elif A[0] > limit:
        print(-1)
    else:
        ans = A[0]
        for i in range(1, n):
            ans *= A[i]
            if ans > limit:
                print(-1)
                exit()

        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
l = list(map(int, input().split(" ")))
l.sort()
a = 1
for i in range(n):
    if a <= 10**18:
        a = a*l[i]
    elif a > 10**18:
        print("-1")
        sys.exit()
if a > 10**18:
    print("-1")
else:
    print(a)

Submission status: Accepted

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

a.sort()

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

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

print(ans)

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 (ans > 10 ** 18):
    break
  
if (ans > 10**18):
  if a.count(0) > 0:
    print(0)
  else:
    print(-1)
else:
  print(ans)

Submission status: Accepted

Solution code:
num = int(input())
numList = list(map(int, input().split()))
max = 1000000000000000000
flg = True
result = 1

if 0 in numList:
    print(0)
else:
    for i in range(num):
        result *= numList[i]
        if result > max:
            flg = False
            break
    if flg:
        print(result)
    else:
        print(-1)

Submission status: Accepted

Solution code:
import sys

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

    if(0 in P):
        print(0)
    else:
        P.sort()

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

        print(mult)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

flg=False
a = 1
for i in l:
	a *= i
	if a>10e17:
		flg=True
		break
 
if flg:
	print(-1)
else:
	print(a)

Submission status: Accepted

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


if 0 in a:
    print(0)
else:
    is_true = True
    ans = a[0]
    key = 10 ** 18
    for i in range(n-1):
        ans *= int(a[i+1])
        if ans > key:
            is_true = False
            break
    if is_true:
        print(ans)
    else:
        print('-1')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import os
import random
import re
import sys
n= int(input())
arr=[int(s) for s in input().split()]
p=1;
count=0
for i in range(n):
    if arr[i]==0 : 
        count=1
        break
for i in range(n):
    p=p*arr[i]
    if(p>1000000000000000000):
        p=-1
        break
if(count==0) : print(p)
else : print(0)

Submission status: Accepted

Solution code:
def aaa():
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = 1;
	for i in range(n):
		if a[i]==0:
			print(0)
			return
	for i in range(n):
		ans *= a[i]
		if ans>1000000000000000000:
			print(-1)
			return
	print(ans)

aaa()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
the = pow(10,18)
ans = 1

if 0 in A:
    print(0)
else:
    for i in range(n):
        ans *= A[i]
        if ans >the:
            print(-1)
            break
        else:
            continue
    if ans <= the:
        print(ans)

Submission status: Accepted

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

def main():
    N = int(input())
    A = sorted([int(v) for v in input().split()])

    over = False
    ans = 1
    for a in A:
        ans *= a
        if ans > 1e18:
            over = True
            break
    
    if over:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
res = 1

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

for x in N:
    res *= x
    if res > pow(10, 18):
        res = -1
        break

print(res)

Submission status: Accepted

Solution code:
from sys import stdin

nn = input()

N=int(nn)

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


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

res=1
for i in arr:
    res*=i
    if res>1000000000000000000:
        print(-1)
        exit();

print(res)

Submission status: Accepted

Solution code:
def main():
    N = int( input())
    t = 10**18
    A = list( map( int, input().split()))
    ans = 1
    # if Counter(A)[0] > 0:
    #     print(0)
    #     return
    A.sort()
    for a in A:
        ans *= a
        if ans > t:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = int(input())
y=[]
# for i in range(0, 100000):
	# y.append(1000000000000000000)
x = list(map(int, input().split())) 
x.sort()
# for i in x:


	# print(i)
prod=1
f=0
for i in x:
	prod*=i
	if(prod>1000000000000000000):
		f=1
		print(-1)
		break
if(f!=1): 
	print(prod)
# print(prod)
# if(prod>1000000000000000000):
# 	print(-1)
# else: 
# 	print(prod)

Submission status: Accepted

Solution code:
from sys import stdin

def main():
  N = int(input())
  P = stdin.readline().rstrip().split()
  if '0' in P:
    print(0)
    return
  # print(P)
  ans = 1
  for a in P:
    ans *= int(a)
    if ans > 1000000000000000000:
      print(-1)
      return
  print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())
c = list(map(int, input().split()))
ans=1
max =10**18

if 0 in c:
    ans =0
else:
    for i in range(n):
        if ans< max:
            ans=ans*c[i]
            if ans > max:
                ans =-1
                break
        else:
            ans = -1
            break
print(ans)

Submission status: Accepted

Solution code:
leng=int(input())
nums=input().split()
x=1

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

for i in range(leng):
    a=int(nums[i])
    x=x*a
    if x>10**18:
        break

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    exit()
lim = 10**18

ans = 1
for i in A:
    ans *= i
    if ans > lim:
        print(-1)
        exit()

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

Submission status: Accepted

Solution code:
N = int ( input().strip() ) ;
arr = list ( map ( int , input().strip().split(" ") ) ) ;
arr.sort() ;

c = 1 ;
m = pow ( 10 , 18 ) ;
for v in arr :
	c *= v ;
	if c ==0 : break ;
	if c > m : 
		c = -1 ;
		break ;
print  ( c ) ;

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

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

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

print(ans)

Submission status: Accepted

Solution code:
a = int(input())
b = input().split(" ")
i = 0
s = 1
f = 0
while i < a :
    if b[i] == "0" :
        print(0)
        f = f + 1
    i = i + 1
i = 0
while (i < a) and f == 0 :
    s = s * int(b[i])
    i = i + 1
    if s > (10 ** 18):
        print("-1")
        break
    if (s <= 10 ** 18) and (i == a):
        print(s)

Submission status: Accepted

Solution code:
import math
import itertools
import functools
import numpy as np



# a, b = map(float, input().split())

# b = int(b * 100)
# a = int(a)

# print(int(a * b / 100))

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

if v[0] == 0:
  print(0)
  exit(0)
ans = 1
for l in v:
    ans *= l
    if ans > 1e18:
      print(-1)
      exit(0)
 
if ans > 1e18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import numpy as np
n = int(input())
a_list = np.array(list(map(int, input().split())))
y = np.argsort(a_list)
if a_list[y[0]] == 0:
    print(0)
else:
    ans = 1
    flag = 1
    for i in range(0, n):
        ans *= int(a_list[y[n - 1 - i]])
        if ans > 10 ** 18:
            flag = 0
            break
    if flag == 0:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=1
if 0 in A:
  print('0')
else:
  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()))

aa=sorted(a)
th=10**18
ans=1

for i in range(len(aa)):
    if aa[i]==0:
        print(0)
        break
    ans*=aa[i]
    if ans>th:
        print(-1)
        break
    if i==len(aa)-1:
        print(ans)

Submission status: Accepted

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

A.sort()

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

print(ans)

Submission status: Accepted

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

input()
l = list(map(lambda x: int(x), str(input()).split(" ")))
r = 1
finished = False

for i in l:
  if i == 0:
    print(str(0))
    sys.exit()
    
for i in l:
    r = r * i
    if r > 10 ** 18:
        print(str(-1))
        sys.exit()

print(str(r))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n= int(input())
a_list = list(map(int, input().split()))
 
a_list = [n for n in a_list if n!=1]  
#print(a_list)
ans=1

if 0 in a_list:
  ans=0
elif len(a_list)>56:
  ans=-1
else:
  for i in a_list:
    ans=ans*i
  if ans>1000000000000000000:
      ans=-1
  
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def ABC_169_B():
    N=int(input())
    A = input().split()
    A = [int(s) for s in A]
    sum=1
    flg=0

    if A.count(0)>=1:
        print(0)
        flg=1

    if flg==0:
     for i in range(len(A)):
         sum=(sum*A[i])
         if sum>10**18:
             print(-1)
             flg=1
             break
    if flg==0:
        print(sum)
        
if __name__ == '__main__':

    ABC_169_B()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import numpy as np
N = int(input())
A = list(map(int, input().split()))
#A = np.array(A)
t = A[0]
for i in range(1,N):
    t *= A[i]
    if int(t) > 1e18:
        for j in range(i,N):
            if A[j] == 0:
                t = 0
        break
if int(t) <= 1e18:
    print(int(t))
else:
    print(-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
TH = 1e18
for i in range(n):
	ans = ans * a[i]
	if ans > TH:
		print(-1)
		sys.exit()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

import sys
from functools import reduce

input = sys.stdin.readline

N = int(input())
A = input().rstrip().split()

def main():
    result = 1
    if '0' in A:
        return 0

    for a in A:
        a = int(a)
        result *= a

        if result > pow(10, 18):
            return -1

    return result

ans = main()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N=int(input())
A=list(map(int,input().split()))
if 0 in A:
  print('0')
  sys.exit()
x=1
for i in A:
  x*=i
  if x>1000000000000000000:
    print('-1')
    sys.exit()
print(x)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
ans=1
if 0 in a:
    print(0)
    exit()
for i in range(n):
    ans=ans*a[i]
    if ans>10**18 and not 0 in a:
      print(-1)
      exit()
if ans>10**18:
    anscheck=False
else:
    anscheck=True
print(ans if anscheck else -1)

Submission status: Accepted

Solution code:
n = int(input())
arr = [int(x) for x in input().split()] 
arr.sort()
prod = 1
flag = 0
for each in arr:
	prod = each * prod
	if prod > 1000000000000000000:
		flag = 1
		break
if flag == 0:
	print(prod)
else:
	print("-1")

Submission status: Accepted

Solution code:
count = int(input())
list = input().split(" ")
state = False
i = 0
num = int(list[i])
i += 1
limit = 10 ** 18
if "0" in list:
  num = 0
  count = 0

while i < count:
  num = num * int(list[i])

  if num > limit:
    print(-1)
    state = True
    break
    
  i += 1

if not state:
  print(num)

Submission status: Accepted

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

Submission status: Accepted

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

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

res = 1
for i in lis:
    if res > 10**18:
        print(-1)
        exit()
    else:
        res *= i
print(res if res <= 10**18 else -1)

Submission status: Accepted

Solution code:
lines = []
for i in range(2):
    lines.append(input())
num = int(lines[0])

out = 1
split = lines[1].split()
if "0" in split:
    out = 0
for i in range(num):
    out = int(split[i]) * out 
    if out > 1000000000000000000:
        out = - 1    
        break
print(out)

Submission status: Accepted

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

ans = 1
if 0 in array:
  ans = 0
else:
  for x in array:
    ans *= x
    if ans > 1000000000000000000:
      ans = -1
      break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
	k = int(input())
	h = tuple(map(int,input().split()))
	ans = 1
	avoid = 0
	if (0 in h):
		print(0)
	else:
		for i in range(k):
			ans = h[i] * ans
			if ans > 10 **18:
				print(-1)
				avoid = 1
				break
		if avoid == 0:
			print(ans)
	


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:

import sys

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

A.sort()
A.reverse()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

abc=0

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

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

Submission status: Accepted

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

n = input()
n_list = sorted([int(i) for i in input().split()])
value = 1
for i in n_list:
    value = value * i
    if value > 10 ** 18:
        value = -1
        break
print(value)

Submission status: Accepted

Solution code:
import sys


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _ = _i()
    m = 10**18
    ret = 1
    for ai in sorted(_ia()):
        ret *= ai
        if ret > m:
            return -1
    return ret


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

Submission status: Accepted

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

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

count = 1
for i in A:
    count *= i
    if 10 ** 18 < count:
        break

if 10 ** 18 < count:
    count = -1

print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
line = list(map(int,input().split()))
a=1
b=0
for i in range(N):
    a*=line[i]
    if a>1000000000000000000:
        for j in range(i,N):
            if line[j]==0:
                print("0")
                b=1
                break
            if j==N-1:
                print(-1)
                b=1
                break
        break
       
if b ==0:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import time
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    ans = 1
    inf = 10**18
    t = time.time()

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

    for i in range(len(A)):
        ans *= A[i]
        if ans > inf :
            print(-1)
            exit()

    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
_,a=open(0)
t=1
for b in sorted(a.split()):
 t*=int(b)
 if t>10**18:t=-1;break
print(t)

Submission status: Accepted

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

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

out = 1
for num in nums:
  out *= num
  if out > 1e18:
    print(-1)
    exit()
print(out)

Submission status: Accepted

Solution code:
import sys
input()
a = list(map(int, input().split()))
ans = 1
flag = False
for i in a:
    if i==0:
        print(0)
        sys.exit()
for i in a:
    ans *= i
    if ans>1000000000000000001:
        print(-1)
        sys.exit()
if ans<1000000000000000001:
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

A.sort()

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

Submission status: Accepted

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

ans = 1

if 0 in N:
    ans = 0
else:
    for i in range(len(N)):
        ans *= N[i]
        if ans > 10**18:
            break

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))
b = 1
for i in range(N):
    if b > 0:
        b *= a[i]
    if a[i] == 0:
        b = 0
    if b > 10**18:
        b = -1
 
print(b, end='')

Submission status: Accepted

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

ans = 1
l = 0;
flag = 0

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

    l+=(len(str(A[i])) -1)
    if l>18:
        flag=1
        continue
    
    ans*=A[i]
    if ans > 1000000000000000000:
        flag = 1

if flag == 0:
    print(ans)
else :
    print(-1)

Submission status: Accepted

Solution code:
n = int(input())
res = 1
L = list(map(int, input().split()))
L.sort()
for elem in L:
    if res != -1:
        res *= elem
    if res > 1e18:
        res = -1
print(res)

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

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

print(ans)