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 sys
sys.setrecursionlimit(10**8)
def line_to_int(): return int(sys.stdin.readline())
def line_to_each_int(): return map(int, sys.stdin.readline().split())
def line_to_list(): return list(map(int, sys.stdin.readline().split()))
def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
# def dp(init, i, j): return [[init]*i for i2 in range(j)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #A = [0]+list(accumulate(A))
# import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a)

n = line_to_int()
a = line_to_list()
ans = a[0]

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def line_to_int(): return int(sys.stdin.readline())
def line_to_each_int(): return map(int, sys.stdin.readline().split())
def line_to_list(): return list(map(int, sys.stdin.readline().split()))
def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
# def dp(init, i, j): return [[init]*i for i2 in range(j)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #A = [0]+list(accumulate(A))
# import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a)

n = line_to_int()
a = line_to_list()
ans = a[0]

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

ans = 1
for num in range(N):
    if 0 in A:
        ans = 0
        break
    ans *= A[num]
    if ans > math.pow(10, 18):
        ans = -1
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

ans = 1
for num in range(N):
    ans *= A[num]
    if 0 in A:
        ans = 0
        break
    elif ans > math.pow(10, 18):
        ans = -1
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

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

Submission status: Time Limit Exceeded

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

ans = 1
for i in range(n):
  ans *= num[i]
  
if ans <= 10**18:
  print(ans) 
else:
  print('-1')

Submission status: Time Limit Exceeded

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


def II(): return int(sys.stdin.readline())


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


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    A = LI()

    ans = 1
    index = 0
    while index < N:
        ans *= A[index]
        index += 1

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


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()

Submission status: Time Limit Exceeded

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

mod = 10**18
ans = 1
for i in range(N):
    ans *= A[i]

if ans > mod:
    print(-1)
    exit()

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

prd=1
for x in l:
	prd*=x
	
if prd>10**18:
	print(-1)
else:
	print(prd)

Submission status: Time Limit Exceeded

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

#print(a)

ans = int(a[0])
for i in range(1,N):
    ans = ans * int(a[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()))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans = 1
for i in range(N):
    ans *= A[i]
    if ans >> 10**18:
        break
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()))
ans = 1
for i in range(N):
    ans *= A[i]
    if ans >> 10**18:
        break
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()))
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:
N=int(input())
A=input().split()
ans=1
for l in range(N):
  b=int(A[l])
  ans*=b
if ans<=1000000000000000000:
  print(ans)
else:
  print("-1")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

res = 1
for i in range(n):
  res = res * nums[i]
  if res <= 10**18 or 0 in nums:
    continue
  else:
    res = -1
    break
    
print(res)

Submission status: Time Limit Exceeded

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

res = 1
for i in range(n):
  res = res * nums[i]
print(res if res <= 10**18 else -1)

Submission status: Time Limit Exceeded

Solution code:
# B Multiplication 2

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

ans = 1
for ai in a:
  ans *= ai

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()))
x = 1
for i in range(N):
    x *= A[i]
if x > 10 ** 18:
    print(-1)
else:
    print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

A.sort()
a=1
b=False
for i in range(N):
    a=a*A[i]
    if a>10**18:
        b=True
        continue

if b==False:
    print(a)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

if 0 in a :
  ans = 0
else :
  ans = 1
  
for i in range(n) :
  ans *= a[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()))

ans = 1
for i in range(n) :
  ans *= a[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()))
for i in range(n-1):
  a[i+1]*=a[i]
print(a[i+1] if a[i+1]<=10**18 else -1)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

res = reduce(lambda a, b: a*b, A)
if res > 10 ** 18:
    print(-1)
else:
    print(res)

Submission status: Time Limit Exceeded

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

for a in A:
  if a == 0:
    prod == 0

for a in A:
  prod *= a

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

print(prod)

Submission status: Time Limit Exceeded

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

for a in A:
  prod *= a

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

print(prod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(1,N):
  ans = 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()))
b=1
for i in a:
  b*=i
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()))
ans = 1

