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: Accepted

Solution code:
import sys
input_num = input()
input_list = input()
 
total_pow = 1
for num in input_list.split(" "):
    total_pow *= int(num)
    if total_pow > 10**18:
        if "0" in input_list.split(" "):
            print("0")
        else:
            print("-1")
        sys.exit()

print(total_pow)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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 LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
ans = 1
if 0 in A:
    print(0)
else:
    for i in A:
        ans *= i
        if ans>10**18:
            print(-1)
            break
    else:
        print(ans)

Submission status: Accepted

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

ans = 1
if 0 in a:
    print(0)
    exit()

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

print(ans)

Submission status: Accepted

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

result = 1
if 0 in A:
    result = 0
else:
    for i in A:
        result *= i
        if result > 10**18:
            result = -1
            break

print(result)

Submission status: Accepted

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

result = 1
A.sort()
for i in A:
    result *= i
    if result > 10**18:
        result = -1
        break

print(result)

Submission status: Accepted

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

resolve()

Submission status: Accepted

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

M = 1
if '0' in A:
    M = 0
else:
    for a in A:
        a = int(a)
        M *= a
        if M > 1000000000000000000:
            M = -1
            break

print(M)

Submission status: Accepted

Solution code:
n = int(input())
an = list(map(int, input().split()))
if 0 in an:
  out = 0

else:
  out = 1
  for a in an:
    out = out * a
    if out > 10 ** 18:
      out = -1
      break
print(out)

Submission status: Accepted

Solution code:
x = int(input())
pro = 1
n = input().split(' ')
li = 10 ** 18
flag = 1
for i in range(x):
    pro = pro * int(n[i])
    if pro > li:
        flag = 0
        break;
if '0' in n:
    flag = 1
    pro = 0
if flag:
    print(pro)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mul=1
key=0
for i in range(len(a)):
    if a[i]==0:
        key=1
        print(0)
        break;
if key==0:
    for i in range(len(a)):
        mul=mul*a[i]
        if mul>1000000000000000000:
            break
    if(mul<1000000000000000001):
        print(mul)
    else:
        print(-1)

Submission status: Accepted

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

limit = 10**18
a.sort()
ans = a[0]

if ans == 0:
    print(0)
else:
    for i in a[1:]:
        ans *= i
        if ans > limit:
            print(-1)
            exit()
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
 
def input():
    return sys.stdin.readline().strip()
 
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]
 
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]
 
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())
 
def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break
 
def log(*args):
    print("DEBUG:", *args, file=sys.stderr)
 
INF = 999999999999999999999999
MOD = 10**9+7
 
n,*A = get_all_int()
 
if min(A) == 0:
    print(0)
    exit()
 
ans = 1
for a in A:
    ans *= a
 
    if ans > 10**18:
        print(-1)
        exit()
 
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline().rstrip('\n')


def calc(N, A):
    result = 1
    A.sort()
    if A[0] == 0:
        return 0
    for i in range(N):
        result *= A[i]
        if result > 10 ** 18:
            return -1
    return result
    

N = int(input())
A = [int(s) for s in input().split()]
print(calc(N, A))

Submission status: Accepted

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

ans = 1
can = 1
zero = 0

if 0 in a:
    zero = 1
    ans = 0

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
lim = int(1e+18)
if a.count(0):
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if lim < ans:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
AS = list(map(int,input().split()))
if 0 in AS:
  print(0)
  exit()
s = 0
sum = 1
l=len(AS)
for i in range(l):
  A=AS[i]
  sum = sum * A
  if sum > 10**18:
    s=2
    break
if sum > 10**18:
  print(-1)
else:
  print(sum)

Submission status: Accepted

Solution code:

n = int(input())
v = list(map(int, input().split(' ')))

ans = 1

if 0 in v:
	print(0)
	exit(0)

for item in v:
	ans = ans * item
	if ans > 1000000000000000000:
		print(-1)
		exit(0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1

a.sort(reverse=True)

if 0 not in a:
    for x in range(n):
        ans *= a[x]

        if ans > 10**18:
            ans = -1
            break
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr) 
ans=1
for val in arr:
 ans*=val 
 if ans>10**18:
   print(-1)
   break
else:
 print(ans)

Submission status: Accepted

Solution code:
from functools import reduce

n = int(input())

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

sim = False
if 0 in numeros:
    print(0)

else:

    multiplicacao = 1

    for i in numeros:
        multiplicacao *= i
        if multiplicacao > 1e18:
            print(-1)
            sim = True
            break
    if sim == False:
        print(multiplicacao)

