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:
N=int(input())
d_pre=input().split()
d=[int(s) for s in d_pre]
d.sort()
d_2=d[::-1]
ans=1
if 0 in d_2:
    print(0)
else:
    for i in range(N):
        ans*=d_2[i]
        if ans>10**18:
            print(-1)
            break
        elif i==N-1:
            print(ans)

Submission status: Accepted

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

a.sort(reverse=True)

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

    if 0 in A:
        print(0)
        return

    for a in A:
        SUM = SUM * a
        if SUM > 1000000000000000000:
            print(-1)
            return

    print(SUM)
main()

Submission status: Accepted

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

    if An[i] == 0:
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in A:
    print("0")
    f = 1
else:

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

if f == 0:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int,input().split()))
lst = sorted(lst)
ans = 1
for i in range (n):
  ans = ans*lst[i]
  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:
  Ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if ans == 10**18+1:
	ans = -1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

flag = 0
ans = 1

if 0 in A:
    print(0)
    flag = 1

for i in range(N):
    if flag == 1:
        break
    ans = ans * A[i]
    if ans > 1000000000000000000 :
        print('-1')
        flag = 1
        break
if flag == 0:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if min(A)==0:
  print(0)
  exit()

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())
a = list(map(int,input().split()))

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

print(sum)

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

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in a:
  	ans = 0
else:
    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 = 1

if 0 in A:
    print(0)

else:

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

    print(a)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
product = 1
A.sort()

for i in range(n):
  product *= A[i]
  if(product > 10**18):
    print("-1")
    break

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin,stdout
for _ in range(1):#int(stdin.readline())):
    n=int(stdin.readline());p=1
    # n,k=map(int,stdin.readline().split())
    a=list(map(int,stdin.readline().split()))
    if 0 in a:
        print(0)
        exit(0)
    for v in a:
        p*=v
        if p>(10**18):
            p=-1
            break
    print(p)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 1
    for i in range(N):
        if ans == -1 and A[i] != 0:
            continue
        ans *= A[i]
        if ans > 10**18:
            ans = -1
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

try:
    idx = a.index(0)
    print(0)

except ValueError:

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

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if a_lst[0] == 0:
    answer = 0
else:
    answer = 1
    for i in range(n):
        a = a_lst[i]
        answer *= a

        if answer > 10 ** 18:
            answer = -1
            break

print(answer)

Submission status: Accepted

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

n = int(input())
a_lst = list(map(int, input().split()))
a_lst.sort()

if a_lst[0] == 0:
    answer = 0
else:
    answer = 1
    for i in range(n):
        a = a_lst[i]
        answer *= a

        if answer > 10 ** 18:
            answer = -1
            break

print(answer)

Submission status: Accepted

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
A.sort()
ans = 1
if A[0] == 0:
    print(0)
    exit()
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())
A = list(map(int, input().split()))

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

print(n)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 1
i = 0
while i < n:
  c *= l[i]
  i += 1
  if c > 1000000000000000000:
    break
if c <= 1000000000000000000:
  print(c)
else:
  print(-1)

Submission status: Accepted

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

prod_max = 10**18
prod = A[0]

if 0 in A:
    print(0)
else:
    for i in range(N-1):
        prod *= A[i+1]
        if prod > prod_max:
            print('-1')
            break
        if i == N - 2:
            print(prod)

Submission status: Accepted

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

Submission status: Accepted

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
    break
    
if 0 in A:
  print(0)
else:
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    if 0 in l:
        print(0)
        return

    prod = 1
    for i in l:
        prod *= i
        if prod > 1000000000000000000:
            print(-1)
            return

    print(prod)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul
import math

def main():
    n = int(input())
    l = list(map(int, input().split()))

    if 0 in l:
        print(0)
        return
    l_sorted = sorted(l, reverse=True)
    log = 0
    seki = 1
    for i in l_sorted:
        log += math.log10(i)
        if log > 18:
            print(-1)
            return
        elif log == 18:
            seki *= i
            if seki != 10 ** 18:
                print(-1)
                return
        else:
            seki *= i
    print(seki)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 1
A.sort()

ans = 1
for a in A:
  ans *= a
  if ans == 0:
    break
  if ans > 10 ** 18:
    ans = -1
    break

print(ans)

Submission status: Accepted

Solution code:
# Multiplication2
import math
N = int(input())
A = sorted(list(map(int,input().split())))
ans = 1
for a in A:
    ans *= a
    if ans == 0:
        break
    elif ans > 10**18:
        ans = -1
        break
