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())
arr=list(map(int,input().split()))
ans=1
arr=sorted(arr)
def solve(arr,ans):
    for i in arr:
        ans*=i
        if(ans>10**18):
            return(-1)
        if(ans==0):
            return(0)
    if(ans>10**18):
        return(-1)
    return(ans)
print(solve(arr,ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

ans=1
for i in range(n):
#    print(ans)
    if ans>10**18:
        print(-1)
        exit()
    else:
        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()))
ans = 1
for i in a:
  if ans*i > 10 ** 18:
    ans = -1
    break
  else:
  	ans *= i
if 0 in a:
  print(0)
else:
  print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin, stdout

N = int(input())
A = [int(x) for x in stdin.readline().split()]
ans = 1
for i in range(N):
  if ans <= 1e18:
    ans *= A[i]
  if A[i] == 0:
    ans *= A[i]

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

Submission status: Accepted

Solution code:
from functools import reduce
n=int(input())
a = tuple(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > pow(10,18):
        ans = pow(10,18)+1

print(ans if ans <= pow(10,18) else -1)

Submission status: Accepted

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

for a in A:
    if(a==0):
        print(0)
        sys.exit()

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

Submission status: Accepted

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

if K.count(0) > 0:
    print(0)
else:
    ans = 1
    burst = False
    for k in K:
        ans *= k
        if ans > 10**18:
            burst = True
            break
    if burst:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

maxi = int(1e18)

ans = 1
for x in a:
    ans *= x
    if ans > maxi:
        ans = -1
        break

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = tuple(map(int, input().split()))

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

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    paramN = input()
    params = list(map(lambda x: int(x), input().split(' ')))
    if len(list(filter(lambda x: x == 0, params))) > 0:
        print(0)
    else:
        result = 1
        for p in params:
            result *= p
            if result > pow(10, 18):
                print(-1)
                return
        print(result)

main()

Submission status: Accepted

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

res = 1
flag = True
if 0 in A:
    print(0)
else:
    for i in range(len(A)):
        res = res * A[i]
        if res > mod:
            flag = False
            break
    if flag:
        print(res)
    else:
        print(-1)

Submission status: Accepted

Solution code:
n=int(input())
alist=list(map(int,input().split()))
import math
mini=min(alist)
if mini==0:
    ans=0
else:
    ans=1
    for i in range(n):
        ans*=alist[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()))

MAX = 10**18


def main():
    for a in A:
        if a == 0:
            print(0)
            return
    total = 1
    for a in A:
        total *= a
        if total > MAX:
            print(-1)
            return

    print(total)


main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse = True)
ans = 1
if a[-1] == 0:
    ans = 0
else:
    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(reverse=True)

ans = 1

if a[-1] == 0:
  ans = 0
else:
  for i in a:
    ans *= i
    if ans > 1000000000000000000:
      print(-1)
      break
    else:
      continue

if ans <= 1000000000000000000:
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

result = 1 

if 0 in numbers:
  result = 0
else:
  for num in numbers:
    result *= num
    if result > 10**18:
      result = -1
      break

print(result)

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  A = [int(i) for i in input().split()]
  A.sort()
  res = 1
  for i in range(N):
    res = res * A[i]
    if res == 0:
      print(res)
      return
    elif res > 10 ** 18:
      print(-1)
      return
  if res > 10 ** 18:
    print(-1)
  else:
    print(res)

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	arr = list(map(int, input().split()))
	ans = arr[0]
	if arr.count(0) > 0:
		print(0)
		return
	for i in range(1, N):
		ans *= arr[i]
		if ans > 1000000000000000000:
			print(-1)
			return
	print(ans)


if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
    for i in range(N):
        if A[i] == 0:
            print(0)
            return
        
    ans = 1
        
    for i in range(N):
        ans *= A[i]
        if ans > INF:
            print("-1")
            return
    print(int(ans))
        
solve()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N = intinp()
A = list(mapint_inp())

lim = 10**18
ans = 1
f = True
if 0 in A:
    ans = 0
else:
    for A_i in A:
        ans = ans*A_i
        if ans > lim:
            f = False
            break

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

Submission status: Accepted

Solution code:
from decimal import Decimal

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

p = Decimal(1)

bad = False

for x in xs:
	if bad:
		if x == 0:
			p = 0
			break
	else:
		p *= Decimal(x)
		if p > 10**18 :
			bad = True
			p = -1

