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()))
sum  = 1
flag = 0
for i in A:
    if(i == 0):
        print(0)
        flag=2
        break
if(flag==0):
    for i in A:
        sum = sum * i
        if(sum > 10**18):
            flag=1
            break
if(flag==0):
    print(sum)
elif(flag==1):
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = input().split()
ans = 1
T = True
for i in range(n):
    if l[i] == '0':
        ans = 0
        break
if ans != 0:
    for i in range(n):
        if ans <= 10**18:
            ans = ans * int(l[i])
        else:
            T = False
            break
if False:
    print(-1)
elif ans > 10**18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

L = 10 ** 18

N = int(input())
A = [N]
A = list(map(int, input().split()))
ans = 1
for i in A:
    if i == 0:
        ans = 0
        break
    elif ans == -1:
        continue
    elif ans * i > L:
        ans = -1
    else:
        ans *= i

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(input().split())

Af =  np.array(A,dtype='float64')
Afans = np.prod(Af,dtype='float64')

if Afans == 0.:
    print('0')
elif Afans >=2e18:
    print('-1')
else:
    Ai =  np.array(A,dtype='int64')
    Aians = np.prod(Ai,dtype='int64')
    if Aians <=np.int64(1e18) and Aians >=np.int64(0):
        print(Aians)
    else:
        print("-1")

Submission status: Accepted

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

multi = 1
a = 1

for i in range(n):
    if n_list[i]==0:
        a = 0
        break

for i in range(n):
    if a == 0:
        multi = 0
        break

    multi *= n_list[i]

    if multi>1e18:
        break

if multi<=1e18:
    print(multi)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

for i in range(0,len(b)):
    b[i]=int(b[i])



state=1
for x in b:
    if x==0:
        state=0
        print("0")
        break

res=1
if state==1:
    for x in b:
        res*=x
        if res>1000000000000000000:
            print("-1")
            state=0
            break

if state==1:
    print(res)

Submission status: Accepted

Solution code:
import sys
n = int(input())
l = list(map(int,input().split()))
if 0 in l:
  print(0)
  sys.exit()
flag = True
anz = 1
for i in l:
  anz *= i
  if anz > 1000000000000000000:
    flag = False 
    break
print (anz if flag else -1)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
y = 1
x.sort()
for i in range(n):
  y *= x[i]
  if y > 1000000000000000000:
     y = -1
     break

print(y)

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 a in A:
        ans *= a
        if ans > pow(10, 18):
            print(-1)
            return
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin, stdout  
  
# suppose a function called main() and 
# all the operations are performed 
def main(): 
  
    # input via readline method 
    n = stdin.readline() 
  
    # array input similar method 
    arr = [int(x) for x in stdin.readline().split()] 
  
    #initialize variable 
    summation = 1
    for x in arr:
        if x==0:
            summation=0
            break
    # calculate sum 
    for x in arr: 
        summation *= x
        if summation>1e18:
            summation=-1
            break
  
    # could use inbuilt summation = sum(arr) 
    if summation>1e18:
        print("-1");
    else:
        print(summation);


    # print answer via write 
    # write method writes only 
    # string operations 
    # so we need to convert any 
    # data into string for input 
    
  
# call the main method 
if __name__ == "__main__": 
    main()

Submission status: Accepted

Solution code:
import sys

N = int(input().rstrip())

limit = pow(10, 18)

nums = list(input().split())

for num in nums:
    num = int(num)
    if num == 0:
        print(0)
        sys.exit(0)

accum = 1
for num in nums:
    num = int(num)
    try:
        accum *= num
    except Exception:
        accum = -1
        break

    if accum > limit:
        accum = -1
        break

print(accum)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
if 0 in A:
    print(0)
    exit(0)
res = 1
for i in A:
    res *= i
    if(res > 1000000000000000000):
        print(-1)
        exit(0)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import sys

n = int(input())
a = [list(map(int,input().split())) for i in range(1)]
arr = a[0]
list.sort(arr, reverse=True)

if arr[-1] == 0:
    print(arr[-1])
    sys.exit()

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

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int, input().split()))
li_k = list(map(lambda n: len(str(n))-1, li))

if 0 in li:
    print(0)
