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:
input()
l=list(map(int,input().split()))
if 0 in l:
  ret = 0
else:
  ret = 1
  for i in l:
    ret *= i
    if ret > 10**18:
      ret = -1
      break
print(ret)

Submission status: Accepted

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

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

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

result = 1
for a in list_A:
    result *= a
    if result > 1e18:
        print(-1)
        exit()

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    input() #n
    a = list(map(int, input().split()))
    prod = 1

    if 0 in a:
        print(0)
        return
    for i in a:
        prod *= i
        if prod > 1e+18:
            print(-1)
            break
    else:
        print(prod)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline

def main():
  n = int(input().strip())
  a = list(map(int, input().strip().split()))
  result = 1
  LIMIT = 10**18
  if 0 in a:
    print(0)
    sys.exit()
  for i in a:
    result *= i
    if result > LIMIT:
      print(-1)
      sys.exit()
  print(result)

main()

Submission status: Accepted

Solution code:
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
    GI()
    CEIL = 10 ** 18

    xs = LGIS()

    prod = 1
    for x in xs:
        prod *= x
        if prod > CEIL:
            prod = -1
            break

    if prod == -1:
        print(0 if 0 in xs else -1)
    else:
        print(prod)

main()

Submission status: Accepted

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


solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
res = 1 
if 0 in a:
  res = 0
else:
  for num in a:
    res *= num
    if res > 10**18:
      res = -1
      break
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
res = 1 
if 0 in a:
  res = 0
else:
  a.sort(reverse=True)
  for num in a:
    res *= num
    if res > 10**18:
      res = -1
      break
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
n = int(input())
a = list(map(int, input().split()))
res = 1 
if 0 in a:
  res = 0
else:
  for num in a:
    res *= num
    if res > 10**18:
      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:
import sys
N=int(input())
a=list(map(int, input().split()))
s=1
# aに0がある場合を省く
if 0 in a:
    print(0)
    sys.exit()
else:
# sが10^18になったら打ち切る
    for i in a:
        if s<10**18:
            s*=i
    if s>10**18:
        print(-1)
        sys.exit()
    print(s)

Submission status: Accepted

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





if __name__ == '__main__':
    solve()

Submission status: Accepted

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

ans = 1
flag_overflow = False
flag_zero = False
for a in A:
  if(flag_overflow) :
    if(a == 0) :
      flag_zero = True
  else :
    ans *= a
    if(ans > 10 ** 18) :
      flag_overflow = True

if(flag_zero) :
  print(0)
elif(flag_overflow) :
  print(-1)
else :
  print(ans)

Submission status: Accepted

Solution code:
def cal():
    n = int(input())
    lst = list(map(int,input().split()))
    if 0 in lst:
    	return 0
    else:
        prod = 1
        for a in lst:
            prod *= a
            if prod > 1000000000000000000:
                return -1
    return prod
print(cal())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import numpy as np

N = int(input())

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

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

mul = A[0]

for i in A[1:]:
    if 1000000000000000000 / i < mul:
        print(-1)
        exit(0)
    mul *= i

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

print(mul)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import numpy as np

N = int(input())

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

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

mul = A[0]

for i in A[1:]:
    if 1000000000000000000 / i < mul:
        print(-1)
        exit(0)
    mul *= i

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

print(mul)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import numpy as np

N = int(input())

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

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

mul = A[0]

if np.sum(A < 0) % 2 == 1:
    for i in A[1:]:
        mul *= i
else:
    for i in A[1:]:
        if 1000000000000000000 / i < mul:
            print(-1)
            exit(0)
        mul *= i

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

print(mul)

Submission status: Accepted

Solution code:
n=int(input())
m=1
inf=10**18
lol=0
l=list(map(int,input().split()))
if 0 in l:
    print(0)
else:

    for i in l:
      m=m*i
      if(m>inf):
        lol=1
        break
    if(lol):
      print(-1)
    else:
      print(m)

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

Submission status: Accepted

Solution code:
from sys import *
from collections import *
from math import *

