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 = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

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

    print(num)

Submission status: Accepted

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

ans = 1
for a in A:
	ans *= a
	if ans > 10 ** 18:
		ans = 10 ** 18 + 1

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

Submission status: Accepted

Solution code:
import numpy as np
import math

n = int(input())
max = 1e+18
is_zero = False
ans = 1
a = input().split()

for i in range(n):
    if (int(a[i]) == 0):
        ans = 0
        is_zero = True
        break

if not is_zero:
    for i in range(n):
        ans *= int(a[i])
        if ans > max:
            ans = -1
            break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

flag = 0

for i in range (N):
    if pre[i] == 0:
        flag = 1

if flag == 0:

    ans = 1

    for i in range (N):
        ans *= pre[i]

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

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

else:
    print("0")

Submission status: Accepted

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

#print(A)

A.sort()
#print(A)

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

Submission status: Accepted

Solution code:
from sys import stdin
input=stdin.readline
a=1
ok=0
n=int(input())
ar=list(map(int,input().strip().split()))
ar.sort()
for i in ar:
    a*=i
    if(i==0):
        ok=1
        print(0)
        break
    if(a>1000000000000000000):
        ok=1
        print(-1)
        break
    # print(i)
if(ok==0):
    print(a)

Submission status: Accepted

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

if __name__ == '__main__':
    for i in l:
        total *= i
        if total > 1000000000000000000:
            total = -1
            break

    if 0 in l :
        total = 0
    print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
As = list(map(int, input().split()))
ans=1
for val in As:
    if val==0:
        ans=0
        break
for val in As:
    if ans==0:
        break
    if val==0:
        ans=0
        break
    ans=val*ans
    if 10**18<ans:
        ans=-1
        break

print(ans)

Submission status: Accepted

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

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 range(n):
    l = len(str(ans))
    L = len(str(a[i]))
    if a[i] > 10**18:
        print(-1)
        exit()
    elif l+L > 20:
        print(-1)
        exit()
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
# from numba import njit


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

    Aset = set(A)

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

    A.sort(reverse=True)

    res = 1
    INF = 10 ** 18

    for i in range(N):
        res *= A[i]
        if res > INF:
            res = -1
            break

    print(res)



main()

Submission status: Accepted

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

X = 1

for i in range(N):
    if a[i] == 0:
        X = 0

if X == 1:
    for i in range(N):
        X = X * a[i]
        if X > 1000000000000000000:
            X = -1
            break

print(X)

Submission status: Accepted

Solution code:

N = int(input()) 
A = list(map(int, input().split()))
S = set(A)
if 0 in S:
  print(0)
  exit()
 
upp = 10**18
flag = 1
ans = 1
#print(A)
for a in A:
  ans *= a
  if ans > upp:
    ans = -1
    break
 
print(ans)

Submission status: Accepted

Solution code:
import sys

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

a = sorted(a)

num = a[0]

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

print(num)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
import sys

#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n=input1()
A=input_array()
if 0 in A:
	print(0)
	sys.exit()
ans=1

for a in A:
	ans=ans*a
	if ans > 10**18:
		break

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

Submission status: Accepted

Solution code:
MAX = 10 ** 18

N, *A = map(int, open(0).read().split())

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

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
tmp = 1
dat = list(map(int, input().split(" ")))
#print(dat, (0 in dat))
over = False
if 0 in dat:
    print ("0")
else:
    for d in dat:
        tmp *= d
        if tmp > 1000000000000000000:
            print ("-1")
            over = True
            break
    if not over:
        print (tmp)

Submission status: Accepted

Solution code:
import sys

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

ans = 1
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())
ls = list(map(int,input().split(' ')))
pro=1
f=0
zero=0
for i in ls:
    if(i==0):
        zero=1
if(zero==1):
    print(0)
else:
    for i in ls:
        pro = pro*i
        if(pro > 1000000000000000000):
            print(-1)
            f=1
            break
    if(f==0 and pro<=1000000000000000000):
        print(pro)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = [int(a) for a in input().split()]
ans = A[0]

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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


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

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

print(ans)
exit(0)

### C++と同じく、実行は、Opt + Ctl + N

'''
# -*- coding: utf-8 -*-
# get a integer
a = int(input())
# get two integers separated with half-width break
b, c = map(int, input().split())
# get a string
s = input()
# output
print('{} {}'.format(a+b+c, s))
'''

Submission status: Accepted

Solution code:
N = int(input())

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


