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:
#from pprint import pprint
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from copy import deepcopy
#from itertools
#from bisect import bisect_right #二分探索用のモジュール bisect_right(a_list,value)

#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。

# = int(input())

# = map(int,input().split())

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

# = [list(map(int,input().split())) for _ in range(XXXX)]

n = int(input())

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

result = 1
overflg = 0

if min(a) == 0:
    print(0)
    exit()

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

print(result)

Submission status: Accepted

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

A.sort()

ans = 1
for a in A:
    ans *= a
    if ans ==0 or ans > 1000000000000000000:
        break
    
if (ans > 1000000000000000000):
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = 1
x = 0
y = 0
for i in range(n):
    s *= a[i]
    if a[i] == 0:
        y += 1
    if s > 1000000000000000000:
        s = 0
        x += 1

if y != 0:
    print(0)
else:
    if x != 0:
        print(-1)
    else:
        print(s)

Submission status: Accepted

Solution code:
def do():
    n=int(input())
    l=list(map(int,input().split()))
    k=1
    if 0 in l:
        return 0
    for i in l:
        k*=i
        if k>1*10**18:
            return -1
    return k
print(do())

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 > 1e18:
            print("-1")
            break
    else:
        print(s)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
zero = A.count(0)
one = A.count(1)

if zero >= 1:
    print(0)
elif (N - one) > 100:
    print(-1)
else:
    ans = 1
    for a in A:
        ans *= a
    if ans > 10**18:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

Solution code:
N = int(input())
CHECK = "OK"
A_list = list(map(int, input().split()))
ans = 0
for i in A_list:
    if i == 0:
        ans = 0
        CHECK = "OK"
        break
    elif ans == 0:
        ans = i
        continue
    else:
        if ans * i > 10 ** 18:
            CHECK = "NG"
        else:
            ans *= i
if CHECK == "OK":
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

limit = 10**18

ans = 1

q = 0

if 0 in x:
    ans = 0
else:
    for i in x:
        ans *= i
        if ans>limit:
            q = 1
            break
    
if q == 1:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
N=int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
input()
a=[int(i) for i in 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:
n = int(input())
a = list(map(int,input().split()))
ans = int(1)
a.sort(reverse=True)
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ans = ("-1")
        break
if 0 in a:
    ans = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sum = 1

if any(b == 0 for b in As):
	sum = 0
else:
	for a in As:
		sum*=a
		if sum > 1000000000000000000:
			sum = -1
			break
print(sum)


#A,B=map(int,input().split())

#print(A*B)

Submission status: Accepted

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

ans = 1

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

Submission status: Accepted

Solution code:
N = int(input())
L1 =[int(i) for i in input().split()]
L2=sorted(L1)
if L2[0]==0:
    print(0)
elif L2[-1]*L2[-2]>10**18:
    print(-1)
else:
    ans=1
    for i in range(N):
        ans*=L2[i]
    if ans<=10**18:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
str = int(input())
str2 = input()
str3 = str2.split(" ")
res = 1
isZero = False
# 0があるかチェック

for i in range(0, str):
    if 0 == int(str3[i]):
        isZero = True
        res = 0

if not isZero:
    for i in range(0, str):
        res *= int(str3[i])
        if res > 10 ** 18:
            res = -1
            break

    
print(res)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    nums = list(map(int, input().split()))
    s = set(nums)
    if 0 in s:
        print(0)
        return
    ans = 1
    bound = 10 ** 18
    for num in nums:
        ans *= num
        if ans > bound:
            print(-1)
            return
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
p=1
flag=1
zero=0 
for i in l:
    if i==0 :
        zero=1 
        break 
if zero==0:
    for i in l:
        p*=i
        if p>1000000000000000000:
            flag=0
            break
    if flag==0:
        print('-1')
    else:
        print(p)
else : 
    print("0")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np


def main(A):
    ans = 1
    for i in A:
        if i == 0:
            return 0
    for i in A:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
    return ans


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

Submission status: Accepted

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

a.sort()

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


print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [] * n
ans = 1

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

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

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

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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 = 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
if (0 in a):
    print(0)
    exit()

for i in a:
    ans*=i
    if ans > 1e18:
        break

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

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int, input().split()))
ans = 1
ok = True
if(0 in nums):
    print(0)
