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
N = int(input())

A = list(map(int, input().split()))
result = A[0]


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

for i in range(1,N):
  result = result * A[i]
  #print(result)

  if result >= 10**18+1:
    print(-1)
    sys.exit()

print(result)

Submission status: Accepted

Solution code:
n = input()
s = list(map(int, input().split()))
a = 1
flag0 = False
flag = True
for i in s:
  a*=i
  if a > 1000000000000000000:
    flag = False
    break
for i in s:
  if i == 0:
    flag0 = True
if flag0:
  print(0)
elif flag:
  print(a)
else:
  print(-1)

Submission status: Accepted

Solution code:
n=int(input())
s = input().split(' ')
ans=1
for i in s:
    if int(i) == 0:
        print(0)
        exit()
for i in s:
    ans=ans*int(i)
    if(ans>1000000000000000000):
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n = ni()
m = nl()
res = 1
if 0 in m:
    print(0)
else:
    for i in m:
        res *= i
        if res > 10**18 :
            print(-1)
            break
    else:
        print(res)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1

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

print(ans)

Submission status: Accepted

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

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

print(X)

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 a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit(0)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=1
if 0 in arr:
    print(0)
else:
    for i in range(N):
        ans*=arr[i]
        if ans>(10**18):
            print('-1')
            exit()
    else:
            print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce 
from operator import mul
N = int(input())
A = sorted(list(map(int,input().split())),reverse = True)

lim = 10 ** 18
ans = 1

if A[-1] == 0:
  print(0)
else:
  for i in A:
    ans *= i
    if ans > lim:
      ans = -1
      break
  print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

a = int(stdin.readline())
A=stdin.readline().split()

product=1
K=0

for k in range(0,a):
    if int(A[k])==0:
        product=0
        K=1
        break
        
if K==0:
   for b in range(0,a) :
       product=product*int(A[b])
       if product > 10 ** 18:
          product = -1
          break



print(product)

Submission status: Accepted

Solution code:
import sys

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

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

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

print(ans)

Submission status: Accepted

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

#if (10 ** 18 + 1) in A
#    print(-1)
#    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()))
ans = 1
if 0 in A:
    print(0)
    exit()
else:
    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())
arr=list(map(int,input().split()))
ans=int(1)
temp=int(0)
for i in range(n):
  if(ans>(10**18)):
    ans=-1
  if(ans!=-1):
  	ans*=arr[i]
  if(arr[i]==0):
    temp=int(1)
if(ans>(10**18)):
  ans=-1
if(temp==1):
  ans=0
print(int(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(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()))
k=1
x=0
if 0 in A:
  print(0)
  x=1
else:
  for i in range(N):
    if k*A[i]>10**18:
      print(-1)
      x=1
      break
    else:
      k=k*A[i]
if x!=1:
  print(k)

Submission status: Accepted

Solution code:
import math

def main():
    # tt = int(input())
    
    tt = 1
    for _ in range(0, tt):
        n = int(input())
        
        arr = input().split(' ')
        arr = sorted(arr)
        mult = 1
        for i in range(0, n):
            mult *= int(arr[i])

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

        print(mult)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
import heapq
import itertools
MAX_INT = int(10e25)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()

ans = 1
cnt = a.count(0)
if cnt:
  print(0)
else:
  for i in range(N):
    ans *= a[i]
    if ans > int(1e18):
      print(-1)
      break
  else:
    print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())
nun_list = list(map(int, input().split()))
result = 0
if nun_list.__contains__(0):
    print(0)
    sys.exit()

for i in range(n):
    if i == 0:
        result = nun_list[i]
    else:
        result = result * nun_list[i]
    if result > 10**18:
        print('-1')
        sys.exit()
print(result)

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
l = [int(x) for x in input().split()]
limit = 10**18
if(0 in l):
    print(0)
    exit()

for x in l:
    x = int(x)
    ans *= x

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

print(ans)

Submission status: Accepted

