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

Submission status: Accepted

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

print(out)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def main():
    n = ii()
    a = lmi()
    a.sort()
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10**18:
            break
    else:
        print(ans)
        return
    print(-1)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:



N = int(input())
A = [int(x) for x in input().split()]
ans = 1
if 0 in A:
    print(0)
    exit()
for x in A:
    ans *= x
    if ans > 10**18:
        ans = -1
        break
print(ans)

Submission status: Accepted

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

    if 0 in A:
        print(0)
        exit()
    ans = 1
    for a in A:
        ans *= a
        if ans > limit:
            print(-1)
            exit()

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
aaa = list(map(int, input().split()))
if 0 in aaa:
    print(0)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

n = int(readline())
a = sorted(map(int, readline().split()))
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        quit()
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
MOD = 10**9+7
# MOD = 998244353

n = int(input())
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    exit()

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

print(ans)

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
if 0 in a:
    print(0)
    exit()
p = 1
for x in a:
    p *= x
    if p>10**18:
        print(-1)
        exit()
print(p)

Submission status: Accepted

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

ans = 1

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

n = int(ri())
a = Ri()
a.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    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 >= 10 ** 18 + 1:
            print(-1)
            exit()
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    ans = 1
    if 0 in A:
        print(0)
        sys.exit()
    for i in range(N):
        ans *= A[i]
        if ans>10**18:
            print('-1')
            break
    else:
        print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
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:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    A = LI()

    if min(A) == 0:
        print(0)
        return
    ans = 1
    for x in A:
        ans *= x
        if ans > INF:
            print(-1)
            return
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
l=L()
ans=1
for i in l:
    ans*=i
    if ans>10**18:
        if 0 in l:
            print(0)
        else:
            print(-1)
        break
else:
    print(ans)

Submission status: Accepted

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

    t = 1
    for x in A:
        t *= x
        if t > 10 ** 18:
            if 0 in A:
                print(0)
            else:
                print(-1)
            return
    print(t)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Accepted

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

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

nmax = 10**18

acc = 1
for a in an:
    acc *= a
    if acc > nmax:
        acc = -1
        break
print(acc)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(main())

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,*A = map(int, read().split())

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    a = list(geta(int))
    a.sort()

    ret = 1
    for ai in a:
        ret *= ai
        if ret > 10**18:
            print(-1)
            return

    print(ret)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
zerocounter=0
for i in range(n):
  if a[i]==0:
    zerocounter=1
    break
if zerocounter==1:
  print(0)
else:
  ans=1
  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())
al = list(map(int, input().split()))

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

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

Submission status: Accepted

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

s = 1

if 0 in a:
    s = 0
else:

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

print(s)

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

print(ans)

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 i in range(N):
    ans *= As[i]
    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()))
for ai in a:
    if ai == 0:
        print(0)
        exit()
ans = 1
for ai in a:
    if ans <= 10 **18:
        ans *= ai
    else:
        print(-1)
        exit()
if ans <= 10 **18:
    print(ans)
else:
    print(-1)
    exit()

Submission status: Accepted

Solution code:
n = input()
a_list = list(map(int,input().split()))
a_list = sorted(a_list)
ac = 1
for a in a_list:
    ac = ac * a
    if ac > 10**18:
        print(-1)
        exit()
print(ac)

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:
        ans=-1
        break
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(1, N):
    ans *= A[i]
    if(ans > 10**18):
        print(-1)
        exit(0)
print(ans)

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
n = ii()
A = iil()
ans = 1
if 0 in A:
    print(0)
    exit()
for item in A:
    ans *= item
    if ans > 1e18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A = list(map(int, rl().split()))
    if any(ai == 0 for ai in A):
        print(0)
        return
    ans = 1
    for ai in A:
        ans *= ai
        if 10 ** 18 < ans:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    solve()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
ans=1
cap=10**18
if 0 in set(A):
  print(0)
else:
  for a in A:
    ans*=a
    if ans>cap:
      print(-1)
      break
    else:
      continue
  else:
    print(ans)

Submission status: Accepted

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

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

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

print(total)

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:
N = int(input())
A = list(map(int, input().split()))
M = pow(10, 18)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    A = LI()

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

    print(ans)

if __name__ == '__main__':
    resolve()

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())
t = [int(i) for i in input().split()]
t.sort()
ans = 1
for i in t:
	ans*=i
	if ans>10**18:
		ans=-1
		break
print(ans)

Submission status: Accepted

Solution code:
MAX_VAL = 10**18

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

ans = 1
for a in A:
    ans *= a
    if ans > MAX_VAL:
        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 aa in a:
    ans*=aa
    if ans>10**18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 1
    if 0 in A_arr:
        cnt = 0
    else:
        for A in A_arr:
            cnt *= A
            if cnt > 10**18:
                cnt = -1
                break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
ans=1
if 0 in lis:
    print(0)
    sys.exit()
for i in range(n):
    ans*=lis[i]
    if ans>10**18:
        print(-1)
        sys.exit()
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, A = Z(), ZZ()
    if 0 in A:
        print(0)
        return
    output = 1
    for a in A:
        output *= a
        if output > 10 ** 18:
            print(-1)
            break
    else: print(output)

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# from functools import lru_cache, cmp_to_key
# from heapq import merge, heapify, heappop, heappush
# from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
# from itertools import combinations as comb, permutations as perm
# from bisect import bisect_left as bl, bisect_right as br, bisect
# from time import perf_counter
# from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n = int(data())
arr = l()
arr.sort()
p = 1
m = 10 ** 18
for i in arr:
    p *= i
    if p > m:
        p = -1
        break
out(p)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

    INF = 10**18

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

print(a())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    aa=LI()

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

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

main()

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
if 0 in A:
  print(0)
  exit()
for ai in A:
  pro *= ai
  if pro > 10**18:
    print(-1)
    exit()
print(pro)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(N):
        if A[i] == 0:
            print(0)
            return
    
    ans = 1
    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:
n = int(input())
a = [int(_) for _ in input().split()]
ans = a[0]
for i in a:
    if i == 0:
        print(0)
        exit()
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())
res = 1
dat = list(map(int, input().split()))
dat.sort()
for i in range(n):
    res *= dat[i]
    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 a.count(0):
    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()))
inf = int(1e18)
ans = 1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    An = [int(x) for x in input().strip().split()]
    ans = 1
    limit = 10 ** 18
    if 0 in An:
        print(0)
        exit()
    for a in An:
        ans *= a
        if ans > limit:
            print(-1)
            exit()
    print(ans)

if __name__ == '__main__':
    main()