Problem:


Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0



Sample input:
2
1000000000 1000000000


Sample output:
1000000000000000000

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    p = 1
    m = pow(10, 18)
    if 0 in A: return 0
    for n in A:
        p = p * n
        if p > m:
            return -1
    return p


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    yyy=10**18
    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))

    x=1
    for a in arr:
        if a==0:
            print(0)
            return
        
        if x==-1:
            continue

        x*=a

        if x > yyy:
            x=-1
    
    print(x)

    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

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

Submission status: Accepted

Solution code:
def B():
    n = int(input())
    a = list(map(int, input().split()))
    res = 1
    for el in sorted(a):
        res *= el
        if res > pow(10,18):
            res = -1
            break
    if res > pow(10,18):
        res = -1
    print(res)
B()

Submission status: Accepted

Solution code:
import sys

N = int(input())

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

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

ans = 1
for a in As:
    ans *= a

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import math

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

ans=1
for ai in a:
    if ai==0:
        ans=0
    if ans!=-1:
        ans*=ai
    if ans>10**18:
        ans=-1

print(ans)

Submission status: Accepted

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

sums=1
for i in A:
    sums=sums*i
    if sums>1000000000000000000:
        sums=-1
        break
    
if 0 in A:
    print(0)
else:
    print(sums)

Submission status: Accepted

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

ans = 1
if A.count(0) >= 1:
    print(0)
    exit()
for i in 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
A.sort(reverse = True)
flag = True

if 0 in A:
    ans = 0
    flag = False

if flag:
    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()))

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:
#!/usr/bin/env python
"""AtCoder Beginner Contest 169: B - 
https://atcoder.jp/contests/abc169/tasks/abc169_b
"""

__author__ = 'bugttle <bugttle@gmail.com>'


def calc(As):
    MAX = 10 ** 18
    ans = 1
    for n in As:
        if n == 0:
            return 0
        ans *= n
        if MAX < ans:
            return -1
    return ans

def main():
    N = int(input())
    As = list(map(int, input().split()))
            
    if As.count(0) != 0:
        print(0)
    else:
        print(calc(As))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
mx = 10**18
arr = list(map(int, input().split()))
arr.sort()
if arr[0] == 0:
    print(0)
else:
    mul = 1
    for i in arr:
        mul *= i
        # print(i, mul)
        if mul > mx:
            print(-1)
            exit(0)
    print(mul)

Submission status: Accepted

Solution code:
import sys
n = int(input())
ans = 1
s = input()
a = [int(x.strip()) for x in s.split(' ')]
if 0 in a:
  print(0)
  sys.exit()
for i in range(n):
  ans *= a[i]
  if ans>1000000000000000000:
    print(-1)
    sys.exit()
print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
def main():
    i = int(input())
    j = list(map(int, input().split()))
    res = 1

    if 0 in j:
        print(0)
        return

    for jj in j:
        res *= jj
        if math.pow(10, 18) < res:
            print(-1)
            return

    print(res)


if __name__ == "__main__":
    main()

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

Submission status: Accepted

Solution code:
import sys
# from random import choice,randint
# from bisect import bisect_left as bl             
# from bisect import bisect_right as br  
# from collections import deque,defaultdict,Counter
# from math import sqrt,floor,ceil
# from itertools import combinations,permutations
# from heapq import heapify,heappop,heappush,heappushpop
# inp=sys.stdin.readline
# out=sys.stdout.write
# flsh=sys.stdout.flush
# ranomd string generator --> a = ''.join(random.choices(string.ascii_lowercase, k = 1000))
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod1=998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

#fact=[1]
#for i in range(1,100001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*100001
#ifact[100000]=pow(fact[100000],mod-2,mod)
#for i in range(100000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()] #use list comprehension for loops
def LF(): return [float(x) for x in inp().strip().split()] #use try and except for dictionaries
def LS(): return inp().strip().split() #declare local variables ... for functions assing them to variables
def I(): return int(inp().strip()) # before using example ... func = len for using len() funtcion
def F(): return float(inp().strip()) #sort dictionary after zipping
def S(): return inp().strip() #use map function for mapping list to a fuction
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a)) #use this for string concatenation
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r,p):                      
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

####################Actualcode################################
def solve():
    n = I()
    a=LI()
    p = 1
    flag=0
    for i in a:
        p*=i
        if p>10**18:
            flag=1
            break
    if 0 in a:
        print(0)
    elif p>10**18 or flag==1:
        print(-1)
    else:
        print(p)
def main():
    solve()

######## Python 2 and 3 footer by Pajenegod and c1729
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

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

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            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')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

inp = lambda: sys.stdin.readline().rstrip('\r\n')
out = lambda x: sys.stdout.write(x)
flsh= lambda: sys.stdout.flush()

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
nums = sorted(map(int, input().split()))
if nums[0] == 0:
    print(0)
