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:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

##### 進数の変換 #####
# bin_str = bin(i)[2:]
# oct_str = oct(i)[2:]
# hex_str = hex(i)[2:]

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	ans = 0
	for i,vol in enumerate(A):
		if i == 0:
			ans = vol
			continue
		ans = ans * vol
	
	if ans > 1000000000000000000:
		print(-1)
		sys.exit()

	print(ans)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索のリバース
def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索
# 存在しない場合: None 存在する場合: その値
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

N = int(input())
A = [int(i) for i in input().split(' ')]
goal = reduce(mul, A)
if goal <= 10**18:
    print(goal)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

val_list = input().split()
answer = 0
for i, val in enumerate(val_list):
    if i == 0:
        answer = int(val)
    else:
        answer = answer * int(val)

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

n = int(input())
l = list(map(int, input().split()))
ans = reduce(lambda x, y: x * y, l)

if ans > 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())
*arr, = map(int, input().split())
res = 1
for i in range(n):
    res *= arr[i]
print(res if res <= 10 ** 18 else - 1)

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 = ans * A[i]
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()))
a.sort()

ans = 1
can = 1
for i in range(N):
    ans = ans * a[i]
    if(ans>1000000000000000000):
        can = 0

if(can==1):
    print(ans)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

ans = 1

for num in arr:
	ans *= 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()))

ans = 1

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

if ans > 1000000000000000000:
    ans = -1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
N = int(input())
A = []
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:
# coding: utf-8
# Your code here!
n = int(input())
L = list(map(int,input().split()))
a = 1
for i in L:
    a = a*i

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = map(int, input().split())
re = 1
for i in l:
  re *= i

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
ans = 1
if(0 in a):
  ans = 0
else:
  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 = map(int, input().split())

ans = 1
INF = 1000000000000000000

for a in A:
    ans *= a

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
b=A[0]

for i in range(1,len(A)):
    b=b*A[i]
    
if(10**18<b):

    print('-1')
    exit()

print(b)

Submission status: Time Limit Exceeded

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

ans = 1
t = 10 ** 18
for i in range(n):
    if a[i] == 0:
        print(0)
        exit(0)
    ans *= a[i]

if ans <= t:
    print(ans)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in 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()))

ans = 1
a_in = [s for s in a if 0 in a]
if a_in:
    print('0')
    exit()
else:
    for i in a:
        ans = ans * i

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

print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 1

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

if ans > 10**18:
    print("-1")
elif 0 in A:
    print("0")
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = 1

N = input()
for x in input().split():
  s *= int(x)

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

Submission status: Time Limit Exceeded

Solution code:
def intlist(x):
    y = []
    for i in range(len(x)):
        y.append(int(x[i]))
    return y
N = int(input())
A = intlist(input().split())
M = 1

for i in range(N):
    M = M * A[i]
if M > 10**18:
    M = -1
        
print(M)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = [int(_) for _ in input().split()]

ans = 1


for i in An:
    ans = 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()))
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()))
p = 1
q = 1
for i in range(n//2):
  p *= a[i]
  q *= a[n//2+i] 

if n%2 == 0:
  r = p*q
else:
  r = p*q*a[-1]  
  
if r <= 10**(18):
    print(r)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
Atxt=input()
Ans=1
Flag=0
for i in range(N):
    Ans*=int(Atxt.split(" ")[i])
    if (Ans>10**18 and Flag==0):
        Ans=-1
        Flag=1
    elif (Ans==0):
        break
print(Ans)

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

Submission status: Time Limit Exceeded

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

ans = 1
flag = 0
for x in range(len(i)):
    ans = ans * i[x]
    if ans > 1000000000000000000:
        flag = 1
    if i[x] == 0:
        flag = 2

if flag == 1:
    print(-1)
elif flag == 2:
    print(0)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) #1行目のNを取得する
i = list(map(int, input().split()))

result = 1

for x in range(N):
  result *= i[x]

  
if(result>pow(10,18)):
   result = -1
print(result)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    A_list = [int(item) for item in input().split()]

    is_zero = False
    res = 1

    for item in A_list:
        res *= item

        if item == 0:
            is_zero = True
            break
    else:
        if res > 10 ** 18:
            print(-1)
        else:
            print(res)

    if is_zero:
        print(0)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

mul = reduce(mul,a)
if mul > MAX:
    print(-1)
else:
    print(mul)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

mult = 1
A = list(map(int, input().split()))
if 0 in A:
    print(0)
else:
    try:
        for a in A:
            mult *= a
            
        if mult > 10**18:
            print("-1")
        else:
            print(mult)
    except:
        print("-1")

Submission status: Time Limit Exceeded

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

    ans = 1
    th = 1000000000000000000

    for a in A:
        ans *= a
    if ans > th:
        print('-1')
    else:
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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
flag = False
zeros = False
for i in a:
    ans *= i
    if (ans > pow(10,18)):
        flag = True
    if i == 0:
        zeros = True

if (flag):
    ans = -1
if (zeros):
    ans = 0

print(ans)

Submission status: Time Limit Exceeded

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

sum = 1
i = 0
while i < len(A):
    sum *= A[i]
    i+=1
    if sum > 1000000000000000000 and 0 not in A:
      break

if sum > 1000000000000000000:
    sum = -1

print(sum)

Submission status: Time Limit Exceeded

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

N = functools.partial(functools.reduce, operator.mul)
ans = N(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()))
ans=1
for i in range(n):
    if a[i]==0:
        ans=0
        exit
    ans*=a[i]

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