for i in range(N):
    if A[i] == 0:
        ans = 0
        break
    else:
        ans *= A[i]

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

Submission status: Time Limit Exceeded

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

pr = 1
for i in range(n):
  pr *= ary[i]

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

Submission status: Time Limit Exceeded

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

ans = 1

for d in data:
  ans = ans * int(d)

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()))
a.sort(reverse=True)
if a[-1]==0:
    print(0)
    exit()
ans=a[0]
for i in range(len(a)-1):
    ans*=a[i+1]
if ans>1000000000000000000:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    pass


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = list(map(int, input().split()[:a]))
c = 1
for i in b:
    c*=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()))

n = 1

for i in a:
    n *= i

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

Submission status: Time Limit Exceeded

Solution code:
import functools
from operator import mul


n = int(input())

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

product = 1

for num in nums:
    product *= num

if product > 1e18:
    product = -1

print(product)

Submission status: Time Limit Exceeded

Solution code:
import functools
from operator import mul


n = int(input())

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

product = functools.reduce(mul, nums, 1)

if product > 1e18:
    product = -1

print(product)

Submission status: Time Limit Exceeded

Solution code:
x = input()
y = input().split()
t = 1
for z in y:
    t *= int(z)
if t > 1000000000000000000:
    print(-1)
else:
    print(t)

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

Submission status: Time Limit Exceeded

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

ans=1
if 0 in A:
    ans = 0
else:
    for a in A:
        A.reverse()
        if a > 10**18:
            ans = -1
            break
        else:
            ans *= a
            if ans > 10**18:
                ans = -1
                break
print(ans)

Submission status: Time Limit Exceeded

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

ans=1
if 0 in A:
    ans = 0
else:
    for a in A:
        A.reverse()
        if a > 10**18:
            ans = -1
            break
        else:
            ans *= a
            if ans > 10**18:
                ans = -1
print(ans)

Submission status: Time Limit Exceeded

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

ans=1
if 0 in A:
    ans = 0
else:
    for a in A:
        A.reverse()
        if a > 10**18:
            ans = -1
        else:
            ans *= a
            if ans > 10**18:
                ans = -1
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
an = [int(num) for num in input().split()]

answer = an[0]
check = 10**18
for i in range(1,len(an)) :
  answer *= an[i]

if answer <= check:
  print(answer)
else :
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int , input().split()))
    max_number = 10 ** 18
    result = 1
    if 0 in A:
        print(0)
        return
    for a in A:
        result = result * a
    if result > max_number:
        print(-1)
    else:
        print(result)

    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int , input().split()))
    result = reduce(lambda x, y: x * y, A)
    max_number = 10 ** 18
    if 0 in A:
        print(0)
        return
    if result > max_number:
        print(-1)
    else:
        print(result)

    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int , input().split()))
    result = reduce(lambda x, y: x * y, A)
    max_number = 10 ** 18
    if result > max_number:
        print(-1)
    else:
        print(result)

    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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()))
t = 1
a = 10 ** 18

if 0 in A:
    t = 0
else:
    for i in A:
        t *= i

if t > a:
    print("-1")
else:
    print(t)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
nums = map(int, input().split(' '))
result = 1
for i in nums:
    result *= 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()))
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
n = int(input())
a = list(map(int, input().split()))

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

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

Submission status: Time Limit Exceeded

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

for i in a:
    ans *= i

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

Submission status: Time Limit Exceeded

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

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()))
re = 1
if int(0 in A) == 1:
  re = 0
  N = 0
for i in range(N):
  re *= A[i]
if re > 10**18:
  re = -1
print(re)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
re = reduce(mul,A)
#print(reduce(mul,A))
#for i in range(N):
#  re *= A[i]
if re > 10**18:
  re = -1
print(re)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()

MAX = 10**18
result = 1
for i in input().split():
    result *= int(i)

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

Submission status: Time Limit Exceeded

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()

MAX = 10**18
result = 1
M = FLI()

for m in M:
    result *= m

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
s=1
for x in l:
    s *= 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()))
result = 1
for i in A:
    result *= i

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
number = input().split(" ")