print(ans)

Submission status: Accepted

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

ans=1
thresh=10**18
A.sort()
for i in range(N):
    ans = ans * A[i]
    if ans > thresh:
        ans=-1
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split(" ")
kotae=1
listaa = [int(n) for n in a]
lista = sorted(listaa)
if lista[0]==0:
  print(0)
  exit()
for i in range(n):
  kotae*=lista[i]
  if kotae>10**18:
    kotae=-1
    break
if kotae>10**18:
  kotae=-1
print(kotae)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(s) for s in input().split()]
b = int(1)
flag = int(0)
flag2 = int(0)

#0がないか確認する
for i in range(N):
  if a[i] == 0:
    flag = 1
    break
  else:
    pass

for i in range(N):
  b = b * a[i]
  if b > 1000000000000000000:
    flag2 = 1
    break
  else:
    pass

if flag == 1:
  print("0")
elif flag2 == 1:
  print("-1")
else:
  print(int(b))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

tmp = 1
for i in range(N):
	tmp = tmp * A[i]
	if tmp > 1000000000000000000:
		print(-1)
		sys.exit()

print(tmp)

Submission status: Accepted

Solution code:
import sys

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


for i in range(N):
    if p[i] == 0:
        print(0)
        sys.exit()

product = 1
for i in range(N):
    product = product * p[i]
    if product > 10 ** 18:
        print(-1)
        sys.exit()
        break

print(product)

Submission status: Accepted

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

Submission status: Accepted

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

def main(a):
  if 0 in a:
    ans = 0
  else:
    ans = 1
    for item in a:
      ans *= item
      if ans > 1000000000000000000:
        ans = -1
        break
  return ans

ans = main(a)
print(ans)

Submission status: Accepted

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

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 a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)
  
main()

Submission status: Accepted

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

def multi(lst):
  count = 1
  if 0 in lst:
    return 0
  for i in lst:
    if count*i > 10**18:
      return -1
    else:
      count *= i
  return count

print(multi(lst))

Submission status: Accepted

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

fin = 1
if 0 in A:
    fin = 0
else:
    for i in A:
        fin *= i
        if fin > 10**18:
            print(-1)
            sys.exit()
            
print(fin)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
  n = int(input())
  a = input().split()
  a = [int(x) for x in a]
  ans = 1

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

Submission status: Accepted

Solution code:
n = int(input())
sum = 1
flag = 1
limit = 1000000000000000000
nums = list(map(int, input().split()))
for num in nums:
  if num == 0:
    sum = 0
    break;
  if flag == 1:
    sum *= num
  if sum > limit or sum == -1:
    flag = 2
    sum = -1
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
numbers = sorted(map(int, input().split()), reverse=True)
ans = 1
for i in numbers:
    ans *= i
    if ans > 10**18:
        ans = -1
        break
if 0 in numbers:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A1 = 1
if 0 in A:
    print(0)
else:    
    for j in range(N):
        A1 *= A[j]
        if A1>10**18:
            print(-1)
            break
    else:
        print(A1)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    length = 1
    limit = 10 ** 18
    if 0 in A:
        print(0)
        return
    for i in range(N):
        length = length *  A[i]
        if length > limit:
            print('-1')
            return
    print(length)
    return
if __name__ == '__main__':
    main()

Submission status: Accepted

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

def f(a):
    ans = 1
    if 0 in a:
        return 0
    for i in a:
        ans *= i
        if ans > 1e+18:
            return -1
    return ans

print(f(a))

Submission status: Accepted

Solution code:
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y

n = ini()
a = inl()
ans = 1
lim = 10 ** 18
for i in a:
        ans *= i
        if ans > lim:
                ans = -1
                break
if min(a) == 0:
        ans = 0
print(ans)

Submission status: Accepted

Solution code:

N=int(input())
A_list=sorted(list(map(int, input().split())), reverse=True)
ans=1

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

Submission status: Accepted

Solution code:
N=int(input())
A_list=sorted(list(map(int, input().split())), reverse=True)
ans=1

for a in A_list:
  ans*=a
  if ans>1e+18:
    ans=-1
    break
if 0 in A_list:
  ans=0
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
def main():
    N = int(input())
    A_array = tuple(map(int, input().split()))
    
    if 0 in A_array:
        print("0")
        return 0
        
    ans = 1
    for A in A_array:
        ans *= A
        if ans > 10 ** 18:
            print("-1")
            return 0
            
    print(ans)

