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()))
x = 1

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

for i, v in enumerate(A):
  if i >= N:
    break
  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()))
ans = 1
cnt_0 = a.count(0)
if cnt_0 >= 1:
    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())
arr = list(map(int, input().split()))
z=1
flag=0
zero=1
for i in range(n):
    z=z*arr[i]
    if(z>1000000000000000000):
        flag=1
        break
for i in range(n):
    if(arr[i]==0):
        zero=0
if(flag==0 or zero==0):
    print(z*zero)
else:
    print("-1")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 10 ** 18

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

A.sort(reverse=True)
ans = A[0]

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

print(ans)

Submission status: Accepted

Solution code:
n= int(input())
line= input().split(' ')
 
tot=1

for a in line:
	if a=='0':
		tot=0
		break

if tot==1:
	for a in line:
		tot*= int(a)
		if tot>10**18:
			tot=-1
			break

print(tot)

Submission status: Accepted

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

result = 1

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

Submission status: Accepted

Solution code:
import sys

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

Flag = True
ans = 1

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:



def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    MAX = 10**18
    for a in sorted(A):
        if a == 0:
            print(0)
            return
        ans *= a
        if ans > MAX:
            print(-1)
            return

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

flag_0 = False

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

Submission status: Accepted

Solution code:


def main():
    _ = int(input())
    a = [int(i) for i in input().split()]
    if 0 in a:
        print(0)
        return
    a.sort()

    limit = 10**18
    result = 1
    for i in a[::-1]:
        result *= i
        if result > limit:
            print(-1)
            return
    print(result)

main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

a.sort(reverse=True)

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = sorted([int(value) for value in input().split(" ")], reverse=True)
    result = 1
    if 0 in A:
        print(0)
        exit()
    for value in A:
        result *= value
        if result>10**18:
            print(-1)
            exit()
    
    print(result)


if __name__=="__main__":
    main()

Submission status: Accepted

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

ans = 1
for aa in a:
  if aa == 0:
    ans = 0
    break

for aa in a:
  ans *= aa
  if(ans > 1000000000000000000):
    ans = -1
    break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans=1
i=0
while ans<=1000000000000000000 and i<N:
    ans=ans*A[i]
    i+=1

if A.count(0)>0:
    print(0)
else:
    print(ans if ans<=1000000000000000000 else "-1")

Submission status: Accepted

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

list.sort(A, reverse=True)
mx = 10 ** 18
mul = 1

if 0 in A:
    print(0)
    exit(0)
    
for a in A:
    mul *= a
    if mul > mx:
        mul = -1
        break

print(mul)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
n = input()
a = [int(i) for i in input().split()]
ans = 1
if 0 in a:
  print("0")
  sys.exit()  

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

Submission status: Accepted

Solution code:
def sol():
    n = int(input())
    mul = 1
    arr = list(map(int, input().split()))
    arr.sort()
    for i in arr:
        mul*=i
        if(mul>10**18):
            print(-1)
            return
    print(mul)
sol()

Submission status: Accepted

Solution code:


def main():
    sc =Scan()
    n = sc.intarr()
    a = sc.intarr()
    a.sort()
    total = 1    
    for num in a:
        total = total * num
        if total > 1000000000000000000:
            print("-1")
            return
    
    print(total)
        
class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        return line.split(' ')
      
      
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:

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

def multiply_list(num_list):
    if 0 in num_list:
        return 0

    numlist_2 = [num for num in  num_list if num >= 2 ]


    if len(numlist_2) >= 60:
        return -1

    ans = 1
    for num in numlist_2:
        ans *= num

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

    return ans

print(multiply_list(num_list))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
  x*=a[i]
  if x<=1000000000000000000:
    pass
  else:
    print("-1")
    exit()
  
