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:
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

# 定数
MOD = int(1e9 + 7)
INF = 1e18
DX = [0,  0, 1, -1, 1,  1, -1, -1, 0]
DY = [1, -1, 0,  0, 1, -1,  1, -1, 0]
PI = 3.14159265358979323846264338327950288

"""=======　関数 ==============================================================="""
# 約数列挙(O(√n))
def divisor(n):
    ret = []
    for i in range(1, n+1):
        if i*i > n:
            break
        if n % i == 0:
            ret.append(i)
            if i*i != n:
                ret.append(n/i);
    return sorted(ret)

# エラトステネスの篩
def search_sosuu(n):
    sosuu = [True] * n
    sosuu[0] = sosuu[1] = False
    for i in range(2, n):
        if sosuu[i]:
            for j in range(2, n):
                if(i*j > n):
                    break
                else:
                    sosuu[i*j] = False
    return sosuu

# 素因数分解(O(√n))
def div_prime(n):
    prime_factor = []
    for i in range(2, n+1):
        if i*i > n:
            break
        count = 0
        while n % i == 0:
            count += 1
            n //= i
        if count:
            prime_factor.append((i, count))
    if n != 1:
        prime_factor.append((n, 1))
    return prime_factor

# 素数判定(O(√n))
def is_sosuu(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    elif N%2 == 0:
        return False
    for i in range(3, int(math.sqrt(n)), 2):
        if n % i == 0:
            return False
    return True

# 最大公約数(O(logn))
def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    while r:
        a, b = b, r
        r = a % b
    return b

# 最小公倍数(O(logn))
def lcm(a, b):
    g = gcd(a, b)
    return g * (a//g) * (b//g)

# 階乗(O(n))
def factorial(n):
    if n <= 1:
        return 1
    return (n * factorial(n-1)) % MOD

# 高速コンビネーション計算(前処理:O(N) 計算:O(1))
MAX_COMB = 200005
fac = [0] * MAX_COMB
finv = [0] * MAX_COMB
inv = [0] * MAX_COMB
com_inited = False
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX_COMB):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    com_inited = True
def com(n, k):
    if not com_inited:
        COMinit()
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

# 繰り返し2乗法(O(logP))
def repeat_squaring(base, sisuu):
    if sisuu == 0:
        return 1
    if sisuu % 2 == 0:
        t = repeat_squaring(base, sisuu / 2) % MOD
        return t * t % MOD
    return base * repeat_squaring(base, sisuu - 1) % MOD

# 単発コンビネーション(O(logn))
def fast_com(a, b):
    bunshi = 1
    bunbo = 1
    for i in range(1, b + 1):
        bunbo *= i
        bunbo %= MOD

        bunshi *= (a - i + 1)
        bunshi %= MOD

    ret = bunshi * repeat_squaring(bunbo, MOD - 2) % MOD

    while ret < 0:
        ret += MOD
    return ret

# 2直線の交差判定
def is_cross(x1, y1, x2, y2, X1, Y1, X2, Y2):
    dx_ai = X1 - x1;
    dy_ai = Y1 - y1;
    dx_bi = X1 - x2;
    dy_bi = Y1 - y2;
    
    dx_ai2 = X2 - x1
    dy_ai2 = Y2 - y1
    dx_bi2 = X2 - x2
    dy_bi2 = Y2 - y2

    si = dx_ai * dy_bi - dy_ai * dx_bi
    si2 = dx_ai2 * dy_bi2 - dy_ai2 * dx_bi2
    
    si3 = dx_ai * dy_ai2 - dy_ai * dx_ai2
    si4 = dx_bi * dy_bi2 - dy_bi * dx_bi2

    return si * si2 < 0 and si3 * si4 < 0

# 木の根からの深さ
def tree_depth(edge, start_node, n_node):
    dist = [INF] * n_node
    dist[start_node] = 0

    S = queue.LifoQueue()
    S.put((start_node, 0))

    while not S.empty():
        node, d = S.get()
        dist[node] = d

        for next in edge[node]:
            if d[next] == INF:
                S.put((next, d + 1))

    return dist


'''
1行のint=====================================
N, K = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''



N = int(input())

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

ans = 1

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

A = input().split()  

answer = 1

sort = sorted(A)

for i in range(N) :
    answer = answer * int(sort[i])
    if answer == 0:
        print('0')
        quit()
    if answer > 1000000000000000000 : 
        print('-1')
        quit()


print(answer)

Submission status: Accepted

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

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


n = I()
a = list(MI())

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

print(ans)

Submission status: Accepted

Solution code:
import sys
n=int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
for i in range(len(a)):
  ans *= a[i]
  if ans > 1000000000000000000:
    print(-1)
    sys.exit()
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = 1
# print(max(A))
if 0 in A:
    print(0)
elif max(A) > 10**18:
    print(-1)
else:
    for i in A:
        B *= i
        if B > 10 ** 18:
            B = -1
            break
    print(B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
else:
    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 > 10 ** 18:
            print(-1)
            break
    else:
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
cur = 1
if 0 in l:
    print(0)
    exit()
for i in l:
    cur *= i
    if cur > 1000000000000000000:
        print(-1)
        exit()
print(cur)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([int(i) for i in input().split()])
res=1
for x in A:
    res = res*x
    if res > 10 ** 18:
        res = -1
        break
print(res)

Submission status: Accepted

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

if 0 in a :
  ans=0
else:
  for i in range(n):
    if len(str(ans))>=19:
      ans='-1'
      break
    else:
      ans*=a[i]
if ans==1000000000000000000:
  ans=1000000000000000000
elif len(str(ans))>=19:
  ans=-1
print(ans)

Submission status: Accepted

Solution code:
import functools
import operator

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

if 0 in a_list:
    ans = 0
else:
    k = len(a_list) - a_list.count(1)
    # print(k)
    if k > 60:
        ans = -1
    else:
        ans = functools.reduce(operator.mul, a_list)
        if ans > 10 ** 18:
            ans = -1
        else:
            pass
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
n=int(input())
s=input().split()
ans=1
d=1;
e=1
for i in s:
    if i=='0':
        e=0


for i in range(n):
    ans=ans*int(s[i])
    if ans>np.power(10,18):
        d=0
        break;

if d==0 and e==1:
    print(-1)
elif e==0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

lines = stdin.readlines()
n = int(lines[0])
a = sorted(map(int, lines[1].split()))
ans = 1
for x in a:
    ans *= x
    if ans > 1e18 or ans < 0: ans = -1
print(ans)

Submission status: Accepted

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


print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil, factorial, log,tan,pi,cos,sin,radians
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
from fractions import Fraction
from functools import reduce
from decimal import *
import string
import sys
import os
import re
inf = float('inf')
mod_ = int(1e9) + 7
mod = 998244353

def factors(n):
    from functools import reduce
    return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sieve(m):
    n=1
    primes = {}
    arr=set([])
    for i in range(2, int(m ** 0.5) + 1):
        a = n // i
        b = m // i
        for k in range(max(2, a), b + 1):
            c = i * k
            primes[c] = 1

    for i in range(max(n, 2), m + 1):
        if i not in primes:
            arr.add(i)

    return arr


class DisjointSetUnion:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
 
    def find(self, a):
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a:
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a
 
    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a != b:
            if self.size[a] < self.size[b]:
                a, b = b, a
 
            self.num_sets -= 1
            self.parent[b] = a
            self.size[a] += self.size[b]
 
    def set_size(self, a):
        return self.size[self.find(a)]
 
    def __len__(self):
        return self.num_sets



def main():
    n=int(input())
    prod=1
    arr=list(map(int,input().split()))
    arr.sort()
    for i in arr:
        if i==0:
            prod=0
            break
        elif prod>10**18:
            print(-1)
            exit()
        prod*=i

    if prod>10**18:
        print(-1)
        exit()
    print(prod)
    # n,m=
    # print(n*m)












    



# region fastio

BUFSIZE = 8192

class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

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


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    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()

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

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

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 1

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

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


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

Submission status: Accepted

Solution code:

def main():
    N = int(input())
    A = [int(arg) for arg in input().split()]
    ans = 1

    for i in range(N):
        if A[i] == 0:
            print(0)
            return

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#2問目
MAX = 10 ** 18
N = int(input())
A = list(map(int, input().split()))
result = 1

if 0 in A:
    result = 0
else:
    for i in range(N):
        result *= A[i]
        if result > MAX:
            result = -1
            break
print(result)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
from sys import exit
n = int(input())
ans = 1
a = list(map(int, input().split()))
if 0 in a:
	print(0)
	exit()
for x in a:
	ans *= x
	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:
    ans=0
else:
    for i in a:
        ans*=i
        if ans>10**18:
            ans=-1
            break
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
al = stdin.readline().rstrip().split()
ans = 1
flag = 0
for a in al:
	ans = ans * int(a)
	if ans < 0 or ans > 1000000000000000000:
		flag = 1
		ans = -1

print(ans)

Submission status: Accepted

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

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

ans = 1
for i in lis:
    ans *= i
    if ans >= 10**18:
        break

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

Submission status: Accepted

Solution code:
def m():  
    N = int(input())
    A = list(map(int, input().split()))
    times = 1
    c = 0

    for i in A: 
        if times <= 10**18 and c < N:
            times *= i
            c += 1   
    if times > 10 ** 18:
        times = -1
    if 0 in A:
        times = 0
    print(times)
m()

Submission status: Accepted

Solution code:
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = int(input())
a = inpl()
flag = 0
t = 1
for i in range(0, n):
    if a[i] == 0:
        flag = 1
        print(0)
        break

aaa = 0

if not flag:

    for i in range(0, n):
        t *= a[i]
        if t > 1000000000000000000:
            print(-1)
            aaa = 1
            break
    if not aaa:
        print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

if a_list[-1] == 0:
  print(0)
  sys.exit()

if a_list[0] > 1000000000000000000:
  print(-1)
  sys.exit()

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

  if ans > 1000000000000000000:
    print(-1)
    sys.exit()

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul
l = int(input())
x = list(map(int, input().split()))
# print(x)
# result = reduce(mul, x)
result = 1
limit = 10 ** 18
for i in x:
  if result < limit or i == 0:
    result = result * i
if limit < result:
  result = -1
print(result)

Submission status: Accepted

Solution code:
_ = input()
data = list(map(int, input().split()))
p = 1
m = 10 ** 18

if data.count(0) > 0:
  print(0)
  exit()

for d in data:
  p *= d
  if m < p:
    print(-1)
    exit()
print(p)

Submission status: Accepted

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

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

ans = 1
a_li = [a for a in a_li if a != 1 and a != 0]
a_li.append(1)
for a in a_li:
    ans *= a
    if ans > 1000000000000000000:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
sol = 1
nula = 0
over = 0
for i in l:
    if (i == 0):
        nula = 1
    sol = sol * i
    if sol>1000000000000000000:
        over = 1
        sol = 0
if (nula == 1):
    print(0)
elif (over == 1):
    print(-1)
else:
    print(sol)

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	a = input().split(" ")
	for i in range(n):
		a[i] = int(a[i])
	for ai in a:
		if ai == 0:
			print("0")
			return
	ans = 1
	for ai in a:
		ans *= ai
		if ans > 1e18:
			print("-1")
			return
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

ar=[]
total=1
big=False
lion = False
A=N-1
ar = list(map(int, input().strip().split(' ')))

if 0 in ar:
      print("0")
      big=True
      lion=False
      
while big == False and lion == False:
      for i in range (0,N):
            total=ar[i]*total
            if i == A:
                  lion = True
            if total>(1000000000000000000):
                  big=True
                  lion=True
                  break

if big == False and lion == True:
      print(total)

if big == True and lion == True:
      print("-1")

Submission status: Accepted

Solution code:
from functools import reduce
n = int(input())
A = list(map(int,input().split()))
b = sorted(A,reverse=True)
c = 1
if b[-1] == 0:
    c = 0
else:
    for i in range(n):
        if c > 10 ** 18:
            break
        c *= b[i]
    

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
if A[0] == 0:
    print(0)
    exit()

ans = 1
check = 10 ** 18

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
res = 1

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

for x in N:
    res *= x
    if res > pow(10, 18):
        res = -1
        break

print(res)

Submission status: Accepted

Solution code:
import numpy as np

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = A[0]
    if 0 in A:
        ans = 0
    else:
        for i in A[1:]:
            ans *= 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):
  ans *= a[i]
  if ans > 1000000000000000000:
    ans = -1
    break

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

print(ans)

Submission status: Accepted

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

arr.sort()
flag=0
pdt=1
for i in range(n):
  pdt=pdt*arr[i]
  if(pdt>1000000000000000000):
    flag=1
    break

if(flag==1):
  print(-1)
else:
  print(pdt)

Submission status: Accepted

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

Submission status: Accepted

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

val = 1

if 0 in A:
  print('0');
else:
  LIMIT = pow(10, 18)
  for v in A:
    val = val * v
    if val > LIMIT:
      val = -1
      break
  print(val)

Submission status: Accepted

Solution code:
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = int(input())
a = inpl()
flag = 0
t = 1
for i in range(0, n):
    if a[i] == 0:
        flag = 1
        print(0)
        break

aaa = 0

if not flag:
    
    for i in range(0, n):
        t *= a[i]
        if t > 1000000000000000000:
            print(-1)
            aaa = 1
            break
    if not aaa:
        print(t)

Submission status: Accepted

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

def manipulate(A_i):
    if 0 in A_i:
        return 0
    
    ans = 1
    
    for a in A_i:
        ans *= a
        if ans > 10 ** 18:
            return -1
    
    return ans

print(manipulate(A_i))

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if 0 in data:
    print(0)
    exit(

    )
answer = 1

for x in data:
    answer *= x
    if answer > 1e+18:
        answer = -1
        break

print(answer)

Submission status: Accepted

Solution code:
def main():
    n = input()
    A = [int(i) for i in input().split()]
    if 0 in A:
        print("0")
        return
    ans = 1
    max_num = pow(10, 18)
    for a in A:
        ans *= a
        if ans > max_num:
            print("-1")
            return
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
input_num = int(input())
line = input().split(" ")
over_flg = False
if ("0" in line):
    print("0")
else:
    output = 1
    for i in range(input_num):
        output = output * int(line[i])
        if output > 10 ** 18:
            over_flg = True
            break
    if over_flg:
        print("-1")
    else:
        print(output)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

print(ans)

Submission status: Accepted

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

def mp(a):
    b=[]
    if len(a)==1:
        b.append(a[0]) 
    elif len(a)%2==0:
        for i in range(0,len(a),2):
            b.append(a[i]*a[i+1]) 
    else:
        for i in range(0,len(a)-1,2):
#            print(i)
            b.append(a[i]*a[i+1]) 
#        print("1",a[len(a)//2+1])
        b.append(a[len(a)-1]) 
    return b

c=aa.copy()
while len(c)>1:
    c=mp(c)   
#    print(c)
    
if c[0]<=10**18:
    print(c[0])
else:
    print(-1)

Submission status: Accepted

Solution code:
MAX = 10 ** 18

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
liste = input().split()
number = [int(x) for x in liste]
total = 1
i = 0
if 0 in number:
    total = 0
else:
    while i < N:
            total *= number[i]
            i = i + 1
            if total > 10**18:
                total = -1
                break
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def two(a):
    if 0 in a:
        return 0
    res = 1
    for el in a:
        res *= el
        if res > 1e18:
            return -1
    return res
n = int(input())
a = list(map(int, input().split()))
print(two(a))

Submission status: Accepted

Solution code:
input()
total = 1
A = sorted(map(int, input().split()))
if not A[0]:
    print(0)
    quit()
for n in A:
    if total * n > 10 ** 18:
        print(-1)
        break
    total *= n
else:
    print(total)

Submission status: Accepted

Solution code:
n=int(input())
lst=list(map(int,input().split()))
lst.sort()
mul=1
flg=0
for i in lst:
    mul=mul*i
    if mul>1e18:
        flg=1
        print(-1)
        break
if flg==0:
    print(mul)

Submission status: Accepted

Solution code:
#import numpy


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

#dtype('int64')

#ans = numpy.prod(a, dtype = 'int64')

ans = 1

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


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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
n0 = A.count(0)
n1 = A.count(1)
import math
ans = 1
if N-n0-n1>60:
  ans = -1
for i in range(N):
  if A[i] == 0 or ans == 0:
    ans = 0
    break
  elif ans <0:
    ans = -1
  elif math.log10(A[i])+math.log10(ans)>18:
    ans = -1
    b = 1
  else:
    ans *= A[i]

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

Submission status: Accepted

Solution code:

N = int(input())

aaa = list(map(int, input().split()))
ans = 1

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


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


print(ans)

Submission status: Accepted

Solution code:
def total_power(n, a):
    half_total = []
    start = 0
    end = len(a)
    if n%2 == 0:
        start = 0
    else:
        start = 1 
        half_total.append(a[0])

    for i in range(start, end, 2):
        half_total.append(a[i]*a[i+1])
    if len(half_total) == 1:
        return half_total[0]
    else:
        return total_power(len(half_total), half_total)


n = int(input())

a_str = input()
a_strs = a_str.split(' ')
a = [int(s) for s in a_strs]
total = total_power(n, a)

if total <= 1e+18:
    print (total)
else:
    print('-1')

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	a = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	if min(al) == 0:
		return 0
	ret = 1
	for v in al:
		ret *= v
		if ret > 10**18:
			return -1
	return ret
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)