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:
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import os
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from io import BytesIO, IOBase
from typing import Dict, List, Optional, Set, Tuple

MAX = pow(10, 18)


def solve(values: List[int]) -> int:
    if 0 in set(values):
        return 0
    prod = 1
    for v in values:
        prod *= v
        if prod > MAX:
            return -1
    return prod


def do_job(stdin, stdout):
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    _N = int(stdin.readline().strip())
    values = list(map(int, stdin.readline().split()))
    # values = []
    # for _ in range(N):
    #     values.append(stdin.readline().split())
    result = solve(values)
    print(result, file=stdout)


def print_output(testcase: int, result, stdout) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result), file=stdout)
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result), file=stdout)


BUFSIZE = 8192


class FastIO(IOBase):
    # pylint: disable=super-init-not-called, expression-not-assigned
    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):
    # pylint: disable=super-init-not-called
    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 configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("L%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(IOWrapper(sys.stderr))
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    stdin = IOWrapper(sys.stdin)
    stdout = IOWrapper(sys.stdout)
    do_job(stdin, stdout)
    stdout.flush()
    for h in LOG.handlers:
        h.flush()
    return 0


if __name__ == "__main__":
    sys.exit(main())

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 ans > 10**18:
        print(-1)
        exit(0)

print(ans)
exit(0)

Submission status: Accepted

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

A.sort()

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(x) for x in 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)
            break
    if ans<=10**18:
        print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = [int(e) for e in input().split()]

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = 1
for a in A:
    res *= a
    if res > pow(10, 18):
        print(-1)
        exit()
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):
    ans *= a[i]
    if ans > 10**18:
      ans = -1
      break
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()

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

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


if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
import sys

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

ans = 1
if 0 in A:
    print(0)
    sys.exit()
    
for num in A:
    ans *= num
    if ans > 10 ** 18:
        print(-1)
        sys.exit()
print(ans)

Submission status: Accepted

Solution code:
import sys

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

# print(A)
ans = 1
MAX = 10 ** 18
if 0 in A:
    print(0)
    sys.exit()
for a in A:
    ans *= a
    if ans > MAX:
        print(-1)
        sys.exit()
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(map(int,input().split()))
ANS=1
for a in A:
    ANS*=a
    if ANS>10**18:
        print(-1)
        break
else:
    print(ANS)

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


n = int_input()

a = list_input()

MAX = pow(10, 18)
flag = True
p = 1

for i in a:
    if i == 0:
        p = 0
        break

for i in a:
    p = p*i
    # print(p)
    if (p > MAX):
        flag = False
        break

# print(MAX)
if flag == True:
    print(p)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=1
for i in range(N):
    ans *= A[i]
    if ans > int(1e18):
        break
if 0 in A:
    print(0)
elif ans>int(1e18):
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
if 0 in a:
    print(0)
    quit()
ans = 1
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        quit()
print(ans)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N = int(input())
A = inpl()
ans = 1
bound = 10**18
A.sort(reverse=True)
if A[-1] == 0:
    print(0)
else:
    for a in A:
        ans *= a
        if ans > bound:
            print(-1)
            break
    else:
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
    sys.exit()
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()))

A.sort()

ans = A[0]

for i in range(N):
    if i == 0:
        continue
    ans = ans * A[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
if 0 in A:
    print(0)
    exit()
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()))
for aa in a:
  if aa==0:
    print(0)
    exit(0)

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

Submission status: Accepted

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

A.sort()
ans=1
maximum=10**18
for a in A:
  if a==0:
    print(0);exit()
  ans*=a
  if ans>maximum:
    print(-1);exit()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

if a[0] == 0:
    print(0)
    exit()
else:
    ans = a[0]
    for i in range(1, 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()))

ans=1
if 0 in A:print(0);exit()
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())
nums = [int(i) for i in input().split()]

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        return 0
    i = 1
    for a in A:
        i *= a
        if i > 10 ** 18:
            return -1

    return i

print(main())

Submission status: Accepted

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

MAX=pow(10,18)

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

Submission status: Accepted

Solution code:
def main(n: int, a: list):
    if 0 in a:
        print(0)
        return

    ans = a[0]

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

    print(ans)


if __name__ == "__main__":
    n = map(int, input().split())
    a = list(map(int, input().split()))

    main(n, a)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# a,b = map(float, input().split())

# print(int(a*b))

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

ans = 1
if l.count(0) != 0:
    print(0)
    exit()