print(x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
value = 1

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

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

Submission status: Accepted

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

A=sorted(A,reverse=True)
def mul(A):
    if 0 in A:
      return 0
    m=1
    for na in A:
        m*=na
        if m>10**18:
          return -1
    return m
    
print(mul(A))

Submission status: Accepted

Solution code:
N=int(input())

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

Submission status: Accepted

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


def main():
    limit = 10**18
    N = int(input())
    A = list(map(int, input().split()))
    assert N == len(A)
    answer = 1
    if 0 in A:
        print(0)
        exit()
    for i in A:
        answer *= i
        if answer > limit:
            print("-1")
            exit()
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    a_list = list(filter((1).__ne__, a_list))

    if 0 in a_list:
        print('0')
        return

    result = 1

    for a in a_list:
        result = result * a

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

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    temp=1
    for a in sorted(pin()):
        temp*=a
        if temp>10**18:
            print(-1)
            return
    print(temp)
#%%submit!
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = map(int,input().split())
def kake(a):
  res=1
  for i in sorted(a):
    res*=i
    if res > 10**18:
      return -1
  else:
    return res
print(kake(A))

Submission status: Accepted

Solution code:
temp1 = input()
n = int(temp1)

temp2 = input().split(" ")

nums = [int(a) for a in temp2]


temp = nums[0]

limit = pow(10, 18)

for i in range(1, n):
    temp = temp * nums[i]
    if temp > limit:
        break;

if temp <= limit:
    print(temp)
else:
    if 0 in nums:
        print(0)
    else:
        print(-1)

Submission status: Accepted

Solution code:
import sys
ans = 1
N = int(input())
A = list(map(int, input().split()))  
if A.count(0):
    print(0)
else:
    for _ in range(N):    
        ans *= A[_]
        if ans > pow(10,18):
            print(-1)
            sys.exit()
    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):
    if A[i] == 0:
        ans = 0
        break
    ans = ans * A[i]
    if ans > 10**18:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

result = 1
for A in Alist:
  result *= A
  if result > 1000000000000000000:
    if 0 in Alist:
      result = 0
    break

if result > 1000000000000000000:
  print("-1")
else:
  print(result)

Submission status: Accepted

Solution code:
N = int(input())
A = list(input().split())
flag = 0
for i in range(N):
    A[i] = int(A[i])
    if A[i] == 0:
        flag = -1
sum = 1

for i in range(N):
    if sum <= 10**18:
        sum = sum * A[i]
    else:
        break


if sum <= 10**18:
    print(sum)
else:
    if flag == -1:
        print(0)
    else:
        print(-1)

Submission status: Accepted

Solution code:
n = int(input())
result = 1
flag = True
numlist = list(map(int,input().split()))
if 0 in numlist:
    print("0")
    flag = False
else:
    for i in numlist:
        result *= i
        if result > 10**18:
            print("-1")
            flag = False
            break

if flag:
    print(result)

Submission status: Accepted

Solution code:
input()
lis = list(map(int,input().split()))
s = 1
if 0 in lis: print(0)
else:
    for i in range(len(lis)):
        s = s * lis[i]
        if s>1000000000000000000: print(-1); exit()
    print(s)

Submission status: Accepted

Solution code:
n = int(input())
vals = list(map(lambda v: int(v), input().split()))
vals.sort(reverse=True)
i = 0
sum = 1

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

while (i < len(vals)):
  sum = sum * vals[i]
  if (sum > 10e17):
    print(-1)
    exit()
  i = i + 1

print(sum)

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

Submission status: Accepted

Solution code:
N=int(input())
status=0
res=0
arr=[eval(i) for i in input().split()]
for i in arr:
    if i==0:
        status=1
        break
#print(N,": ",arr)
if status==0:
    res=1
    for i in arr:
        res=res*i
        if res>10**18:
            res=-1
            break

print(res)

Submission status: Accepted

Solution code:

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

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

for a in A:
    if a == 0:
        ans = 0

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int, input().split()))
c_nega = 0
flag = False
for i in range(n):
  if d[i] == 0:
    flag = True
    break

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

