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: Wrong Answer

Solution code:
import numpy as np

N = int(input())
s = input().split()
k = [int(_) for _ in s]
p = np.prod(k)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
P=list(map(int,input().split()))
import numpy
P=numpy.array(P)

result =numpy.prod(P)
 
if result>10**18:
    print('-1')
else:
    print(str(result))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = sorted(map(int, input().split())) 
B=np.array(A)
S=np.prod(B)
if S> 10**18:
  S=-1
print(S)

Submission status: Wrong Answer

Solution code:
def multi(L):
    ans = 1
    for l in L:
        if ans <= (10**18):
            ans *= l
            print(ans)
        else:
            ans = -1
            break
    return ans
 
N = int(input())
A_list = list(map(int, input().split()))

print(multi(A_list))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
output = np.prod(A)
if abs(output) > 10**18:
  print(-1)
else:
  print(output)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
thres = 10**18
res = A[0]
if 0 in A:
    print(0)
    exit()
for i in range(N-1):
    res *= A[i+1]
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

print(a)

p = np.prod(a, axis=0)

print(p)

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

Submission status: Wrong Answer

Solution code:
n=int(input())

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

if len(a) % 2 == 1: 
  for i in range(1, int(len(a)/2)+2):
    print(ans)
    if ans > 10**18 or ans == 0:
      break
    if i == int(len(a)/2) + 1:
      ans = ans*a[i-1]
    else:
      ans = ans*a[i-1]*a[-1*i]
elif 0 in a:
  pass
    
else:
  for i in range(0, int(len(a)/2)):
    if ans > 10**18 or ans == 0:
      break
    ans = ans*a[i]*a[-1 - i]
    

if ans > 10**18:
  print('-1')
  print(ans)
elif 0 in a:
  print(0)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int, input().split()))
i=0
ans=1
flag=0
k=1e18
while(n>i):
	ans*=p[i]
	if(p[i]==0):
		break
	if(ans>k):
		break
	i+=1		
if(ans>k):
		print(-1)
else:
		print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
l = sorted(l, reverse = True)
sum = l[0]

f = True

a = 0 in l

b = 1000000000000000000

for i in range(1,n):
  if sum > b  and a==False:
    print(-1)
    f = False
    break
  sum *= l[i]

if f == True and sum <= b:
  print(sum)
else:
  print(-1)

Submission status: Wrong Answer

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

ans=1
flag=False
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        flag=True
        ans=ans%10**18

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

Submission status: Wrong Answer

Solution code:
import sys

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

ans = 1

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=list(map(int,input().split()))
A=np.array(A)
ans=np.prod(A)
if ans >= 10**(18):
    ans=-1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = input()
a = list(map(int, input().split()))
if N == len(a):
    c = np.prod(a)

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

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO



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

    ans = 1

    for i in range(0, N):
        ans = ans * A[i]

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

    print(ans)
    
resolve()

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
a=deque()
a=list(map(int,input().split()))
b=0
s=1
for i in range(n):
  l=a.pop()
  s=s*l
  if len(str(s)) >= 19:
    if s==10**18:
      break
    s=-1
    break
  elif l==0:
    s=0
    break

if len(str(s))>19:
  print(-1)
else:
  print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())

A=[int(N) for N in input().split()]
ans=np.prod(A)


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

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
b = np.uint64(np.array(a))
t = np.uint64(1)

for i in range(n):
    t = t*b[i]
    if b[i] == 0:
        break
    if t > np.uint64(10**18):
        break

if t > np.uint64(10**18) :
    print('-1')
else:
    print(t)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
num = int(input())
nums = list(map(int,input().split()))
ans = 1
for j in nums:
    ans = ans * j
if(len(str(ans))>18):
    print('-1')
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
upper = pow(10,18)
result = np.prod(np.array(A).astype('int64'))
if upper < result:
    print(-1)
elif result < 0:
    print(-1)
else:
    print(result)

Submission status: Wrong Answer

Solution code:
# coding:utf-8
N=int(input())
l = list(map(int, input().split()))
import functools
import operator
result = functools.reduce(operator.mul, l)
print(result)

Submission status: Wrong Answer

Solution code:
a = []
x = 1

n = int(input())
a = input().split()

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

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

Submission status: Wrong Answer

Solution code:
import sys

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

limit = pow(10, 18)

nums = []

nums = input().rsplit()