for i in range(n):
    ans *= l[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    inf = 10**18
    ans = 1
    if 0 in A:
        print(0)
        exit()
    for a in A:
        ans *= a
        if ans > inf:
            print(-1)
            exit()
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

if len(list(filter(lambda v : v == 0, A))) > 0:
    print(0)
else:

    x = 1
    MAX = 10 ** 18
    for a in A:
        x *= a
        if x > MAX:
            x = -1
            break

    print(x)

Submission status: Accepted

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 1
border = pow(10, 18)
ng = 0
if 0 in A:
    print(0)
    ng = 1

for a in A:
    if ng == 1:
        break
        
    ans *= a
    if ans > border:
        print(-1)
        ng = 1
        break

if ng == 0:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

res = 1
for t in a:
    res *= t
    if res > 10**18:
        print(-1)
        sys.exit()
    if res == 0:
        print(res)
        sys.exit()
else:
    print(res)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 1
check = 0
for i in A:
    ans *= i
    if ans > 10**18:
        check += 1
        break
        
if min(A)==0:
    print("0")
elif check>0:
    print("-1")
else:
    print(ans)

Submission status: Accepted

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

border = pow(10, 18)

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

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

print(ans)

Submission status: Accepted

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

limit = 10 ** 18
A.sort()
ans = 1
for a in A:
    ans *= a
    if ans > limit:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys, random, math
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
    inf = 10 ** 20

#    t = int(input())
#    t, a, b = map(int, input().split())
    t = 1
    
    for _ in range(1, t+1):
    #    print("Case #{}: ".format(_), end = '')
        
        n = int(input())
        ans = 1
        for x in sorted([int(x) for x in input().split()]):
            ans *= int(x)
            if(ans > 1e18):
                ans = -1
        
                break
        
        print(ans)
        
main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def task(n, a):
    for value in a:
        if value == 0:
            print(0)
            return

    ans = a[0]
    limit = pow(10, 18)
    for i in range(1, n):
        ans *= a[i]
        if ans > limit:
            print(-1)
            return

    print(ans)


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

Submission status: Accepted

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

A.sort()
result = 1

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()

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

Submission status: Accepted

Solution code:
def solve(n, a_list):
    res = 1
    if 0 in a_list:
        return 0
    for i in range(n):
        res *= a_list[i]
        if res > 10 ** 18:
            return -1
    return res


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


def test():
    assert solve(2, [1000000000, 1000000000]) == 1000000000000000000
    assert solve(3, [101, 9901, 999999000001]) == -1
    assert solve(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]) == 0


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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
if 0 in a:
  print(0)
  exit()
ans = 1
for x in a:
  ans *= x
  if ans > 1e18:
    print(-1)
    exit()
    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import sqrt,gcd,ceil 
def ii():return int(input())
def mi():return map(int,input().split())
def li():return list(mi())
def si():return input()

n=ii()
a=li()
s=1
if 0 in a:
    print(0)
    exit(0)
for i in a:
    s*=i
    if(s>1e18):
        break
if(s>1e18):
    s=-1
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

t = 10 ** 18

n = INT()
a = LIST()
ans = 1
a.sort(reverse=True)
if a[-1] == 0:
    print(0)
    exit()
for i in a:
    ans *= i
    if ans > t:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

limit = int(1e18)

answer = 1

over = False

for a in a_i:
    answer *= a
    if answer > limit:
        over = True
        break

if min(a_i) == 0:
    over = False
    answer = 0

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

Submission status: Accepted

Solution code:
## necessary imports
# import sys
# input = sys.stdin.readline
# from math import ceil, floor;

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp

## gcd function
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a, a)

## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
    if(k > n - k): 
        k = n - k 
    res = 1
    for i in range(k): 
        res = res * (n - i) 
        res = res / (i + 1) 
    return int(res) 

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
    hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        else:
            hi = mid
    return lo

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;


# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e6 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve() 
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()))
## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

n = int(input()); a = sorted(int_array());
ans = 1; f = 1;
for i in a:
    ans *= i;
    if ans > int(1e18):
        f = 0; break;
if f:
    print(ans);
else:
    print(-1);

Submission status: Accepted

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


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

judge = False

for e in a:
    if e == 0:
        judge = True
if judge:
    print(0)
    exit()

res = 1
for e in a:
    res = res*e
    if res > 10**18:
        res = -1
        break


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

Submission status: Accepted

Solution code:



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

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

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

print(ans)

Submission status: Accepted

Solution code:
from math import *
from sys import stdin,stdout
input=stdin.buffer.readline

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

Submission status: Accepted

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

print(ans)
exit()

Submission status: Accepted

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

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

Submission status: Accepted

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

f = True
for i in A:
  if i == 0:
    print(0)
    f = False
    break

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