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:
def main():
	N = int(input())
	A = list(map(int,input().split()))

	while len(A)>1:
		if len(A)%2 == 1:
			A += [1]
		A = [A[2*i]*A[2*i+1] for i in range(len(A)//2)]

	if A[0] > 1000000000000000000:
		print(-1)
	else:
		print(A[0])

main()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
result=1
if 0 in a:
	print(0)
	exit()
for i in range(n):
	result *= a[i]
	if result > 1000000000000000000 and a[i] != 0:
		print(-1)
		exit()
print(result)

Submission status: Accepted

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

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

answer=1
e18=10**18
for a in alist:
  answer*=a
  if answer>e18:
    print(-1)
    break
else:
  print(answer)

Submission status: Accepted

Solution code:
import sys

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

result = 1

if "0" in AList:
    print(0)
    sys.exit()
    
for element in AList:
    result = result * int(element)

    if result > 1e+18:
        print(-1)
        sys.exit()

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

#入力
# s = input()[0:-1]
# n = int(input())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]
n = int(input())
a = list(map(int, input().split()))
# ab=[]
# for i in range():
#     a,b = map(int, input().split())
#     ab.append([a,b])


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

Submission status: Accepted

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

Submission status: Accepted

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

c = 0
d = 0

for i in b:
    if i == 0:
        c += 1
    elif i > 10**18:
        d += 1
        
if c > 0:
    print(0)
    exit()
if d > 1 and c == 0:
    print(-1)
    exit()

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

Submission status: Accepted

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

if alist[0]==0:
  print(0)
  sys.exit(0)

answer=1
e18=10**18
for a in alist:
  answer*=a
  if answer>e18:
    print(-1)
    break
else:
  print(answer)

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 a:
    ans *= i
    if ans > 1e18:
        break

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

Submission status: Accepted

Solution code:
N = int(input())
num = 1
flag = 0
c=list(map(int, input().split()))
for i in c:
    if i == 0:
        flag = 1
        print("0")
if flag == 0:
    for i in c:
        num *= i
        if num > 1000000000000000000:
            print("-1")
            flag =1
            break
if flag == 0:

    print(num)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    limit = 10**18
    ans = 1
    for a in A:
        if limit % a != 0:
            if limit / a <= ans:
                ans = -1
                break
        else:
            if limit / a < ans:
                ans = -1
                break
        ans *= a
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline

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

    if A.count(0):
        print(0)
        return

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

Main()

Submission status: Accepted

Solution code:
N = int(input())
num = 1
flag = 0
c=[int(i) for i in input().split()]
for i in c:
    if i == 0:
        flag = 1
        print("0")
if flag == 0:
    for i in c:
        num *= i
        if num > 1000000000000000000:
            print("-1")
            flag =1
            break
if flag == 0:
    
    print(num)

Submission status: Accepted

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

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

ans = 1;
for i in range(n):
  if (a[i] == 0):
    print('0')
    sys.exit()
 
for i in range(n):
    
  ans *= a[i]
  if (ans > 1000000000000000000):
    print('-1')
    sys.exit()
  

print(ans)

Submission status: Accepted

Solution code:
# a= int(input())
# list1 =[]

n = int(input())
a = list(map(int,input().split()))
# print(a)
# a.sort(reverse=True)
# print(a)
if 0 in a :
    ans  = 0
    print(ans)
else :
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10**18 :
            print(-1)
            break
if ans <= 10**18 and ans != 0 :
    print(ans)

Submission status: Accepted

Solution code:
def main():
    LIMIT = 10 ** 18

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

    mul = 1
    for x in A:
        mul *= x
        if mul > LIMIT:
            if any(x == 0 for x in A):
                print(0)
            else:
                print(-1)
            return
    print(mul)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import functools
import operator
def II(): return int(input())
def LII(): return double(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N = II()
    #A = [0]*N
    ans = 1
    A= LI()
    
    if A.count(0)>0:
        print(0)
    else:
        for i in range(N):
            ans = ans*int(A[i])
            if ans-1000000000000000000>0:
                print(-1)
                break


        if ans-1000000000000000000<=0:
            print(ans)
    


    


if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
num = list(map(int,input().split()))
num.sort()
if(num[0] == 0):
    print(0)
else:
    ans = 1
    f = 0
    for i in range(len(num)):
        ans *= num[i]
        if(ans >1000000000000000000):
            print(-1)
            f = 1
            break
    if(f == 0):
        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:
import numpy as np
from sys import stdin


def get_result(data):
    A = sorted(data[1])
    ans = 1
    for val in A:
        ans = ans * val
        if ans > 10**18:
            ans = -1
            break
        elif ans == 0:
            ans = 0
            break
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Submission status: Accepted

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

flag = 0
if data.count(0) > 0:
	print(0)
else:
  a = data[0]
  for i in range(1,n):
    a = a*data[i]
    if a > 10**18:
      flag = 1
      break
      
  if flag == 1:
    print('-1')
  else:
    print(a)

Submission status: Accepted

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

print(m)

Submission status: Accepted

Solution code:
n = int(input())

ans = 1
flag = True
a = list(map(int, input().split()))

a.sort()

if a[0] == 0:
    print(0)
    exit(0)

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
M=1
A.sort()
if A[0]==0:
	M=0
else:
	for j in A:
		M=M*j
		if M>10**18:
			M=-1
			break
print(M)

Submission status: Accepted

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

for b in a:
    if b:
        ans *= b
        if ans > pow(10, 18):
            ans = -1
            break
    else:
        ans = 0
        break

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input()) 
A = list(map(int, input().split()))
b = 1
i = 10**18
A = sorted(A)
for a in A:
  if b > i:
    break
  b *= a
print(-1 if b > i else b)

Submission status: Accepted

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

Submission status: Accepted

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

vt = 1

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

print(vt)

Submission status: Accepted

Solution code:
import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
LIMIT = 10 ** 18
n=int(input())
#a=(int,read.split())
a=[int(i) for i in input().split()]
if 0 in a:
	print(0)
	exit()

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
sum=1
flag=False
INF=1e18
for x in a:
    if(flag==False):
        sum*=x
    if(sum>INF):
        flag=True
if(0 in a):
    print(0)
elif(flag):
    print(-1)
else:
    print(sum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from decimal import *
import numpy as np
input = stdin.readline
N = int(input())
A = list(map(Decimal,input().split()))
np_A = np.array(A)
ans = np_A[0]

zero_flag = False
if 0 in A:
    zero_flag = True

flag = True

for i in range(1, N, 1):
    ans = Decimal(ans)*Decimal(np_A[i])
    #print(ans)
    if ans > 10**18:
        flag = False
        break


if zero_flag == True:
    print(0)


else:
    if flag == False:
        print(-1)

    else:
        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, *A = map(int, open(0).read().split())
b = 1
A = sorted(A)
for a in A:
  if b > 10**18:
    break
  b *= a
print(-1 if b > 10**18 else b)

Submission status: Accepted

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

count = int(input())
num = []
num = input().split()

hantei = 0
for i in range(count):
    if int(num[i]) == 0:
        hantei = 1
        total = 0
    else:
        continue
      #print("z")
      
if hantei == 0:
    total = 1
    for i in range(count):
        total = int(num[i])*total
        if total > 10**18:
            total = -1
            break
    
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
v = list(map(int, input().split()))
limit = 10 ** 18

answer = 1
if 0 in v:
  answer = 0
else:
  for i in v:
    answer = answer * i
    if answer <= limit:
      continue
    else:
      answer = -1
      break
print(answer)

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > int(1e18):
            print(-1)
            return
    print(prod)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
LIMIT = 10 ** 18
n=int(input())
#a=(int,read.split())
a=[int(i) for i in 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())
a=list(map(int,input().split()))
x=1
if 0 in a:
    print(0)
    exit()
 
for i in range(len(a)):
    x=a[i]*x
    if x>10**18:
        print(-1)
        exit()
print(x if x<=10**18 else -1)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
if 0 in a:
    print(0)
else:
    s=1
    for c in range(n):
        s=s*a[c]
        if s>10**18:
            s=-1
            break
    print(s)

Submission status: Accepted

Solution code:
n = int(input())
# for i in range(n):
#     m = int(input())
#     k = k*m
op = 1
p = list(map(int,input().split()))
p.sort()
for i in p:
    op = op*i

    if op > 10**18:
        print(-1)
        exit(0)

print(op)

Submission status: Accepted

Solution code:
while True:
	try:
		N=input()
	except:
		break
	a=list(map(int, input().split(" ")))
	#print(a)
	ans=1
	for v in a:
		ans*=v
		if 1000000000000000000 < ans:
			ans = -1
			break
	if any([v==0 for v in a]):
		ans=0
	print(ans)

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())
a=deque()
a=list(map(int,input().split()))
s=0
if a.count(0) == 0:
  s=1
  for i in range(n):
    l=a.pop()
    s=s*l      
  
    if len(str(s)) >= 19:
      if s == 10**18 and i==n-1:
        break
      s=-1
      break

    
print(s)

Submission status: Accepted

Solution code:
import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
LIMIT = 10 ** 18
n=int(input())
#a=(int,read.split())
a=[int(i) for i in input().split()]
if 0 in a:
	print(0)
	exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
res = 1
for i in range(N):
    if A[i] == 0:
        res = 0
    if res < 0:
        continue
    res *= A[i];
    if res > 1e+18:
        res = -1

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
	try:
		N=input()
	except:
		break
	a=list(map(int, input().split()))
	#print(a)
	ans=1
	for v in a:
		ans*=v
		if 1000000000000000000 < ans:
			ans = -1
			break
	if any([v==0 for v in a]):
		ans=0
	print(ans)

Submission status: Accepted

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

if A_list[0]==0:
    answer = 0
else:      
    answer = 1
    for a in A_list:
        answer *= a
        if len(str(answer-1)) > 18:
            answer = -1
            break
print(answer)

Submission status: Accepted

Solution code:
n = int(input())

a = [*map(int, input().split())]
for e in a:
    if e == 0:
        print(0)
        exit(0)

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

print(ans)

Submission status: Accepted

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

INF = 10 ** 18 + 1
ans = 1
for e in a:
    ans *= e
    ans = min(ans, INF)

if ans == INF:
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
N=input()
ls=[int(s) for s in input().split()]
ans=1
flag=1
for e in ls:
  ans*=e
  if ans>10**18:
    flag=0
    break
zeroflag=1
for e in ls:
  if e==0:
    zeroflag=0
if flag==1:
  print(ans)
else:
  print(-1*zeroflag)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = input().split()
    ans = 1
    if "0" in A:
        print(0)
    else:
        for i in A:
            ans = int(i) * ans
            if ans > 1e+18:
                print(-1)
                return
        else:
            print(ans)
        return
resolve()

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort()
#print(A_list)
if A_list[0]==0:
    answer = 0
else:      
    answer = 1
    for a in A_list:
        answer *= a
        if len(str(answer-1)) > 18:
            answer = -1
            break
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

for b in a:
    if b == 0:
        ans = 0
        break
    else:
        ans *= b
        if ans > pow(10, 18):
            ans = -1
            break

print(ans)

Submission status: Accepted

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


if 0 in a :
    print(0)
    exit() ##インタラクティブシェルを終了させる関数

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    limit = 10**18

    _mul = 1
    for a in A:
        _mul *= a
        if _mul > limit:
            _mul = limit+1

    if _mul > limit:
        print(-1)
    else:
        print(_mul)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
int(input())
a = sorted(list(map(int, input().split())))
result = 1
if a[0] == 0:
    print("0")
    exit()
for _a in a:
    result *= _a
    if result > 10**18:
        print("-1")
        exit()
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
li=list(map(int,input().split()))
li.sort()
if li[0]==0:
  print(0)
  sys.exit()
else:
  ans=1
  for i in li:
    ans*=i
    if ans>1000000000000000000:
        print(-1)
        sys.exit()
    else:
        continue
    
  if ans>1000000000000000000:
      print(-1)
  else:
      print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    exit()
ans = 1
for i in a:
    ans *= i
    if len(str(ans)) >= 19 and ans != 10**18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

ans = 1
flag = 0
a.sort()

for i in range(n):
    ans = ans * a[i] // 1
    if ans > 10**18:
        flag = 1
        break



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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    limit = 10**18

    if 0 in A:
        print(0)
        return

    _mul = 1
    for a in A:
        _mul *= a
        if _mul > limit:
            print(-1)
            return

    print(_mul)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys

def main():
    n = int(input())
    a=sys.stdin.readline().rstrip().split()
    if '0' in a:
        print(0)
        return
    ans=1
 
    for i in a:
        ans=ans*int(i)
        if ans>1000000000000000000:
            print("-1")
            return
    else:
        print(ans)
main()

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
if a[0]==0:print(0);exit()
ans=1
for q in a:
  ans*=q
  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()
ans = 1
for x in a:
  ans *= x
  if ans > (10 ** 18):
    ans = -1
    break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
ans = 0 + (0 not in a)
for x in a:
    ans *= x
    if ans > 10 ** 18:
        print(-1)
        exit()
if ans > 10 ** 18:
    print(-1)
    exit()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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:
n = int(input())
a = [int(_) for _ in input().split()]
a.sort()
ans = 1
for i in a:
    if i == 0:
        ans = 0
        break
    ans *= i
    if ans > 10**18:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
ans = 1
if 0 in lis:
  print(0)
  exit()
for num in lis:
  ans *= num
  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 )
else:
  ret = 1
  for a in A:
    ret = ret * a
    if ret > 10 ** 18:
      ret = -1
      break
  print( ret )

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A = LI()

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

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

print(s)

Submission status: Accepted

Solution code:
def main():    
    N = int(input())
    a = list(map(int,input().split()))
    res = 1
    if 0 in a:
        print(0)
        return
    for i in a:
        res *= i
        if res > 10**18:
            print(-1)
            return
    print(res)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = li[0]
for i,l in enumerate(li):
    if i == 0:
        continue
    else:
        #print(l,'l')
        ans *= l
        if ans > 10**18:
            print(-1)
            exit()
        #print(ans)
if ans > 10**18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

x=10**18 
flag=0;
for i in a:
	if i==0:
		flag=1
		break

for i in a:
	ans=ans*i
	if ans>x:
		break
if flag==1:
	ans=0
if ans>x :
	print(-1) 
else:
	print(ans)

Submission status: Accepted

Solution code:
N = input()
listed = input().split()
mul = 1
for num in listed:
  num = int(num)
  if num == 0:
    mul = 0
    break
  if mul != -1:
    mul *= num
    if mul > 10**18:
      mul = -1
print(mul)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
ans = 1
ng = 0
if 0 in A:
  print("0")
else:
  for i in range(N):
    ans *= A[i]
#    print(i,ans)
    if ans > 1000000000000000000:
      print("-1")
      ng = 1
      break
  if ng==0:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

n = int(input())
An = [int(x) for x in input().split()]

for i in range(n):
    if An[i] == 0:
        print(0)
        quit()

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

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