Submission status: Accepted

Solution code:
import sys
N = int(input())
s = list(map(int, input().split()))
if 0 in s:
    print(0)
    sys.exit()
result = 1
for value in s:
    result *= value
    if result > pow (10,18):
        print(-1)
        sys.exit()
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
#import random
#sys.setrecursionlimit(100000000)
input = sys.stdin.readline
 
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input()))
def inara():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############

n=inp()
ara=inara()
for num in ara:
	if num==0:
		print(0)
		exit(0)

ans=1
for num in ara:
	ans*=num
	if ans>1000000000000000000:
		print(-1)
		exit(0)

print(ans)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
MX=10**18
prod=1
for q in sorted(a):
  prod*=q
  if prod>MX:
    print(-1)
    exit()
print(prod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in a:
    print(0)
    exit()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

product = 1

if 0 in list_num:
    print(0)
else:
    checker = True
    for i, num in enumerate(list_num):
        product *= num
        if product > 10**18:
            checker = False
            break
        
    if checker:
        print(product)
    else:
        print(-1)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
for aa in a:
  if aa==0:
    print(0)
    exit(0)

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

Submission status: Accepted

Solution code:
n = int(input())
num = list(map(int, input().split()))
limit = 10**18
 
num.sort()
result = num[0]

if result == 0:
    print(0)
else:
    for i in num[1:]:
        result *= i
        if result > limit:
            print(-1)
            exit()

    print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = [int(s) for s in input().split()]
if 0 in S:
  l = 0
else:
  l = 1
  for s in S:
    l = l * s
    if l > 10**18:
      l = -1
      break
print(l)

Submission status: Accepted

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

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

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return
    A1 = A[::2]
    A2 = A[1::2]

    if N%2 ==1:
        ans *= A1[-1]
    for i,j in zip(A1,A2):
        ans *= i*j
        if ans >10**18:
            return print(-1)

    return print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

if 0 in A:
  print(0)
else:
  print(ans)

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split()))
if 0 in ar:
    print(0)
    exit()
b = 1
for r in ar:
    b *= r
    if b > 10 ** 18:
        print(-1)
        exit()
print(b)

Submission status: Accepted

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

if 0 in A:
  print(0)
  exit()

ans = A[0]

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

print(ans)

Submission status: Accepted

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

A = sorted(A)

if A[0] == 0:
    print("0")
else:
    ans = 1
    for item in A:
        ans = ans*item
        if ans > 10**18:
            print("-1")
            exit()

    print(ans)

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
if 0 in ar:
    print(0)
    exit()
b = 1
for r in ar:
    b *= r
    if b > 10 ** 18:
        print(-1)
        exit()
print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    aa=map(int,input().split())
    x=1
    for a in aa:
        if a == 0:
            print(0)
            return
        if x<1000000000000000000:
            x*=a
    if x>1000000000000000000:
        print(-1)
    else:
        print(x)
main()

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
if 0 in ar:
    print(0)
    exit()
b = 1
for r in ar:
    b *= r
    if b > 10 ** 18:
        print(-1)
        exit()
print(b)

Submission status: Accepted

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

A.sort(reverse=True)

for i in range(N - 1, -1, -1):
    if A[i] == 0:
        print(0)
        exit()

r = 1
upper = pow(10, 18)
for i in range(N):
    r *= A[i]

    if r > upper:
        print(-1)
        exit()

print(r)

Submission status: Accepted

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

if 0 in A:
  print(0)
  exit()

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

Submission status: Accepted

Solution code:
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)
            break
    else:
        print(ans)

Submission status: Accepted

Solution code:
import math
import sys
N = input()
i = list(map(int, input().split()))
result = 1
if 0 in i:
  print(0)
  sys.exit()
for x in i:
  result *= x
#  if(len(str(result)) >= 19):
  if(result > 10**18):
    print(-1)
    sys.exit()
print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import sys
N = input()
i = list(map(int, input().split()))
result = 1
if 0 in i:
  print(0)
else:
  for x in i:
    result *= x
    if(result >= 10**18):
      break
  if(result > 10**18):
    print(-1)
  else:
    print(result)

Submission status: Accepted

Solution code:
from sys import stdin
from functools import reduce 

# 標準入力から読み込み
inputs = [list(map(int, input().split())) for _ in range(2)]
inputs = inputs[1]

if (0 in inputs):
  output = 0
else:
  output = reduce((lambda x, y: -1 if (x * y) > 1e18 or x < 0 or y < 0  else (x * y)), inputs)

print(output)

Submission status: Accepted

