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:
# B  => TLE
n = int(input())
a = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
n = input()
ar = map(int, input().split(' '))

product = 1
exe = 1
maxP = 1000000000000000000

for val in ar:
    product *= val
    # print(product)
    if(product > maxP):
        product = -1
        break

for e in ar:
    if(e == 0):
        exe = 0

print(product * exe)
# print(exe)

Submission status: Accepted

Solution code:
N = int(input())
AS = [int(x) for x in input().split()]
result = 1
for x in AS:
    if x == 0:
        result = 0
        break
    if result == -1:
        continue
    result *= x
    if result > 10 ** 18:
        result = -1

print(result)

Submission status: Accepted

Solution code:
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

a = sys.stdin.readline().strip()
arr = list(map(int, sys.stdin.readline().strip().split()))
mod = 10**18

ans = arr[0]
for i in range(1, len(arr)):
    ans *= arr[i]
    if ans > mod:
        ans = -1
        break

if 0 in arr:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
N, = map(int, input().split())
X = sorted(list(map(int, input().split())))
R = 1
for x in X:
    if x == 0:
        print(0)
        break
    R*=x
    if R >10**18:
        print(-1)
        break
else:
    print(R)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import functools
import operator

prod2 = functools.partial(functools.reduce, operator.mul)

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

# val = prod2(nums)

val = 1
if 0 in nums:
    val = 0

else:
    for num in nums:
        val *= num
    
        if val > 1e18:
            val = -1
            break


print(val)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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


ans = 1
a.sort()

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A_i = list(map(int, input().split()))
    t = 10**18

    if 0 in A_i:
        print(0)
        return

    acc = 1
    for i in A_i:
        acc *= i
        if t < acc:
            print(-1)
            return

    print(acc)
    return


main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline

N = int(readline())
A = list(map(int, readline().split()))
A.sort(reverse=True)

if A[-1] == 0:
    print(0)
    exit()

for i, x in enumerate(A):
    if i == 0:
        result = x
        continue

    result = result * x

    if result > 10**18:
        print(-1)
        exit()

else:
    print(result)

Submission status: Accepted

Solution code:
n = int(input())
total = 1;
a = list(map(int, input().split()))
if 0 not in a:
    for i in a:
        total*=i
        if total>int(1e18):
            total = -1
            break
    print(total)
else: print(0)

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

Submission status: Accepted

Solution code:

def main():
    import sys
    import math
    def input():
        return sys.stdin.readline()[:-1]
    N=int(input())
    A=list(map(int,input().split()))
    c=1
    if 0 in A:
        print(0)
        sys.exit()
        
    for x in A:     
        c=c*x
        if c>10**18:
            print(-1)
            sys.exit()

    print(c)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

print(result)

Submission status: Accepted

Solution code:
n=int(input())
a=map(int,input().split())
val = 1
exceed = 0
for i in a:
	if(exceed==0 or i==0):
		val*=i
	if(val==0):
		print(0)
		exit(0)
	if(val>1000000000000000000):
		exceed=1
if(exceed==0):
	print(val)
