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:
num = int(input())
line = input().split()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
    N = int(input())
    A_list = [int(_) for _ in input().split()]
    ans = 1
    for i in range(N):
        ans *= A_list[i]

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

Submission status: Time Limit Exceeded

Solution code:
times = int(input())
count = 0
nums = list(map(int, input().split()))
total = 1

while count < times:
    total = total * nums[count]
    count += 1

if total < 1000000000000000001:
    print(total)
else:
    print(-1)

Submission status: Time Limit Exceeded

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


def multiplyList(myList):
    n = functools.reduce(operator.mul, myList, 1)
    if int(n) <= 1000000000000000000:
        return n
    else:
        return -1

print(multiplyList(n))

Submission status: Time Limit Exceeded

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

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

ans=1

for a in A:
    a=int(a)
    if a==0:
        ans=0
        break
    if a!=1:
        ans*=a

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

Submission status: Time Limit Exceeded

Solution code:
m = int(input())
n = input().split()
s=[]
for i in n:
    s.append(int(i))
s.sort()
ans=1
for i in s:
    ans*=i
    if ans==0:
        break
    elif ans <= 10**18:
        continue
    else:
        ans=-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator
n = int(input())
l = input().split()
m = []
for i in range(n):
    m.append(int(l[i]))
ans = functools.reduce(operator.mul, m)
if ans <= 10**18:
    print(ans)
else:
    print(-1)

Submission status: Time Limit Exceeded

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')
if C <= 10**18:
  print(C)

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 (ans > 10**18):
  print(-1)
else:
  print(ans)

Submission status: Time Limit Exceeded

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

count = int(input())
list = list(map(int, input().split()))
if 0 in list:
    print(0)
else:
    sum = reduce(lambda x, y: x*y, list)
    if sum > 1000000000000000000:
        sum = -1
    print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
user_int = input()
kk = user_int.split()

res =1 
for w in kk:
    val = int(w)
    res = res*val

if(res>pow(10,18)):
    print(-1)
else:
    print(res)

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:
    if(i == 0):
        print(0)
        flag=1
        break
    else:
        sum = sum * i
if(flag==0):
    if(sum > 10**18):
        print(-1)
    else:
        print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

temp = input().split()

for i in temp:
  a = a * int(i)
  
if(a > 1000000000000000000):
  print ("-1")
else:
  print (a)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
numbers = input().split()
sum = 1
for i in range(num):
  sum *=int(numbers[i])
if (sum>(10**18)):
  print (-1)
else :
  print (sum)

Submission status: Time Limit Exceeded

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

res = 1
i = 0
while (i < n):
  res *= a[i]
  i += 1
  
if (res > 1000000000000000000):
  res = '-1'

print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=int(input())
li=list(map(int,input().split()))
L=deque(li)
ans=1
for i in range(n):
    x=L.popleft()
    ans*=x
if ans>10**18:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

n = int(input().rstrip())
nums = map(int,input().rstrip().split(' '))

ans = reduce(mul, nums)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list = input().split(" ")
x = 1
for num in list:
  x = x * int(num)
  
if x <= 10**18:
  print(x)
else:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator

N = int(input())#リストの要素数
 
#L = input().split()
#L = map(lambda x: int(x), L)
#ASW = functools.reduce(operator.mul, L)
L = list(map(int,input().split()))
ASW = functools.reduce(operator.mul, L)
 
if ASW > 10**18:
  ASW = -1
  
print(ASW)

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 > 1000000000000000000:
  print('-1')
else:
  print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import math

N = int(input())

sums = 1;
string = input().split()

for i in range(N):
    sums = sums * int(string[i])

if(sums > pow(10,18)):
    print(-1)
    exit()
print(sums)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():

    n=int(input())
    p=tuple(map(int,input().split()))
    s=1
    for i in range(n):
        s*=p[i]
    if s>=10**18+1:
        print(-1)
        sys.exit()
    print(s)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = [int(i) for i in 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:
from functools import reduce
N = int(input())
As = list(map(int,input().split()))
f = True
r = reduce(lambda x, y: x * y, As)

if 1000000000000000001 <= r:
  print("-1")
else:
  print(r)

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
from functools import reduce

n = int(input())
num = list(map(int, input().split()))
num = [ Fraction(i) for i in num ]

if 0 in num:
    print(0)
else:
    mult = reduce(lambda x, y: x*y, num)
    if mult > 10**18:
        print(-1)
    else:
        print(int(mult))

Submission status: Time Limit Exceeded

Solution code:
import sys

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

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
As =[int(x) for x in input().rstrip('\n').split()]
if 0 in As:
  res = 0
else:
  res = 1
  for i in As:
    res =res*i
    if res > 10**18:
      res = -1
print(res)

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:
  mul = -1


print(mul)

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
from functools import reduce

n = int(input())
num = list(map(int, input().split()))
num = [ Fraction(i) for i in num ]

if 0 in num:
    print(0)
elif len([i for i in num if i >= 10**18]) != 0:
    print(-1)
else:
    mult = reduce(lambda x, y: x*y, num)
    if mult > 10**18:
        print(-1)
    else:
        print(int(mult))

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

from operator import mul
from functools import reduce
x = reduce(mul,a)
if x<=10**18:
    print(x)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans=1

for a in A:
    if a==0:
        ans=0
        break
    if a!=1:
        ans*=int(a)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
A = input().split()
total = 1
for value in A:
	total *= int(value)
if (total > 10**18):
	print(-1)
else:
	print(total)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
num_list = input().split(" ")
result = 1
con = num >= 2 and num <= 100000
if con == True and num == len(num_list):
    for i in num_list:
        i = int(i)
        if i >= 0 and i <= 1000000000000000000:
            result = result * i
        else:
            result = result
    if result > 1000000000000000000:
        print(-1)
    else:
        print(result)
else:
    print()

Submission status: Time Limit Exceeded

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



# 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()]
ans = functools.reduce(operator.mul, v)
 
if ans > 1e18:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans = 1
for i in range(N):
    ans *= A[i]
if ans > 1000000000000000000:
    ans = -1
print(ans)

Submission status: Time Limit Exceeded

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

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]
if result > 10**18:
  print(-1)