print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict


#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))


n = readInt()
a = readInts()

ans = 1

d = defaultdict(int)

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

for i in a:
	d[i]+=1

for k in d:
	ans*=k**d[k]
	if ans>10**18:
		print(-1)
		exit()

else:
	print(ans)

Submission status: Accepted

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

ans = 1

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

print(ans)

Submission status: Accepted

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

for i in range(len(A)):
    if len(str(answer)) + len(str(A[i])) <= 20:
        answer *= A[i]
    else:
        print(-1)
        exit()

if answer <= 1000000000000000000:
    print(answer)
else:
    print(-1)

Submission status: Accepted

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

result=1

for i in A:
    if i == 0:
        result=0
        break

if result != 0:
    for i in A:
        result = result * i
        if result > max_result:
            result = -1
            break
    
print(result)

Submission status: Accepted

Solution code:
n = int(input())

a = [0] * n

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

sum = 1
cnt = 0
if 0 in a:
    print(0)
else:
    for i in a:
        sum *= i
        if sum > 1000000000000000000:
            print(-1)
            cnt = 1
            break
    if cnt == 0:
        print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().strip())
seq = list(map(int, stdin.readline().split()))

mul = 0
if 0 not in seq:
  mul = 1
  for k in seq:
    mul *= k
    if mul>int(1e18):
      mul = -1
      break
print(mul)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline
 
n = int(input())
l = list(map(int,input().split()))

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

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

print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

if 0 in Ls:
    print(0)
else:
    ans=1
    for i in Ls:
        ans=(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()))

answer = 1

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


print(answer)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
#print(N)

A = input().split()
#print(A)

L = [int(b.strip()) for b in A]
#print(L)

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

ret = 1
for v in L:
  ret = ret * v
  if ret > 1000000000000000000:
    print(-1)
    sys.exit()

print(ret)

Submission status: Accepted

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

res = 1
for x in a:
	if res == 0 or res == -1:
		break
	res = res * x
	if res > 1000000000000000000:
		res = -1

print(res)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

kekka=1

for i in range(N):
    kekka*=A[i]
    if kekka>10**18:
        kekka=10**18+1

if kekka>10**18:
    kekka=-1


print(kekka)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    if 0 in A:
        print(0)
        return

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

    print(ans)

main()

Submission status: Accepted

Solution code:
INF = 1000000000000000000
N = int(input())
flag = 1
l = list(map(int,input().split()))
if 0 in l:
  print(0)
  import sys
  sys.exit()
sum = 1
for i in l:
  sum = sum*i
  if sum > INF:
    print(-1)
    flag = 0
    break
  else:
    pass
    
if flag:
  print(sum)

Submission status: Accepted

Solution code:
N = int(input())

A = input().split()
result = 1

A.sort()
fl = True

if int(A[0]) == 0:
    print(0)
else:
    for i in A:
        result *= int(i)
        if result > 10**18:
            fl = False   
            break                
    if fl:
        print(result)
    else:
        print(-1)

Submission status: Accepted

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

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:
        if i <= 1e18:
            t = ans * i
            if t <= 1e18:
                ans = t
            else:
                ans = -1
                break
        else:
            ans = -1
            break
print(ans)

Submission status: Accepted

Solution code:
'''input
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

'''

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

if 0 in a:
	print(0)
	exit(0)
 
for i in a :
  # print(prod)
  if  i * prod > 1e18:
    print(-1)
    exit(0)
  else:
    prod = prod *  i
 
print(prod)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    input()
    A = read_list()
    if 0 in A:
        print(0)
        return

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

limit = 1000000000000000000

sum = 1
for i in range(N):
    if (limit < sum or sum == -1):
        sum = -1
    else:
        sum *= AB[i]
    if (AB[i] == 0):
        print(0)
        exit()

if (limit < sum):
    sum = -1

print(sum)

Submission status: Accepted

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

def solve(N: int, A: "List[int]"):
    A.sort()
    ans =1
    for a in A:
        ans = ans * a

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


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
n = ni()
A = list(ma())
ans = 1
for a in A:
    ans*=a
    #print(ans)
    if ans>10**18:
        ans = -1
        break
mi = min(A)
if mi>0:
    print(ans)
else:
    print(0)

Submission status: Accepted

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