else:
    ans = 1
    for num in nums:
        ans = ans * num
        if ans > 10**18:
            break
    if ans > 10**18:
        print('-1')
    else:
        print(ans)

Submission status: Accepted

Solution code:
import sys
_ = int(input())
ns = list(map(int, input().split()))
total = 1
flg = False
if 0 in ns:
    print(0)
    sys.exit(0)
for n in ns:
    if total > 10**18:
        flg = True
        break 
    total = total*n
if flg or total > 10**18:
    print(-1)
else:
    print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
# def gcd(a,b):
#     if b==0:

#         return a
#     else:
#         return gcd(b,a%b)
def main():
    # mod=10**9+7
    #for _ in range(int(input())):
    n=int(input())
    arr=[int(k) for k in input().split()]
    res=1
    counter=0
    for i in range(n):
        if arr[i]==0:
            counter=1
            print(0)
            break
    if counter==0:
        count=0
        for i in range(n):
            res*=arr[i]
            if res>10**18:
                count=1
                print(-1)
                break
        if count!=1:
            print(res)








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")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = input()

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

temp = pow(10, 18)
ans = 1
flag = 0

if 0 in a:
    print(0)
    flag = 1
else:
    for i in a:
        ans = ans * i
        if ans > temp:
            print(-1)
            flag = 1
            break

if flag == 0:
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


LIMIT = 10 ** 18


def prod(xs):
    xs.sort()
    res = 1
    if 0 in xs:
        return 0
    for x in xs:
        res *= x
        if res > LIMIT:
            return None
    return res


def main():
    n = int(input())
    bs = [int(z) for z in input().split()]
    res = prod(bs)
    if res is None:
        print(-1)
    else:
        print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  maximam = 10**18

  result = 1
  if 0 in A:
    print(0)
    return True

  for a in A:
    result *= a
    if result > maximam:
      print(-1)
      return True
  print(result)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import numpy as np

def test():
    D = 1e18
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return 0
    s = 1
    for i in A:
        s *= i
        if s > D:
            print(-1)
            return 0
    print(s)
    return 0

if __name__ == "__main__":
    test()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

N = rri()
arr = rrm()



def solve(N, arr):
    ans= arr[0]
    if 0 in arr:
        return 0
    for i in range(1, N):
        if ans > 10**18:
            return -1
        else:
            ans *= arr[i]
    if ans >10**18:
        return -1
    return ans

print(solve(N, arr))

Submission status: Accepted

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

Submission status: Accepted

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

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())
a=list(map(int,input().split()))
b=1
for i in range(n):
  if a[i]==0:
    b=0

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split(" ")))
ans = 1
lim = 10**18

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


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

print(ans)

Submission status: Accepted

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

s=1
over=False

if 0 in ls:
    s=0
else:
    for i in ls:
        s*=i
        if s>10**18:
            over=True
            break


if over:
    print(-1)
else:
    print(s)

Submission status: Accepted

Solution code:
'''input
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
'''

n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 1
for i in arr:
	ans = ans*i 
	# print(ans, i)
	if(ans > 1e18):
		print(-1)
		exit()


print(ans)

Submission status: Accepted

Solution code:
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())

"""========main code==============="""
t=ii()

a=ll()
s=1
f=0
val=10**18
if 0 in a:
    print(0)
else:    
    for i in a:
        s*=i
        if(s>val):
            f=1
            break
    if f:
        print(-1)
    else:
        print(s)

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

n = int(ipt())
a = [int(i) for i in ipt().split()]
if 0 in a:
    print(0)
    exit()
ans = 1
for i in a:
    if 10**18/ans < i:
        print(-1)
        exit()
    ans *= i
if ans > 10**18:
    print(-1)
else:
    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 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())

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

A.sort()

res = 1

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

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools



sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
A =  [int(i) for i in input().split()]
ans = 1
flag = 0

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

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

Submission status: Accepted

Solution code:
import math

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

for i in range(1,len(A)):
  a*=A[i]
  if pow(10,18)<a:
    print('-1')
    exit(0)
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

  if flag == 0:
    print(mul)

Submission status: Accepted

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

List.sort()
ans = 1
for i in List:
    ans *= i
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)

Submission status: Accepted

Solution code:

import numpy as np

n = int(input())

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

ans = 1

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

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

Submission status: Accepted

Solution code:
N = int(input())
a_list = [int(_c) for _c in input().split(" ")]
a_list = sorted(a_list)

res = 1
flg = False
for a in a_list:
    res = res * a
    if res > 10 ** 18:
        flg = True
        break

if flg:
    print(-1)
else:
    print(res)

Submission status: Accepted

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

ans = 1

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