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()))
ans=1
for i in range(n):
  if A[i]==0:
    print(0)
    exit()
for i in range(n):
  if len(str(A[i]))>19:
    print(-1)
    exit()
  ans*=A[i]
  if ans>10**18:
    print(-1)
    exit()
print(ans)

Submission status: Accepted

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

Ans=1
if As.count(0):
    print(0)
    exit()
else:
    for A in range(N):
        if Ans>10**18:
            Ans=-1
            print(Ans)
            exit()
        else:
            NewAns=Ans*As[A]
            Ans=NewAns
    if Ans>10**18:
        Ans=-1
    
    print(Ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 1
a.sort()
for i in range(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 = 1000000000000000000
res = 1

A.sort(reverse=True)

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

for val in A:
    res = res * val
    if res > x:
        print('-1')
        break
else:
    print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
total = 1

if a.count(0) > 0:
    print(0)
else:
    for num in a:
        total *= num
        if total > 1000000000000000000:
            total = -1
            break
    print(total)

Submission status: Accepted

Solution code:
from sys import stdin

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

ans = 0

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

print(ans)

Submission status: Accepted

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

print(B(N,A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import operator
from functools import reduce

def main():
    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)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

if flag == 0:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
border = 1000000000000000000

N = int(input())
nums = list(map(int, input().split()))
if 0 in nums:
    print(0)
    exit()

result = 1
for n in nums:
    result = result * n
    if result > border:
        print(-1)
        exit()
print(result)

Submission status: Accepted

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

def judge(A):
  for i in range(len(A)):
    if A[i] == 0:
      print(0)
      return
  result = 1
  for i in range(N):
    result = result * A[i]
    if result > 1000000000000000000:
      print(-1)
      return
  if result <= 1000000000000000000:
    print(result)
    return
  
judge(A)

Submission status: Accepted

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
     
a = 1
if 0 in num_list:
    print(0)
else:
    for x in num_list:
        a = a * x
        if (a > 1000000000000000000):
            print("-1")
            break
    if (a <= 1000000000000000000):
      print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = int(input())
y = list(map(int, input().split(" ")))
s = 1
hoge = False
for i in y:
    if i ==0:
        print(0)
        hoge = True

def f():
    s = 1
    for i in y:
        s *= i
        if s>10**18:
            print(-1)
            return
    print(s)
if not hoge:
    f()

Submission status: Accepted

Solution code:
n=int(input())
a_list=list(map(int,input().split()))
num1=a_list.count(1)
import functools
import operator
if 0 in a_list:
    print("0")
elif n > 60+num1:
    print("-1")
else:
    p = functools.reduce(operator.mul, a_list)

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
buf = list(map(int,input().split()))
cnt = 1
flag = True
for i in range(N) :
    if buf[i] == 0 :
        print(0)
        exit()
for i in range(N) :
    cnt = cnt * buf[i]
    if cnt > 10 ** 18 :
        flag = False
        break

if flag == True :
    print(cnt)
else :
    print("-1")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

ans = 1
for i in li:
    if(i == 0):
        ans = 0

for i in li:
    ans *= i
    if(ans > 1000000000000000000):
        ans = -1
        break
    
print(ans)

Submission status: Accepted

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

A = sorted(A)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

limit = pow(10,18)

f = 0
for i in range(N):
    if A[i] != 0 and f == 0:
        ans *= A[i]
    elif A[i] != 0:
        pass
    else:
        print(0)
        exit()

    if ans > limit:
        f = 1

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

Submission status: Accepted

Solution code:
N=int(input())

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

mul = 1
for i in A:
    mul = mul * i
    if mul > 10 ** 18:
        mul = -1
        break

if 0 in A:
    mul = 0

print(mul)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().strip().split()))
ans = 1
can = 1
for i in range(0, n):
  if a[i] == 0:
    can = 2
if can != 2:
  for i in range(0, n): 
    ans = ans * a[i]
    if ans > 1000000000000000000:
      can = 0
      break
if can == 2:
  print("0")
elif can == 1:
  print(ans)
else : 
  print("-1")

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

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

cnt = 1
if 0 in a:
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
n = int(input())
numbers = [ int(i) for i in input().split()]
if 0 in numbers:
    print(0)
else:
    result = 1

    max = 10**18
    for i in range(n):
        result *= numbers[i]    
        if result > max:
            break


    if result > max:
        print(-1)
    else:
        print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
N = int(input())
#開業されたN個要素を受け付ける
#input_list = [int(input()) for i in range(N)]
input_org = input()
keta = input_org.replace(' ', '')
input_list = list(map(int, input_org.split()))
ans = 1
#print(input_list)
#print( 0 in input_list)
if (0 in input_list):
    ans = 0
elif len(keta) - N > 20:
    ans = -1
else:
    for input in input_list:
        ans = ans*input
        if ans > 1000000000000000000:
            ans = -1

print(ans)

Submission status: Accepted

Solution code:
import math
n= int(input())

l = list(map(int,input().split()))
l.sort(reverse = True)

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

Submission status: Accepted

Solution code:
import sys

N = int(input())

Line = [int(s) for s in input().split()]
Line.sort()

ans = 1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if az>0:
    print(0)
else:
    for i in range(len(a)):
        ans*= a[i]
    
        if ans>=1000000000000000001:
            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 a:
        ans *= i
        if ans > 10 ** 18:
            print(-1)
            exit()

    print(ans)

Submission status: Accepted

Solution code:

# number of elements 
n = int(input()) 
  
# Below line read inputs from user using map() function  
a = list(map(int,input().strip().split()))[:n] 
  
mask = 1;
flag = 0;
for num in a:
    if(num == 0):
            flag = 1
mask = 1;
flagex  = 0;
if(flag == 1):
    print(0)
else:
    for num in a:
        mask *= num;
        if(mask > 1000000000000000000):
            flagex = -1;
            break;
    if(flagex == -1):
        print(-1);
    else:
        print(mask);

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
ans=a[0]
for i in a:
    if i==0:
        print(0)
        exit()
for i in a[1:]:
    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()))