elif sum(li_k) > 18:
    print(-1)
else:
    ans = li[0]
    for i in li[1:]:
        ans *= i
        if ans > 1000000000000000000:
            break
    if ans > 1000000000000000000:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = 1
f = 0
a.sort()
for i in range(n):
    #print(a[i])
    x = x*a[i]
    if x == 0:
        print(0)
        f = 1
        break
    elif x > 1000000000000000000:
        print(-1)
        f = 1
        break
if f == 0:
    print(x)

Submission status: Accepted

Solution code:
n=int(input())
ans=1
zero=False
minus=False
li = input().split()
for i in li:
  a=int(i)
  if a==0:
    zero=True
    break
  if minus:
    continue
  ans*=a
  if ans>1000000000000000000:
    minus=True

if minus:
  ans=-1
if zero:
  ans=0
print(ans)

Submission status: Accepted

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

b1=1
b2=0
b3=0

if 0 in a:
  print(0)
else:
  for i in range(n):
    b1*=a[i]
    b2*=a[i]
    if b1>=10**9:
      b2+=b1//(10**9)
      b1%=10**9
    if b2>=10**9:
      b3+=b2//(10**9)
      b2%=10**9
      break
  
  if b3>=1 and (b1!=0 or b2!=0):
    print(-1)
  else:
    print(b3*(10**18)+b2*(10**9)+b1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
nums = [int(e) for e in input().split()]
g = 1;
for a in nums:
  if a == 0:
    print("0");
    sys.exit()
for i in nums:
  g*=i;
  if g>1000000000000000000:
    print("-1")
    sys.exit()
print(g)

Submission status: Accepted

Solution code:
import sys

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

if a[0] == 0:
    print(0)
else:
    ans = 1
    while a:
        ans *= a.pop()
        if ans > 10**18:
            print(-1)
            sys.exit()
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = sorted([int(x) for x in input().split()], reverse=True)

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

ans = 1
s = 10 ** 18
for a in a_list:
    ans *= a
    if ans > s:
        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()
ans = 1

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def aaa(a_list):
    ans = 1
    for i in a_list:
        ans = ans * i
        if ans > 10**18:
            return -1
    return ans

N = input()
a = input().split()
a = [int(i) for i in a]

if 0 in a:
    print(0)
else:
    print(aaa(a))

Submission status: Accepted

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

import sys
import numpy as np

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

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

a = [s for s in aa if s != 1]
a.sort(reverse=True)

# keta = 0
# for item in a:
#     k = len(str(item))
#     keta += k-1
#     if keta>18:
#         print(-1)
#         sys.exit()

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

# arr = np.array(a)
# ans = arr.prod()
# if ans>10**18:
#     print(-1)
#     sys.exit()

print(prod)

Submission status: Accepted

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

a = sorted(a)
ans = a[0]
tmp = 0


for i in range(n-1,0,-1):
    ans = ans * a[i]
    if ans > check:
        tmp  = 1
        break
    elif a[0] == 0:
        tmp = 2
        break

if tmp == 1:
    print('-1')
elif tmp == 0:
    print(ans)
elif tmp == 2:
    print('0')

Submission status: Accepted

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

while ans <= 10**18 and i < N:
  ans *= A_n[i]
  i +=1
if ans > 10**18:
  if 0 in A_n:
    print(0)
  else:
    print(-1)
else:
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    _ = int(input())
    a = list(map(int, input().split()))
    res = 1
    for x in a:
        if x == 0:
            print(0)
            return
    for x in a:
        res *= x
        if res > int(1e18):
            print(-1)
            return
    print(res)


solve()

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int,input().split()))
c = int(As[0])
i = 0
f = True
if 0 in As:
  print("0")
else:
  for x in As:
    if i == 0:
      i += 1
      continue
    c = c * x 
    if 1000000000000000001 <= c:
      print("-1")
      f = False
      break
  if f:
    print(c)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

n = int(input())
a = list(map(int, input().split()))
ans = 1
flag = True

for ta in a:
    ans *= ta
    if (ans > 10 ** 18):
        flag = False
        ans = 1

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

Submission status: Accepted

Solution code:
import sys

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

ans = 1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N    = int(input())
A    = input().split()
Pro  = 1
PrF  = 1
PrFF = 1

