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:
import operator
from functools import reduce

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

ans = reduce(operator.mul, A, 1)

if ans <= 1000000000000000000:
    print(ans)
    exit()

print(-1)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    input()
    aList = list(map(int, input().split()))
    result = 1
    for num in aList:
        result *= num
    print(result if result <= 10**18 else -1)

Submission status: Time Limit Exceeded

Solution code:
g=0
f=1
n=int(input())
s=str(input())
a=s.split(" ")
for i in a:
  if int(i)==0:
    g=1
    break
  f=f*int(i)
if g==1:
  print(0)
elif f>10**18:
  print(-1)
else:
  print(f)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num = input().split()
ans = 1
jadge = 10 ** 18

for  i in num:
    ans = int(ans) *  int(i)
    
if int(ans) > int(jadge):
     print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from operator import mul

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

j = 1000000000000000000

ans = 1

ans = reduce(mul, An)


if ans <= j :
    print(ans)
    
else :
    print('-1')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8
N=int(input())
l = list(map(int, input().split()))
import functools
import operator
result = functools.reduce(operator.mul, l)
if(result>1000000000000000000):
  print("-1")
else:
  print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
temparr = input()
temparr = temparr.split()
flag = 0 

arr = []
first = 0 
totallen = 0 
for i in  temparr:
    if first == 0 :
        totallen += len(i)
        first = 1 
    else:
        totallen += len(i) - 1 
    if totallen > 19:
        flag = 2
        break
    if "0" in temparr:
        flag = 1 
        break 
    if i == "1" :
        continue
    arr.append(int(i))
if flag == 2:
    print("-1")
elif flag == 1 :
    print("0")
else:
    ans = 1
    arr = sorted(arr)
    arr = arr[::-1]
    for i in arr:
        ans *= i 
        if ans > 1000000000000000000:
            flag = 1 
            break 
    if flag == 0 :
        print(ans)
    else:
        print(-1)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
p=list(map(int, input().split()))
i=0
ans=1
flag=0
k=1e18
while(n>i):
	ans*=p[i]
	if(p[i]==0):
		break
	if(ans>k):
		flag=1
	i+=1		
if((ans>k or flag==1) and ans!=0):
		print(-1)
else:
		print(ans)

Submission status: Time Limit Exceeded

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

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


if __name__ == '__main__':
    sieve()

Submission status: Time Limit Exceeded

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

b=1
for j in a:
	b *=j
if b >10**18:
	print(-1)
else:
	print(b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

zeroexists = 0
Alist = []
A = input()
A = A.split()
for a in A:
    Alist.append(int(a))
    if a == 0:
        zeroexists = 1
        break

def program(alist,zeroexists):
    ans = 1
    if 0 in Alist:
        return 0
    for a in Alist:
        ans *= a
    if ans > 10**18:
        return int(-1)
    return int(ans)

print(program(Alist,zeroexists))

Submission status: Time Limit Exceeded

Solution code:
import numpy,math
n=int(input())
l=[int(x) for x in input().split()]
m=1
for x in l:
    m=m*x
if m>math.pow(10,18):
    print(-1)
else:
    print(m)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
c = int(1)
N = int(input())
A = [int(x) for x in input().split()]
for k in range(N):
    c*=A[k]
if c>10**18:
    print(-1)
else:
    print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

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

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

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/local/bin/python3
# coding: utf-8
n = input()
hairu = input()
kita = hairu.split(" ")
a = []
seki = 1
for c in kita:
    a.append(c)

try:
    for c in a:
        seki = seki * int(c)
    if seki > 10**18:
        print("-1")
    else:
        print(seki)
except:
    print("-1")

Submission status: Time Limit Exceeded

Solution code:
# Nの入力
N = int(input())

# A1,A2,..Anの入力
A = list(map(int,input().split()))

flg = 0         
# A1,A2...Anの積
A_multi = 1
for a in A:
    A_multi = A_multi * a

A_len = len(str(A_multi))
if A_len > 19:
    flg = 1

if A_len == 19:
    if A_multi > 10**18:
        flg = 1

if flg == 1:
    print("-1")
else:
    print(A_multi)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input().split()
mul = 1
for i in a:
  j = int(i)
  mul *= j
 
if mul > 1000000000000000000:
  print("-1")
else:
  print(mul)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = input().split()
c = 1
for i in range(a):
    if b[i] == 0:
        c = 0
        break

    c = c*int(b[i])

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num_list = list(map(int, input().split()))
multiple = 1
for num in num_list:
  multiple *= num
if 1000000000000000000 < multiple:
  print(-1)
else:
  print(multiple)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from operator import mul


N = int(input())
A = list(map(int,input().split()))
B = reduce(mul, A)
if B <=1E18:
  print(B)
else:
  print('-1')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst1 = []
lst1 = [int(item) for item in input().split()]
ans = 1
flag = 0
for num in lst1:
	if num == 0:
		flag=1
		print(0)
if flag == 0:
	for num in lst1:
		ans *= num
	if ans > 1000000000000000000:
		print(-1)
	else:
		print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

n = int(input())

a_list = [int(i) for i in input().split()]
result = reduce(lambda x, y: x * y, a_list)
if result > 10 ** 18:
    print(-1)
else:
    print(result)

Submission status: Time Limit Exceeded

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

if o==0:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
a = a.astype(np.object)
ans = np.prod(a)
if ans > 10**18:
  print(-1)
else:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)
N = int(input())
A = list(map(int, input().split()))
RedWine = prod(A)
if RedWine > 1000000000000000000:
    print(-1)
