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:
n = int(input())
a = list(map(int, input().split()))
result = 1
for i in a:
    result *= i
if result > 10**18:
    print(-1)
else:
    print(result)

Submission status: Time Limit Exceeded

Solution code:
from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin,stdout
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math
import math
import time
from queue import Queue
# PradeepGhosh_2017076

if __name__ == '__main__':
	n=int(input())
	l=list(map(int,input().split(" ")))
	p=1
	for i in range(n):
		p=p*l[i]
	if(p>1000000000000000000):
		print(-1)
	else:
		print(p)

Submission status: Time Limit Exceeded

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

ans = 1
for a in A:
    ans *= a
    if 1000000000000000000 < ans:
        ans = -1
    elif a == 0:
        ans = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
total=1
A=list(map(int,input().split()))
if A.count(0)>=1:
  total=0
else:
  for i in range(N):
    total*=A[i]

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

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:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul
from decimal import Decimal

mod = 998244353
INF = 10 ** 13
sys.setrecursionlimit(2147483647)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

n = I()
A = LI()
ret = 1
flg = 0
for a in A:
    if a == 0:
        print(0)
        exit()
    ret *= a
    if ret > 10 ** 18:
        flg = 1

if flg:
    print(-1)
else:
    print(ret)

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    s *= a[i]
    if 0 in a and s > 10**18:
        print(0)
        break
    elif 0 != a and s > 10**18:
        print(-1)
        break
    
if s <= 10**18:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


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

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

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#/usr/bin/python3
n = int(input())
list_a = list(map(int, input().split()))
result = 1
#if 0 in list_a:
#        print(0)
#        exit()
  
for i in range(n):
    result *= int(list_a[i])
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 = 1
for i in range(n):
    s *= a[i]
    
if s > 10**18:
    print(-1)
else:
    print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
result=1
A=input().split()
for j in range(N):
  result=result*int(A[j])
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()))
cnt = 1

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

if(cnt <= 1e18):
    print(cnt)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
def main():
    num_1 = input()
    lis = list(input().split())
    s = 1
    num_2 = int (num_1)
    if 0 in lis:
        return 0
    for x in range(num_2):
        s = s * int(lis[x])
    if s > 10**18:
        return -1
    return s

print(main())

Submission status: Time Limit Exceeded

Solution code:
def main():
    num_1 = input()
    lis = list(input().split())
    s = 1
    num_2 = int (num_1)
    for x in range(num_2):
        s = s * int(lis[x])
    if s > 10**18:
        return -1
    return s

print(main())

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
values = input().split()

mult = 1
for i in range(len(values)):
  mult *= int(values[i])
  
if mult > 10**18:
  print(-1)
else:
  print(mult)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

x = 1
s = str.split(input(), " ")
for i in s:
    x *= int(i)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

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

def inZero(nums):
  return 0 in nums

def isOverDigits(nums):
  digits = 0

  for i in range(len(nums)):
    digits += len(str(nums[i])) - 1

  if digits > 18:
    return True
  else:
    return False

def calcAns(nums):
  ans = 1
  for i in range(len(nums)):
    ans = ans * nums[i]
  return ans

if inZero(a_list):
  print(0)
  sys.exit()

ans = calcAns(a_list) 

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()))
m=1
for x in A:
	m*=x
    
if(m>10**18):
  print('-1')
  
else:
  print(m)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())

a = deque(map(int,input().split()))
ans = 1
for i in range(n):
    ans = ans * a.popleft()



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()))
max = 10 ** 18
ans = 1

for ele in a:
    ans = ans * ele

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_n = list(map(int, input().split(' ')))
total = 1
boolean = True
for i in A_n:
    total *= i

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

Submission status: Time Limit Exceeded

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

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




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

Submission status: Time Limit Exceeded

Solution code:
#TIME : 
import sys
from math import sqrt
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

MAX = 10**18
n = inp()
a = inlt()
if 0 in a:
    print(0)
    exit()
res = 1
for num in a:
    res*=num
if res > MAX:
    print(-1)
else:
    print(res)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
# スペース区切りの整数の入力
input_str = input()
val_list = list(map(int, input_str.split()))
ans = 1
for i in range(N):
    ans = val_list[i]*ans
ans
if 1000000000000000000 < ans:
    print(-1)
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 = ans * a[i]


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

Submission status: Time Limit Exceeded

Solution code:
ans = 1
n = int(input())
A = [int(i) for i in input().split()]
A.sort()
for i in A:
    if i==0:
        print('0')
        exit()
    ans *= i