if '0' in A:
    print(0)
    PrF = 0
    
if PrF:
    for T in range(0,len(A)):
        if int(A[T]) == pow(10,18):
            PrFF = 0
            print('-1')
            break
        else:
            Pro = Pro*int(A[T])
            if Pro > pow(10,18):
                PrFF = 0
                print('-1')
                break

if PrF & PrFF:
    print(Pro)

Submission status: Accepted

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

ans = a_list[0]
count = a_list.count(0)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a1=sorted(a,reverse=True)
a2=sorted(a)
ans=1
if len(a)<90:
    for i in range(len(a)):
        ans*=a[i]

else:
    if a2[0]==0:
        ans=0
    elif a1[90]>1:
        ans=-1
    else:
        del a1[90:]
        for i in range(len(a1)):
           ans*=a1[i]
if ans>10**18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

else:
  for a in A:
    X*=a
    if X>=1000000000000000001:
      print(-1)
      break
  else:
    print(X)

Submission status: Accepted

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

Submission status: Accepted

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

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

answer = 1
for _ in A:
    answer *= _
    if answer > 1000000000000000000:
        print('-1') 
        exit()

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
check = [i for i in A if i == 0]
if 0 in check:
    print(0)
else:   
    A.sort(reverse=True)
    work = 1
    for a in A:
        work *= a
        if work > 10**18:
            print('-1')
            break
    else:
        print(work)

Submission status: Accepted

Solution code:
n = map(int, input().split())
a = list(map(int, input().split()))
flag0 = False
flag1 = False
b = 1
for e in a:
    if e == 0:
        flag0 = True

    if b * e > 1000000000000000000:
        b = 0
        flag1 = True

    b *= e

if flag0 == True:
    print(0)
elif flag1 == True:
    print(-1)
