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())
a = list(map(int,input().split()))
a = sorted(a)
ans = 1
for i in range(n):
         ans *= a[i]
         if ans == 0:
                  print(ans)
                  exit()
         elif ans > (10 ** 18):
                  print(-1)
                  exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
N, *A = map(int, open(0).read().split())

while len(A) > 1:
  n = len(A)
  if n & 1:
    A.append(1)
    n += 1
  L, R = A[:n//2], A[n//2:]
  A = [x * y for x, y in zip(L, R)]
x = A[0]
if x > 10 ** 18:
  x = -1
print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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:
ans = 1
n = int(input())
A = [int(i) for i in input().split()]
A.sort()
for i in A:
    if i==0:
        print('0')
        exit()
    ans *= i
    if ans>10**18:
        print('-1')
        exit()
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = [*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:
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())
a = list(map(int, input().split()))

seki = 1

a.sort()
if a[0] == 0:
	print(0)
	exit()
else:
	for i in range(N):
		seki = seki * a[i]
		if seki > 1e18:
			print(-1) 
			exit()
print(seki)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
t=1;print([t:=(-1,t:=t*int(a))[0<=t<=1e18]for a in[*open(0)][1].split()][-1])

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(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(map(int,input().split()))
A.sort()
ans = 1
flag = 0
for i in range(N):
  ans *= A[i]
  if ans == 0:
    print(0)
    flag += 1
    break
  elif ans > 10**18:
    print(-1)
    flag += 1
    break
if flag == 0:
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

  if 0 in A:
    print(0)
    return

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

  print(p)
main()

Submission status: Accepted

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

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

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

print(mul)

Submission status: Accepted

Solution code:
n = int(input())
list = input().split(" ")

if '0' in list:
    print(0)
    exit()

x = 1
for i in list:
    x = x * int(i)
    if x > 10**18:
        print(-1)
        exit()
print(x)

Submission status: Accepted

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

if a[0]==0:
    print(0)
    exit()
else:
    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())
li = list(map(int, input().split()))
x = 1
if 0 in li:
    print(0)
else:
    for i in li:
        x = x * i
        if x > 10**18:
            print(-1)
            exit()
    print(x)

Submission status: Accepted

Solution code:
# import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()


N = int(input()) # 1行, 単数

arg = list(map(int, input().split())) # 1行, 配列
m = 1

if 0 in arg:
  print(0)
else:
  for A in arg:
    m = A * m
    if m > 1000000000000000000:
      m = -1
      break;
  print(m)

Submission status: Accepted

Solution code:
t=1;[t:=(-1,t:=t*int(a))[0<=t<=1e18] for a in[*open(0)][1].split()];print(t)

Submission status: Accepted

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

  if 0 in A:
    print(0)
    return
  
  num = 1
  max_num = 10**18
  for i in A:
    num *= i
    
    if num > max_num:
      print(-1)
      return
  
  print(num)
  
main()

Submission status: Accepted

Solution code:
INF = int(1e18)


def main():
    N, *A, = map(int, open(0).read().split())
    ans = 1
    if 0 in A:
        print(0)
        return
    for a in A:
        ans *= a
        if INF < ans:
            print(-1)
            break
    else:
        print(ans)
    return


main()

Submission status: Accepted

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

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return

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

    print(anser)

main()

Submission status: Accepted

Solution code:
"""
    This template is made by Satwik_Tiwari.
    python programmers can use this template :)) .
"""

#===============================================================================================
#importing some useful libraries.
from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().strip() #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)


#===============================================================================================
# code here ;))

def solve():
    n = int(inp())
    a = lis()
    ans = 1
    if(a.count(0)>0):
        print(0)
    else:
        ans = 1
        f = False
        for i in range(0,n):
            ans*=a[i]
            if(ans > (10**18)):
                f = True
                break
        if(f):
            print(-1)
        else:
            print(ans)

testcase(1)

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

x=1

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

Submission status: Accepted

Solution code:
n = int(input())
A = [*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:
count = int(input())
nums = input().split(" ")

product = 1

if ("0" in nums):
    print(0)
else:
    for i in nums:
        product *= int(i)
        if (product > 10**18):
            print(-1)
            exit()
    print(product)

Submission status: Accepted

Solution code:
n = input()
a_array = input().split(' ')

seki = 1
end = False

if "0" in a_array:
    print(0)
else:
    for a in a_array:
        a = int(a)
        seki *= a

        if seki > 10**18:
            print(-1)
            end = True
            break

    if end == False:
        print(seki)

Submission status: Accepted

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

A.sort()

ans = 1
for i in A:
    ans *= i
    if ans > MAX:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 1
    A.sort()
    for a in A:
        ans *= a
        if ans > 10**18:
            return -1
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = [*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 = sorted(list(map(int, input().split())))
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()))
    result = 1
    if 0 in A:
        print(0)
        return

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

main()

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 > 1e18:
            print(-1)
            return

    print(prod)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n  = int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
for i in a:
  ans*=i
  if ans>int(1e18):
    print(-1)
    sys.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()
  
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 = sorted([int(i) for i in input().split()],reverse=True)

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

x = A[0]  
for i in A[1:]:
  x *= i
  if x > 10**18:
    print('-1')
    exit();
    
print(x)

Submission status: Accepted

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

Submission status: Accepted

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

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

    print(prod)

main(A)

Submission status: Accepted

Solution code:
x1 = input()
x2 = [int(i) for i in input().split(" ")]

result = 0
if 0 in x2:
  None 
else:
  result = 1
  for xv in x2:
     result = xv * result
  
     if 10**18 < result : 
        result = -1
        break


print(result)

Submission status: Accepted

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

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

ans = 1
for d in data:
    ans *= d
    if ans > 10**18:
        ans = -1
        break

print(ans)

Submission status: Accepted

Solution code:
t=1
for a in[*open(0)][1].split():t*=int(a);t=(-1,t)[0<=t<=1e18]
print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
t=1
for a in[*open(0)][1].split():t=(-1,t:=t*int(a))[0<=t<=1e18]
print(t)

Submission status: Accepted

Solution code:
t=1
for a in sorted([*open(0)][1].split()):t=(-1,t:=t*int(a))[0<=t<=1e18]
print(t)

Submission status: Accepted

Solution code:
N = int(input())
count = 1
inputs = [int(i) for i in input().split()]
if 0 in inputs:
    print(0)
    quit()
else:
    for daude in inputs:
        if daude > 10 ** 18:
            count = -1
            break
        count *= daude
        if count > 10 ** 18:
            count = -1
            break
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
#import cython
 
def main():
    read = lambda: sys.stdin.readline().rstrip()
    
    #N: cython.longlong = 0
    n = int(read())
    a = list(map(int,read().split()))
    ans = 1
    flag = True
    iszero = any(num == 0 for num in a)
    if iszero: print(0)
    else:
        for num in a:
          ans *= num
          if ans > 10**18:
            flag = False
            break
        print(ans if flag else -1)
 
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
from decimal import Decimal
'''
N = ii()
A = li()
ans = 1
for num in A:
    ans *= num
    if ans > 10**18:
        if 0 in A:
            print(0)
        else:
            print(-1)
        exit()

print(ans)
'''

'''
N = ii()
A = li()
ans = 1
inf = Decimal('1000000000000000000')
for num in A:
    if ans <= inf / Decimal(str(num)):
        ans *= num
    else:
        if 0 in A:
            print(0)
        else:
            print(-1)
        exit()
print(ans)
'''


N = ii()
A = li()
if 0 in A:
    print(0)
    exit()
ans = 1
for num in A:
    #print(ans, 10**18 / num, 10**18//num)
    #if ans < (10**18+1) / num or ans == 10**18//num:
    if ans <= 10**18//num:
        ans *= num
    else:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
from decimal import Decimal
'''
N = ii()
A = li()
ans = 1
for num in A:
    ans *= num
    if ans > 10**18:
        if 0 in A:
            print(0)
        else:
            print(-1)
        exit()

print(ans)
'''

'''
N = ii()
A = li()
ans = 1
inf = Decimal('1000000000000000000')
for num in A:
    if ans <= inf / Decimal(str(num)):
        ans *= num
    else:
        if 0 in A:
            print(0)
        else:
            print(-1)
        exit()
print(ans)
'''

N = ii()
A = li()
if 0 in A:
    print(0)
    exit()
ans = 1
for num in A:
    if ans < (10**18+1) / num or ans == 10**18//num:
        ans *= num
    else:
        print(-1)
        exit()
 
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
import collections

N = int(input())
A = list(map(int, input().split()))
res = 1
if 0 in A:
    print(0)
    sys.exit()
for i in range(N):
    res *= A[i]
    if res > 1e18:
        print(-1)
        sys.exit()
print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = map(int, input().split())
a = sorted(a)
s = 1
for x in a:
    s *= x;
    if s > 1e18:
        print(-1)
        exit()
print(s)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
from decimal import Decimal
'''
N = ii()
A = li()
ans = 1
for num in A:
    ans *= num
    if ans > 10**18:
        if 0 in A:
            print(0)
        else:
            print(-1)
        exit()

print(ans)
'''

N = ii()
A = li()
ans = 1
inf = Decimal('1000000000000000000')

for num in A:
    if ans <= inf / Decimal(str(num)):
        ans *= num
    else:
        if 0 in A:
            print(0)
        else:
            print(-1)
        exit()

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    arr = list(map(int,input().split()))
    if 0 in arr:
        return 0
    prod = 1
    max1 = 10**18
    for i in arr:
        prod*=i
        if(prod==0):
            return 0
        if(prod>max1):
            return -1
    return prod

print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int, input().split()))
hasZero = False
for x in a:
    if x == 0:
        hasZero = True
