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 resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    th = 10**18
    if 0 in A:
        print(0)
        return
    for a in A:
        ans *= a
        if ans > th:
            print(-1)
            return 
    print(ans if ans <= th else -1)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
p = 1
done = 0

if A[0] == 0:
  print(0)
else:
  for An in A:
    p = p * An
    if p > 10 ** 18:
      print(-1)
      done = 1
      break
  if done == 0:
    print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

_ = input()
N = sorted([int(v) for v in input().split()])
s = 1
for n in N:
    s *= n
    if s == 0 or s > 10**18:
        break

print(s if s <= 10**18 else -1)

Submission status: Accepted

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

for i in range(n):
  if a[i] == 0:
    sum = 0

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())
ans =1
A = list(map(int,input().split()))
for i in A:
        if i == 0:

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

kMax = 10**18

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

for i in I:
    ans *= i
    if ans > kMax:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

a = sorted(a, reverse=True)

multi = 1

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

for i in a:
  multi *= i
  if multi > 10**18:
    print('-1')
    sys.exit()

print(multi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# author Sidratul
#

from math import prod

if __name__ == '__main__':
    n = input()
    a = list(map(int, input().split(' ')))
    s = 1
    a.sort()
    x = True
    for i in range(len(a)):
        s = s * a[i]
        if s > 10**18:
            print(-1)
            x = False
            break
    if x:
        print(s)

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans=1
for e in a:
  ans *= e
  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()
ans=1
for i in range(n):
	ans=ans*L[i]
	if ans>pow(10,18):
		print(-1)
		exit()
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
ans = 1
if 0 in A_list:
    ans = 0
else:
    for A in A_list:
        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()
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()))
if 0 in a:
  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 = [int(x) for x in input().split()]
sum = 1
big = False
if 0 in A:
    print(0)
else:
    for a in A:
        sum *= a
        if sum > 10**18:
            big = True
            break
    if big:
        print(-1)
    else:
        print(sum)

Submission status: Accepted

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

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

prod = 1

for a in A:
    prod *= a
    if prod > 1e18:
        print(-1)
        exit()

print(prod)

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

Submission status: Accepted

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

# Aに0が含まれていたら、積も0とする
# Aに0が含まれていなければ、順に積を取り、10^18を超えたら終了する
ans = 0
if 0 not in A:
  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())
an=[int(i) for i in input().split()]
ans=1
for a in an:
  ans*=a
  if ans>10**18:
    ans=-1
    break
    
if 0 in an:
  ans=0
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()

c=1

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

print(c)

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 = 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 = 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:
from sys import exit

n = int(input())
num_list = [int(i) for i in input().split()]
if 0 in num_list:
    print(0)
    exit()
ans = 1
for i in range(n):
    ans *= num_list[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
cnt = 1
for ai in a:
  cnt *= ai
  if cnt > 10 ** 18:
    print(-1)
    exit()
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
 
ans = 1
for x in a:
  if ans <= 10**18:
    ans = ans * x

print(-1 if ans > 10**18 else 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:
        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
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())
lst = list(map(int, input().split()))
ans = 1
if 0 in lst:
    ans = 0
for i in range(n):
    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()))
A.sort()
res = 1
for i in A:
    res*=i;
    if res>10**18:
        res = -1
        break
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
if any(j == 0 for j in A) == True:
    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())
arr = list(map(int,input().split()))
res = 1
flag = 1
arr.sort()
inf = int(1e18)
for i in range(n):
  res = res*arr[i]
  if(res > inf):
    flag = 0
    break
 
if(flag == 0):
  print(-1)
else:
  print(res)

Submission status: Accepted

Solution code:
#b問題
n=int(input())
ans=1
a=list(int(y) for y in input().split())
# print(a)
if 0 in a:
    print(0)
else:
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
            ans=-1
            break
    print(ans)

Submission status: Accepted

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

m=1
l=10**18

if a.count(0) >= 1:
    print(0)
    sys.exit()

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

print(m)

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

Submission status: Accepted

Solution code:
import numpy as np

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

#ans = np.prod(Alist)
Alist.sort()
ans = 1
for i in range(N):
  #print (Alist[i])
  ans*= Alist[i]
  if Alist[i]==0:
    break
  if ans >10**18:
    break

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

Submission status: Accepted

Solution code:
import numpy as np

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

#ans = np.prod(Alist)
Alist.sort()
ans = 1
for i in range(N):
  #print (Alist[i])
  ans*= Alist[i]
  if Alist[i]==0:
    break
  if ans >10**18:
    break

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

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
ans = A[0]
if ans == 0:
    print(ans)
    exit()
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()))

ans = A[0]
if A.count(0) >= 1:
  ans = 0
else:
  for i in range(1,N):
    ans *= A[i]
    if ans > 10**18:
      ans = -1
      break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
list_a = [int(x) for x in input().split()]
list_a_str = [str(s) for s in list_a]
ans = 1

for i in range(0, n):
    if list_a_str[i] in '0':
        print('0')
        exit()

for i in range(0, n):
    ans *= list_a[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 = 0
if 0 not in A:
  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())