else:
    for i in nums:
        ans *= i
        if(ans > int(1e18)):
            ok = False
            break
    if(not ok):
        print(-1)
    else:
        print(ans)

Submission status: Accepted

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

def product_many(N):
    if 0 in N: return 0
    ans = 1
    for x in N:
        if (10 ** 18 / ans) < x: return -1
        ans *= x
        if ans > 10 ** 18: return -1
    return ans

def main():
    _ = input()
    N = list(map(int, input().split()))
    print(product_many(N))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 1

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

print(ans)

Submission status: Accepted

Solution code:
'''
    handle - pruvi007
    questionName - 
    Contest - 
    Topic - 
    Platform - 
'''
from sys import stdin, stdout
from collections import defaultdict

def main():
    n = int(stdin.readline())
    a = list(map(int,stdin.readline().split()))
    f = 1
    flag=0
    a = sorted(a)
    for i in range(n):
        f = f*a[i]
        if f>10**18:
            flag=1
            break
    if flag:
        print("-1")
    else:
        print(f)

main()

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:
from sys import stdin
N = int(stdin.readline().rstrip())
A = list(map(int, stdin.readline().rstrip().split()))

result = 1
if 0 in A:
    print(0)
    exit()

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

Submission status: Accepted

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

a_sorted=sorted(a)
ans = 1

if a_sorted[len(a_sorted)-1] == 0:
  ans = 0
else:
  for i in range(len(a_sorted)):
    ans = ans * a_sorted[i]
    if ans > 1000000000000000000:
      ans = -1
      break

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

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

ans=1

for i in range(n):
  if ans>0 or a[i]==0:
    ans=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()))
a.sort()
b=1
if a[0]==0:
  print(0)
  exit()
for i in range(N):
  b=b*a[i]
  if b>10**18:
    print(-1)
    exit()
print(b)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
ans = 1
flg = False

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

Submission status: Accepted

Solution code:
def LI():
    return list(map(int, input().split()))

_ = int(input())
a = LI()
ans = 1
mod = pow(10, 18)

def main(ans):
    if 0 in a:
        ans = 0
    else:
        for i in a:
            ans *= i
            if ans > mod:
                ans = -1
                break
    print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 1

if min(X) == 0:
  print(0)
  x = -1
else:
  for i in range(N):
    x = x * X[i]
    if x > 10 ** 18:
      print(-1)
      x = -1
      break
    
if x > 0: print(x)

Submission status: Accepted

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

result = 1
a.sort(reverse=True)

if a[-1]==0:
    result = 0
else:
    for ai in a:
        result *= ai
        if result > MAX_RSESULT:
            result = -1
            break
print(result)

Submission status: Accepted

Solution code:
from functools import reduce
import operator

def f():
    input()
    s = input().split()

    if "0" in s:
        return 0

    ans = 1
    for num in map(int,s):
        ans *= num
        if ans > 10 ** 18:
            return -1
    return ans

print(f())

Submission status: Accepted

Solution code:
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
#from collections import deque
#import heapq
#from fractions  import gcd
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
ans=1
if 0 in a:
  print(0)
  exit()
for i in range(n):
    ans*=a[i]
    if ans>pow(10,18):
      print(-1)
      break
else:
    print(ans)

Submission status: Accepted

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

LIMIT = 18

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

ans = 1
for a_i in a:
    if len( str( ans ) ) + len( str( a_i ) ) > LIMIT + 2:
        print( -1 )
        break
    elif len( str( ans ) ) + len( str( a_i ) ) > LIMIT:
        if ans * a_i > 10 ** 18:
            print( -1 )
            break
    ans *= a_i
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):
    ans*=a[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)
else:
  for i in range(n):
    ans *= a[i]
    if ans > pow(10,18):
        ans = -1
        print(ans)
        break
  if ans != -1:
    print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A_list = [int(i) for i in input().split()]
    if 0 in A_list:
        print(0)
        return
    prod = 1
    for A in A_list:
        prod = prod * A
        if prod > (10**18):
            print(-1)
            return
    print(prod)

resolve()

Submission status: Accepted

Solution code:
from __future__ import division, print_function

''' Hey stalker :) '''
INF = 10 ** 10
TEST_CASES = False

def main():
    get_int()
    li = get_list()
    res = 1
    if 0 in li:
        print(0)
        return
    limit = 10**18
    for i in li:
        res *= i
        # print(res)
        if res > limit:
            print(-1)
            return
    print(res)