main()

Submission status: Accepted

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

if 0 in A:
    print(0)
else:
    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())
MM = input().split()
total = 1
for i in MM:
  total = total*int(i)

  if total > 10**18:
    break
for i in MM:
  if int(i) == 0:
    total = 0
if total > 10**18:
  print(-1)
else:
  print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
res = 1
if 0 in a:
    print(0)
    exit()
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()))
res_max = 10 ** 18
res = 1
for i in A:
  if i == 0:
    print("0")
    exit()
for i in A:
  res *= i
  if res > res_max:
    print("-1")
    exit()
print(res)

Submission status: Accepted

Solution code:
def Qb():
    n = int(input())
    lina = list(map(int, input().split()))

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

    ans = 1
    for a in lina:
        ans *= a
        if 10 ** 18 < ans:
            ans = -1
            break
    print(ans)

if __name__ == '__main__':
    Qb()

Submission status: Accepted

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

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

    print(n)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    t = list(map(int, input().strip().split()))

    r = 1
    if 0 in t:
        print(0)
        return

    for tt in t:
        r *= tt
        if r > 10**18:
            print(-1)
            return

    print(r)

main()

Submission status: Accepted

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
n = I()
li = LI()
ans = 1
if 0 in li:
  print(0)
else:
  for k in li:
    ans *= k
    if ans > 10**18:
      print(-1)
      break
  else:
    print(ans)

Submission status: Accepted

Solution code:

def main():
    MAX = 1_000_000_000_000_000_000
    n = int(input())
    nums = [int(_x) for _x in input().split()]
    if 0 in nums:
        print(0)
        return

    result = 1
    for num in nums:
        result = result * num
        if result > MAX:
            print(-1)
            return
    print(result)


main()

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
    if 0 in A:
        return 0
    m = 1
    for a in A:
        m *= a
        if m > 10**18:
            return -1
    return m

print(solve())

Submission status: Accepted

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

if 0 in An:
  print(0)

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

  else:
    print(mult)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
def main():
    n, *a = map(int, read().split())

    if 0 in a:
        print(0)
        sys.exit()
    a = deque(a)
    s = 10 ** 18
    r = 1
    while a:
        r = r * a.popleft()
        if r > s:
            print(-1)
            sys.exit()
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
INF = 10**18

A = 1
if 0 in a:
    print(0)
    exit()
else:
    for i in a:
        A *= i
        if A > INF:
            print(-1)
            exit()

print(A)

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys  # sys.exit()を使いたいので

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

if 0 in a:
# 0が1つでもあれば0です
    print(0)
else:
# 0がない場合
    cur = 1  # 現在の数値
    for x in a:
        cur *= x
        if cur > 10 ** 18:
        # 10**18を超えたので終了します
            print(-1)
            sys.exit()
    print(cur)  # 10**18以下なので、出力します

Submission status: Accepted

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

ans = 1

if 0 in a:
    print(0)

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

Submission status: Accepted

Solution code:
input()

result = 1
a = [int(x) for x in input().split()]
if 0 in a:
  print(0)
  exit()

for x in a:
  if result > 10 ** 18:
    print(-1)
    exit()
  result *= x
  
if result > 10 ** 18:
  print(-1)
else:
  print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = input()
l = list(map(int,input().split()))
li = sorted(l)
n = 1

for i in li:
    n *= i
    if n > 1000000000000000000:
        break

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

Submission status: Accepted

Solution code:
N = int(input())

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

m = 1

A.sort()
if A[0] == 0:
    print(0)
    exit(0)


for a in A:
    m = m * a

    if m > 1000000000000000000:
        print(-1)
        exit(0)



print(m)

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = list(map(int, input().split()))
A.sort()
res = 1
for a in A:
  res *= a
  if res > 1e18:
    print(-1)
    sys.exit()
print(res)

Submission status: Accepted

Solution code:
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def swap(a,b):
	tmp=a
	a=b
	b=tmp
	return a,b

n=int(input())
A=input_array()
MAX=10**18
A=sorted(A)
ans=A[0]
for i in range(1,len(A)):
	ans*=A[i]
	if ans==0:
		break
	elif ans>MAX:
		ans=-1
		break
	else:
		pass

print(ans)

Submission status: Accepted

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

print(ans)