prod = 1
overflow_flag = False

if 0 in As:
    print(0)
else:
    for a in As:
        prod *= a

        if prod > 10**18:
            overflow_flag = True
            break

    if overflow_flag:
        print("-1")
    else:
        print(prod)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(str(ans))

Submission status: Accepted

Solution code:
n = input()
ar = map(int,input().split())
ar = list(ar)
mul=1
ar=sorted(ar)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

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


flag = True

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
lis = [0] * (n+1)


for i in range(n):
    if a[i] == 0:
        lis[i+1] += 1
    lis[i+1] += lis[i]
#print(lis)
if lis[-1] > 0:
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if lis[-1]-lis[i+1] == 0:
        if ans > int(1e18):
            print(-1)
            exit()
print(ans)

Submission status: Accepted

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

      break
  if flag:
    print(ans)

Submission status: Accepted

Solution code:

n=int(input())
l1=list(map(int,input().split()))
p=1
k=0
if 0 in l1:
  print("0")
  exit()
for i in range(n):
  p*=l1[i]
  if p>10**18:
    k=1
    break
if k==1:
  print("-1")
else:
  print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input());
ans = 1;
lis = list(map(int,input().split()))
flag = False
flag2 = False
for i in range(n):
    if lis[i]==0:
        flag = True
    if ans*lis[i]>=1000000000000000001:
        flag2 = True
    else:
        ans *= lis[i]

if flag:
    print(0)
elif flag2:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

res = 1

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

for i in a:
    res *= i
    
    if (res > 1000000000000000000):
        res = -1
        break
        

if res == -1:
    for i in a:
        if i == 0:
            res = 0
            break

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

over = False
mul = 1
if 0 in a:
    mul = 0
for a_ in a:
    mul *= a_
    if mul > 10**18:
        mul = -1
        break
print(mul)

Submission status: Accepted

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

Submission status: Accepted

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

ans=1


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

print(ans)

Submission status: Accepted

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

ans = 1
zero = 0
for i in range(n):
    if a[i] == 0:
        zero += 1

if zero > 0:
    print(0)
    exit(0)

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
nums = input().split()
end = False
result = 1
for num in nums:
  if num == "0":
    print(0)
    end = True
    break
if not end:
  nums = [int(s) for s in nums]
  for num in nums:
    result = result * num
    if 10**18< result:
      result = -1
      break
  print(result)

Submission status: Accepted

Solution code:
N = int(input())
List = list(map(int, input().split()))
a=1
if  0 in List:
    print(0)

else:
    for i in List:
        a=a*i
        if a>10**18:
            print('-1')
            break
if not a>10**18 and not 0 in List:
    print(a)

Submission status: Accepted

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

fflag = False
for i in range(n):
    if a[i] == 0:
        fflag = True
        break

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

if flag == True:
    print(ans)

Submission status: Accepted

Solution code:
N=input()
s=input().split()
a = [int(j) for j in s]
lim=10**18

for i in range(int(N)):
    if(i==0):
      mul=int(a[0])
      if(0 in a):
          print(0)
          break
    else:
      mul=mul*int(a[i])
    if(mul>lim):
      print(-1)
      break
    if(i==int(N)-1):
      print(mul)
      break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in a:
    ans = 0
else:
    threshold = 10**18
    ans = 1
    for val in a:
        ans *= val
        if ans > threshold:
            ans = -1
            break
print(ans)

Submission status: Accepted

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

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

num = 1
for ele in a:
  num *= ele
  if num > 1000000000000000000:
    print(-1)
    sys.exit()

print(num)

Submission status: Accepted

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

print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 20:04:25 2020