else:
    print(b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    for x in a:
        if x==0:
            print(0)
            return

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

    print(ans)

solve()

Submission status: Accepted

Solution code:
N = int(input())
arr = sorted(map(int, input().split()))
INF = 10 ** 18
ans = 1
for num in arr:
    ans *= num
    if ans > INF:
        ans = -1
        break
    elif ans == 0:
        break

print(ans)

Submission status: Accepted

Solution code:
'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

n = int(input()) 
  
a = list(map(int,input().strip().split()))[:n] 
x=1
flag=0
flag1=0
for i in range(n):
    if a[i]==0:
        x*=0
        flag1=1
        break
if flag!=1: 
    for i in range(n):
        if x*a[i]>1000000000000000000:
            flag=1
            break
        else:
            x*=a[i]
        
if flag1==1:
    print(0)
elif flag==1:
    print(-1)
else:
    print(x)

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 = 1
for a in sorted(A, reverse=True):
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

line = input().rstrip()
N = int(line)
line = input().rstrip()
line = line.split(' ')
mult = 1

numbers = []
for i in range(N):
    numbers.append(int(line[i]))
numbers.sort()

if numbers[0] == 0:
    mult = 0
else:
    for A in numbers:
        if math.log10(mult) + math.log10(A) > 18.0:
            mult = -1
            break
        mult = mult * A
        if mult > 10**18:
            mult = -1
            break

print(mult)

Submission status: Accepted

Solution code:
N = int(input())
numbers = [int(n) for n in input().split()]
mlt = 1
if 0 in numbers:
    print(0)
else:
    for n in numbers:
        mlt *= n
        if mlt > 1000000000000000000:
            mlt = -1
            break
    print(mlt)

Submission status: Accepted

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

s = 1
for i in range(N):
    if mlist[i] == 0:
        print(0)
        s = 0
        break
    elif s > 0:
        s *= mlist[i]

    if s > 10 ** 18:
        s = -1
if i == N-1 and s != 0:
    print(s)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()
out = 1
for d in data:
    out *= int(d)
    if out > 10**18:
        out = -1
        break

if '0' in data:
    print(0)
else:
    print(out)

Submission status: Accepted

Solution code:
import sys

n = input()
A = sorted([int(x) for x in input().split()], reverse=True)

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

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

print(product)

Submission status: Accepted

Solution code:
N = int(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
answer = A[0]

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

x = 10**18
ans = 1
for a in A:
    if ans != -1:
        ans *= a
    if ans > x:
        ans = -1
    if a == 0:
        ans = 0
        break
print(ans)

Submission status: Accepted

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

mul=1
i=0

if 0 in p:
  print(0)
else:
  while mul<=1000000000000000000 and i!=n:
    mul=mul*p[i]
    i+=1
  if mul>1000000000000000000 or i!=n:
    print(-1)
  else:
    print(mul)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

N = int(input())
A = map(int, input().split())
res = int(1)
Lim = int(1000000000000000000)
#print(Lim)
for X in A:
    #print(X)
    if X == 0:
        res *= X
        continue
    if res > Lim:
        continue
    res *= X
if res > Lim:
    print(-1)
else:
    print(res)

Submission status: Accepted

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

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


ans = 1
over = 10**18

for num in nums:
    ans = ans * num

    if ans > over:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

kosuu = int(input())
arr = list(map(int, input().split()))

hoge =1

if 0 in arr:
    print(0)

else:
    for num in arr:
        hoge = hoge*num
        if hoge>1000000000000000000:
            print(-1)
            kosuu=0
            break
    if kosuu>0:
        print(hoge)

Submission status: Accepted

Solution code:
# coding: utf-8

#import numpy as np

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

thr = 10**18

res = 1

if 0 in A:
    res = 0
else:
    for a in A:

        res *= a

        if res > thr:
            res = -1
            break

print(int(res))

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):
        a = A[i]
        for j in range(19):
            if a <= 10**j:
                m = j
                break
        for k in range(19):
            if ans <= 10**k:
                n = k
                break
        if(m+n > 19):
            print(-1)
            break
        elif(ans*a == 10**18):
            ans = ans*a
        elif(ans*a > 10**18):
            print(-1)
            break
        else:
            ans = ans*a
        if i == N-1:
            print(ans)

Submission status: Accepted

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

	if(ans != -1):
		ans *= i
	if(i == 0):
		ans = 0
		break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = [int(x) for x in input().split()]
res = 1
flag = False
for i in range(n):
    if flag == False:
        res *= arr[i]
    if arr[i] == 0:
        print(0)
        exit()
    if res > 10**18:
        flag = True
if res > 10**18:
    print(-1)
else:
    print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
A_str = input().split()
A_array = map(int, A_str)

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

res = 1
for A in A_array:
    res *= A
    if res > 10 ** 18:
        res = -1
        break

print(res)

Submission status: Accepted

Solution code:
MAX = 10 ** 18

N = int(input())
liste = list(map(int, input().split()))
res = 1 
for i in range(N):
    if(liste[i] == 0):
        print(0)
        exit(0)

for i in range(N):
    res *= liste[i]
    #print(res, liste[i])
    if(res > MAX):
        print(-1)
        exit(0)

if(res > MAX):
    print(-1)
else: 
    print(res)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba
#import math

def run():
    N = int(input())
    A = list(map(int, input().split()))
    limit = 10 ** 18
    ret = 1
    if 0 in A:
        print(0)
        return None
    for a in A:
        ret *= a
        if ret > limit:
            print('-1')
            return None
    print(ret)



if __name__ == "__main__":
    run()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin, stdout 
def main(): 
	n = stdin.readline() 
	arr = [int(x) for x in stdin.readline().split()] 
	ok = 0
	pro = 1 
	INF = 1e18
	for x in arr:
		if(x == 0):
			ok = 1
	if(ok==1):
		return 0 
	else:
		for x in arr:
			pro = pro*x ;
			if(pro > INF):
				return -1
	return pro
# call the main method 
if __name__ == "__main__": 
	ans = main()
	stdout.write(str(ans))

Submission status: Accepted

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

reg = A[0]
flg=True
if 0 in A:
    print(0)
    flg=False
    reg=0
for i in range(1, N):
    reg *= A[i]
    if reg>10**18:
        print(-1)
        flg=False
        break
if flg:
    print(reg)

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 numpy 
n = int(input())
a = list(map(int,input().split()))
re = 1
if 0 in a:
    print("0")
else:
    for i in a :
        re = re * i
        if re > 1000000000000000000:
            print("-1")
            quit()
    print(re)