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.sort()
ans=1

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

    

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  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):
      ans*=a[i]
      if ans >1000000000000000000:
        ans=-1
        break
  print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ms = list(map(int, input().split()))
iter_ms = iter(ms) 
r = 1
if 0 in ms:
  r = 0
else:
    for i in range(n):
        x = next(iter_ms)
        r *= x
        if r > 10 ** 18:
            r = -1
            break
        
print(r)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=1
if 0 in A:
    print(0);exit()
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())
l=list(map(int,input().split()))
c=1
if not 0 in l:
    for li in l:
        c*=li
        if c > 10**18:
            
            break
    if c > 10**18:
        print('-1')
    else:
        print(c)
else:
    print(0)

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 range(N):

    if ans * A[i] > 10**18:
        print(-1)
        exit()

    ans *= A[i]

print(ans)

Submission status: Accepted

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

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

if flag:
  print(ans)

Submission status: Accepted

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

a_sum = 1

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

    print(a_sum)

Submission status: Accepted

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

Submission status: Accepted

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


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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(lambda a : int(a), input().split(" ")))
ans = 1
if A.count(0) > 0:
  ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
vec=list(map(int,input().split()))
vec.sort()
#print(vec)

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

    print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC169
# B Multiplication 2
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
x = 1
for i in A:
    if A[-1] == 0:
        print(0)
        exit()
    else:
        x = x * i
        if x > 10 ** 18:
            print(-1)
            exit()
print(x)

Submission status: Accepted

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

ans = 1
for i in a:
    if i == 0:
        print(0)
        exit()

for i in a:
    ans *= i
    if ans > pow(10, 18):
        ans = -1
        break


        

print(ans)

Submission status: Accepted

Solution code:
n = map(int,input().split())
a = list(map(int,input().split()))
LIM = 10**18

ans = 1

if 0 in a:
    print(0)
    exit()
else:
    for i in a:
        ans *= i
        if ans > LIM:
            print(-1)
            exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    x = int(input())
    list1 = list(map(int, input().split(" ")))
    result = 1

    if 0 in list1:
        print(0)
        return

    for i in list1:
        result *= i
        if result > 1000000000000000000:
            print("-1")
            exit()
    print(result)

main()

Submission status: Accepted

Solution code:
def main():
    x = int(input())
    list1 = list(map(int, input().split(" ")))
    result = 1

    if 0 in list1:
        print(0)
        return 
    
    for i in list1:
        result *= i
        if result > 1000000000000000000:
            print("-1")
            exit()
    print(result)

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int,input().split()))
flg = True
ans = 1
A.sort()
for a in A:
    ans *= a
    if ans > 10**18:
        flg = False
        break
    if ans == 0:
        break
if flg:
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(ans)
    return ans


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

Submission status: Accepted

Solution code:

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

R=1
if 0 in A:
    print("0")
else:
    for i in range(0, N):
        R=R*A[i]
        if R>1000000000000000000:
            print("-1")
            exit()
        
    print(R)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
answer = 1
flag = 1
zero = 0
for i in range(n):
    answer *= A[i]
    if answer > pow(10,18):
        flag = 0
        break
if 0 in A:
    print(0)
elif flag ==0:
    print('-1')
else:
    print(answer)

Submission status: Accepted

Solution code:
n, *A = list(map(int, open(0).read().split()))

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

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

print(ans)

Submission status: Accepted

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

ans = 1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in c:
    print(0)
else:
    for i in c:
        ans = ans*i
        if ans <= mod:
            pass
        else:
            print('-1')
            break
    if ans <= mod:
        print(ans)

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return

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


if __name__ == '__main__':
    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 range(N):
  ans *= a[i]
  if ans > pow(10,18):
    print(-1)
    exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def func(n, a):
	if(0 in a):
		return 0
	tmp = [0 for i in range(n)]
	tmp[0] = a[0]
	for i in range(1, n):
		tmp[i] = tmp[i-1] * a[i]
		if(tmp[i] > 10**18):
			return '-1'
	
	return str(tmp[-1])

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

Submission status: Accepted

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