Solution code:
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
#from fractions import *
from bisect import *
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
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")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
#vsInput()

n=Int()
a=array()
ans=1
if(0 in a):
    print(0)
    exit()
for i in a:
    ans*=i
    #print(ans)
    if(ans>10**18):
        ans=-1
        break
print(ans)

Submission status: Accepted

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

ans = 1

if 0 in A:
  print(0)
  exit()

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
 
now = 1
ok = False
 
a.sort()
 
for i in range(len(a)):
	now *= a[i]
	if now > 1000000000000000000 :
			print(-1)
			ok = True
			break
 
if ok == False:
	print(now)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

N = int(input())
x = sorted(list(map(int, input().split())))
t = 1

for num in x:
    t = t * num
    if t > 10 ** 18:
        print(-1)
        sys.exit()

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
x = sorted(list(map(int, input().split())))
t = 1
for num in x:
    t = t * num
    if t > 10 ** 18:
        print(-1)
        sys.exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
thres = 10**18

if 0 in A:
  print(0)
  sys.exit()

for i in A:
  ans = i * ans
  if ans > thres:
    print(-1)
    sys.exit()

print(ans)

Submission status: Accepted

Solution code:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########

def resolve():
    n = ii()
    a = mi()
    if 0 in a:
        print(0)
        return
    res = 1
    for i in a:
        res = res * i
        if(res > 10**18):
            print(-1)
            return
    print(res)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys

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

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

cur = 1
for a in a_list:
  cur *= a
  if cur > 10 ** 18:
    print(-1)
    sys.exit()

print(cur)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
res = 1
if 0 in A:
    res = 0
for a in A:
    if res > 10 ** 18 // max(1, a):
        res = -1
        break
    res *= a
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in li_a:
    print(0)
    exit(0)
w = li_a[0]
for a in li_a[1:]:
    w = w * a
    if w > 10 ** 18:
        print(-1)
        exit(0)
else:
    print(w)
    exit(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    N = int( input())
    t = 10**18
    A = list( map( int, input().split()))
    ans = 1
    if Counter(A)[0] > 0:
        print(0)
        return
    for a in A:
        ans *= a
        if ans > t:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
array=[]
array+=map(int,input().split())
flag=0
flag2=0
s=1
for m in range(len(array)):
    if array[m]==0:
        flag=1
        break
    s=s*array[m]
    if s>10**18:
        flag2=1
        break
flag3=0
if flag==1:
    print("0")
elif flag2==1:
    for i in range(m,len(array)):
        if array[i]==0:
            flag3=1
            print("0")
    if flag3==0:
        print("-1")

else:print(s)

Submission status: Accepted

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

if 0 in li:
  print(0)
else:
  result = 1
  flag = True
  for i in range(n):
    result *= li[i]
    if result > 10 ** 18:
      flag = False
      print(-1)
      break
  if flag == True:
    print(result)

Submission status: Accepted

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

if 0 in a:
    print(0)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
if 0 in A:
  print(0)
  exit()
  
for r in A:
  ans *= r
  if ans > 1e18:
      print(-1)
      exit()
      
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

seki = 1

if (A_s.count(0) > 0):
    print(0)
    exit()

for i in range(N):
    seki *= A_s[i]
    
    if (seki > 10 ** 18):
        print(-1)
        exit()

print(seki)

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
b.sort()
an=1
c=0

for m in b:
  an*=m
  if(an>10**18):
    print("-1")
    c=1
    break
if(c!=1):
  print(an)

Submission status: Accepted

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

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    for a in A:
        if a == 0:
            return 0
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            return -1
    return ans

def main():
    print(solve())

main()

Submission status: Accepted

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 1
    for i in a:
        ans *= i
        if (ans > 1e18):
            print(-1)
            exit()
    print(ans)
main()

Submission status: Accepted

Solution code:
import math

def a():
    a,b = map(int,input().split())
    print(a * b)


def b():
    n = int(input())
    a = list(map(int, input().split()))
    max = pow(10,18)

    if 0 in a:
        print(0)
    else:
        mul = 1
        for i in a:
            mul *= i
            if mul > max:
                print(-1)
                break
        else:
            print(mul)



def c():
    print('')



def d():
    print('')


b()

Submission status: Accepted

Solution code:
from sys import exit, stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 1
if 0 in A:
    print(0)
    exit()
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

aa = set(A)
ans = 1
for i in range(len(A)):
    if(ans > 10**18):
        if(0 not in aa):
            ans = -1
            break
        else:
            ans = 0
    ans *= A[i]

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

Submission status: Accepted

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