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 = tuple(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()))
A.sort()

flag=0
for x in A:
    if x==0:
        print('0')
        exit()

    if flag==0:
        ans=x
        flag=1
        continue

    ans = ans * x
    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 i in A:
    if res > 10**18:
        print(-1)
        sys.exit()
    res *= i

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

Submission status: Accepted

Solution code:
#import math
#=input()
n=int(input())
#=map(int,input().split())
a=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

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 = [int(num) for num in input().split()]
ans = 1
if 0 in a:
    ans = 0
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())
arr=[int(i) for i in input().split()]
if 0 in arr:
    print(0)
    exit()
f=1 
prod=1 
for i in arr:
    prod*=i 
    if prod>10**18:
      f=0 
      break
        
print(prod if f else -1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 1
for i in l:
  if i == 0:
    ans = 0

for i in l:
  ans *= i
  if ans > 1e18 or ans == 0:
    break
if ans > 1e18:    
  print(-1)
else:
  print(ans)

Submission status: Accepted

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

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

m = 10 ** 18

s = 1
for aa in a:
    s = s * aa
    if s > m:
        print(-1)
        exit(0)

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n =ni()
    s = na()
    s.sort()
    l = pow(10,18)
    ans = 1
    for i in s:
        ans *= i
        if ans > l:
            print(-1)
            return
    print(ans)
    return


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 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()))
result = 1
if 0 in aList:
  print(0)
  exit()
for a in aList:
  result = result * a
  if result > 10 ** 18:
    print('-1')
    exit()
print(result)

Submission status: Accepted

Solution code:
import sys
import math

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


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

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

print(result)

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()
LIS=LI()

MX=1000000000000000000
res = 1
if 0 in LIS:
    print(0)
else:
    for i in LIS:
        res *= i
        if res > MX:
            print(-1)
            exit(0)
    print(res)

Submission status: Accepted

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

T = 10**18

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
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())
A = list(map(int, input().split()))

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int, input().split()))
Ans = 1
if min(L) == 0:
    print(0)
else:
    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())
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:
        ans = -1
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = list(map(int, readline().split()))
a.sort()
ans = 1
for aa in a:
    ans *= aa
    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
hantei = True
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        hantei = False
        break

if a.count(0) >= 1:
    hantei = True
    ans = 0
print(ans) if hantei else print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2020/05/31
# AtCoder Beginner Contest 169 - B

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

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

# Output
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
over = 10 ** 18
isOver = False
is0 = False
ans = 1
for a in A:
    ans *= a
    if ans > over:
        isOver = True
        ans = 1
    elif ans == 0:
        is0 = True
if is0:
    print(0)
elif isOver:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

# print(A)

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

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))

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

print(now)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a.sort()
x = 1
for i in range(n):
    x *= a[i]
    # print(i,x)
    if x > 10**18:
        print(-1)
        quit()
print(x)

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache



def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)



def main():
    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)










if __name__ == "__main__":

    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 1
for x in arr:
    ans *= x
    if ans > 10**18:
        ans = 10**19

if ans == 10**19:
  print(-1)
else:
  print(ans)

Submission status: Accepted

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

if As[0] == 0:
    print(0)
    exit()
b = 1
for a in reversed(As):
    b *= a
    if b > 10**18:
        print(-1)
        exit()
print(b)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

list.sort(A, reverse=True)

if A[-1] == 0:
  print(0)
  exit()

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

print(mul)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
ans = arr[0]

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import random
import collections

# available on Google, not available on Codeforces
# import numpy as np
# import scipy
import math


def solve(lst):  # fix inputs here
    # console("----- solving ------")
    if 0 in lst:
        return 0
        
    res = 1
    for r in lst:
        res *= r
        if res > 10**18:
            return -1

    return res

def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return


# for case_num in range(int(input())):
    # read line as a string
    # strr = input()

    # read line as an integer
_ = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer

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

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    # grid = []
    # for _ in range(nrows):
    #     grid.append(input())

res = solve(lst)

    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def abc169_b():
    _ = int(input())
    A = list(map(int, input().split()))
    lim = 10**18

    if 0 in A: return 0

    ans = 1
    for a in A:
        ans *= a
        if lim < ans: return -1
    return ans

print(abc169_b())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N=input()
A=list(map(int,input().split()))
ans=1
for i in range(len(A)):
  if A[i]==0:
    print(0)
    sys.exit()
for i in range(len(A)):
  ans=ans*A[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()))
ans = 1
lim = int(1e+18)
if a.count(0):
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if lim < ans:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
n=int(input())
a= list(map(int, input().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)
        sys.exit()

print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
li=list(map(int,input().split()))
ans=1
if 0 in li:
    print('0')
    import sys
    sys.exit()
    
for l in li:
    ans*=l
    #print(ans)
    if ans > 10**18:
        print('-1')
        break
else:
    print(ans)

Submission status: Accepted

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

m = 10 ** 18

ans = 1
ex = False
for i in range(n):
    if a[i] == 0:
        print(0)
        ex = True

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

Submission status: Accepted

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()

ans=1

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
ans = 1
if 0 in A:
    ans = 0
else:
    for i in range(N):
        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()))

M = 10**18

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

Submission status: Accepted

Solution code:

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

    if a.count(0) >= 1:
        print("0")
        return

    MAX = 1000000000000000000
    ans = 1
    for x in a:
        if (ans <= MAX):
            ans *= x

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

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:
n = int(input())
a = list(map(int, input().split()))

ans = 1

for x in a:
    ans = ans * x

    if (ans > 10**18):
        ans = -1;
        break

for x in a:
    if x == 0:
        ans = 0

print(ans)

Submission status: Accepted

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

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

ans = 1
for i in a:
    ans *= i
    if ans > pow(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 a in A:
        ans *= a
        if ans > 10**18:
            ans = -1
            break

    print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

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

Submission status: Accepted

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

prod = 1
flag = 0
lim = 1e18
A.sort()
for num in A:
  prod = num*prod
  if prod > lim:
    flag = 1
    break
if flag == 1:
  print(-1)
else:
  print(prod)

Submission status: Accepted

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

    ans = A[0]
    if 0 in A:
        print(0)
        return

    for i in range(1, N):
        ans = ans * A[i]

        if ans > (10 ** 18):
            ans = -1
            break

    print(ans)


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(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()))
total = 1
count = 0
for i in range(n):
    total *= A[i]
    if total > 10**18:
        count += 1
        break

if 0 in A:
    print('0')
elif count == 1:
    print('-1')
else:
    print(total)

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

Submission status: Accepted

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

tmp = A[0]
index = 1
while tmp < 10**18 and index < N:
    tmp *= A[index]
    index += 1

A.sort()

if A[0] == 0:
    print(0)
elif tmp > 10**18:
    print(-1)
else:
    print(tmp)

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, input().split()))
result = A[0]

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

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

print(result)

Submission status: Accepted

Solution code:
import os
import sys
from io import BytesIO, IOBase


def main():
    n = int(input())
    arr = list(map(int, input().rstrip().split()))
    product = 1
    if 0 in arr:
        print(0)
        return
    for num in arr:
        if product * num > 10**18:
            product = -1
            break
        product *= num
    print(product)

#.........................................FAST INPUT OUTPUT.......................................
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

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

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

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

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


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


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

#....................................END OF FAST I/O............................................

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result = 1
ok = True
if 0 in A:
    result = 0
else:
    for a in A:
        result *= a
        if result > 10 ** 18:
            ok = False
            break

if ok:
    print(result)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

if a[-1] == 0:
	print(0)
	exit()

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