A.sort()
ans = A[0]
INF = 1000000000000000000
for i in range(1,n):
    l,r = len(str(ans)),len(str(A[i]))
    if l+r > 21:
        ans = -1
        break
    else:
        ans = ans * A[i]
        if ans > INF:
            ans = -1
            break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
List = list(map(int,input().split()))
ans = 1
for item in List:
  ans *= item
  if ans > 10 **18 or ans <= -1:
    ans = -1
print(ans)

Submission status: Accepted

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

ans = l[0]

minn = min(l)

if (minn == 0):
    print(0)
else:
    for i in range(1,len(l)):
        ans = ans * l[i]

        if ans >= 1000000000000000001:
            break
    
    if ans >= 1000000000000000001:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

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

ans=1

if a.count(0)>=1:
  ans=0
else:
  for i in a:
    ans*=i
    if ans>10**18:
      ans=-1
      break

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

N = int(input())
A = list(map(int, input().split()))
#A = np.array(A)
ans = 1
c = 1
for i in range(N):
    ans = ans*A[i]
    if ans > 10**18:
        #print("{}".format(-1))
        c=0
        break

if c==1:
    print("{}".format(ans))
elif c==0:
    if 0 in A:
        print("{}".format(0))
    else:
        print("{}".format(-1))

Submission status: Accepted

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

if 0 in lista:
    ans = 0
else:
    lista.sort(reverse=True)
    for i in range(n):
        ans *= lista[i]
        if(ans > limitNumber):
            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:
    mul=1
    for a in A:
        mul*=a
        if mul>10**18:
            print(-1)
            exit()
    print(mul)

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 a in A_list:
        ans=ans*a
        if ans>10**18:
            ans=-1
            break
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

num_data = sys.stdin.readlines()
str_num_list = num_data[1].split()
num_list = [int(s) for s in str_num_list]
ans = 1
if 0 in num_list:
  ans = 0
else:
  for i in range(int(num_data[0])):
    ans *= num_list[i]
    if ans > pow(10, 18):
      ans = -1
      break

print(ans)

Submission status: Accepted

Solution code:

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

t = 1
ans = 1
count = 0

if 0 in A:
    ans = 0
else:  
    for a in A:
        ans *= a
        t *= a
        while t >= 10:
            t /= 10
            count += 1
            if count >= 19:
                ans = -1 
                break

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

Submission status: Accepted

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

ans = 1

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

print(ans)

Submission status: Accepted

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

a.sort()
if a[0]==0:
  print(0)
  
else:
  s=1
  for i in a:
    s*=i
    if s>10**18:
      print(-1)
      exit()
      
  print(s)

Submission status: Accepted

Solution code:
import sys
n=int(input())
data=list(map(int,input().split()))
num=1
if any(i==0 for i in data):
    print(0)
    sys.exit()
else:
    for i in data:
        num*=i
        if 10**18<num:
            print(-1)
            sys.exit()
print(num)

Submission status: Accepted

Solution code:
import sys

N = int(input())

As = [int(n) for n in input().split()]
As_set = set(As)

limit = 10**18

prod = 1

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

over = False
for A in As:
    prod *= A
    if prod > limit:
        print(-1)
        sys.exit(0)

print(prod)

Submission status: Accepted