if inputs.count(0) >= 1:
    multiple = 0
    
else:
    for i in range(N):
        if i == 0:
            multiple = inputs[0]
        else:
            multiple *= inputs[i]

        if multiple > 10**18:
            multiple = '-1'
            break

print(multiple)

Submission status: Accepted

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

ans = a[0]

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

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
res = 1
for i in A:
    res *= i
    if res > 10**18:
        res = -1
        break
if A.count(0) != 0:
    res = 0
print(res)

Submission status: Accepted

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

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

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

print(Result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans = 1
flg = 0
max = 10 ** 18 + 1

for i in range(n):
    if a[i] == 0:
        ans = 0
        break
    if flg == 0:
        ans = ans * a[i]
    if ans // max > 0:
        ans = -1
        flg = 1

if flg != 0 and ans != 0:
    ans = -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

printed = False
if 0 in a:
    print(0)
    printed = True

ans = 1

for x in a:
    ans *= x
    if ans > 1e18:
        if not printed:
            print(-1)
            printed = True
        break    
    
if not printed:
    print(ans)

Submission status: Accepted

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

mul = 1

A.sort()

for i in range(N):
  mul *= A[i]
  if mul == 0 or mul > 10 ** 18:
    break

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

Submission status: Accepted

Solution code:
N=int(input())

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

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

res=1
for x in A:
	res*=x
	if res>pow(10,18):
		print('-1')
		exit()

else:
	print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        if ans <= 10**18:
            ans = ans * i
        else:
            break

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

Submission status: Accepted

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

ans = 1

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

        if i == N - 1:
            print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = 1
m = 10 ** 18
if(0 in a):
  print(0)
  quit()

for i in range(n):
  total *= a[i]
  if(total > m):
    total = -1
    break
print(total)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

if 0 in ai:
    print(0)
else:
    for a in ai:
        ans *= a
        if ans > 1000000000000000000:
            ans = -1
            break
    print(ans)

Submission status: Accepted

Solution code:
# 

from sys import stdin
input = lambda: stdin.readline().rstrip()

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

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

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

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

def dfs(l, r):

    if l==r:
        return A[l]
    mid = (l+r)//2
    ans = 1
    ans = ans * dfs(l, mid)
    ans = ans * dfs(mid+1, r)
    return ans

ans = dfs(0, len(A)-1)

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()]
if 0 in a:
    print(0)
    exit()
a.sort(reverse=True)
ans=1
x=10**18
for i in a:
    ans*=i
    if ans>x:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

A.sort()
sum = 1
for a in A:
    sum *= a
    if sum > (10 ** 18):
        sum = -1
        break
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
if a[0]==0:
    print(0)
else:
    a.sort(reverse=True)
    # print(a)

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

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

Submission status: Accepted

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

ans = 1
for i in a:
    ans *=i
    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()))
a.sort()
ans=1
for i in a:
    ans*=i
    if ans>pow(10,18):
        print(-1)
        exit()
    elif ans==0:
        print(0)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
a = LI()

if (0 in a):
    ret = 0
else:
    ret = a[0]
    for i in range(1,n):
        ret = ret * a[i]
        if(ret > 1000000000000000000):
            ret = -1
            break

print(ret)

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    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:
            ans = -1
            print(ans)
            exit()
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

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:
        ans=0
        break
if ans==0:
    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:
n = int(input())

ans = 1

a = [int(x) for x in input().split()]
for i in range(n):
    ans = min(10 ** 30, ans * a[i])

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    num_list = list(map(int, input().split()))
    ans = 1
    MAX = 1e18
    for i in num_list:
        ans = ans*i
        if ans > MAX:
            ans = -1
            break
    if 0 in num_list:
        print(0)
    else:
        print(ans)

Submission status: Accepted

Solution code:
n=int(input())
seq=list(map(int,input().split()))
p=1
f=1
c=int(1e18)
if 0 in seq:
    print(0)
else:
    for i in range(n):
        p*=seq[i]
        if p>c:
            print(-1)
            f=0
            break
            
    if f==1:
        print(p)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().rstrip())
A = list(map(int, sys.stdin.readline().rstrip().split()))

if A.count(0) > 0:
    print(0)
else:
    x = 1
    for a in A:
        x *= a
        if x > 1000000000000000000:
            print(-1)
            sys.exit()
    print(x)