Submission status: Accepted

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

if 0 in A:
        ans = [0]
else:
    ans = [1]*N
    
    for i,a in enumerate(A):
        if i==0:
            ans[i] = a
        else:
            ans[i] = ans[i-1]*a

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

Submission status: Accepted

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

ans = 1
stop = False
for i in range(n):
  if a[i] == 0 :
    stop = True
  
aaa = False

if stop :
  print(0)
else :
  for j in range(n):
    if aaa == False:
      ans *= a[j]
      if ans > 1000000000000000000:
        aaa = True
  if aaa == True:
    print(-1)
  else :
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

c = 1
able = True
if not 0 in A:
  for a in A:
    c = c * a
    if c > 1e18:
      able = False
      break
else:
  c = 0

if able:
  print(c)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
i=0
con=1
mod=10**18
ans=1
why=0
while con==1:
  ans=ans*a[i]
  i+=1
  if ans>mod and i!=n:
    ans=1
    why=1
  elif ans>mod and i==n:
    con=0
    ans=1
    why=1
  elif i==n:
    con=0
if ans==0:
  print(0)
elif why==1:
  print(-1)
else:
  print(ans)

Submission status: Accepted

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

for i in sorted(ln):
    if a > 10**18 or a == 0:
        break
    else:
        a = a*i
        
    
    
if a> 10**18:
    print('-1')
else :
    print(a)

Submission status: Accepted

Solution code:
N=int(input())
# a=int(input())
# a,b=map(int,input().split(" "))
A=[int(_) for _ in input().split(" ")]

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

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

print(ans)

Submission status: Accepted

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

for cnt in range(n):
    if a[cnt] == 0:
        print(0)
        flag = 1
        break

if flag == 0:
    for cnt in range(n):
        ans *= a[cnt]
        if ans > INF:
            print(-1)
            flag = 1
            break

if flag == 0:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int,input().split()))
if 0 in li:
    print(0)
else:
    sum = 1
    for i in range(N):
        sum = sum*li[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
if a.count(0):
    print(0)
    exit()

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

print(ans)

Submission status: Accepted

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

m = 1

for num in l:
    if num == 0:
        print(0)
        exit()

for num in l:
    m *= num
    if m > 1000000000000000000:
        print(-1)
        exit()

print(m)

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:
import sys
a=int(input())
b=list(map(int,input().split()))
c=b.count(0)
if c>0:
    print('0')
    sys.exit()
ans=1
for i in range(a):
  ans=ans*b[i-1]
  if ans>10**18:
      print('-1')
      sys.exit()
      
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())

ans=1
for a in A:
    if a==0:
        ans*=a
    elif ans==-1:
        pass
    else:
        ans*=a
        if 10**18<ans:
            ans=-1

if 10**18<ans:
    print -1
else:
    print ans

Submission status: Accepted

Solution code:
import sys

n=int(input())
a = list(map(int, input().split())) #a1 a2 a3 // b1 b2 b3
if a.count(0)>=1:
    print(0)
    sys.exit()
ans=1
for at in a:
  ans*=at
  if ans>10**18:
    print(-1)
    sys.exit()
print(ans)

Submission status: Accepted

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

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

        return ans


if __name__=="__main__":
        ans = main()
        print(ans)

Submission status: Accepted

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

l.sort(reverse = True)
ans = l[-1]
for i in range(n-1):
    ans *= l[i]
    if ans > 10**18:
      ans = -1
      break
    elif ans == 0:
      ans = 0
      break

print(ans)

Submission status: Accepted

Solution code:
import sys
N=int(input())
A=[int(i) for i in input().split(" ")]
if 0 in A:
    print(0)
    sys.exit(0)
A=sorted(A,reverse=True)
mul=1
for a in A:
    mul*=a

    if mul>10**18:
        print(-1)
        sys.exit(0)

print(mul)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