if hasZero:
    print(0)
    exit(0)
res = 1
limits = 10**18
for x in a:
    res *= x
    if res > limits:
        res = -1
        break
print(res)

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

limit = 10 ** 18

l = sorted([int(i) for i in input().split()])

flg = True
if l[0] == 0:
    flg = False
    print(0)
else:
    ans = 1
    for i in l:
        if ans > limit:
            print(-1)
            flg = False
            break
        else:
            ans *= i
            
if flg:
    print(ans if ans <= limit else -1)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  data = list(map(int, input().split()))
  if 0 in data:
    print(0)
    return
  
  c = 1
  for d in data:
    c *= d
    if c > 10 ** 18:
      print(-1)
      return
  
  print(c)


if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:

N=int(input())
sA=input().split(" ")
A=[]

for i in range(N):
    A.append(int(sA[i]))

flag=False

zero=False
th=pow(10,18)
for i in range(N):
    if(A[i]==0):
        zero=True
        break
    elif(A[i]>th):
        flag=True
        break

S=1
for i in range(N):
    S*=A[i]
    if(S>th):
        flag=True
        break

if(zero):
    print(0)
else:
    if(flag):
        print(-1)
    else:
        print(S)

Submission status: Accepted

Solution code:
import math
n=input()
a=list(map(int,input().split()))
a.sort()
x=pow(10,18)
s=int(1)
c=True
for i in a:
	s*=i
	if(s>x):
		print('-1')
		c=False
		break