else:
    print(RedWine)

Submission status: Time Limit Exceeded

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


count  = reduce(mul, nums)
if count  > cnt :
        print(-1)
else:
         print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = []
p = 1
c = 0

a = list(map(int,input().strip().split()))[:n] 

for i in range(n):
    if a[i]==0:
        c = 1
    p *= a[i]
if c == 1:
    print(0)
elif p > 1000000000000000000:
    print(-1)
else:
    print(p)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a=int(input())

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

result=1
for i in range(a):
  if 2 <= a and a <= 10**5:
    result*=A[i]
    if result==0:
      break
    

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import decimal
n = int(input())
a = list(map(int,input().split()))

a_n = np.array(a,dtype=np.dtype(decimal.Decimal))
#print(a_n)
#a_n.sort()
tmp = np.prod(a_n)

#result = int(np.prod(a_n))
#print(tmp)

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

Submission status: Time Limit Exceeded

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    num = 1000000000000000000
    ans = 1
    for i in a_list:
        ans *= i
    
    if ans <= num:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator

N = int(input())
A = list(map(int, input().split()))
li = [2,5,7,9]
num = functools.reduce(operator.mul, A)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num_list = list(map(int, input().split()))
multiple = 1
for num in num_list:
  multiple *= num
if 10 ** 18 < multiple:
  print(-1)
else:
  print(multiple)

Submission status: Time Limit Exceeded

Solution code:

import math

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

if 0 in a:
    print(0)

else:
    val=1
    for i in range(len(a)):
        val*=a[i]
    
    print(val if val<=10**18 else '-1')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(0,n):
	result = result*a[i]

if result > 1000000000000000000:
	print("-1\n")
else:
	print(result)

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 > 1000000000000000000:
    print("-1")
else:
    print(result)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  a = input().split()
  res = 1;
  for i in range(n):
    res *= int(a[i])
  if (res > 10 ** 18):
    print('-1')
    return
  print(res)  
  return
  
main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

n = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
 
numeros = list(map(int,input().split()))
 
multiplicacao = 1
 
asdsd = True
 
for x in numeros:
    multiplicacao *= x
 
 
if multiplicacao > 1e18:
    print(-1)
 
else:
    print(multiplicacao)

Submission status: Time Limit Exceeded

Solution code:
def main():
  from sys import stdin
  input = stdin.readline
  n = int(input())
  a = tuple(map(int, input().split()))
  b = 0
  ans = 1
  for i in range(n):
    if(a[i] == 0 and b == 0):
      print(0)
      b = 1
  for i in range(n):
    ans = ans * a[i]
    if(ans > 1000000000000000000 and b == 0):
      print(-1)
      b = 1
  if(b == 0):
    print(ans)
if(__name__ == '__main__'):
  main()

Submission status: Time Limit Exceeded

Solution code:
# Nの入力
N = int(input())

# A1,A2,..Anの入力
A = list(map(int,input().split()))

flg = 0         
# A1,A2...Anの積
A_multi = 1
for a in A:
#    print(a)
    A_multi = A_multi * a
    A_len = len(str(A_multi))
#    print(a,A_len,A_multi)

if A_len > 19:
    flg = 1

if A_len == 19 and A_multi > 10**18:
    flg = 1

if flg == 1:
    print("-1")