Solution code:
n=int(input())
a_list=list(map(int, input().split()))
multi_sum=1
LIMIT=1000000000000000000

if 0 not in a_list:
    for a_i in a_list:
        multi_sum*=a_i
        if multi_sum > LIMIT:
            multi_sum=-1
            break
else:
    multi_sum=0

print(multi_sum)

Submission status: Accepted

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

a = sorted(a)

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

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

Submission status: Accepted

Solution code:


n=int(input())
arr=list(map(int,input().split()))
arr.sort()
ans=1
v=True
for i in arr:
    ans=ans*i
    if ans==0:
        v=False
        print(0)
        break
        
    if ans>1000000000000000000:
        v=False
        print(-1)
        break

if v:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

a.sort()

if a[0] == 0:
    print(0)
    exit()

total = a[0]

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

Submission status: Accepted

Solution code:
def iput(): return int(input())
def mput(): return map(int, input().split())
def lput(): return list(map(int, input().split()))
 
def solve():
    n = iput()
    a = lput()
    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)
    return 0
 
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split(" ")))
l.sort();
t=1000000000000000000
at=1;
f=True;
for x in l:
  at=at*x;
  if(at>t):
    f=False
    break
if(f):
  print(at)
else:
  print(-1)

Submission status: Accepted

Solution code:
#ABC169b

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

sum = 1

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

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

Submission status: Accepted

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

if A.count(0) != 0:
    print(0)
    sys.exit()

for i in A:

    ans = ans*i
    if ans > int(10**18):
        print(-1)
        sys.exit()
 
if ans > int(10**18):
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lim = 10**18
ans,exc = 1,False
a = list(map(int,input().split()))
# print(a)
if 0 in a:
  print(0)
else:
  for x in a:
    ans *= x
    if ans > lim:
      exc = True
      print("-1")
      break
  if not exc:
    print(ans)

Submission status: Accepted

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

# ans = np.prod(num_list)
ans = num_list[0]
for i in range(1, N):
    if ans > 10**18:
        break
    ans *= num_list[i]


if 0  in num_list:
    print(0)
elif ans > 10**18:
    print("-1")
else:
    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:
        Ans = -1
        break

print(Ans)

Submission status: Accepted

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

if "0" in a:
  ans = 0