input = stdin.readline

n = int(input())
arr = list(map(int, input().split()))
arr.sort()
mul = 1
for x in arr:
	mul *= x
	if mul > 10 ** 18:
		print(-1)
		exit(0)
print(mul)

Submission status: Accepted

Solution code:
def main():
    # 制約条件
    MAX_RESULT = 1000000000000000000
    
    N = int(input())
    A = [int(x) for x in input().split()]
    
    if 0 in A:
        result = 0
        print(result)
        return
    
    result = 1
    
    for x in A:
        result *= x
        if result > MAX_RESULT:
            print(-1)
            return
    print(result)
main()

Submission status: Accepted

Solution code:
n = eval(input())
a = input().split()
prod = 1
for i in range(0, n):
    a[i] = int(a[i])
a = sorted(a)
for i in range(0, n):
    prod *= int(a[i])
    if prod > 1e18:
        break
if prod > 1e18:
    print(-1)
else:
    print(prod)

Submission status: Accepted

Solution code:
_ = input()
nums = list(map(int,input().split()))
flg = True

ans = nums[0]

if 0 in nums:
  ans = 0
else:
  for num in nums[1:]:
    ans *= num
    if ans > 1e18:
      flg = False
      break
ans = ans if flg else -1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 1
for i in l:
    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()))
a.sort()
max_num = 10 ** 18
ans = 1
for i in a:
    ans *= i
    if ans > max_num:
        ans = -1
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def multipilation():
    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)
    
multipilation()

Submission status: Accepted

Solution code:
itl = lambda: list(map(int, input().strip().split()))


def solve():
    L = 10 ** 18
    N = int(input())
    A = itl()
    for i in range(N):
        if A[i] == 0:
            return 0
            
    curr = 1
    for i in range(N):
        curr *= A[i]
        if curr > L:
            return -1
    return curr


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
N = input()
Ai = input().split()
Ai = [int(Ai[k]) for k in range(int(N))]
K = Ai[0]
T = True
for j in range(int(N)):
  if Ai[j] == 0:
    K = 0
    T = False
    print(0)
for i in range(1,int(N)):
  K = K * Ai[i]
  if K > 1000000000000000000:
    K = -1
    break
if T:
  print(K)

Submission status: Accepted

Solution code:
n = int(input())
MX = 10**18
a = [int(x) for x in 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:
import sys

number = int(input())
box = list(map(int,input().split()))

for var in box:
    if var == 0:
        print("0")
        sys.exit()

overflow = 1e18
ans = 1
for var in box:
    if overflow/var < ans:
        print("-1")
        sys.exit()
    ans *= var

if ans <= overflow:
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return

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

    print(total)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

ans = 1

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

for a in sorted(A, reverse=True):
    ans *= a
    if 10**18 < ans:
        print(-1)
        sys.exit()


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
arr = [int(x) for x in input().split()]
arr.sort()
for each in arr:
    ans *= each
    if (ans > 1e18):
        print(-1)
        exit(0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#169B
N=int(input())
As=list(map(int,input().split()))

if min(As)==0:
    num=0
else:
    num=1
    for i in range(N):
        num *= As[i]
        if num>10**18:
            num=-1
            break

print(num)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(N)

Submission status: Accepted

Solution code:
##169

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
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())
given_list = [int(i) for i in input().split()]

limit = 10**18
ans = 1

if 0 in given_list:
    print(0)
else:
    for i in given_list:
        ans *= i
        if ans > limit:
            print('-1')
            break
    if ans <= limit:
        print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1

for x in range(N):
    ans *= A[x]
    if ans > 10**18:
        ans = -1
        break
        
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
s=input().split()
result=1
if '0' in s:
  print(0)
else:
  for i in range (N):
    result=result*int(s[i])
    if result> 10**18:
      print(-1)
      break
    elif i==N-1 and result<=10**18:
      print(result)

Submission status: Accepted

Solution code:
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


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


from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret


def bunsu(n):
    ret = []
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            tmp = 0
            while (True):
                if n % i == 0:
                    tmp += 1
                    n //= i
                else:
                    break
            ret.append((i, tmp))

    ret.append((n, 1))
    return ret

MOD = 998244353
def solve():
    n = getN()
    nums = getList()

    if 0 in nums:
        print(0)
        return
    ans = 1
    for num in nums:
        ans *= num
        if ans > 10 ** 18:
            print(-1)
            return

    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

if 0 in A :
    ans = 0

for x in range(N) :
    ans *= A[x]
    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 x in range(N) :
    ans *= A[x]
    if ans > 10E+17 :
        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 x in range(N) :
    ans *= A[x]
    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
    N = 0

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

print(ans)

Submission status: Accepted

Solution code:
k=input()
a=list(map(int,input().split()))
p=1
count=0
if(len(a)==0):
    print("0")
elif 0 in a:
    print("0")
else:
    while(count<len(a)):
        p*=a[count]
        count+=1
        if(p>pow(10,18)):
            print("-1")
            break
    if(p<=pow(10,18)and len(a)>0):
        print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())

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

a = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
limit = 10**18
sum = 1

if 0 in A_list:
    print(0)
else:
    for i in  A_list:
        sum = sum * i
        if sum > limit:
            sum = -1
            break
    print(sum)

Submission status: Accepted

Solution code:
from functools import reduce

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

MAX  = 10 ** 18

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

result = 1
  
for x in xs:
  result *= x
  
  if result > MAX:
    print(-1)
    exit(0)
    
print(result)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# B - Multiplication 2

n = int(input())
a = list(map(int, input().split()))
limit = 10 ** 18
for i in range(1, n):
    a[i] = min(a[i] * a[i - 1], limit + 1)

print(a[-1] if a[-1] <= limit else -1)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
limit = 1000000000000000000
ans = 1
for i in range(N):
    if A[i] == 0:
        ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
p = 1
for i in a:
    p *= i
    if p > 1e18:
        p = -1
        break
print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    x = 1
    if 0 in a:
        print(0)
        return
    for i in range(len(a)):
        b = a[i]
        x *= b
        if x > 1000000000000000000:
            print(-1)
            return
    print(x)
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 > 1000000000000000000:
            print(-1)
            return
    print(prod)
main()

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
zero = False
fl = False
x = 1
for i in lst:
    if(i==0):
        zero = True
        break
    if not fl:
        x*=i
    if(x>1e18):
        fl = True
if zero:
    print(0)
elif fl:
    print(-1)
else:
    print(x)

Submission status: Accepted

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


main()

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:
import sys

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

Submission status: Accepted

Solution code:
def multiply(num_list):
  # if "0" in list, return 0
  if 0 in num_list:
    return 0
  
  # if res > 10^18: return -1
  MAX = pow(10,18)
  res = 1
  for i in num_list:
    res *= i
    if res > MAX:
      return -1
  return res

input()
num_list = list(map(int,input().split()))
print(multiply(num_list))

Submission status: Accepted

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

count = 1

if A.count(0) != 0:
    print("0")
else:
    for c in A:
        count *= c
        if count > 10 ** 18:
            print("-1")
            break
            
    else:
        print(count)

Submission status: Accepted

Solution code:
def multiply(num_list):
  # if "0" in list, return 0
  if 0 in set(num_list):
    return 0
  
  # if res > 10^18: return -1
  MAX = pow(10,18)
  res = 1
  for i in num_list:
    res *= i
    if res == 0:
      return 0
    if res > MAX:
      return -1
  return res

input()
num_list = list(map(int,input().split()))
print(multiply(num_list))

Submission status: Accepted

Solution code:
def multiply(num_list):
  # if "0" in list, return 0
  if 0 in num_list:
    return 0
  
  # if res > 10^18: return -1
  MAX = pow(10,18)
  res = 1
  for i in num_list:
    res *= i
    if res == 0:
      return 0
    if res > MAX:
      return -1
  return res