else:
    print(A_multi)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = list(map(int,input().split()))
n = 1
m = 1
aa = a/2

c = 0
d = 0

if a%2 == 1:
    aa = (aa*2+1)//2

for i in b:
    if i == 0:
        c += 1
    elif i > 10**18:
        d += 1
        
if c > 0:
    print(0)
    exit()
if d > 1 and c == 0:
    print(-1)
    exit()
    
for i in range(int(aa)):
  n = n * b[i]

for i in range(int(aa),a):
    m *= b[i]

if n * m <= 10**18:
    print(n*m)
    exit()
  
print('-1')

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

for i in range(n):
  if i == 0:
    b = c[i]
  else:
    b = b*c[i]
    


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
cnt = 10 **18
N = map(int, input().split())
nums = list(map(int, input().split()))


count  = reduce(mul, nums)
if count  > cnt :
        print(-1)
else:
         print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a_list = [int(i) for i in input().split()]
result = 1
for a in a_list:
    result *= a
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()))
 
s = A[0]
for i in range(1, n):
  s *=A[i]
 
if s <= 1000000000000000000:
  print(s)
elif s > 1000000000000000000:
  print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = input().split(' ')
ans = 1
for i in range(N):
    tkn = int(nums[i])
    if tkn > 1e+18:
        ans = 1e+18 + 1
        break
    elif tkn == 0:
        ans = 0
        break
    else:
        ans *= tkn

print(-1) if ans > 1e+18 else print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
N=int(sys.stdin.readline())
values = []
res = 1
values=(sys.stdin.readline().split())
for v in values:
    res *= int(v)
if res > 1000000000000000000:
  print(-1)
else:
  print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
max=1000000000000000000
pro=1
flag=0
for i in range(0,len(a)):
    pro=pro*a[i]
    if(pro>max and (0  not in a) ):
        print(-1)
        flag=1
        break
if(flag==0):
    print(pro)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

Alist = []
A = input()
A = A.split()
for a in A:
    Alist.append(int(a))

def program():
    ans = 1
    for a in Alist:
        ans *= a
    if ans > 10**18:
        return int(-1)
    return int(ans)

print(program())

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = list(map(int,input().split()))
ans = 0
ansa = nums[0]
ansz = nums[-1]
for i in range(1,n//2):
    ansa *= nums[i]
    ansz *= nums[-(i+1)]
if n%2==0:
    ans = ansa*ansz
else:
    ans = ansa*ansz*nums[n//2]
if ans <= 10**18:
    print(ans)
else:
    print('-1')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

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<=1000000000000000000):
    print(result)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = input()

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

total = 1

if str(a) in '0':
	total = 0
else:
	for i in a:
		total *= i

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
state = 0
i = 1
ans = a[0]
while len(a) > i:
    memo = a[i]
    ans *= a[i]
    if memo == 0:
        state = 2
    if ans > 1000000000000000000 and state != 2:
        state = 1
    i += 1

if state == 1:
    print(-1)
if state == 2:
    print(0)

if state == 0:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst1 = []
lst1 = [int(item) for item in input().split()]
ans = 1
for num in lst1:
	ans *= num
if ans > 1000000000000000000:
	print(-1)
else:
	print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

total = 1
for a in li:
    total *= a
    if a == 0:
        total = 0
        break
    elif 10 ** 18 < total:
        total = -1


  
print(total)

Submission status: Time Limit Exceeded

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

for i in range(0,n):
	result = result*int(a[i])

if result > 1000000000000000000:
	print("-1\n")
else:
	print(result)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout  
  
# suppose a function called main() and 
# all the operations are performed 
def main(): 
  
    # input via readline method 
    n = stdin.readline() 
  
    # array input similar method 
    arr = [int(x) for x in stdin.readline().split()] 
  
    #initialize variable 
    summation = 1
      
    # calculate sum 
    for x in arr: 
        summation *= x 
  
    # could use inbuilt summation = sum(arr) 
    if summation>1e18:
        print("-1");
    else:
        print(summation);


    # print answer via write 
    # write method writes only 
    # string operations 
    # so we need to convert any 
    # data into string for input 
    
  
# call the main method 
if __name__ == "__main__": 
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
lis=list(map(int, input().split()))
def calc(i, y):
  if i==n-1:
    return y
  elif y>10**18:
    return "-1"
  elif y==0:
    return 0
  else:
    return calc(i+1, lis[i+1])*y
result=calc(0, lis[0])
if result>10**18:
  print("-1")
else:
  print(result)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = input().split()

for i in range(0,len(b)):
    b[i]=int(b[i])



res=1
state=1
length = len(b)
for i in range(0,length):
    res*=b[i]
    if res==0:
        print(res)
        state=0
        break

if state==1:
    if res>1000000000000000000:
        print("-1")
    else:
        print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())#リストの要素数