else:
	print(-1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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 numpy as np
import math
n = int(input())
a= list(map(int,input().split()))
a.sort(reverse=1)

ans = a[0]

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

A.sort()
ans = 0

if A[0] == 0:
    print(ans)
    exit()

for i in A:
    if ans != 0:
        ans = ans * i
    else:
        ans = i
    if ans > 1000000000000000000:
        print("-1")
        exit()

print(ans)

Submission status: Accepted

Solution code:
N      = input()
A_list = list(map(int, input().split()))
answer = 1

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

Submission status: Accepted

Solution code:
N = int(input())
li = input().split()
a = 1
sikataganai = False
try:
  h = li.index('0')
  print(0)
  sikataganai = True
except:
  for i in range(N):
    a *= int(li[i])
    if a > 10 ** 18:
      print(-1)
      exit()
  if not sikataganai :
    print(a)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= A[i]
    if(ans > 1000000000000000000):
        if 0 in A:
            print("0")
            quit()
        else:
            print("-1")
            quit()
print(ans)

Submission status: Accepted

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

if A.count(0) > 0:
    print(0)
    sys.exit()
    
ans = 1
for i in range(N):
    ans *= A[i]
    # print("A[i] = {}, ans = {}".format(A[i], ans))
    if ans > 10 ** 18:
        print(-1)
        sys.exit()

print(ans)

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

Submission status: Accepted

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

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


print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
numlist = list(map(int, input().split()))
if 0 < numlist.count(0):
    print('0')
    quit()

total = 1
for i in numlist:
  total *= i
  if 10 ** 18 < total:
    print('-1')
    quit()

print(total)

Submission status: Accepted

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

v = 1
if 0 in a:
    print(0)
    exit()
for i in range(n):
    v *= a[i]
    if v > 1E18:
        print(-1)
        exit()
print(v)

Submission status: Accepted

Solution code:
def resolve():
    import numpy as np
    from decimal import Decimal

    n = int(input())
    A = np.array(list(map(Decimal, input().split())))
    if 0 in A:
        print(0)
        return

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

resolve()

Submission status: Accepted

Solution code:
import sys
N=int(input())
ans=1
numbers=input().split()
zero="0" in numbers
if zero:
  print(0)
  sys.exit()
for j in range(N):
  num=int(numbers[j])
  ans=ans*num
  if ans>1000000000000000000:
    print(-1)
    sys.exit()
print(ans)

Submission status: Accepted

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

for ele in a:
    ans *= ele
    if ans > MV :
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	list1 = [int(t) for t in input().split()]
	list1.sort()
	ans = 1
	b = 0
	for i in range (0, n):
		ans = ans * list1[i]
		if int(ans) > int(1000000000000000000):
			print(-1)
			return
	print(ans)
	return

if __name__ == "__main__":
  #Run as main program
  main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
MAX = 10**18
ret = 1
flag = True
if 0 in A:
    print(0)
else:
    for a in A:
        ret *= a
        if ret > MAX:
            print(-1)
            flag = False
            break
    if flag and ret <= MAX:
        print(ret)

Submission status: Accepted

Solution code:
import sys
N = input()
A = list(map(int,input().split()))
B = False
total = 1
for a in A:
    if a == 0:
        print(0)
        sys.exit()
    elif total <=10**18:
        total *= a
    else:
        B = True
if B or total>10**18:
    print(-1)
else:
    print(total)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int, input().split()))
if 0 in arr:
  print("0")
else:
  done=False
  mul=1
  for i in range(len(arr)):
    if mul*arr[i]<=int(1e18):
      mul*=arr[i]
    else:
      print("-1")
      done=True
      break
  if not done:
    print(mul)

Submission status: Accepted

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

b=a[0]
if a.count(0)>0:
    print(0)
    sys.exit()

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

print(b)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.readline
n = int(input())
aaa = list(map(int, read().split()))
aaa.sort()
ans = 1
for a in aaa:
    ans *= a
    if ans == 0:
        break
    if ans > 10 ** 18:
        ans = -1
        break
print(int(ans))

Submission status: Accepted

Solution code:
import math
import fractions
import collections
import itertools
N=int(input())
A=list(map(int,input().split()))
A.sort()
#A=[10**5]*(10**5)
#N=10**5
ans=1
flag=1
for i in range(N):
    ans=ans*A[i]
    if ans>10**18:
        flag=0
        break
if flag==1:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
N = int(input())

A_str = input().split()

A = []

for Ai_str in A_str:
    Ai = int(Ai_str)

    if Ai == 0:
        print(0)
        exit()

    A.append(Ai)

product = 1

for Ai in A:
    product *= Ai

    if product > 1000000000000000000:
        print(-1)
        exit()

print(product)

Submission status: Accepted

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

work = 1
exceeded = False
for i in a:
    work *= i
    if work > 1000000000000000000:
        exceeded = True
        break