total = 1
a_sort = sorted(a)
if a_sort[0] == 0:
    print("0")
    sys.exit()

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

print(total)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:

in_d = input()
n = int(in_d)

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

result = 0
if 0 in a:
    print(0)
else:
    result = 1
    limit = 10 ** 18
    over = 0
    a.sort()
    for v in a:
        result *= v
        if result > limit:
            over = 1
            break
    if over == 1:
        print(-1)
    else:
        print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A.sort()
cnt = 1
for i in A:
    cnt *= i
    if cnt > 10**18:
        print(-1)
        exit()

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
while True:
    try:
        listA=list(map(int,input().split()))
        #listA<-[1,2,2,3,1]
        #ここに逐次処理を書けばいいと思う。
    except:
        break;

product=1
for i in listA:
  if product<10**18+1:
  	product=product*i
    
if listA.count(0)>0:
  print(0)
    
elif product<10**18+1:
  print(product)
  
elif product>=10**18+1:
  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
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())
out = 1
an = list(map(int,input().split()))
check = True
if 0 in an:
  print(0)
else:
  for a in an:
    out *= a
    if out>1000000000000000000:
      check = False
      break
  if check:
      print(out)
  else:
      print(-1)

Submission status: Accepted

Solution code:
def calc(a, n):
    for x in range(n):
        if a[x] == 0:
            return 0

    result = 1
    max = 10 ** 18
    for x in range(n):
        result *= a[x]
        if result > max:
            return -1

    return result

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

print(calc(a, n))

Submission status: Accepted

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

Submission status: Accepted

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

"""
ans = 1
flag = 0
for i in li:
  if i == 0:
    flag = 1
    break
  ans *= i

if flag == 1:
  print(0)
elif ans > 10**18:
  print(-1)
else:
  print(ans)
"""
ans = 1
flag = 0
li.sort()
if li[0] == 0:
  print(0)
else:
  for i in li[::-1]:
    ans *= i
    if ans > 10**18:
      flag = 1
      break

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

Submission status: Accepted

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

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

print(p)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
answer = 1
lens = int(input())
arrs = [int(x) for x in input().split()]
if 0 in arrs:
    answer = 0
else:
    for x in arrs:
        answer *= x
        if answer > int(10 ** 18):
            answer = -1
            break
print(answer)

Submission status: Accepted

Solution code:
# created by dipta10 

n = int(input())
ls = list(map(int, input().split(' ')))

ls = sorted(ls)
f = 1
ans = 1
inf = 1000000000000000000
for x in ls:
    ans *= x
    if ans > inf:
        f = 0
        break

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = map(int, input().split())
a = list(map(int, input().split()))
ans = 1
flag = True if 0 in a else False

if flag:
    print(0)
    exit()

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(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 sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = 1

if 0 in a:
    print(0)
else:
    for i in range(len(a)):
        ans *= a[i]
        if ans > (1000000000000000000):
            print(-1)
            sys.exit()
    else:
        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):
  if A[i] == 0:
    ans = 0
    break
  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()))
a.sort()

x = 1
for i in a:
    x *= i
    if x > 10**18:
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

b=0

for i in a:
    if(i==0):
        b=1

if b:
    print(0)
    exit()

ans=1

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
As = [int(x) for x in input().split()]
flag = False
flag2 = False
for a in As:
    if a == 0:
        flag = True
        break
ans = 1
if not flag:
    for i in range(n):
        ans *= As[i]
        if ans > 1000000000000000000:
            flag2 = True
            break
if flag:
    print(0)
elif flag2:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

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

m = 1
j = 0

if 0 in AS:
    print(0)
    j = 1
    

if j == 0:
    for i in AS:
        m = m * i
        if m > 10**18 and j == 0:
            print(-1)
            j = 1
            break
        elif m == 0:
            break
        else:
            continue

if j == 0:
    print(m)

Submission status: Accepted

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

print(ans)