L = list(map(int,input().split()))

for i in range(0,N-1):
  L[i+1] *= L[i]
  
if L[N-1] > 10**18:
  L[N-1] = -1
  
print(L[N-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import decimal
N = int(input())
A = list(map(int, input().split()))

new_A = np.array(A, dtype=np.dtype(decimal.Decimal))
Answer = int(new_A.prod())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans = 1
max = 1000000000000000000
for i in range(len(N)):
  ans = ans * N[i]

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

Submission status: Time Limit Exceeded

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

total = 1
for a in li:
    total *= a
    if a == 0:
        total = 0
        break

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(input().split())
ans=1
f=0
i=0
while(i<n):
    if i==n-1:
        ans=ans*int(a[i])
    else:
        ans=ans*int(a[i])*int(a[i+1])
    if f==0 and ans>1000000000000000000:
        f=1
    if ans==0:
        print(0)
        exit()
    i+=2
if f==1:
    print(-1)
    exit()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import sys
N=int(input())
A=list(map(int, input().split()))
A_dict=collections.Counter(A)
ANS=1

if 0 in A_dict.keys():
    print("0")
    sys.exit()
for i in A_dict.keys():
    ANS=ANS*(i**A_dict[i])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A = input().rstrip().split(' ')
B=1
for i in range(N):
    B *= int(A[i])
if B<0 or B>1000000000000000000:
    print(-1)
else:
    print(B)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = (int(x) for x in input().split())
sum  = 1
flag = 0
for i in A:
    sum = sum * i
    if(i == 0):
        print(0)
        flag=2
        break
    if(sum > 10**18):
        flag=1
if(flag==0):
    print(sum)
elif(flag==1):
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input().strip())
ans = int(1)
a = map(int, input().strip().split());
for i in a:
	ans *= i
if ans > int(1e18):
	print(-1)
else:
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

n = int(input())
a = [int(_) for _ in input().split()]
#mul = 0

#for i in range(n):
mul = reduce(lambda x,y: x*y, a)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
numList = list(int(num) for num in input().strip().split())[:n]
ans = 1
for num in numList:
	ans *= num
if ans > 1e18:
	print(-1)
else:
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())

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

result=1
for i in range(a):
  if 2 <= a and a <= 10**5:
    result*=A[i]
    
if 0 <= result and result <= 10**18:
  print(result)
      
else:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
max=1000000000000000000
pro=1
flag=0
for i in range(0,len(a)):
    pro=pro*a[i]
    if(pro>max and 0  not in a ):
        print(-1)
        flag=1
        break
    else:
        continue
if(flag==0):
    print(pro)

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    re *= l[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()))

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

sum = 1
for i in a:
    sum *= i

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

Submission status: Time Limit Exceeded

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

b1=1
b2=0
b3=0
for i in range(n):
  b1*=a[i]
  b2*=a[i]
  b3*=a[i]
  if b1>=10**9:
    b2+=b1//(10**9)
    b1%=10**9
  if b2>=10**9:
    b3+=b2//(10**9)
    b2%=10**9
  
if b3>=1 and (b1!=0 or b2!=0):
  print(-1)
else:
  print(b3*(10**18)+b2*(10**9)+b1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = 1
A = [int(x) for x in input().split()]
i = 0
while i < N : 
  if A[i] == 0:
    ans = 0
    break
  ans = ans * A[i]
  i = i + 1
    
if ( ans > 1000000000000000000 ) : 
  print(-1) 
else :
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
n=int(input())
lis=list(map(int,input().split()))
ans=reduce(mul,lis)
if ans>1000000000000000000:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
input = stdin.readline
n = int(input())
a = tuple(map(int, input().split()))
b = 0
ans = 1
for i in range(n):
  if(a[i] == 0 and b == 0):
    print(0)
    b = 1
for i in range(n):
  ans = ans * a[i]
  if(ans > 1000000000000000000 and b == 0):
    print(-1)
    b = 1
if(b == 0):
  print(ans)

Submission status: Time Limit Exceeded

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