input()
num_list = list(map(int,input().split()))
print(multiply(num_list))

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split(" ")]
l=sorted(l)
ans=1
for i in l:
    ans*=i
    if ans>10**18:
        print("-1")
        exit(0)
print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())
an = list(map(int, input().split()))
condition = an.count(0)
if condition > 0:
    print(0)
    sys.exit()
a0 = an[0]
for i in range(len(an) - 1):
    a0 = a0 * an[i+1]
    if a0 > 10 ** 18:
        a0 = -1
        break
print(a0)

Submission status: Accepted

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

answer=1
for a in alist:
  answer*=a
  if answer==0:
    print(0)
    break
  elif answer>10**18:
    print(-1)
    break
else:
  print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
ans=1
a=input().split()
#print(a)
if '0' in a:
    ans=0
    print(ans)
else:
    for i in a:
        ans=ans*int(i)
        if ans>10**18:
            ans=-1
            break
    print(ans)

Submission status: Accepted

Solution code:
import sys
count = int(input())
a = list(map(int, input().split()))
#0が出た時点で終了する
for i in a:
    if i == 0:
        print(0)
        sys.exit()
#合計の計算        
total = 1
for j in a:
    total = total*j
    #10^18超えた時点で終了する
    if total>10**18:
        print(-1)
        sys.exit()

print(total)

Submission status: Accepted

Solution code:
import numpy as np
import sys
#import copy


def xnxn(n=0):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


def sp_xnxn(n=0):
    """
    args:
        int n: a number of lows to read
    example
        input   1
        retrun  [1]

        input   123
        return  [1,2,3]

        input   123
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        return [int(k) for k in xsxs()]
    else:
        return [[int(k) for k in xsxs()] for _ in range(n)]


def xsxs(n=0):
    """
    args:
        int n: a number of lows to read 
    example:
        input   AA
        retrun  AA

        input   A BBB CC
        return  ["A","BBB","CC"]

        input   A BB CCC
                D
        return  [["A","BBB","CC"],
                ["D"]]
    """
    if n == 0:
        temp = list(input().split())
        if len(temp) == 1:
            return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        return [list(input().split()) for _ in range(n)]


def sp_xsxs(n=0):
    """
    args:
        int n: a number of lows to read 
        example:
            input   A
            retrun  ["A"]

            input   ABC
            return  ["A","B","C"]

            input   ABC
                    D
            return  [["A","B","C"],
                    ["D"]]
    """
    if n == 0:
        return [s for s in xsxs()]
    else:
        return [[s for s in xsxs()] for _ in range(n)]


n = xnxn()
a = xnxn()

temp = 1

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

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

print(temp)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    sub = 1
    a_ls = list(map(int, input().split()))
    for i in range(n):
        if a_ls[i] == 0:
            print(0)
            return
    for i in range(n):
        sub*=a_ls[i]
        if 10**18 < sub:
            print(-1)
            return
    print(sub)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
#####sorting a dictionary#####
def dict_sort(ans):
    ans=sorted(ans.items(),reverse=True,key=lambda kv:(kv[1]))
flag=[0]*1000002
def seive_primes():
    flag[0]=flag[1]=1
    i=2
    while i*i<=1000000:
        if flag[i]==0:
            j=i*i
            while j<=1000000:
                flag[j]=1
                j+=i
        i+=1
def sqr(n):
    return n*n
def inp():
    ls=list(map(int,input().split()))
    return ls
N=int(input())
ls=inp()
if 0 in ls:
    print(0)
    exit(0)
ans=1
for i in ls:
    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()))
ans = 1
b = True
if 0 in a:
	print(0)
	exit()
for i in a:
	ans*=i
	if (ans>1000000000000000000):
		b = False
		break
if (b):
	print(ans)
else:
	print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
argList =list(map(int, input().split())) 
ret = 1
if 0 in argList:
    ret = 0
else:

    for i in argList:
        ret = ret*i
        if ret > 10**18 :
            ret = -1
            break
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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