''' FastIO Footer: PyRival Library, Thanks @c1729 and contributors '''
import os
import sys
from bisect import bisect_left, bisect_right
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
# else:
#     sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
if __name__ == "__main__":
    if TEST_CASES:
        [main() for _ in range(int(input()))]
    else:
        main()

Submission status: Accepted

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

import sys

def main():
    n = int(input())
    numbers = [int(i) for i in input().split()]
    ans=1
    if 0 in numbers:
        print(0)
        sys.exit()
    else:
        for number in numbers:
            ans*=number
            if ans <= 1000000000000000000:
                continue
            else:
                print(-1)
                sys.exit()
        print(ans)            

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = 1
f1 = 0
f2 = 0
l = input().split()
for i in range(n):
    a *= int(l[i])
    if a > 1000000000000000000 :
        f1 = 1
        a = 1
    if a == 0:
        f2 = 1
    
if f2 == 1:
    print(0)
elif f1 == 1:
    print(-1)
else :
    print(a)

Submission status: Accepted

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

p = 10 ** 18

ans = 1

if 0 in A:
    ans = 0
else:
    for a in A:
        ans = ans * a
        if ans > p:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
import math
import sys
from collections import *
from itertools import *

N = int(input())

OVERFLOW = 10 ** 18

seq = list(map(int, input().split()))
seq.sort()
if seq[0] == 0:
    print(0)
    sys.exit(0)

result = 1
for n in reversed(seq):
    result *= n
    if result > OVERFLOW:
        print(-1)
        sys.exit(0)
print(result)

Submission status: Accepted

Solution code:
# Code for B - Multiplication 2
# Use input() to fetch data from STDIN
import sys

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

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

total = 1
for x in a:
    if x > 10 ** 18:
        print(-1)
        sys.exit(0)

    total = total * x;

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

print(total)

Submission status: Accepted

Solution code:
import sys

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

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

kijun = 10 ** 18

res = 1
for x in a:
  res *= x
  if res > kijun:
    print("-1")
    sys.exit()
print(res)

Submission status: Accepted

Solution code:
def default():
    maxi=1000000000000000000
    n=int(input())
    answer=1
    temp=input()
    temp=temp.split()
    flag=0
    for i in range(0,n):
        temp[i]=int(temp[i])
    temp.sort()
    for i in range(0,n):
        answer*=temp[i]
        if(answer>maxi):
            flag=1
            break
        if(temp[i]==0):
            flag==2
            break
    if(flag==1):
        print(-1)
    else:
        if(flag==2):
            print(0)
        else:
            print(answer)

if(__name__=="__main__"):
    default()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
t = int('1'+'0'*18)
ans = 1
if min(A)==0:
    print(0)
else:
    for a in A:
        ans *= a
        if ans > t:
            print(-1)
            exit()
    print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
ans=1
if 0 in A:
    ans=0
else:
    for i in range(0,N):
        ans=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()))
c = 1

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

print(c)

Submission status: Accepted

Solution code:
N = int(input())

A = list(map(int,input().split(" ")))
flag = 0
ans = 1

if 0 in A:
    flag = 2
    print(0)

if flag != 2:
    for x in A:
        ans *= x
        #print(ans)
        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 = list(map(int,input().split()))
a=sorted(a,reverse = True)
if a[-1]==0:
    print(0)
    exit()
else:
    
    number = a[0]
    for i in range(1,n):
        number = number * a[i]
        if number > 10**18:
            print(-1)
            exit()

print(number)

Submission status: Accepted

Solution code:
from math import log10

N = int(input())
A = list(map(int, input().split()))
s = 1
threshold = 10**18
if 0 in A:
    print(0)
else:
    for a in A:
        s *= a
        if s > threshold:
            print(-1)
            break
    else:
        print(s)

Submission status: Accepted

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

answer = 1
zero_exist = False
up_to_threshold = False
for i in range(n):
    if answer>int(1e+18):
        up_to_threshold = True
    else:
        answer*=a[i]
    if a[i] == 0:
        zero_exist = True
    
if zero_exist == True:
    print(0)
elif up_to_threshold == True or answer > int(1e+18):
    print(-1)
else:
    print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys

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

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

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

Submission status: Accepted

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