Submission status: Time Limit Exceeded

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

ans = 1
for i in range(len(ilist)):
  ans = ans * ilist[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:
    print(-1)
else:
    print(ans)

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 pow(10,18)<result:
    print(-1)
else:
    print(result)

Submission status: Time Limit Exceeded

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

if 0 in A:
    print(0)

else:
    total = 1
    for i in range(N):
        total *= A[i]

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ss=[a for a in input().split()]
 
res=1
for i in ss:
    res=res*int(i)
    

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

Submission status: Time Limit Exceeded

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

ans = 1
flag = False
A.sort()
for i in range(N):
  ans *= A[i]
  if(ans>1000000000000000000):
    flag = True

if(flag):
  print(-1)
else:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
_ = int(input())

result = 1
num = list(map(int, input().split()))

for i in num:
    result = result * i

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

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())
l = []
l += list(map(int, input().split()))

r = 1
for e in l:
    r = r * e

if r > 10 **18:
    print('-1')
    sys.exit()
        
print(r)

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:
from functools import reduce
def do():
    n=int(input())
    l=list(map(int,input().split()))
    # k=1
    v=reduce(lambda x, y: x*y, l)
    if v > 1 * 10 ** 18:
        return -1
    return v
print(do())

Submission status: Time Limit Exceeded

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

A.sort()
total = 1
flag = 9
for i in range(N-1,-1,-1):
  total *= A[i]
  if total > 10**18:
    flag = 0
    break
  elif min(A) == 0:
    flag = 1
    break
  
if flag == 0:
  print(-1)
elif flag == 1:
  print(0)
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 > pow(10,18):
    ans = -1
    print(ans)
else:
  print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a = list(map(int,input().split()))
c = 1
for i in range(n):
    c = c*a[i]
    if c == 0:
        print(0)
        sys.exit()

if c > 10**18:
        print(-1)
        sys.exit()
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
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")
    sys.exit()
else:
    print(c)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

if sum>1000000000000000000:
    sum = -1

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys

kaisu = int(input())
num = list(map(int,input().split(' ')))
val = 1
for i in range(0, kaisu):
    val = val * num[i]


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
try:
    N=int(input())
    
    if N>=2 and N<=10**5:
        
        A=input().split(' ')
        counter=0
        
        for i in A:
            if int(i)>=0 and int(i)<=10**18:
                counter+=1
        if counter==len(A):
            product=1
            for i in A:
                product*=int(i)
            if product>10**18:
                print('-1')
            else:
                print(product)
            
except Exception as e:
    print(e)

Submission status: Time Limit Exceeded

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

multi = 1

for i in range(n):
    multi = multi*n_list[i]

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
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())
s = input().split()
a = 1
for i in range(N):
    a *= int(s[i])
if a > 10 ** 18:
    print("-1")
else:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
ans = 1
an = list(map(int,input().split()))
for n in range(N):
  a = an[n]
  ans = ans * a
if ans > 1e18:
  print(-1)
else:
  print(ans)

Submission status: Time Limit Exceeded

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


Con = 10**18
ans = functools.reduce(lambda a,b: a*b,A)
print(ans if ans<=Con else "-1")

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]
print(mul if mul <= 1e18 else -1)

Submission status: Time Limit Exceeded

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    n = int(stdin.readline().rstrip())
    #A, B = map(float, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    import functools
    import operator
    result = functools.reduce(operator.mul, A)
    if result > 10**18:
        print(-1)
    else:
        print(result)


main()

Submission status: Time Limit Exceeded

Solution code:
def LI():
    return list(map(int, input().split()))

_ = int(input())
a = LI()
ans = 1
mod = pow(10, 18)

def main(ans):
    for i in a:
        ans *= i
        if ans == 0:
            break
    if ans > mod:
        ans = -1
    print(ans)


if __name__ == "__main__":
    main(ans)

Submission status: Time Limit Exceeded

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

tmp = 1
for num in A:
    tmp *= num
if tmp <= 1e18:
    print(tmp)
else:
    print(-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("-1")
else:
    print(ans)

Submission status: Time Limit Exceeded

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

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

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

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

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans=1

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = A[0]
    for i in A[1:]:
        ans *= i
    if ans > 10**18:
        ans = -1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

ar = [0 for _ in range(n)]

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

res = 1

for i in range(n):
    res = res*ar[i]

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

# N = 2
# ARR = [1000000000, 1000000000]

def calculate(n,arr):
    res = 1

    for i in range(n):
        res = res * arr[i]

    if res > 1000000000000000000:
        res = -1

    return res

print(calculate(N,ARR))

Submission status: Time Limit Exceeded

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

for i in range(n):
    res = res * a[i]
    
if res > 1000000000000000000:
    res = -1

print(res)

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