Problem:


Score : 200 points

Problem Statement

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

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

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

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

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

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

Sample Input 3

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

Sample Output 3

0



Sample input:
2
1000000000 1000000000


Sample output:
1000000000000000000

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()
ans=1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
m = 1
for i in a:
    m = m * i
    if m > 1000000000000000000:
        m = -1
        break
if 0 in a:
    print(0)
else:
    print(m)

Submission status: Accepted

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

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

print(0 if 0 in set(A) else 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 > 10**18:
        print("-1")
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = 1
c = int(1e18)
flag = 0
for i in range(n):
    if a[i]==0:
        flag = 1
if flag==1:
    print(0)
    exit()
for i in range(n):
    b *= a[i]
    if b>c:
        print(-1)
        exit()
print(b)

Submission status: Accepted

Solution code:

def parse():
  N = int(input())
  A = list(map(int, input().split(" ")))
  return N, A

def power(base, exp):
    """ Fast power calculation using repeated squaring """
    if exp < 0:
        return 1 / power(base, -exp)
    ans = 1
    while exp:
        if exp & 1:
            ans *= base
        exp >>= 1
        base *= base
    return ans

def main():
  N, A = parse()
  A = sorted(A)
  if A[0] == 0:
    print(0)
    exit(0)

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

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = 10 ** 18


def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return

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

    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
if min(A) == 0:
  ans = 0
  print(ans)
  quit()

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
ans = 1
A = list(map(int,input().split(' ')))
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:
n = int(input())
ai = [int(i) for i in input().split()]

ans = 1

ai.sort(reverse=True)

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

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

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    N = II()
    A = LMIIS()
    A.sort()
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)
    
main()

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 a:
        if i == 0:
            ans = 0
            break
        elif ans * i > 10 ** 18:
            ans = -1
            break
        else:
            ans *= i

    print(ans)

Submission status: Accepted

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

ans = 1
var = pow(10,18)

if 0 in A:
    ans = 0
else:
    for i in range(len(A)):
        ans *= A[i]
        if ans > var:
            ans = -1
            break

print(ans)

Submission status: Accepted

Solution code:
# Problem B - Multiplication 2

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
sum = 1

# calc
if 0 in a_nums:
    print(0)
else:
    for a in a_nums:
        sum *= a
        if sum>10**18:
            sum = -1
            break

    # output
    print(sum)

Submission status: Accepted

Solution code:
from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

n = I()
a = LI()

la = list(a)
if 0 in la:
    print(0)
    exit()
tmp = 1
for i in range(n):
    if pow(10,18)<tmp*a[i]:
        print(-1)
        exit()
    else:
        tmp *= a[i]

print(tmp)

Submission status: Accepted

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

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
ans = 1 
upper = int(1e18)
for i in range(n):
    ans *= a[i]
    if ans > upper:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a = 1
if 0 in A:
    print(0)
    exit()


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

Submission status: Accepted

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

ans = 1
LIMIT = 1000000000 ** 2
for a in A:
    ans *= a
    if ans > LIMIT:
        print(-1)
        exit()
        
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 A:
    ans*=i
    if ans>10**18:
        print(-1)
        sys.exit()
print(ans)

Submission status: Accepted

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


if e == 1:
    print(-1)
else:
    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()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INT_MAX=10**11+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
n=int(input())
A=INPUT()
bool=False
for i in range(n):
    if A[i]==0:
        bool=True
        break