if work > 1000000000000000000:
    exceeded = True

if exceeded:
    print(-1)
else:
    print(work)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys 
input = lambda : sys.stdin.readline().strip()
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    ans = 1
    ok = True
    for i in range(n):
        ans*=a[i]
        if ans>(10**18):
            ok = False
            break
    if ok:
        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)
else:
    for i in range(N):
        ans = 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 a.count(0) > 0:
    print(0)
    exit()
for i in a:
    ans = ans * i
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
s=input().split()
if '0' in s:
  print(0)
  sys.exit()
l=list(map(int,s))
max=10**18
ans=1
while n>0:
  ans *= l[n-1]
  n-=1
  if ans>max:
    print(-1)
    sys.exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans,flag = 1,0
for elem in sorted(arr):
    ans = ans*elem
    if ans>1e18:
        flag = 1
        break
    if ans==0: break
    
if flag==1: print(-1)
else: print(ans)

Submission status: Accepted

Solution code:
n = int(input())
up = int("1"+"0"*18)

a = list(map(int, input().split()))
ans = a[0]

def calc(a):
    x = ans
    for i in range(1, len(a)):
        x = x * a[i]

        if (x > up):
            x = -1
            return x

    return x

if (0 in a):
    ans = 0
else:
    ans = calc(a)

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())
if 0 in a:
    print('0')
    exit()
ans = 1
for x in a:
    ans = ans * x
    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 ans>10**18:
      print(-1)
      break
    elif i==n-1:
      print(ans)

Submission status: Accepted

Solution code:
import sys

t = 10**18


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

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

ans = 1
for i in range(n):
    ans = ans*li[i]
    if ans > t:
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(input())
ans = 1
ass = input().split(" ")

for b in ass:
	a = int(b)
	if ans == -1:
		if a == 0:
			ans = 0
	else:
		ans *= a
		if ans > 1000000000000000000:
			ans = -1;
		
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans = int(1)
flag = True

for i in a:
    if i == 0:
        print(0)
        flag = False

if flag:
    for i in range(n):
        ans = ans * a[i]
        if ans > int(1000000000000000000):
            flag  = False
            break

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

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int,input().split()))
res = 1
flag = 0
if 0 in arr:
  print("0")
  flag = 1
if not flag:
  for i in range(n):
    res *= arr[i]
    if res>1000000000000000000:
      print("-1")
      flag = 1
      break
if not flag:
  print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
num = input().split()
ans = int(num[0])
cov = 10**18
if ('0' in num):
  ans = 0  
else:
  for i in range (int(N)-1):
    if ans == -1 or ans == 0:
      break
    else:
      ans *= int(num[i+1])
    if int(ans) > int(cov):
      ans = -1
print(ans)

Submission status: Accepted

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

print(-1 if x>10**18 else x)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from collections import deque as deq

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

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

r = 1
l = 10**18
for a in A:
    r *= a
    if r > l:
        r = -1
        break

print(r)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
#a, b = map(int, input().split())
#x, y, z = map(int, input().split())
#a, b, h, m = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
p = 1
if 0 in arr:
	print(0)
else:
	for i in reversed(arr):
		p *= i
		if p > (10**18):
			print(-1)
			exit()
	print(p)

Submission status: Accepted

Solution code:
def b():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    max = 10**18
    if 0 in A:
        print(0)
        return

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

    print(ans)


##########
if __name__ == "__main__":
    b()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
      
n = int(input())
la = list(map(int, input().split()))
import sys
if my_index(la, 0) > 0:
  print(0)
  sys.exit()

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

Submission status: Accepted

Solution code:
n = int(input()) 
a = list(map(int,input().strip().split()))[:n]
pro=1
f=1
a.sort()
for i in a:
  pro=pro*i
  if(pro>1000000000000000000):
    f=0
    print(-1)
    break
if(f==1):
  print(pro)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