# for i in range(0, N - 1):
#     a = input()
#     if a == 0:
#         print(0)
#         sys.exit(1)
#     nums.append(a)

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

    if accum > limit:
        accum = -1
        break

print(accum)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if x>=1000000000000000000:
    print(-1)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
B = np.array(A)
V = np.prod(B)
if V<= 10**18:
  print(V)
else:
  print('-1')

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A = np.array(a)
a_mul = int(np.prod(A))

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
a = a.astype(np.int64)
ans = np.prod(a)
if ans > 10**18:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
i=1
sum=A[0]
if sum<=10**18 and i<=N-1:
   sum*=A[i]
   i+=1
if sum>10**18:
   sum=-1
print(sum)

Submission status: Wrong Answer

Solution code:
def multiplyList(myList): 
    result = 1
    for x in myList: 
        result = result * x
        if(result > 1000000000000000000):
        	return 1000000000000000001
    return result 

t=int(input())
l=list(map(int,input().split()))
m = 1;
for i in range(len(l)):
	if(l[i] == 0):
		m = 0;
if(m == 0):
	print(-1)
else:
	n = multiplyList(l)
	if(n > 1000000000000000000):
		print("-1")
	else:
		print(n)

Submission status: Wrong Answer

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

for i in range(0,n):
	result = result*int(a[i])

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

Submission status: Wrong Answer

Solution code:
A=input()
list1=input().split()
A=int(A)
Ans=1
#---------------------------

if "0" in list1:
    print("0")
    
else:
    for i in range(0,A):
        Ans=Ans*int(list1[i])    
        if Ans >10**18:
            print(-1)
            break
        else:
            print(Ans)

Submission status: Wrong Answer

Solution code:
import numpy
n = int(input())
a = list(map(int,input().split()))
a = numpy.array(a)
count =numpy.prod(a)
if count>1000000000000000000:
  print("-1")
else:
  print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())
x=list(map(int, input().split()))
 
ans=np.prod(x)
  
if ans > 1000000000000000000:
  ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input());
ans=int(1);

tempstr = input();
temp = tempstr.split(' ')
for i in range(n):
    if ans <= 1000000000000000000:
        ans =ans* int(temp[i]);
    elif temp[i] == 0:
        ans=0;
        break;
    else:
        ans = -1;
        
if ans>=1000000000000000000:
    ans = -1;
            
print(ans);

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np;
from numba import jit
import warnings
warnings.simplefilter('ignore')

@jit
def slove(ans, A):
    zero = False
    for a in A:
        if a == 0:
            zero = True
            return 0
        if a > 10 ** 18 and not(zero):
            return -1
        ans *= a
    return ans

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    ans = slove(1, A)
    if ans > 10 ** 18:
        print(-1)
        quit()
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
c=10**9
a=1
count=0
for i in range(n):
    a=a*l[i]
    if a//c>=c:
        print("-1")
        exit()
    elif a//c>=1:
        a=a%c
        count=count+1


if count==0:
    print(a)
elif count==1:
    print(a*c)
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split(' ')]
 
sum = 1
lsum = 0

min_v = min(a)
a.sort(reverse=True)

for x in a:
    sum *= x
    if min_v != 0 and sum != 10**18 and (sum // 10**18) == 1:
        break
    if sum * min_v == 0:
        sum = 0
        break

if sum == 10**18:
    print(sum)
elif sum != 0 and sum // 10**18 == 1:
    print(-1)
else:
    print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = (int(input()))
a = list(map(int, input().split()))
if N == len(a):
    c = np.prod(a)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
ans = int(np.prod(a))
if ans > 10**18:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from numba import njit
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))


@njit
def f(A):
    ans = 1
    limit = 10**18
    if np.sum(A == 0) != 0:
        return 0
    for i in A:
        ans = ans*i
        if ans > limit or i > limit:
            return -1
    return ans
print(f(A))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=list(map(int,input().split()))
A=np.array(A)
ans=np.prod(A)
if ans > 10**(18):
    ans=-1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
 
n = input()
 
ls = list(map(int, input().split()))
ls_a = np.array(ls)

if(np.prod(ls_a) > 10**18):
  print(-1)
else:
  print(np.prod(ls_a))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
l = sorted(l, reverse = True)
sum = l[0]

f = True

a = 0 in l

b = 1000000000000000000

for i in range(1,n):
  if sum > b  and a==False:
    print(-1)
    f = False
    break
  sum *= l[i]

if f == True and sum < b:
  print(sum)
else:
  print(-1)