if ans>10**18:
        print('-1')
        exit()
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)
else:
         print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


def main():
    MOD = 10 ** 18
    n = int(input())
    A = list(map(int, input().split()))
    ans = 1
    for a in A:
        ans *= a

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  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)
main ()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
anser = 1
for a in input().split(" "):
    anser = anser * int(a)

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 1
    A.sort()
    for a in A:
        ans *= a

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


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 1
    for a in A:
        ans *= a

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


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

if(mul > 1000000000000000000):
    mul = -1

print(mul)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

result = 1
for i in A:
    result *= i

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

Submission status: Time Limit Exceeded

Solution code:
INF = int(1e18)


def main():
    N, *A, = map(int, open(0).read().split())
    ans = 1
    for a in A:
        ans *= a
    print(-1 if INF < ans else ans)
    return


main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
INF = int(1e18)


def main():
    N, *A = map(int, open(0).read().split())
    ans = reduce(lambda Ai, x: Ai * x, A)
    print(-1 if INF < ans else ans)
    return


main()

Submission status: Time Limit Exceeded

Solution code:
INF = int(1e18)


def main():
    input()
    *A, = map(int, input().split())
    ans = 1
    for a in A:
        ans *= a
    print(-1 if INF < ans else ans)
    return


main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
INF = int(1e18)


def main():
    input()
    *A, = map(int, input().split())
    ans = reduce(lambda Ai, x: Ai * x, A)
    print(-1 if INF < ans else ans)
    return


main()

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
p = math.prod(map(int, input().split()))
print(p if p <= 1e18 else -1)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from operator import mul

N = int(input())

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

if 0 in A:
  print(0)
  exit();
  
B = reduce(mul,A)

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

Submission status: Time Limit Exceeded

Solution code:
# import sys 
# input = sys.stdin.readline
 
 
n = int(input())
 
a= list(map(int,input().split())) 
 
def main(a):
    if 0 in a:
        print(0)
        quit()
     
    ans = 1
    for i in a:
        ans *= i 
        
        if ans > 1000000000000000000:
            ans = -1
    
    print(ans) 
    
main(a)

Submission status: Time Limit Exceeded

Solution code:
# import sys 
# input = sys.stdin.readline
 
 
n = int(input())
 
a= list(map(int,input().split())) 
 
def main(a):
    if 0 in a:
        print(0)
        quit()
     
    ans = 1
    for i in a:
        ans *= i 
        
        if ans > 10**18:
            ans = -1
    
    print(ans) 
    
main(a)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
count = int(input())
nums = input().split(" ")

product = 1

if ("0" in nums):
    print(0)
else:
    for i in nums:
        product *= int(i)
    if (product > 10**18):
        print(-1)
    else:
        print(product)

Submission status: Time Limit Exceeded

Solution code:
count = int(input())
nums = input().split(" ")

product = 1

if ("0" in nums):
    print(0)
else:
    for i in range(count):
        product *= int(nums[i])
    if (product > 10**18):
        print(-1)
    else:
        print(product)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for number in num_list:
    result = result * number
  
if result > 10 ** 18:
    result = -1
        
print(result)

Submission status: Time Limit Exceeded

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

for number in num_list:
    result = result * number
  
def if_test(result):
    if 10 ** 18 < result:
        print(-1)
    else:
        print(result)
        
if_test(result)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(int,input().split()))
prod  = 1
valid = 0
for i in arr:
    prod*=i

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(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())
sum = list(map(int,input().split()))
x = 1

for i in range(n):
    x *= sum[i]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    k = input()
    n = [int(x) for x in input().split()]
    ans = 1
    flag = False
    # print(n)
    for i in n:
        # print(ans)
        ans *= i

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

main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input(""))
k=1
li=list(map(int,input("").split(" ")))
if 0 in li:
    print("0")
else:
    for i in li:
        k*=int(i)
    if k>1000000000000000000:
        print("-1")
    else:
        print(k)

Submission status: Time Limit Exceeded

Solution code:
n=int(input(""))
k=1
li=input("").split(" ")
if "0" in li:
    print("0")
else:
    for i in li:
        k*=int(i)
    if k>1000000000000000000:
        print("-1")
    else:
        print(k)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
inputNum = int(input())

if 2 <= inputNum <= 10**5:
    list = list(map(int, input().split()))
    if inputNum == len(list):
        val = 1
        for item in list:
            val = val * item
        if 0 <= val <= 10**18:
            print(val)
        elif 10**18 < val:
            print(-1)