A = [int(x) for x in input().split()]

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr) #配列を昇順ソートしておく(配列に0がある場合0が先頭に来るので、場合分けの必要がなくなる)
ans=1
for val in arr:
 ans*=val #Pythonは多倍長整数をサポートしているので単に積を求めれば十分
 if ans>10**18:
   print(-1)
   break
else:
 print(ans)

Submission status: Accepted

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


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

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*ans
        if ans > (10**18):
            ans = '-1'
            break
print(ans)

Submission status: Accepted

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

result = 1

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

print(result)

Submission status: Accepted

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

judge = True
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

MAX = 10 ** 18


def solve(N: int, A: "List[int]"):
    A = sorted(A)
    answer = 1
    for a in A:
        answer *= a
        if answer > MAX:
            return -1
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, A = map(int, line.split())
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, A)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

MAX = 10 ** 18


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


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, A = map(int, line.split())
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, A)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
N = input()
A = list(map(int, input().split()))
C = sorted(A)
l = len(A)
i = 0
S = 1

while i < l:
   S = S * C[i]
   i = i + 1
   if S > 1000000000000000000:
        print(-1)
        break
   elif i == l:
        print(S)
        break

Submission status: Accepted

Solution code:
N = input()
A = list(map(int, input().split()))
C = sorted(A)
l = len(A)
i = 0
S = 1

while i < l:
   S = S * C[i]
   i = i + 1
   if S > 1000000000000000000:
        print(-1)
        break
   elif i == l:
        print(S)
        break

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

pyn()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a =int(input())
l = list(map(int,input().split()))
l.sort()
import numpy as np
times = 1
for i in l:
  times*=i
  if times>10**18:
    times = -1
    break
print(times)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
#print(a)
if a[0]==0 :
  print(0)
  exit()

res = 1

lim = 10**18

for i in(a):
  res *= i
  if res > lim :
    print(-1)
    exit()
  
print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(n) for n in input().split(' ')]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    
    if A.count(0) != 0:
        print(0)
        return

    ans = 1

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

    print(ans)
    
main()

Submission status: Accepted

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

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False
        break

for i in range(n):
    if a[i] == 0:
        ok = True
        ans = 0

if ok == True:
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

  if (0 in A):
    print("0")
    return

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

Submission status: Accepted

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

ans = 1

for a in A:
    if A[n-1] == 0:
        ans = 0
        break
    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
if 0 in a:
  print(0)

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

Submission status: Accepted

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

p = 1

for i in range(n):
  if a[i] == 0:
    print(0)
    exit()

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

print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
nums = input().split()

zero_flag = False
for item in nums:
  if item == '0':
    zero_flag = True
    break
    
if zero_flag:
  seki = 0
else:
  seki = 1
  for item in nums:
    seki *= int(item)
    if seki > 10**18:
      seki = -1
      break

print(seki)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n=II()
	A=LI()
	A.sort()

	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:
# This is a sample Python script.

# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press ⌘F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    arr = sorted(arr)  # 配列を昇順ソートしておく(配列に0がある場合0が先頭に来るので、場合分けの必要がなくなる)
    ans = 1
    for val in arr:
        ans *= val  # Pythonは多倍長整数をサポートしているので単に積を求めれば十分
        if ans > 10 ** 18:
            print(-1)
            break
    else:
        print(ans)

# See PyCharm help at https://www.jetbrains.com/help/pycharm/

Submission status: Accepted

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

print(S)

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(str(ans))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans =1;
iszero = False

if 0 in A:
  iszero = True
for i in range(N):
  if(iszero):
    ans = 0
    break
  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()))

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
if 0 in set(a):
    print(0)
    quit()
res = 1
for x in a:
    res *= x
    if res > 10**18:
        print(-1)
        quit()
print(res)

Submission status: Accepted

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

Submission status: Accepted

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


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


print(ans)

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
A = sorted(readInts())
th = 10**18
if A[0] == 0:
    print(0)
else:
    ans = 1
    for i in range(n-1,-1,-1):
        ans *= A[i]
        if ans > th:
            print('-1')
            exit()
    print(ans)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
a.sort()
if a[0] == 0:
    print(0)
    exit()
b = 1
for c in a:
    b *= c
    if b > 10 ** 18:
        print(-1)
        exit()

print(b)

Submission status: Accepted

Solution code:

def Li():
    return list(map(int, input().split()))


N = int(input())
A = Li()

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

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))[::-1]
if 0 in A:
    print(0)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

c = 1
j = 0

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

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return

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

    print(ans)

main()

Submission status: Accepted

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

A.sort()
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
if 0 in A:
    ans = 0
else:
    for a in A:
        ans *= a
        if ans > 10 ** 18:
            ans = -1
            break

print(ans)

Submission status: Accepted

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

r = 1
for v in A:
    if v == 0:
        r = 0
        break

    r *= v
    if r > 1000000000000000000:
        r = -1
        break

print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#10^18こえたら-1
n = int(input())
Arr = list(map(int, input().split( )))
Arr = sorted(Arr)
if Arr[0] == 0:
  print(0)
  exit()
s = 1
for i in range(n):
  s *= Arr[i]
  if s > 10**18:
    print(-1)
    exit()
print(s)

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(n):
        m = m * a[i]
        if m > 10 ** 18:
            print(-1)
            break
        elif i == n - 1:
            print(m)

Submission status: Accepted

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

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

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