@author: k
"""

n = int(input())
a = input().split()
inf = 1000000000000000000
ans = 1
f = 1
for x in a:
    x = int(x)
    if x == 0:
        f = 0
    if ans == -1:
        continue
    ans = ans*x
    if ans > inf:
        ans = -1
print(ans*f)

Submission status: Accepted

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

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

if ans <= 10 ** 18 and flg == 0:
    print(ans)

Submission status: Accepted

Solution code:
from decimal import *
n = int(input())
a=list(map(Decimal,input().split()))
a.sort()
ans = 1
for i in a:
    ans *= i
    if ans > 1000000000000000000:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
import  functools
import operator
prod=functools.partial(functools.reduce, operator.mul)
a=list(map(int,input().split()))
a.sort(reverse=True)
if a[0]*a[1]>10**18 and a[-1]!=0:
    print(-1)
    exit()
if a[-1]==0:
    print(0)
    exit()
    
ans=prod(a)

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
list.sort(a, reverse = True)
ones = a.count(1)
for i in range(len(a)-ones):
    if 0 in a:
        ans =0
        break
    ans = ans * a[i]
    if ans >10**18:
        break

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

Submission status: Accepted

Solution code:
#intの場合
N = int(input()) #ここで標準入力

#List にしたい時
#intの場合
huga = list(map(int, input().split()))
if 0 in huga:
    print(0)
else:
    ans = 1
    flg = 0
    for number in huga:
        ans = ans * number
        if ans > 10**18:
            flg = 1
            break
    if flg == 0:
        print(ans)
    else:
        print('-1')

Submission status: Accepted

Solution code:
a = int(input())
c = list(map(int, input().split()))
ans = int(1)
m = int(1000000000000000000)
ok = True
o = False
for i in c :
    if i == 0:
        print(0);
        o = True
        break
    elif ok == True :
        ans = int(ans*i)
        if ans > m:
            ok = False
if not ok and not o:
    print(-1)
elif not o :
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import sys
def main():
  n = int(input().strip())
  l = list(map(int, input().split()))
  sum = 1
  if 0 in l :
    print (0)
    return

  for i in l:
    sum *= i
    if sum - 1000000000000000000 > 0:
      print (-1)
      return
  print (sum)
main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

import sys


def input():
    return sys.stdin.readline()


def resolve():
    n = int(input().rstrip())
    a_list = list(map(int, input().split()))
    flag = False
    try:
        if a_list.index(0):
            flag = True
            print(0)
            exit()
    except:
        if flag:
            exit()
        ans = 1
        for i in a_list:
            ans *= i

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

        print(ans)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input());

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

ans = 1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
 
if __name__ == '__main__':
    str = input()
    str = input().strip()
 
    arr = [int(e) for e in str.split()]
    if 0 in arr:
        print(0)
        sys.exit()
 
    total = 1
    for e in arr:
        total *= e

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

    print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
largenum = 10**18
from functools import reduce
from operator import mul
def main():
    n = int(input())
    a = list(map(int, input().split()))

    if 0 in a:
        print(0)
        sys.exit()
    r = 1
    for i1 in range(n):
        r *= a[i1]
        if r > largenum:
            print(-1)
            sys.exit()
    print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 1
for i in range(N):
    if A[i] == 0:
        ok1 = True
for i in range(N):
    ans *= A[i]
    if ans > 1000000000000000000:
        ok2 = True
        break

if ok1:
    print(0)
elif ok2:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

for i in a:
  multi *= i
  if multi > pow(10,18):
    break
if multi > pow(10,18):
  print("-1")
else:
  print(multi)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INFTY=10**18

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    if(a.count(0)!=0):
        return 0
        
    res=a[0]
    for i in range(1,n):
        res*=a[i]
        if res>INFTY:
            return -1
    return res

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = list(map(int,input().split()))
f = False;
for i in range(n):
  if a[i] == 0:
    f = True
if f:
  print(0)
  sys.exit(0)
ans = 1
for i in range(n):
  ans *= a[i]
  if ans > 1e18:
    print(-1)
    sys.exit(0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
values = input().split(' ')
for idx in range(0, n):
    values[idx] = int(values[idx])

result = 1
limit = 10**18
if 0 in values:
    result = 0
else:
    for idx in range(0, n):
        result = result * values[idx]
        if result > limit:
            result = -1
            break

print(result)

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
a = list(map(int, input().split(' ')))
for i in range(n):
    if a[i] == 0:
        print(0)
        exit()
for i in range(n):
    ans *= a[i]
    if 1000000000000000000 < ans:
        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:
  ans = 0
if ans != 0:
  for num in A:
    if ans * num > 1e+18:
      ans = -1
      break
    ans = ans * num
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
A = sorted(list(map(int,input().split())))
if A[0] == 0:
    ans = 0
else:
    ans = 1
    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)
    exit()

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
ans = A[0]
if 0 in A:
  ans = 0
for i in range(N-1):
  ans = ans * A[i+1]
  if ans > 10**18 or ans < -1:
    ans = -1  

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = 1
for i in range(n):
    if a[i] == 0:
        m = 0
        print("0")

if m == 1:
    for j in range(n):
        m = m * a[j]
        if m > 10**18:
            break
    if m > 10**18:
        print("-1")
    else:
        print(m)