if c:
	print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math,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 > pow(10,18):#pythonはオーバーフローしないからこれでも行ける
        print(-1)
        sys.exit()

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

Submission status: Accepted

Solution code:
n = int(input())
MX = 10**18
a = list(map(int, input().split()))
for x in a:
  if x == 0:
    print(0)
    exit(0)
ans = 1
for x in a:
  ans *= x
  if ans > MX:
    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 range(N):
  tmp = A[i]
  ans = ans * tmp
  if(ans > 10**18):
    print("-1")
    exit()
print(str(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input(""))
k=1
# li=list(map(int,input("").split(" ")))
li=input().split(" ")
if '0' in li:
    print("0")
else:
    for i in li:
        k*=int(i)
        if k>1000000000000000000:
            print("-1")
            break
    else:
        print(k)

Submission status: Accepted

Solution code:
n=int(input(""))
k=1
li=list(map(int,input("").split(" ")))
if 0 in li:
    print("0")
else:
    for i in li:
        k*=int(i)
        if k>1000000000000000000:
            print("-1")
            break
    else:
        print(k)

Submission status: Accepted

Solution code:
#@author: Behradm

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

    a.sort()
    res = 1
    for i in range(n):
        res *= a[i]
        if (res > 1000000000000000000):
            print(-1)
            return 0
    print(res)

if (__name__ == "__main__"):
    main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list([int(x) for x in input().split()])
L = int(10**18)

if 0 in A:
    ans = 0
else:
    ans = 1
    for a in A:
        ans = ans * a
        if ans > L:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    total = 1

    if 0 in a :
        print(0)
        return

    for i in a :
        total *= i

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

    print(total)

if __name__ == "__main__" :
    solve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A = list(map(int,input().split()))

flag = 1

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

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

Submission status: Accepted

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

    total = 1

    if 0 in a :
        print(0)
        return

    for i in a :
        total *= i

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

    print(total)

if __name__ == "__main__" :
    solve()