def main():
    import sys

    input = sys.stdin.readline

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if ls.count(0) > 0:
    result = 0
else:
    result = 1
    for i in ls:
        result *= i
        if result > 10 ** 18:
            result = -1
            break
print(result)

Submission status: Accepted

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

def main(ls):
    if ls.count(0) > 0:
        print(0)
        return
    result = 1
    for i in ls:
        result *= i
        if result > 10 ** 18:
            print(-1)
            return

    print(result)

main(ls)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_list_min = sorted(a_list)

ans = 1

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
limit = 10 ** 18

a = sorted(a, reverse=False)
ans = a[0]
for i in range(1, n):
    ans *= a[i]
#    logging.debug("i = {},a[i]= {},ans = {}".format(i,a[i],ans))#
    if ans > limit:
        print("-1")
        exit()
print(ans)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = 1
e = 0
for d in range(a):
  c = c * b[0]
  b.pop(0)
  if c > 1000000000000000000:
    print(-1)
    e = 1
    break
if e == 0:
  print(c)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
kazu = int(input())
word = input()
score = word.split()

maxn = 10**18
zero = 0
answer = 1
scin = [0]*kazu

for i in range(kazu):
    scin[i] = int(score[i])
    if scin[i] == 0:
        zero = 1
if zero == 1:
    answer = 0
else:
    for j in range(kazu):
        answer *= scin[j]
        if answer > maxn:
            answer = -1
            break
print(answer)

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 = [int(s) for s in input().split()]

ans = 1
if 0 in A:
    ans = 0
else:
    for a in A:
        ans *= a

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

count = 1

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

else:
    print(count)

Submission status: Accepted

Solution code:
import sys

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

if A[0] == 0:
    print(0)
    sys.exit()

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

Submission status: Accepted

Solution code:
import sys

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

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

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

print(ans)

Submission status: Accepted

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

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

if ans<=10**18:
    print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
prod = 1
for i in arr:
	prod *= i
	if prod>10**18:
		prod = -1
		break
print(prod)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
ans = 1
for val in b:
  ans *= val
  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 range(len(a)):
  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()))

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

Submission status: Accepted

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

print(p)

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return

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

main()

Submission status: Accepted

Solution code:
def func():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for item in A:
        prod *= item
        if prod > 1e18:
            print(-1)
            return
    print(prod)

func()

Submission status: Accepted

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

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

res = 1

for n in L:
    res *= n
    if res > 10**18:
        print(-1)
        exit()
    
print(res)

Submission status: Accepted

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

l = 1
for i in range(18):
    l *= 10

ans = 1

for A_ in A:
    ans *= A_
    if ans > l:
        ans = -1
        break

if 0 in A: ans = 0

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())
l = list(map(int,input().split()))
l.sort()
ans = 1
rec = True
for i in range(N):
    ans = ans * l[i]
    if ans > 10**18:
        rec = False
        break

if rec:
    print(ans)
else:
    print('-1')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Alst = list(map(int, input().split()))
ans = 1
rec = True
if 0 in Alst:
    print(0)

else:
    for i in range(N):
        ans = ans * Alst[i]
        if ans > 10**18:
            rec = False
            break

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

Submission status: Accepted

Solution code:
N = int(input())
Alst = list(map(int, input().split()))
Alst.sort()
ans = 1
rec = True
for i in range(N):
    ans = ans * Alst[i]
    if ans > 10**18:
        rec = False
        break

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

Submission status: Accepted

Solution code:
import sys

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

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

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

print(result)

Submission status: Accepted

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

ans = 1

for i in As:
    ans *= i
    ans = min(ans, 10**18 + 1)

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

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

Submission status: Accepted

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]

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

Submission status: Accepted

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

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

if __name__ == "__main__":
    resolve()

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 typing import Collection


def multply(nums: Collection[int]) -> int:
    if 0 in nums:
        return 0

    result = 1

    for i in nums:
        result *= i
        if result > 10**18:
            return -1

    return result

count_num = int(input())
nums = map(int, input().split())
print(multply(list(nums)))

Submission status: Accepted