Solution code:
#整数の入力
N = int(input())
#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))

if((0 in A_list) ==True):
  print("0")
  exit()
  
ans = 1
for i in range(N):
  if(ans<=10**18):
    ans = ans * A_list[i]
  else:
    print("-1")
    exit()
    
if(ans<=10**18):
    print(ans)
else:
  print("-1")

Submission status: Accepted

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

N = int(readline().strip())
A = readline().split()

ans = 1
limit = 10**18
for i in range(N):
  if A[i] == '0':
    print(0)
    exit()
for i in range(N):
  ans *= int(A[i])
  if ans > limit:
    ans = -1
    break
print(ans)

Submission status: Accepted

Solution code:
from math import log
from functools import reduce
N = int(input())
A = sorted(list(map(int, input().split())))
if A[0] == 0:
  print(0)
else:
  ans = 1
  for a in reversed(A):
    ans *= a
    if ans > 10**18:
      ans = -1
      break
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
  if A[i] == 0:
    ans += 1
if ans >= 1:
  ans = 0
  print(ans)
else:
  ans = 1
  k = 0
  while ans <=10**18 and k<N:
    ans *= A[k]
    k += 1
  if k == N and ans <= 10**18:
    print(ans)
  else:
    print('-1')

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 1
f = True
if a[0] == 0:
    print(0)
    f = False
else:
    for aa in a[::-1]:
        ans*=aa
        if ans > 10**18:
            print(-1)
            f = False
            break
if f:
    print(ans)

Submission status: Accepted

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

ans = 1
flg = True

if 0 in A: print(0)
else:
    for i in range(N):
        ans *= A[i]
        if ans > 1e18:
            flg = False
            break

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

Submission status: Accepted

Solution code:
import sys

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

s = 1
LIM = 10 ** 18
ret = -1
for a in A:
    if a == 0:
        print(0)
        sys.exit(0)
for a in A:
    s *= a
    if s > LIM:
        print(-1)
        sys.exit(0)
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

AS = map(int, input().split())

SAS = sorted(AS, reverse = True)
BAR = 10 ** 18

ans = 0
if SAS[-1] == 0:
	ans = 0
else:
	ans = SAS[0]
	for A in SAS[1:]:
		ans *= A
		if ans > BAR:
			ans = -1
			break
print(ans)

Submission status: Accepted

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

def main():
    N = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    MAX_V = 10 ** 18

    if A[-1] == 0:
        print(0)
        exit()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

# 実行環境(0:vscode, 1:atcoder)
MODE = 1

# 入力の次元
DIMENSION = 2

# int型に変換
INT_TYPE = 1

if not (MODE):
    with open("input.txt", "r") as f:
        s = f.read()
else:
    s = sys.stdin.read()

if DIMENSION == 0:
    if INT_TYPE == 1:
        s = int(s)
elif DIMENSION == 1:
    if INT_TYPE == 0:
        s = s.split()
    elif INT_TYPE == 1:
        s = [int(x) for x in s.split()]
elif DIMENSION == 2:
    if INT_TYPE == 0:
        s = [x.split() for x in s.splitlines()]
    elif INT_TYPE == 1:
        s = [[int(y) for y in x.split()] for x in s.splitlines()]

N = s[0][0]

if s[1].count(0) > 0:
    print(0)
else:
    A_sort = sorted(s[1])
    val = 1
    for i in range(N):
        val *= A_sort[N - i - 1]
        if val > 1e18:
            print(-1)
            sys.exit()
    print(val)

Submission status: Accepted

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

if 0 in a:
    print(0)
    flg = 2
if flg != 2:
    for i in range(1,n):
        ans = ans * a[i]
        if ans > 10 ** 18:
            flg = 1
            print(-1)
            break


if flg == 0:
    print(ans)

Submission status: Accepted

Solution code:

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

t = 10**18
if 0 in A:
    print(0)