Submission status: Wrong Answer

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

a_n = np.array(a,dtype=np.int64)
#print(a_n)
a_n.sort()
tmp = np.prod(a_n[:-2])
tmp = tmp * a_n[-2]* a_n[-1] 
#result = int(np.prod(a_n))
#print(tmp)

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

x = np.prod(L, dtype="int64")

if len(str(x)) < 19 or x == 1000000000000000000:
    print(str(x))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = input()   
l = list(map(int,arr.split(' ')))
sum = l[0]
for i in range(1,n):
  sum *= l[i]
  if sum >= 1e18:
    print(-1)
    break
if sum < 1e18:
  print(sum)

Submission status: Wrong Answer

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

for j in range(N-1):
    X[j] = X[j] * X[j+1]
    if X[j] > 10**18:
        print(-1)

print(X[j])

Submission status: Wrong Answer

Solution code:
import numpy as np

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
import numpy as np

N = int(input())

sums = 1;
string = input().split()

candis = []
for i in range(N):
    candis.append(int(string[i]))


candis = np.sort(np.array(candis))

if(candis[0] == 0):
    print(0)
    exit()
    
candis = candis[::-1]
    
for i in range(N):
    sums = sums * candis[i]
    if(sums > pow(10,18)):
        print(-1)
        exit()
print(sums)

Submission status: Wrong Answer

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

s = np.prod(a)

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

Submission status: Wrong Answer

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

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

if(f == 0):
    print(0)
elif(f == 1):
    print(-1)
else:
    print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
from numpy.compat import long

n = int(input())
a = list(map(long ,input().split()))
p = np.prod(a)

if len(str(p))>=19:
    print("-1")
else:
    print(p)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = input()
listA = list(map(int, input().split()))
ans = np.prod(np.array(listA), axis=0)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans=np.prod(a)

if ans>10**18 or ans < 0:
  print(-1)
else:
  print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
P=list(map(int,input().split()))
import numpy
P=numpy.array(P)

result =numpy.prod(P)
 
if result>10**18:
    print(-1)
else:
    print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
ma = 10**18
ans = np.prod(a)
if ans > ma:
    print(-1)
else:
    print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split()))
 
a = 1
i = 0
j = 0
    
while i<n:
  while j < n:
    if data[j]==0:
    	  a = 0
    	  break
    j +=1
  break
  a = a*data[i]
  i += 1
 
if a > 10**18:
  a = -1
 
print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
lim = 10**18
ans = np.prod(a)
 
if ans >= lim:
  ans = -1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int,input().split(" ")))
 
s = num[0]
 
for i in range(1,n):
  s = s * num[i]
    
if len(str(s)) > 17:
  print(-1)
else:
  print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
upper = pow(10,18)
result = np.prod(np.array(A).astype('int64'))
if upper < result:
    print(-1)
else:
    print(result)

Submission status: Wrong Answer

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

for i in x :
  b = b * i
  
if i > 100000000:
  print(-1)
else:
  print(b)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
n=int(input())
ans=1
a=np.array(input().split()).astype(int)


ans=np.prod(a)
if ans>pow(10,18):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=map(int,input().split())
k=1
for s in l:
    k=s*k
    if k>10**18:
        break

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lim = math.pow(10,18)

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]

    if x > lim * 10:
        break

if x > lim:
    x = -1

print(math.floor(x))

Submission status: Wrong Answer

Solution code:
import sys
def main():
    N = int(input())
    A_list = [int(_) for _ in input().split()]
    ans = 1
    
    for i in range(N):
        ans *= A_list[i]
        if ans>10**18:
            ans = -1
        break
    out = ans

    print(out)

main()

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np
import functools
import operator
def II(): return int(input())
def LII(): return double(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N = II()
    #A = [0]*N
    ans = 1
    A= LI()
    #ans = np.prod(A)
    #for i in range(N):
    #    ans = ans*int(A[i])
    ans = functools.reduce(operator.mul, A)
        
    if ans>1e+18:
        print(-1)
    else:
        ans = int(ans)
        print('{:.20g}'.format(ans))
        #print(int(ans))
    
    


    


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

for an in a:
  if an == 0:
    result = 0
    break
  result = an*result
  print(result)
  
if result > 10**18:
  result = -1
  
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = input()   
l = list(map(int,arr.split(' ')))
sum = l[0]
for i in range(1,n):
  sum *= l[i]
  if sum > 1e18:
    print(-1)
    break
if sum <= 1e18:
  print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

m=np.prod(a)
if m > 10**18:
    print("-1")
else:
    print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
input_int = list(map(int, input().split()))
result = int(np.prod(input_int))
if result > 1e+18:
  result = -1
print(int(result))

Submission status: Wrong Answer

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

a_n = np.array(a,dtype=np.int64)
#print(a_n)
a_n.sort()
tmp = int(np.prod(a_n[:-2]))
tmp = tmp * a_n[-2]* a_n[-1] 
#result = int(np.prod(a_n))
#print(tmp)

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

Submission status: Wrong Answer

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

lim = math.pow(10,18)

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]

    if x > lim:
        break

