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: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

N = int(input())

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

result = reduce(mul,A)

if result <= 1*10**18 :
    print(result)

else :
    print("-1")

Submission status: Time Limit Exceeded

Solution code:
max = 10**18

n = int(input())
A = list(map(int,input().split()))
ans = 1
for i in A:
    ans *= i

if ans > max:
    print('-1')
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n):
  ans *= a[i]

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

Submission status: Time Limit Exceeded

Solution code:
import sys

limit = 1E18
n = int(input())
total = 1
# A string
line = str(input())

if line.startswith("0 ") or " 0" in line:
    print(0)
    exit()

for i in line.split():
    x = int(i)
    total *= x

print(-1 if total > limit else total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
array = list(map(int, input().split()))
ans = 1
for i in array:
    ans *= i
if ans > 1000000000000000000:
    ans = -1
print(ans)

Submission status: Time Limit Exceeded

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



MAX = pow(10, 18)

ans = A[0]


for i in range(1, N):
    ans *= A[i]

if ans > MAX:
    ans = -1

print(str(ans))

Submission status: Time Limit Exceeded

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 :
        ans = -1
    else :
        a += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
arr=list(map(int,input().split(" ")))
res=1
for i in range(n):
  res=res*arr[i]
if(res>1000000000000000000):
  print("-1")
else:
  print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
x = math.prod(a)
print(x if x <= 1000000000000000000 else -1)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

N = int(input())
A = list(map(int,input().split()))
anser = reduce(mul, A)
if anser > 10 ** 18:
    print("-1")
else:
    print(anser)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
a = int(input())
n = input().split()
results = list(map(int, n))


def multiplyList(myList):
    if int(reduce(lambda x, y: x*y, myList)) <= 1000000000000000000:
        return reduce(lambda x, y: x*y, myList)
    else:
        return -1

print(multiplyList(results))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=input().split()
ans = 1
for x in l:
    ans*=int(x)
if ans>10**18:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
ans = 1
flag = 1
for a in map(int, input().split()):
    ans *= a
    if ans > 10 ** 18:
        flag = 0
    if a == 0:
        flag = 1
        break
if flag == 0:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

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

list = [int(s) for s in input().split()]

for i in list:
    re *= i
    
if(re > 1000000000000000000):
    print("-1")
else:
    print(re)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def li():
    return list(map(int,input().split()))
n=int(input())
p=li()
s=1
for i in range(n):
    s*=p[i]
if s>=10**18+1:
    print(-1)
    sys.exit()
print(s)

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator
n=int(input())
a=list(map(int,input().split()))
b=functools.partial(functools.reduce,operator.mul)
if b(a)>10**18:
    print(-1)
else:
    print(b(a))

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator
def souseki():
    N = input()
    H = list(map(int,input().split()))
    result = 1
    prod = functools.partial(functools.reduce, operator.mul)
    result = prod(H)
    result = -1 if result > 10**18 else result
    print(result)

souseki()

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator

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

prod = functools.partial(functools.reduce, operator.mul)
x = prod(list(A))
if x > 10**18:
    print(-1)
else:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list( map( int, input().split()))
    sum = 1
    for i in a:
        sum *= i
    if sum >1000000000000000000:
        print(-1)
    else:
       print(sum)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
max = 10**18
x=1
for a in range(N):
    x = x * A[a]
    
else:
    if x <= max:
        print(x)
    else:
        print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
N = int(input())
X = list(map(int, input().split()[0:N]))
Re = reduce(lambda x, y: x*y, X)
if Re > 10**18:
    print(-1)
else:
    print(Re)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce


n = int(input())
a = list(map(int, input().split()))
ans = reduce(lambda x, y: x * y, a)
print(-1 if ans > 10**18 else ans)

Submission status: Time Limit Exceeded

Solution code:
a = input()
b = input().split()
c = int(1)
for i in b:
	c *= int(i)
if c > 10**18:
  c = -1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
score=1
for i in range(n):
    score = score* a[i]


if score <= 10 ** 18:
    print(score)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
N = input()
B = input().split()

if 2 <= int(N) <= 10**5 and int(N) == len(B):
    check = all(0 <= int(elem) <= 10**18 for elem in B)
    S = 1
    if check:
        for i in range(len(B)):
            S *= int(B[i])
        if S > 10**18:
            print("-1")
        else:
            print(S)
    else:
        print("choose right value")
else:
    print("choose right value")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
n=int(input())
    #a,b=input().split(#" ")#a,bがともに文字列のとき
    #a,b=map(int, input().split(" "))
    #mapでとってもstrで変換すればappend可能
    #s=input()
    #a=[i for i in s]#int(i)にすれば数字も行ける
nl=list(map(int, input().split(" ")))#数字の時
    #print(a)
    #brray=[list(map(int, input().split(" ")))for i in range(n)]
    #print(brray)
n=len(nl)
ans=1
    #from itertools import accumulate

#a = list(range(1, 11))
    #ans = list(accumulate(nl))     # itertoolsの戻り値はイテレータとなっているので必要に応じてlist化します．
    #print(a)
    #print(b)
for i in range(n):
        ans=ans*nl[i]
if ans>10**(18):
        print(-1)
        sys.exit()
print(ans)
    #for i in range(1,n+1,2):#これで1個飛ばしループになる

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n = input()
n_list = [int(i) for i in input().split()]
value = 1
for i in n_list:
    value = value * i


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

Submission status: Time Limit Exceeded

Solution code:
import math

n = input()
 
a = list(map(int, input().split()))
 
total = 1
 
for i in a:
	total *= i
 
if total > math.pow(10, 18):
	total = -1
 
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math

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

X = 1
Y = 1
Z = 1
L = len(A)

if L%2 == 0:
    for i in range(int(math.floor(L/2))):
        X = X * A[i]
        Y = Y * A[-1 - i]
else:
    Z = A[int(math.floor(L/2)) + 1]
    for i in range(int(math.floor(L/2))):
        X = X * A[i]
        Y = Y * A[-1 - i]

    # for i, b in enumerate(A):
    #     if i == 0:
    #         X = b
    #     else:
    #         X = X * b



if X*Y*Z > 1000000000000000000:
    print('-1')
else:
    print(X*Y*Z)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline

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

for i in a:
    ans = ans*i
    if ans > 1000000000000000000:
        ans = -1
        exit
    elif ans == 0:
        exit

print(ans)

Submission status: Time Limit Exceeded

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

X = 1
for i in range(0,N):
    X = X * A[i]

if X <= 10**18:
    print(X)
else:
    print("-1")

Submission status: Time Limit Exceeded

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

ans = reduce(lambda x, y: x*y, a)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

total = 1
for a in li:
  total *= a
  
if math.pow(10,18) < total:
  total = -1
  
print(total)

Submission status: Time Limit Exceeded

Solution code:
count = int(input())
list = list(map(int, input().split()))
sum = list[0]
for i in range(count - 1):
    sum = sum * list[i + 1]

if sum > 1000000000000000000:
    sum = -1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
result = 1
checker =False
for j in a:
  if j > 1000000000000000000:
    result = -1
    checker =True
if 0 in a:
  result = 0
  checker=True
while checker==False:
  for i in range(len(a)):
    result = result*a[i]
  checker = True
    

if result <= 1000000000000000000:
  print(result)
else:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
N = input()
A = list(map(int, input().split()))
num = 1
for i in A:
  if 0 in A:
    num = 0
    break
  elif num > 1000000000000000000:
    break
  num = num*int(i)
if num > 1000000000000000000:
  print(-1)
else:
  print(num)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
y = list(map(int,input().split()))
z = 1
for index in range(len(y)):
  z = z * y[index]
if z > 10**18:
    print(-1)
else:
    print(z)

Submission status: Time Limit Exceeded

Solution code:
# from operator import mul
# from functools import reduce

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

ans = 1
# ans = reduce(mul, a) #=> 1320

for i in range(n):
  ans *= a[i]
  if a[i] == 0:
    break

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

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    ans*=A[i]

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
se = 1
c = True
for n in range(N):
  se *= A[n]
  if A[n] == 0:
    se = 0
    break
if se >  10**18:
  print("-1")
  c = False
if c:
  print(se)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import lru_cache
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

BIG = 10**(18)

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

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

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
l = list(map(int, input().split()))
res = 1
flag = 0
for i in l:
	res *= i
	if i == 0:
		flag = 0
		res = 0
	if(res > 1000000000000000000):
		flag = 1
if flag == 1:
	print('-1')
else : print(res)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[*map(int,input().split())]
a=1
while A:
  a*=A.pop()
if a > 10**18:
  print(-1)
else:
  print(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = input().split()
numbers = [int(n) for n in a]
product = 1
for i in range(N):
    product *= numbers[i]
if product > 10 ** 18:
    print('-1')
else:
    print(product)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
n=int(input())
a=list(map(int,input().split()))

result=reduce(mul,a)
if result<=10**18:
  print(result)
else:
  print('-1')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
list=input().split(" ")
x=1
for i in list:
  x*=int(i)
if x>1e18:
  print(-1)
else:
  print(x)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
list=[int(i) for i in input().split()]
x=list[0]
k=1
while k<n:
  y=x*list[k]
  x=y
  k=k+1
if y>1000000000000000000:
  print(-1)
else:
  print(y)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(i) for i in input().split(" ")]
res=1
xx=10**18
for i in a:
    res*=i
if res>xx:
    print(-1)
else:
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator
n = int(input())
a = list(map(int, input().split())) 
result = functools.reduce(operator.mul, a)

if result <= 10**18:
	print(result)
else:
	print(-1)

Submission status: Time Limit Exceeded

Solution code:
def main():
	from sys import stdin
	import math, sys, functools, operator

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

	junk = input()

	li = [int(x) for x in stdin.readline().rstrip().split()]

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

	result = functools.reduce(operator.mul, li)

	if pow(10,18) < result :
		print (-1)
	else :
		print(result)

main()

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
import functools
import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm


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=prod(A)
if p<0:
    p=p*(-1)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

s = 1
for i in range(N):
    s *= mlist[i]

if s <= 1000000000000000000:
    print(s)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x1 = input()
x2 = [int(s) for s in input().strip().split(" ") ]
 
if len(x2) >0 :
   result =  1
else :
   result =  0

for x in x2:
   result *= x 

if 10**18 < result :
 print("-1")
else:
 print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
anz = 1
for i in l:
    anz *= i
print(anz if anz <= 1000000000000000000 else -1)

Submission status: Time Limit Exceeded

Solution code:

t = int(input())
pro = 1
n = input()
for i in n.split():
	pro = pro * int(i)
if pro > 1000000000000000000:
	print('-1')
else:
	print(pro)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=1
li = input().split()
for i in li:
  ans*=int(i)
  if ans>1000000000000000000:
    ans*=-1

if ans<0:
  ans=-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a= input().split()
level = pow(10, 18)
product = 1

if n%2 == 1:
  a.append(1)
  n += 1

for num in range(int(n/2)):
  product *= int(a[num]) * int(a[n - 1 - num])

if product > level:
  print("-1")
else:
  print(product)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
N = input()
listA = map(int, input().split())
ans = reduce(mul, listA)

if(ans>1.0E+18):
    print("-1")
else:
    print(ans)

Submission status: Time Limit Exceeded

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

result = 1

for tmp in AList:
    result *= tmp
    if result == 0: break

print(result if result <= pow(10, 18) else -1)

Submission status: Time Limit Exceeded

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

if n % 2 == 0:
    for i in range(n//2):
        ans *= a[i]
        ans *= a[n-i-1]

if n % 2 == 1:
    for i in range(n//2):
        ans *= a[i]
        ans *= a[n-i-1]

    ans *= a[n//2+1]

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
arr=input()
prod=1
k=1;
l=list(map(int,arr.split(' ')))
for x in l:
    if(x==0):
        prod=0
        if(k==0):
            continue
    prod*=x
    if(prod>1000000000000000000):
        k=0
        prod=-1

    
print(prod)

Submission status: Time Limit Exceeded

Solution code:
MAX = 10**18
def main():
    N = map(int,input())
    A = list(map(int,input().split(' ')))
    ans = 1
    for a in A:
        if a == 0:
            print(0)
            exit(0)
        ans *= a

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(x) for x in input().split()]
prod = 1
for x in A:
    if x == 0:
        prod = 0
        break
    else:
        prod *= x
if prod == 0:
    print(0)
else:
    if prod <= 10 ** 18 and prod != 0:
        print(prod)
    else:
        print(-1)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from operator import mul
N = int(input())
a = list(map(int,input().split()))

ans = reduce(mul, a)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

N = int(input())
AS = map(int, input().split())

ans = reduce(lambda a,b: a*b, AS)
if ans > pow(10, 18):
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
c = int(1)
N = int(input()) #1行目のNを取得する
i = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる
for k in range(N):
    c=c*i[k]
if c>10**18:
    print('-1')
else:
    print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

limit = 1E18
n = int(input())
total = 1
# A string
line = str(input())
for i in line.split():
    x = int(i)
    total *= x

print(-1 if total > limit else total)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

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

C = reduce(mul, x)
if C > 10**18:
  print(-1)
else:
  print(C)

Submission status: Time Limit Exceeded

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

count = 0
ans = 1
while True:
    ans *= nums[count]
    count+=1
    if N == count:
        if ans > (10**18):
            print(-1)
        else:
            print(ans)
        sys.exit()

Submission status: Time Limit Exceeded

Solution code:
n = input()
arr = input().split(' ')
ans = 1
for i in arr:
  ans *= int(i)

if ans > int(1e18):
  print(-1)
else:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
ans = 1
n = input()
n = int(n)
nums = input().split()
for i in range(n):
    mul = int(nums[i])
    ans = ans * mul

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
n = int(input())
li = list(map(int, input().split()))

ans = reduce(lambda x, y: x * y, li)
print(ans) if ans <= 10 ** 18 else print(-1)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
N = int(input())
S = reduce((lambda x, y: x * y), [int(i) for i in input().split()])
print(-1 if S>10**18 else S)

Submission status: Time Limit Exceeded

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

ans = functools.reduce(operator.mul, A)
    
if len(str(ans)) < 19:
  print(ans)
elif ans == 1000000000000000000:
  print(ans)
else:
  print(-1)

Submission status: Time Limit Exceeded

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

kk = int(1)

for wInt in inList:
 kk = kk * wInt

kkLim = int(10 ** 18)

if (kk <= kkLim) :
        print(kk) 
else :
        print('-1')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
P=[list(map(int,input().split()))]
import functools
import operator
result = functools.reduce(operator.mul,P[0])
if result>10**18:
    print(-1)
else:
    print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline

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

for i in a:
    ans = ans*i
    if ans > 1000000000000000000:
        ans = -1
        exit
    elif ans == 0:
        exit

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
n = int(input())
tab = [int(n) for n in input().split()]
res = reduce(lambda x, y: x*y, tab)
if res > pow(10, 18):
  print("-1")
else:
  print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

over = 10**18

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

Submission status: Time Limit Exceeded

Solution code:
import operator
from functools import reduce

n = int(input())

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


sum = reduce(operator.mul, a, 1)


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = input()
b = input().split()
c = int(1)
for i in b:
	c *= int(i)
if c > 1000000000000000000:
  c = -1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)
N=int(input())
A=list(map(int,input().split()))
def f(i):
  if i==0:
    return 1
  else:
    return f(i-1)*A[i-1]
a=f(N)
print(a if a<=10**(18) else -1)

Submission status: Time Limit Exceeded

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

for i in range(0, N):
    ans *= A[i]

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
from collections import Counter
cnt = Counter(a)
if 0 in cnt:
    print(0)
    quit()
ans = 1
for i, j in cnt.items():
    #print(i, j)
    ans *= i ** j
if ans > 10 ** 18:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# import numpy as np
# import functools
# import operator

N = int(input())
A = input().split()
# prod = functools.partial(functools.reduce, operator.mul)
# sum = functools.reduce(operator.mul, A, 1)
lim = False
zero = False
sum = 1
for i in A:
    sum = sum * int(i)
    if i == 0:
        zero = True
        break

if 1000000000000000000 < sum:
    print(-1)
elif zero:
    print(0)
else:
    print(sum)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

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

ans = reduce(mul,A)
if ans > 10 ** 18:
  ans = -1
print (ans)

Submission status: Time Limit Exceeded

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

if arr.count(0):
    print(0)
else:
    res = 1
    for i in arr:
        res*=i
    if res >10**18:
        print('-1')
    else:
        print(res)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
N = int(input())
L = list(map(int, input().split()))

ans = reduce(lambda x,y:x*y,L)
if (ans > pow(10,18)):
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
B = input().split()

if 2 <= int(N) <= 10**5 and int(N) == len(B):
    check = all(0 <= int(elem) <= 10**18 for elem in B)
    S = int(1)
    if check:
        for i in range(len(B)):
            S *= int(B[i])
    else:
        print("choose right value")
    if S > 10**18:
        print("-1")
    else:
        print(S)
else:
    print("choose right value")

Submission status: Time Limit Exceeded

Solution code:

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

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

for i in range(int(n)):
    ans *= a[i]

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

Submission status: Time Limit Exceeded

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))
 