ans = 1

for i in number:
    ans *= int(i)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if 0 in a:
  print(0)
else:
  for i in a:
    u *=i
  if u > 1000000000000000000:
    print(-1)
  else:
    print(u)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#ABC169 B-Multiplication2
class Calc():
  def multi(self,x,y):
    x, y, sign, rslt = str(x)+".", str(y)+".",1 ,""
    if x[0]=="-":
      sign*=-1
      x=x[1:]
    if y[0]=="-":
      sign*=-1
      y=y[1:]
    x,y=x.split("."),y.split(".")
    x2 = [int(x[1][-i-1]) for i in range(len(x[1]))] + [int(x[0][-i-1]) for i in range(len(x[0]))]
    y2 = [int(y[1][-i-1]) for i in range(len(y[1]))] + [int(y[0][-i-1]) for i in range(len(y[0]))]
    sum=[0]*(len(x2)+len(y2))
    for i, p in enumerate(y2):
      for j, q in enumerate(x2):
        K=i+j
        sum[K]+=p*q
        while sum[K]>9:
          sum[K+1], sum[K] = sum[K+1] + int(sum[K]/10) , sum[K]%10
          K+=1
    for i in range(len(sum)): rslt+=str(sum[-i-1])
    dclen=len(x[1])+len(y[1])
    if dclen>0: rslt=rslt[:len(rslt)-dclen]+"."+rslt[len(rslt)-dclen:len(rslt)]
    for i in range(len(rslt)):
      if rslt[i]=="0" and (rslt[i+1] if i<len(rslt)-1 else ".")!="." : continue
      else:
        rslt=rslt[max(i,0):]
        break
    return ("-" if sign==-1 else "")+rslt
  
  def max_2(self,x,y):
    X,Y=x,y
    x, y, rslt = str(x)+".", str(y)+".", ""
    if x[0]=="-" and y[0]!="-": return Y
    if x[0]!="-" and y[0]=="-": return X
    if x[0]=="-" and y[0]=="-": return #(略)
    x,y=x.split("."),y.split(".")
    size0,size1 = max(len(x[0]),len(y[0])), max(len(x[1]),len(y[1]))
    x[0],y[0] = "0"*( size0 - len(x[0]) ) + x[0] , "0"*( size0 - len(y[0]) ) + y[0]
    x[1],y[1] = x[1] + "0"*( size1 - len(x[1]) ) , y[1] + "0"*( size1 - len(y[1]) )
    for s in [0,1]:
      for i in range( size0 if s==0 else size1 ):
        p,q=int(x[s][i]),int(y[s][i])
        if p==q: continue
        elif p>q: return X
        elif p<q: return Y
    return X

N=int(input())
A=input().split()
R,lim="1","1"+"0"*17+"1"
for i in range(N): 
  R=Calc().multi(R,A[i])
print( -1 if Calc().max_2(lim,R)==R else R )

Submission status: Time Limit Exceeded

Solution code:
n=int(input()) #get input N
a=list(map(int, input().split())) #get input A
b=1 #first to multiply

for i in a:#multiply all list in A
    b*=i

if b>1000000000000000000: #if more than 10^18
    print("-1")

else: 
    print (b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) #number of input

a = list(map(int,input().strip().split()))[:n] #ask input to multiple in one line

result = 1 
for x in a:
    result = result * x #update result(multiple of all)


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

else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
#user input N
#user input A in list
#function of multiplication of all item in list
#time complexity is O(n)
N = int(input())
A = [int(x) for x in input().split()[:N]]

def multiplyList(list1):
    b = 1
    for i in list1:
        b = b*i
    return b

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

Submission status: Time Limit Exceeded

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

x=0
result = 1

def Calculate (x,i,n,result):
    while x < n:
        result = result*i[x]
        x+=1
        
    if result > 10**18:
        print("-1")
        return

    print(result)
    return

Calculate (x,i,n,result)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
result=1
for i in (a):
    result *= i
 # Multiply elements one by one
if result> (10**18):
     print("-1")
else:
     print(result)