if bool:
    print(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:
N = int(input())
A = list(map(int, input().split()))
ans = A[0]

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
ans = 1
# exit()
A.sort()
# print(A)
for a in A:
    ans *= a
    if ans > 10 ** 18:
        print(-1)
        exit()
else:

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MX = 1000000000000000000
N = int(input())
v = list(map(int, input().split(" ")))
v.sort()
ans = 1
for i in v:
    ans *= i
    if ans > MX:
        print(-1)
        break

if ans <= MX:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def LI():return list(map(int,input().split()))
def yes():return print("Yes")
def no():return print("No")
from collections import deque, defaultdict, Counter
from heapq import heappop, heappush
# import math
# pi=math.pi
# print(pi)
# yes()
# no()
n=int(input())

# s=input()
a=LI()
a.sort()
if a[0]==0:
    print(0)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = 1
f = True

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
arr = sorted([int(x) for x in input().split(' ')])
ans = 1
for i in arr:
    ans = ans * i
    if(ans > (10**18) or ans == 0):
        break
print(-1 if(ans > (10**18)) else ans)

Submission status: Accepted

Solution code:
N = int(input())
AA = list(map(int,input().split()))
res = AA[0]
if 0 in AA:
  print(0)
else:
  for a in AA[1:]:
    res = res*a
    if res>1e18:
      print('-1')
      exit()
  print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = list(map(int, input().split()))
C = 1
if 0 in A:
    print(0)
    sys.exit()
for a in A:
    C *= a
    if C > 1e18:
        print(-1)
        sys.exit()
print(C)

Submission status: Accepted

Solution code:
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        N=int(input())
        A=list(map(int,input().split()))
        if 0 in A:
            return 0
        else:
            i=0
            ans=1
            for i in range(N):
                ans*=A[i]
                i+=1
                if ans>10**18:
                    ans=-1
                    break
            return ans
    print(main())
    
    
resolve()

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    n = II()
    aa = MII()
    t = 1
    if 0 in aa:
        print(0)
        return None
    for a in aa:
        t *= a
        if t > 10**18:
            print(-1)
            return None
    print(t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
s = list(map(int,input().split()))
ok = True
for i in s:
  ans *= i
  if ans>1000000000000000000:
    ok = False
    break
if(0 in s):
  print(0)
else:
  print(ans if ok else -1)

Submission status: Accepted

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

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

    if res > inf:
        print(-1)
        return 0
    else:
        print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N = int(input())
    A_lsit = list(map(int, input().split()))

    answer = 1
    if 0 in A_lsit:
        answer = 0

    for A in A_lsit:
        answer *= A
        if answer > pow(10, 18):
            answer = -1
            break
    print(answer)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

res = 1
for i in a:
    if i == 0:
        res = 0
        break
    if res != -1:
        res *= i
    if res > 10**18:
        res = -1
print(res)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = IL()
A.sort()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    if any(i == 0 for i in a_l):
        print(0)
        return

    ans_max = 10 ** 18
    ans = 1
    for i in a_l:
        ans *= i
        if ans > ans_max:
            ans = -1
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    ans=1
    for x in a:
        if ans *x >10**18:
            print(-1)
            exit(0)
        ans*=x
    print(ans)

# region fastio

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

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

total = 1
if 0 in A:
    N = 0
    total = 0
for i in range(N):
    total *= A[i]
    if total>1000000000000000000:
        total = -1
        break

print(total)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 1
k = 10 ** 18
if 0 in a :
  count=0
else :
  for item in a:
    count = count * item
    if count > k:
      break

if count > k:
  print('-1')
else:
  print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
if A[-1] == 0:
    print(0)
else:
    s = 1
    for a in A:
        s *= a
        if s == 0:
            print(0)
            break
        if s > 10**18:
            print(-1)
            break
    else:
        print(s)

Submission status: Accepted

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

r = 1

for i in A:

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

if 0 in A:
    r = 0
    
print(r)

Submission status: Accepted

Solution code:
n = int(input())
lst = [int(x) for x in input().split()]
res = 1
isHigher = False

if 0 in lst:
  print(0)
else:
  for i in lst:
    res = res * i
    if res > 10**18:
      isHigher = True
      break
  if isHigher:
    print(-1)
  else:
    print(res)

Submission status: Accepted

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

tmp = 1

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

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


print(tmp)

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n = inp()
a = inlist()
a = sorted(a)
res = 1
for i in a:
    res *= i
    if res > 10**18:
        res = -1
        break
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

flag= True
ans=1
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        flag=False
        break

if flag:
    print(ans)
else:
    if 0 in a:
        print(0)
    else:
        print(-1)

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

Submission status: Accepted

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

LIM = 10 ** 18

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

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
MOD = 10**9 + 7
N = int(input())
lisA = list(map(int,input().split()))

ans = lisA[0]
if 0 in lisA:
    print(0)
    exit()

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

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))