if x > lim:
    x = -1

print(math.floor(x))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
S = np.prod(A)
if S > 10**18 :
    print(-1)
else :
    print(S)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

def main():
  n = int(sys.stdin.readline().rstrip())
  a = [int(x) for x in sys.stdin.readline().rstrip().split()]

  ans = np.prod(a)

  if ans > 1000000000000000000:
    ans = -1

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

Submission status: Wrong Answer

Solution code:
a = int(input())

if a == 2:
    aa = 1000000000 * 1000000000
    print(aa)
elif a == 3:
    bb = 101 * 9901 * 999999000001
    if bb > 1000000000000000000:
        print(-1)
elif a == 31:
    cc = 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
    print(cc)

Submission status: Wrong Answer

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

total = 1
for a in li:
    total *= a
    if 10 ** 18 < total:
        total = -1
        break
    elif a == 0:
        total = 0
        break
  
print(total)

Submission status: Wrong Answer

Solution code:
N= int(input())
lists = list(map(int,input().split()))
import math
#print(lists)
q=int(1)
for i in range(N):
    s = lists[i-1]
    q *= s
#print( math.log(q, 10))
if q-pow(10, 18)>=0:
    print(-1)
else:
    print(q)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int, input().split()))
i=0
ans=1
flag=0
k=1e18
while(n>i):
	ans*=p[i]
	n-=1
	if(p[i]==0):
		break
	if(ans>k):
		break
	i+=1		
if(ans>k):
		print(-1)
else:
		print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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



x=np.prod(a)

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

Submission status: Wrong Answer

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

mul=1
i=0

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np 

def input():
    return sys.stdin.readline().strip()
    
n = int(input())
A = list(map(int, input().split()))
sum = np.prod(A)
if sum > 10**18:
    sum = -1
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(e) for e in input().split()]
ans = a[0]
a.pop(0)

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

import sys
n = int(input())
aa = input()
a = aa.split()

for i in range(n):
    if(a[i] == 0):
        print(0)
        sys.exit()

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

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
s = list(map(int, input().split()))
a = np.array(s)
np.sort(a)
num = 1
for i in range(n):
  num = a[i-1] * num
if num > 1000000000000000000:
#if num > 10 ** 18:
  print("-1")
else:
  print(num)

Submission status: Wrong Answer

Solution code:
num = int(input())
nums = list(map(int,input().split()))
ans = 1
error = -1
for j in nums:
    ans = ans * j
if(len(str(ans))>18):
    print(error)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
upper = pow(10,18)
result = np.prod(np.array(A).astype('int64'))
if upper < result:
    print(-1)
else:
    print(int(result))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lim = math.pow(10,18)

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]

    if x > lim:
        break

if x > lim:
    x = -1

print(int(x))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
l = sorted(l, reverse = True)
sum = l[0]

f = True

a = 0 in l

b = 1000000000000000000

for i in range(1,n):
  if sum > b  and a==False:
    print(-1)
    f = False
    break
  sum *= l[i]

if f == True:
  print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import numpy as np
ans = np.prod(a)
if ans < 10**18:
    print(ans)
else:
    print('1')

Submission status: Wrong Answer

Solution code:
N=int(input())
P=[list(map(int,input().split()))]
import numpy
Q=numpy.array(P)
result =numpy.prod(Q[0])
 
if result>10**18:
    print(-1)
else:
    print(result)

Submission status: Wrong Answer

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

ans = 1
over = 10**18

for num in nums:
    ans = ans * num
    if ans >= over:
        print(-1)
        exit()

print(ans)

Submission status: Wrong Answer

Solution code:

import numpy as np
N = int(input())
li = list(map(int, input().split()))
if 10 ** 18 >= np.prod(li):
    print(np.prod(li))
else:
    print(-1)