Submission status: Time Limit Exceeded

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

    total = 1

    for i in a :
        if i == 0 :
            print(0)
            return
        total *= i

    if total > 1000000000000000000 :
        print(-1)
        return

    print(total)

if __name__ == "__main__" :
    solve()

Submission status: Time Limit Exceeded

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

    total = 1

    for i in a :
        if i == 0 :
            print(0)
            return
        total *= i

    if total > 1000000000000000000 :
        print(-1)
        return

    print(total)

if __name__ == "__main__" :
    solve()

Submission status: Time Limit Exceeded

Solution code:
inputNum = int(input())

if 2 <= inputNum <= 10**5:
    list = list(map(int, input().split()))
    val = 1
    for item in list:
        val = val * item
    if 0 <= val <= 10**18:
        print(val)
    elif 10**18 < val:
        print(-1)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n = int(input())
da = NextIntList()
da = sorted(da)
ans = 1
for i in range(n):
    ans *= da[i]
    if ans > 10**18:
        ans = -1

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

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

#while True:
N = int(input())
#	if N>=2 and N<=10**5:break

if 2 <= N <= 10**5:
	num = list(map(int, input().split()))
	ans = reduce(mul,num)
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()))
res = 1
for x in a: res *= x
if res > 10**18: res = -1
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = input().split(sep=' ')
pro = 1
for el in A:
	pro *= int(el)

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

Submission status: Time Limit Exceeded

Solution code:
import functools

n = int(input())
xs = input().split()

def foldSum(acc, x):
    return acc*int(x)

if 0 in xs:
    print(0)
else:
    res = functools.reduce(foldSum, xs, 1)

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

Submission status: Time Limit Exceeded

Solution code:
inputNum = int(input());

if 2 <= inputNum <= 10**5:
    list = list(map(int, input().split()))
    val = 1;
    for item in list:
        val = val * item
    if 0 <= val <= 10**18:
        print(val)
    elif 10**18 < val:
        print(-1)

Submission status: Time Limit Exceeded

Solution code:
import functools

n = int(input())
xs = input().split()

def foldSum(acc, x):
    return acc*int(x)

res = functools.reduce(foldSum, xs, 1)

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

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

while True:
	N = int(input())
	if N>=2 and N<=10**5:break

while True:
	num = list(map(int, input().split()))
	if N==len(num):break

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

Submission status: Time Limit Exceeded

Solution code:
#B
N=int(input())
ans=1
for x in input().split():
    ans*=int(x)

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

Submission status: Time Limit Exceeded

Solution code:
#B
N=int(input())
ans=1
for x in input().split():
    ans*=int(x)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

def main(*, int=int, input=input):
    N = int(input())

    # スペース区切りでの入力(定数個)
    A = list(map(int, input().split()))

    if 0 in A:
        Alog = [0]
    else:
        Alog = [math.log10(x) for x in A]

    print()
    if sum(Alog)>18:
        print(-1)
    else:
        ans = 1
        for a in A:
            ans = ans * a
        if ans > 10**18:
            print(-1)
        else:
            print(ans)
    


if __name__ == "__main__":
    import io, sys
    if "_INPUT" in locals():
        sys.stdin = io.StringIO(_INPUT)
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a = [int(i) for i in input().split()]
tmp = 10**18
if 0 in a:
    print(0)
    sys.exit()
else:
    acc = 1
    for i in a:
        acc *= i
    if len(str(i)) + len(str(acc)) < 19:
        pass
    elif acc > tmp:
        print(-1)
        sys.exit()
print(acc)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def Judge(x,y):
    sum=1
    for i in range(y):
        sum*=x[i]
        #print(sum)
    if sum>10**18:
        return -1
    else:
        return sum

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

c=Judge(a,n)
print(c)

Submission status: Time Limit Exceeded

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

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

Ans=1

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


if Ans <= t:
    if flag==False:
        print(Ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        print(0)
    else:
        answer = 1
        for aa in a:
            answer *= aa
        print(answer if answer <= pow(10, 18) else -1)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

inf = 10**18
ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i

print(ans if ans <= inf else -1)

Submission status: Time Limit Exceeded

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

inf = 10**18
ans = 1
for i in a:
    ans *= i

print(ans if ans <= inf 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 *= A[i]

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
t = int(input())
A = [int(s) for s in input().split(" ")]
ans = reduce(lambda x,y: x*y, A)
print(ans if ans <= 10**18 else -1)

Submission status: Time Limit Exceeded

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

arr.sort()
res = 1
flg = True
for i in range(N):
    res*=arr[i]
    if res >10**18:
        flg = False
        print('-1')
    # print(res, res >=10**18)
if(flg):print(res)