else:
  print(result)

Submission status: Time Limit Exceeded

Solution code:

import operator
from functools import reduce

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

Max = 10 ** 18

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

if result > Max:
    print(-1)
else:
    print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
ans=1
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: Time Limit Exceeded

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

if N % 2 == 0:
  for i in range (N//2):
    A.append(L[i]*L[-1-i])
  for j in range(N//2):
    ans *= A[j]
  
else:
  for i in range(N//2):
    A.append(L[i]*L[-1-i])
  for j in range(N//2):
    ans *= A[j]
  ans *= L[N//2+1]
  
if ans > 10**18:
  print(-1)
else:
  print(ans)

Submission status: Time Limit Exceeded

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')
else:   
  print(x)

Submission status: Time Limit Exceeded

Solution code:
def multiplyList(myList): 
    result = 1
    for x in myList: 
        result = result * x 
    return result 

t=int(input())
l=list(map(int,input().split()))
multiplyList(l)
if(multiplyList(l)>1000000000000000000):
    print("-1")
else:
    print(multiplyList(l))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from operator import mul

t = input() #trash
L = list(map(int, input().split()))
      
ans = reduce(mul, L)

if ans <= 1000000000000000000:
  print(ans)
  
else:
  print("-1")

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
dummy = input()
nums = list(map(int, input().split()))
res = reduce((lambda x, y: x * y), nums)
if res > 10**18:
    print("-1")
else:
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import operator
import functools
n = int(input())
data = map(int, input().split())
# val = 1
# for i in data:
#   val = val * int(i)
#   # print(val)
#   # if val > 10**18:
#   #   break
val = functools.reduce(operator.mul, data)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a =list(map(int,input().split()))
s = 1
f = 0
if not a.count(0) == 0:
  print ("0")
  f += 1
if f == 0:
  for _ in range(n):
    s *= a[_]
  if len(str(s-1)) > 18:
    print("-1")
    f += 1
if f == 0:
  print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = list(map(int,input().split()))
sum = 1
for num in a:
  sum *= num
if sum > 10 ** 18:
  print("-1")
else :
  print("{}".format(sum))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
As =[int(x) for x in input().rstrip('\n').split()]
if 0 in As:
  res = 0
else:
  res = 1
  for i in As:
    res =res*i
  if res > 10**18:
    res = -1
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
input()
l = list(map(int,input().split()))
s = 1
if 0 in l:
    print(0)
    exit()
for i in l:
  s*=i
print(s if s<=10e+17 else -1)

Submission status: Time Limit Exceeded

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:
    print(-1)
else:
    print(int(ans))

Submission status: Time Limit Exceeded

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

product = 1

for i in range(N):
    product *= a[i]

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from operator import mul
N=int(input())
A=[0]*N
A=list(map(int, input().split()))

multi=reduce(mul,A)

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

Submission status: Time Limit Exceeded

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

for i in a:
    sum*=i 

if(sum>pow(10,18)):
    print("-1")
else:
    print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = input().split()
 
mult = 1
for i in range(N):
    mult = mult * int(An[i])
 
if mult > 10**18:
    print(-1)
else:
    print(mult)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n <= 100000:
        ans = 1
        for i in range(0, len(a)):
            ans = ans*int(a[i])

        if ans <= 1000000000000000000:
            print(int(ans))
            return
        else:
            print(int(-1))
            return
    else:
        print(int(-1))
        return

main()

Submission status: Time Limit Exceeded

Solution code:
x1 = input()
x2 = [int(s) for s in input().strip().split(" ") ]
 
result =  1
for x in x2:
  result *= x 

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
mx = 1000000000000000000

n = int(input())
arr = list(map(int, input().split()))
ans = 1
for ele in arr :
    ans = ans * ele
if ans > mx :
	print(-1)
else :
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())
list_input = list(map(int, sys.stdin.readline().strip().split()))

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

if a > pow(10, 18):
    print(-1)
else:
    print(a)

Submission status: Time Limit Exceeded

Solution code:

import sys
from functools import reduce

input = sys.stdin.readline

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

def main():
    result = 1

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

    return result

ans = main()
if ans > pow(10, 18):
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

from operator import mul
from functools import reduce

ans = reduce(mul, a)
if ans - (1000000000000000000) > 0:
  print("-1")
else:
  print(ans)

Submission status: Time Limit Exceeded

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

for i in range (0 , len(A)):
    a = a * A[i]

if a <= b:
    print(a)
else:
    print("-1")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

N = int(input())
A = list(map(int, input().split()))
# prod = functools.partial(functools.reduce, operator.mul)
# sum = functools.reduce(operator.mul, A, 1)
# a = np.array(A, dtype=int)
# print(a)
# print(np.prod(a))

lim = False
zero = False
sum = reduce(lambda a, b: a * b, A)
# for i in A:
#     if i == 0:
#         zero = True
#         break

# if int(zero) == 0:
#     for i in A:
#         sum = sum * int(i)
#         if 1000000000000000000 < sum:
#             lim = True
#             break

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from math import prod
N = input()
B = [int(i) for i in input().split()]

if 2 <= int(N) <= 10**5 and int(N) == len(B):
    S = prod(B)
    if S > 10**18:
        print("-1")
    else:
        print(S)
else:
    print("choose right value")

Submission status: Time Limit Exceeded

Solution code:
import sys

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

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

  ans = 1
  for num in a:
    if num == 0:
      ans = 0
      break
    ans = ans * num

  if ans > 1000000000000000000:
    ans = -1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
arr=input().split(" ")

sum=1
for i in arr:
    sum=sum*int(i)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

for i in A:
    ans = i*ans

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

print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
rev = 1
l = []
for i in range(n//2) :
    ans *= a[i]
    rev *= a[n-i-1]

l.append(ans)
l.append(rev)
if n % 2 == 1 :
    l.append(a[n//2+1])
else :
    l.append(1)

x = 1
for j in range(3):
    x *= l[j]

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

Submission status: Time Limit Exceeded

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

ans = x[0]
for i in range(1,len(x)):
  ans *= x[i] 
  if ans > 10 ** 18 :
    ans = -1
    exit 

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
n = int(input())
tab = [int(i) for i in input().split()]

if reduce(lambda x, y: x*y, tab) > pow(10, 18):
  print("-1")
else:
  print(reduce(lambda x, y: x*y, tab))

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
	n = int(input().strip())
	arr = list(map(int, input().strip().split(' ')))
	product = 1
	for i in arr:
		product *= i
	if product > pow(10,18):
		print("-1")
	else:
		print(product)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from operator import add, mul
N = int(input())
int_list = list(map(int,input().split()))
res = reduce(mul, int_list)
if res <= 10 **18:
    print(res)
else:
    print('-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()))

ans = reduce(mul, A)

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

Submission status: Time Limit Exceeded

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

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

Ans=1

flag=False

for a in A:
    if flag==False:
        Ans=Ans*a
        if 0 in A:
            if flag==False:
                print(0)
                flag=True
                break
        elif Ans > 10**18:
            if flag==False:
                print(-1)
                flag=True
                break
        else:
            pass
    else:
        break


if Ans <= 10**18:
    if flag==False:
        print(Ans)

Submission status: Time Limit Exceeded

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

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

if a > pow(10, 18):
    print(-1)
else:
    print(a)

Submission status: Time Limit Exceeded

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

def main():
    ans = 1 
    for i in a:
        if i == 0:
            print(0)
            return
        ans*=i

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


main()

Submission status: Time Limit Exceeded

Solution code:
x1 = input()
x2 = [int(s) for s in input().strip().split(" ") ]
 
result =  1
for x in x2:
  result *= x 

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

Submission status: Time Limit Exceeded

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


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

print(multiplyList(n))

Submission status: Time Limit Exceeded

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

ans=1

for i in a:
    ans=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()))

total = 0

for i in range(n):
    if i == 0:
        total = a[i]
    else:
        total *= a[i]

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    _ = input()
    ans = 1

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))  # n個の数字がリストに格納される
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:
n=int(input()) 
alist=list(map(int,input().split()))
a=1
for i in alist:
    a=a*i
if a>10**18:
    print('-1')
else:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)



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

result = prod(An)

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()))
result=1
a.sort()
if a[0]==0:
    print(0)
    exit(0)
for i in range(n//2):
    result=result*a[i]*a[n-i-1]
if n%2==1:
    result*=a[n//2+1]
if result==1000000000000000000:
    print(result)
elif 18< len(str(result)):
    print(-1)
else:
    print(result)

Submission status: Time Limit Exceeded

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

ans = a_list[0]

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

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
input()
a = map(int, input().split())
ret = 1
for x in a:
  ret *= x
if ret > 1e+18:
  print(-1)
else:
  print(ret)