def main():
    n=I()
    a=L()
    ans=1
    for i in a:
        ans*=i
    print(ans if ans<=1e+18 else -1)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(leng):
    a=int(nums[i])
    x=x*a

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

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
n=int(input())
a=list(map(int,input().split()))

ans = reduce(mul, a)
if ans > pow(10, 18):
	print("-1")
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(input().split())
ans = int(a[0])
tmp = 0
for  i in range(1,n):
    if '0' in a:
        ans = 0
        break
    ans = ans * int(a[i])

check = 10**18
if ans <= check:
    print(ans)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = input().split()  

answer = 1

for i in range(N) :
    answer = answer * int(A[i])


if answer > 1000000000000000000 : 
    print('-1')
    quit()


print(answer)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=input().split()
ans = 1
for i in range(n):
    l[i]=int(l[i])
for x in l:
    ans*=x
if ans>10**18:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

new = 1
a = list(map(int,input().split()))
for i in a:
	new = new * i 
val = 10**18
if new > val:
	print(-1)
else:
	print(new)

Submission status: Time Limit Exceeded

Solution code:
A=input()
list1=input().split()
A=int(A)
Ans=1
for i in range(0,A):
    Ans= Ans*int(list1[i])
if 10**18<Ans:
    print(-1)
else:   
    print(Ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
A = [None]*n
A = map(int, input().split())
T = math.prod(A)
if T > pow(10,18):
    print(-1)
else:
    print(T)