Solution code:
from typing import Iterable


def multply(nums: Iterable[int]) -> int:
    if 0 in nums:
        return 0

    result = 1

    for i in nums:
        result *= i
        if result > 10**18:
            return -1

    return result

count_num = int(input())
nums = map(int, input().split())
print(multply(list(nums)))

Submission status: Accepted

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

if 0 in a:
    print(0)
else:
    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()))
if 0 in a:
    print(0)
    quit()
s = 1
for x in a:
    s *= x
    # pythonずるくない？
    if s > 1000000000000000000:
        print(-1)
        quit()
print(s)

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

def main():

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

    ans = 1

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

    else:
        ans = 0

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(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:
# abc169_b.py
# https://atcoder.jp/contests/abc169/tasks/abc169_b

# B - Multiplication 2 /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# N個の整数 A1,...,ANが与えられます。
# A1×...×ANを求めてください。
# ただし、結果が 1018を超える場合は、代わりに -1 を出力してください。

# 制約
#     2≤N≤10^5
#     0≤Ai≤10^18
#     入力は全て整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# A1 ... AN

# 出力
# 値 A1×...×ANを整数として出力せよ。ただし、この値が 10^18を超える場合は、代わりに -1 を出力せよ。

# 入力例 1
# 2
# 1000000000 1000000000

# 出力例 1
# 1000000000000000000
# 1000000000×1000000000=1000000000000000000です。

# 入力例 2
# 3
# 101 9901 999999000001

# 出力例 2
# -1

# 101×9901×999999000001=1000000000000000001ですが、これは 10^18を超えるので、代わりに -1 を出力します。

# 入力例 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

# 出力例 3
# 0


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 1
    if min(values) == 0:
        result = 0
    else:
        for value in values:
            result *= value
            if result > 10**18:
                result = -1
                break

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2', '1000000000 1000000000']
        lines_export = [1000000000000000000]
    if pattern == 2:
        lines_input = ['3', '101 9901 999999000001']
        lines_export = [-1]
    if pattern == 3:
        lines_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']
        lines_export = [0]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from decimal import Decimal
# input
n = int(input())
a = list(map(int, input().split()))
out = 1
if 0 in a:
    print(0)
    quit()
for i in range(n):
    out = Decimal(out * a[i])
    if out > Decimal(10**18):
        print(-1)
        quit()
print(out)

Submission status: Accepted

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

for i in range(n):
  ans*=a[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()))

flag = 0
for i in range(len(A)):
	if A[i]==0:
		flag =1

if flag == 1 :
	print("0")
else:
	x = 1
	for i in range(len(A)):
		x = x * A[i]
		if x > 10 ** 18:
			break
          
    
	if x > 10 ** 18:
		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

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

    print(ans)


main()

Submission status: Accepted

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

def f(A):
    for a in A:
        if a == 0:
            print(0)
            return
    v = 1
    for a in A:
        v *= a
        if v > int(1e+18):
            print(-1)
            return
    print(v)
    return

f(A)

Submission status: Accepted

Solution code:
import sys

n = int(input())
A = list(map(int,input().split()))
product = 1

if 0 in A:
    print(0)
    sys.exit()
else:
    for x in range(n):
        product = product*A[x]
        if product > 10**18:
            print(-1)
            sys.exit()

print(product)

Submission status: Accepted

Solution code:
def prod(a):
    if 0 in a:
        return 0
    p = 1
    for ai in a:
        if p * ai <= 10**18:
            p *= ai
        else:
            return -1
    return p

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

Submission status: Accepted

Solution code:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
n = inN()
a = inL()
if 0 in a:
    print(0)
    exit()

sum = 1
t = pow(10,18)
for i in range(n):
    sum *= a[i]
    if sum > t:
        print(-1)
        exit()
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
Ai = list(map(int, input().split()))
p = 1
i = 0
if 0 in Ai:
    print("0")
else:
    while i <= N - 1:
        p = p * Ai[i]
        if p > 10 ** 18:
            print("-1")
            break
        if i == N - 1:
            print(p)
            break
        i += 1