else:
    sum = A[0]
    flag = True
    for i in range(1, N):
        sum = sum * A[i]
        if sum > t:
            flag = False
            break
    if flag:
        print(sum)
    else:
        print(-1)

Submission status: Accepted

Solution code:
import io,sys
sys.setrecursionlimit(10**6)

def main():
    n = int(input())
    A = list(map(int,sys.stdin.readline().rstrip().split()))
    mul = 1
    if 0 in A:
        mul = 0
    else:
        for a in A:
            mul*=a
            if mul>10**18:
                mul=-1
                break
    
    print(mul)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

shre = 10**18
mul = 1
for i in A:
    mul *= i
    if mul > shre:
        print(-1)
        exit()
print(mul)

Submission status: Accepted

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

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 a[1:]:
  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()))

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

ans = 1
for i in A:
    ans *= i
    if 10 ** 18 < ans:
        print("-1")
        exit()

print(ans)

Submission status: Accepted

Solution code:
num = int(input())
a_i = list(map(int, input().split()))
ans = 1
if a_i.count(0) > 0: print(0)
else:
    for x in a_i:
        ans *= x
        if ans > 10 ** 18: 
            ans = -1
            break
    print(ans)

Submission status: Accepted

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

MAX = 10**18
ans = 1
isZero = False
isOverFlow = False
for a in A_list:
  if a == 0:
    isZero = True
    break
  if not isOverFlow:
    ans *= a
  if ans > MAX:
    isOverFlow = True

if isZero:
  print(0)
elif isOverFlow:
  print(-1)
else:
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=1
LIMIT=10**18

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(sys.stdin.readline() for _ in range(n)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# INF = float("inf")
# sys.setrecursionlimit(10000)
import sys,collections
sys.setrecursionlimit(100000)
n = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
if 0 in a:
    print(0)
    exit()
ret = 1
i = 0
lim = 10**18
while i < len(a):
    ret *= a[i]
    if lim < ret:
        print(-1)
        exit()
    i += 1
print(ret)

Submission status: Accepted

Solution code:
import math
import sys
from decimal import *
import itertools

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

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

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

Submission status: Accepted

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

ans = 1

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

Submission status: Accepted

Solution code:

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

Flag = False

if 0 in A:
  Flag = True
else:
  for i in A:
    if ans <= 10**18:
      ans *= i
    else:
      break

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
  print(0)
  quit()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int,input().split()))
arr = sorted(arr,reverse=True)
ans = 1
idx = 0
if arr[-1]==0:
  ans = 0
for a in arr:
  ans *= a
  if ans > 10**18:
    print('-1')
    exit()
print(ans)

Submission status: Accepted

Solution code:
###############################################################################
#Imports
import collections
import itertools
from functools import lru_cache
import sys
import math
###############################################################################
#Constants
MOD = int(1e9)+7
###############################################################################
#Helper
def helper():
	pass
###############################################################################
#Solver
def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	sm = 1
	if 0 in arr:
		print(0)
		return
	for num in arr:
		sm *= num
		if sm > int(1e18):
			print(-1)
			return
	print(sm)

###############################################################################
#Driver
t = 1
for _ in range(t):
	solve()
###############################################################################

Submission status: Accepted

Solution code:
n = int(input());
data = input().split();
co = int(1);
x = 0;

for v in range(n):
    if int(data[v]) == 0:
        x = x + 1;
    
for i in range(n):
    b = int(data[i]);
    co = co * b;
    if co > 1000000000000000000:
        co = -1;
        break;

if x == 0:
    print(co);
else:
    print(0);

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
A = list(map(int,input().split()))
MAX = 10**18
zero = 0
for i in range(N):
    if A[i] == 0:
        zero = 1
        break
if zero == 1:
    print(0)
else:
    cur = 1
    flag = 0
    for i in range(N):
        a = A[i]
        cur *= a
        if cur > MAX:
            flag = 1
            break
    if flag == 1:
        print(-1)
    else:
        print(cur)

Submission status: Accepted

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