lst = list(map(int, readline().split()))
lst.sort()
lst.reverse()
mul = 1
if 0 in lst : 
  print(0)
else :
  for x in lst :
 #   print(x,mul)
    if(mul>10**18):
      mul = -1
      break
    mul*=x

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

  print(mul)

Submission status: Accepted

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

LIMIT = 10 ** 18

zeroflg = 0
for a in A:
    if a == 0:
        zeroflg = 1
        break

if zeroflg == 1:
    res = 0
else:
    res = 1
    for a in A:
        if a == 0:
            res = 0
            break
        if res > LIMIT:
            break
    
        res = res * a

# res = math.exp(sum([math.log(a) for a in A]))

# X = np.array(A)
# res = X.prod()
#
# print(X)

# for a in A:
#     math.log(a)
#
#     res = res * a

if res > LIMIT:
    print('-1')
else:
    print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
flag_over = False
flag_0 = False
len0 = 0

if 0 in A:
    flag_0 = True
for b in B:
    len0 += len(b) - 1
if len0 > 18:
    flag_over = True

if flag_0 == False and flag_over == 0:
    for a in A:
        ans *= a

if ans > 10**18:
    flag_over = True

if flag_0:
    print(0)
elif flag_over:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
s = 1
f = 1
x = 1000000000000000000
l.sort()
if l[0]==0:
  print(0)
elif l[0]==1 and l[-1]==1:
  print(1)
else:
  l = l[::-1]
  for i in l:
      s *= i
      if s>x:
          print(-1)
          f = 0
          break
  if f==1:
    print(s)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

for i in range(0,n):
    if data[i] == 0:
        ans = 0

for i in range(0,n):

    ans *= data[i]

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

Submission status: Accepted

Solution code:
def main():
    if A.count(0) >= 1:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > L:
            print(-1)
            return
    print(ans)


if __name__ == "__main__":
    N = int(input())
    A = [int(a) for a in input().split()]
    L = 10**18
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(" ")
s = 1

for i in range(N):
  if int(A[i]) == 0:
    s = 0

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans=1

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

print(ans)

Submission status: Accepted

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

Con = 10**18

ans = 1
if A.__contains__(0):
    print(0)
else:
    for i in A:
        if ans <=Con:
            ans*=i
        else:
            break
    print(ans if ans<=Con else "-1")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
if 0 in a:
  print(0)
  exit()
for aa in a:
  if aa>10**18:
    print(-1)
    exit()
ans=a[0]
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 = input()
l = [int(each) for each in input().split()]
if 0 in l:
    print(0)
else:
    result = 1
    for each in l:
        result *= each
        if result > 1000000000000000000:
            result = -1
            break
    print(result)

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


ans = 1
for i in range(n):
    ans *= A[i]
    if ans > 1e18:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 1

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

Submission status: Accepted

Solution code:
import sys

n=int(input())
a=list(map(int,input().split()))
x=1
if 0 in a:
    print(0)
    sys.exit()

for i in range(len(a)):
    x=a[i]*x
    if x>10**18:
        print(-1)
        sys.exit()
print(x if x<=10**18 else -1)

Submission status: Accepted

Solution code:
N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
if 0 in L_A:
    print(0)
else:
    k = 1
    for i in range(N):
        k *= L_A[i]
        if k > 10**18:
            print("-1")
            break
    else:
        print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def main():

    test = int(input())
    inp = input().split(' ')
    inp = sorted(inp)
    p=1;
    for x in inp:
        p = p*int(x)
        if p> 10**18 or p==0:
            break;
    
    if(p>10**18):
        print(-1);
    else:
        print(p);

        
        

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import numpy as np

N = int(input())
A = list(map(int,input().split()))
ans = 1
A_log = A
try:
    A_log = list(map(math.log10,A))
except ValueError:
    print(0)
else:
    if sum(A_log) > 18:
        print(-1)
    else:
        for i in A:
            ans *= i
        if ans <= 1e18:
            print(ans)
        else:
            print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)