else:
  for i in range(n):
    ans *= int(a[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.sort()
ans=1
for i in a:
    ans=ans*i
    if ans>(10**18):
        print(-1)
        break
    elif ans==0:
        print(ans)
        break
if ans<=(10**18)and ans!=0:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
answer = 1
zero_check = 0 in a

for i in range(n):
    answer = a[i] * answer
    if zero_check:
        print(0)
        break
    elif answer > 1000000000000000000:
        print(-1)
        break
else:
    print(answer)

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

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

ans = 1
is_zero = False
is_over = False
for i in A_list:
    if i == 0:
        is_zero = True
        break
    if ans > 10**18:
        is_over = True

    if is_over:
        pass
    else:
        ans *= i

if is_zero:
    print(0)
elif is_over or ans > 10**18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
import math
n=input()
li=list(map(int,input().split()))

li.sort()

ans=1
for i in li:
    ans*=i
    if ans>math.pow(10,18):
        print('-1')
        quit()
print(ans)

Submission status: Accepted

Solution code:
# your code goes here
n = input()
res = 1
num_str = input()  # 1 3 2 1 2
num_str_arr = num_str.split(' ')
num_arr = [int(x) for x in num_str_arr]
done = 0
for x in num_arr:
	if x == 0:
		res = 0
	if res <= 1000000000000000000:
		res = res * x
if res > 1000000000000000000:
	print(-1)
else:
	print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
An = []
mul = 1

An = list(map(int,input().split()))
if An.count(0) > 0:
    print("0")
    sys.exit()

for i in An:
    mul *= i
    if mul > 10**18:
        print("-1")
        sys.exit()

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

Submission status: Accepted

Solution code:
N=int(input())
A = list(map(int,input().split()))
A.sort()
x=1
y=True
for i in A:
    x= x*i
    if x > 10**18:
        print('-1')
        y=False
        break
if y:
    print(x)

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
A = list(map(int,input().split()))
if 0 in A:
    print(0)
    exit();

A = deque(A)

if N%2 == 1:
    ans_right = A.pop()
else:
    ans_right = 1

ans_left = 1

for i in range(N//2):
    right = A.pop()
    left = A.popleft()
    
    ans_right = ans_right * right
    ans_left = ans_left * left

    if ans_right > 10**18 or ans_left> 10**18 or ans_left*ans_right> 10**18:
        print(-1)
        exit()


else:
    print(ans_right*ans_left)

Submission status: Accepted

Solution code:

from functools import *
import sys
sys.setrecursionlimit(100000)

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


N=input()
a=acinput()

if min(a)==0:
    print(0)
    sys.exit()
res=1

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

Submission status: Accepted

Solution code:
n = input()
list = input().split()

ans = 1
max_ans = 10**18

if "0" in list:
    ans = 0
else:       
    for num in list:
        ans = ans * int(num)
        if ans > max_ans:
            ans = -1
            break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
line = input().split()

MAX = 1000000000000000000

ans = 1

if not '0' in line:
    for l in line:
        if l == 0:
            ans = 0
            break
        if not ans > MAX:
            ans = int(l) * ans

else:
    ans = 0


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

Submission status: Accepted

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

ans = 1
lim = pow(10, 18)
for a in A:
    ans *= a
    if ans > lim:
        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:
    print(0)
else:
    for i in A:
        ans *= i
        if ans > 1000000000000000000:
            print(-1)
            exit()
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

A.sort()

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

print(ans)

Submission status: Accepted

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

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

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


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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1

has_zero = False
for a in A:
    if a == 0:
        has_zero = True

# print("here?")

for a in A:
    # print("here?2")
    # print(a)
    ans *= a
    if ans > 1000000000000000000:
        ans = -1
        break

if has_zero is True:
    print('0')
else:
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B_fix
# CreatedDate:  2020-05-31 21:22:32 +0900
# LastModified: 2020-05-31 21:25:40 +0900
#


import os
import sys
#import numpy as np
#import pandas as pd


def main():
    n = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
        print(0)
        return 
    sum = 1
    for a_ in A:
        sum*=a_
        if sum > 10**18:
            print(-1)
            return
    print(sum)    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
n = int(input())
c = 1
a = list(map(int,input().split()))
ok = 0;
for i in range(0,n):
    c *= a[i]
    if c > 1000000000000000000:
        ok = 1
        break
for i in range(0,n):
    if a[i] == 0:
        ok = 0
        c = 0
if (ok):
    print(-1)
else:
    print(c)

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int,input().split())]
ok = 0
ans = 1
lim = 10**18
for i in range(n):
  ans *= A[i]
  if(ans>lim):
      ok =1
      break
if(ok and 0 not in A):
    print(-1)
elif(0 in A):
    print(0)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
d = deque()

ar = [0 for _ in range(n)]

ar = [int(s) for s in input().split()]

ar.sort()
res = 1
flag = 0

if(ar[0] == 0):
    res = 0
else:
    ar = [i for i in ar if i != 1]
    if(len(ar) < 50):
        for i in ar:
            res = res*i
            if(res > 10**18):
                print(-1)
                flag = 1
                break
    else:
        print(-1)
        flag = 1

if(flag == 0):
    print(res)

Submission status: Accepted

Solution code:
from functools import reduce
N = int(input())
A = [*map(int, input().split())]

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

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

Submission status: Accepted

Solution code:
def f(a):
	res = 1
	for i in range(n):
		res *= int(a[i])
		if res > 10 ** 18:
			if zer(i):
				return 0
			else:
				return -1
	return res

def zer(i):
	for j in range(i, n):
		if a[j] == "0":
			return True
	return False
n = int(input())
a = input().split()

print(f(a))

Submission status: Accepted

Solution code:
import sys
N=int(input())

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

ans=1

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

for a in a_list:
    ans*=a

    if ans > 1000000000000000000:
        print(-1)
        sys.exit(0)

print(ans)

Submission status: Accepted

Solution code:
s = int(input())
l = input().split()

if "0" in l:
    print(0)
else:
    p = int(l[0])
    flag = True
    for el in l[1:]:
        p *= int(el)
        if p > 10**18:
            print(-1)
            flag = False
            break
    if flag:
        print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

tmp = 1
A.sort()
#print(A)
if A[0] == 0:
    print(0)
    exit()
for i in range(n):
    tmp *= A[i] 
    if tmp > 10**18:
            tmp = -1
            print(tmp)
            exit()
print(tmp)

Submission status: Accepted

Solution code:
n=int(input())
mul=1
limit=1000000000000000000
x=input().split()
for i in range (n):
    p=int(x[i])
    if(p==0):
        mul=0
        break
if(mul==0):
    print(mul)
else:
    for i in range (n):
        p=int(x[i])
        mul*=p
        if(mul>limit):
            break
    if(mul>limit):
      print(-1)
    else:
      print(mul)

Submission status: Accepted

Solution code:
import sys
def input():
  return sys.stdin.readline()[:-1]


n = input()
a = input().split()
r = 1

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

for i in range(len(a)):
  aa = int(a[i])
  r *= aa
  if r > pow(10, 18):
    print(-1)
    exit()

print(r)