for i in range(n ) :
    if l[i] == 0  :
        res= 0
        break
if res == 0 :
    print(0)
else :

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())


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

s=1

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

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

Submission status: Accepted

Solution code:
n = int(input())
datas = input().split(' ')
datas = [int(x) for x in datas if x != '1']

if 0 in datas:
    print(0)
else:
    sums = 1
    for data in datas:
        d = int(data)
        sums *= d
        if sums > 1000000000000000000:
            sums = -1
            break
    print(sums)

Submission status: Accepted

Solution code:
int(input())
numbers = tuple(map(int, input().split(' ')))

if 0 in numbers:
    print(0)
else:
    mul = 1
    for n in numbers:
        mul *= n
        if mul > 10 ** 18:
            print(-1)
            break
    else:
        print(mul)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  n, = map(int, input().split())
  aa = list(map(int, input().split()))
  
  res_max = 10 ** 18
  
  if any(a == 0 for a in aa):
    print(0)
    exit()

  res = 1
  for a in aa:
    res *= a
    if res > res_max:
      res = -1
      break
  
  print(res)
    


if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
N=int(input())
lis = list(map(int, input().split()))
ans=1
j=True
if lis.count(0) > 0:
    print(0)
else:
    for a in lis:
        ans*=a
        if ans > pow(10,18):
            j=False
            break
    if j:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
a.sort()
if 0 in a:
    print(0)
    exit()
base = 10 ** 18
for num in a:
    ans *= num
    if ans > base:
        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
k=0
if a[-1]==0:
    print(0)
    exit()
else:
    while k<n:
        if len(str(ans))<19:
            ans*=a[k]
            k+=1
        else:
            print(-1)
            exit()
if len(str(ans))<19 or ans==10**18:
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

    if 0 in a:
        ans = 0
    else:
        mx = 10 ** 18
        ans = 1
        for ai in a:
            ans *= ai
            if mx < ans:
                ans = -1
                break
    
    print(ans)

Submission status: Accepted

Solution code:
import sys
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')
    sys.exit()
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)

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

Submission status: Accepted

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

def get_res(a_list):
  if 0 in a_list:
    return 0
  res = 1  
  for a in a_list:
    res *= a
    if res>10**18:
      return -1

  return res
print(get_res(a_list))

Submission status: Accepted

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n = int(input())
a = list(map(int, input().split()))
sort = sorted(a)
ans = sort[0]

for i in range(1,n):
    if ans <= 1000000000000000000:
        ans = ans * sort[i]

if ans <= 1000000000000000000:
 print(ans)
else:
 print("-1")

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline().rstrip("\n"))
l = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
s = 1
if 0 in l:
    print(0)
else:
    for i in l:
        s *= i
        if s > 10**18:
            print(-1)
            break
    else:
        print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
flg = True
input_a = list(input().split())

if '0' in input_a:
    print(0)
else:
    for a in input_a:
        _a = int(a)
        ans *= _a
        if ans > 10 ** 18:
            print(-1)
            flg = False
            break

    if flg:
        print(ans)

Submission status: Accepted

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

def judge(check):
  if check > 1e18:
    print(-1)
    exit()

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

for num in a:
  check = check * num
  judge(check)
  
print(check)

Submission status: Accepted

Solution code:
n = int(input())
li = [int(x) for x in input().split()]
ans = 1
if 0 in li:
    print("0")
else:
    for i in range(n):
        ans = ans * li[i]
        if ans > 1000000000000000000:
            print("-1")
            exit()
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
import math
import sys
n=int(input())
a=list(map(int,input().split()))
tmp=0
for i in range(n):
    if a[i]==0:
        print(0)
        sys.exit()
    else:
        t=math.log10(a[i])
        tmp+=t
    
if tmp>18:
    print(-1)
    sys.exit()
else:
    ans=1
    for i in range(n):
        ans*=a[i]
if ans>10**18:
    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(0)

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

print(ans)