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

ans = 1

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

if 0 in A:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop
import bisect

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

N = int(input())
A = list(map(int,input().split())) ## 横一列

A.sort(reverse=True)

LIMIT = int(1e18)

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

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

print(ans)

Submission status: Accepted

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

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())
ls=list(map(int,input().split()))
ls.sort()
ans=1
for i in range(N):
  ans*=ls[i]
  if ans==0:
    print(0)
    break
  elif ans>10**18:
    print(-1)
    break
else:
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
N = ri()
A = ri_()
ans = 1
for i in range(N):
    ans = ans * A[i]
    if ans > 1000000000000000000:
        ans = -1
        break
if 0 in A:
    print(0)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n = inp()
a = inpl()
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


def solve(a):
    ans = 1
    over = False
    for e in a:
        if not over:
            ans *= e
        else:
            if e == 0:
                return 0
        if ans > 10 ** 18:
            over = True
    if not over:
        return ans
    else:
        return -1


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    print(solve(a))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

A.sort()

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

print(ans)

Submission status: Accepted

Solution code:
import itertools
import copy
from collections import deque
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
ans = 1
if a[-1] == 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 = [int(x) for x in input().split()]
if 0 in A:
    print(0)
    exit()
ans = 1
for x in A:
    ans *= x
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
#include <CodeforcesSolutions.h>
#include <ONLINE_JUDGE <solution.cf(contestID = "1359",problemID = "C",method = "GET")>.h>
"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    n = inp()
    a = inlt()
    q = 1
    for i in range(n):
        q = q * a[i]
        if q > 10 ** 18:
            q = -1
            break
    if 0 in a:
        q = 0
    print(q)
                
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
    sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))

#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline  
main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import copy

def multiply(N, AList):
    Multiply = 1
    for Num in range(N):
        if(AList[Num] == 0):
            return 0
    for Num in range(N):
        Multiply *= AList[Num]
        if(Multiply > 10**18):
            return -1
    return Multiply


if(__name__ == "__main__"):

    N = int( input().strip() )
    AList_Str = input().strip().split()
    AList = [0] * N
    for Num in range(N):
        AList[Num] = int( AList_Str[Num] )


    Multiplies = multiply(N, AList)
    print(Multiplies)

Submission status: Accepted

Solution code:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()

a = LIST()
a.sort()
if(0 in a):
    print(0)
else:
    ans = 1
    for el in a:
        ans*=el
        if(ans>10**18):
            break
    if(ans>10**18):
        print(-1)
    else:
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections
import heapq
N = int(input())
a = list(map(int, input().split()))
ans = 1
max_ = pow(10, 18)
if 0 in a:
    print(0)
    exit()
for tmp in a:
    ans *= tmp
    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:
    print("0")
    exit()
ans = 1
for a in range(N):
    ans *= A[a]
    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
tip = 0
sub = 0
for i in range(N):
  ans = ans * A[i]
  if ans > 10 ** 18:
    tip = 1
    ans = 0
  if A[i] == 0:
    sub = 1
if sub == 1:
  ans = 0
elif tip == 1:
  ans = -1
print(ans)

Submission status: Accepted

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

maxs = 10**18

def main():
    for i in line:
        if i==0:
            return 0
    ans = 1
    for i in line:
        ans *= i
        if ans > maxs:
            return -1
    return ans

print(main())

Submission status: Accepted

Solution code:
N = int(input())

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

product = 1
flag = 0

if(0 in As):
  print (0)
else:
  for i in range(N):
    product*= As[i]
    if(product > 10** 18):
      print(-1)
      flag = 1
      break
  if(flag == 0):
    print(product)

Submission status: Accepted

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

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

output = A[0]

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

Submission status: Accepted

Solution code:
import sys

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

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

for i in range(n):
  total *= a[i]
  if total > 1000000000000000000:
    print(-1)
    sys.exit()

print(total)

Submission status: Accepted

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

A.sort()

sum = 1
for i in A:
    sum *= i
    if sum > 10**18:
        sum = -1
        break

ans = sum

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split()))

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

print(ans)

Submission status: Accepted

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

result = 1
for x in sorted(a):
    result *= x

    if result == 0:
        print(0)
        exit()

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

print(result)

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))

ans=1
flg=True

for i in range(N):
    ans*=A[i]
    if ans>10**18:
        flg=False
        break
for i in range(N):
    if A[i]==0:
        flg=True
        ans=0
        break

if flg:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
n=int(input())

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

t.sort()

ans = 1

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import sys

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

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    a = [int(x) for x in input().split()]

    if 0 in a:
        print(0)
        return

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

    print(ans)


main()

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:
n=int(input())
A=list(map(int, input().split()))
t=1
A.sort()
if A[0]==0:
    print(0)
    exit()
A.reverse()
for i in range(n):
    t*=A[i]
    if t>1000000000000000000:
        print(-1)
        exit()
print(t)

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 range(1, n + 1):
    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()))

x = 1
a.sort()
for i in range(0,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()))
ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        if ans <= 1000000000000000000:
            ans *= i
        else:
            ans = -1
            break
if ans > 1000000000000000000:
    ans = -1

print(ans)

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

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

inf = 10**18

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

print(int(ans))

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    A.sort()

    ret = 1
    for a in A:
        if 10**18 < ret*a:
            ret = -1
            break
        else:
            ret *= a

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(0)
  exit(0)
res = 1
for x in a:
  res *= x
  if res > 10 ** 18:
    print(-1)
    exit(0)
print(res)

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    ans = A[0]

    if min(A)==0:
        print(0)
        return

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

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
LI = lambda: list(map(int, input().split()))

n = int(input())
a = LI()
prod = 1
if 0 in a:
    print(0)
else:
    for x in a:
        prod *= x
        if prod > 10**18:
            print(-1)
            break
    else:
        print(prod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

    big = 10**18
    count = 1

    ju = True


    if 0 in A:
        count = 0
    else:
        for i in range(len(A)):
            count = count * A[i]

            if count > big:
                ju = False
                break


    if ju:
        print(count)
    else:
        print("-1")




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n  = int(input())
arr = list(map(int, input().split(" ")))
z = 10 ** 18
ret = 1
for i in arr:
    #print(i)
    if(ret != -1):
        ret *= i
    elif ret == -1 and i == 0:
        ret = 0
    if( ret > z):
        ret = -1
    
print(ret)

Submission status: Accepted

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


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

Submission status: Accepted

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

def main():
    n = int(input())
    a = sorted(map(int, input().split()))
    ans = 1
    for x in a:
        ans *= x
        if ans > 10 ** 18:
            print(-1)
            exit()
    print(ans)

main()

Submission status: Accepted

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

result = 1
for el in a:
    result = result * el
    if result > 10 ** 18:
        result = -1
        break

if 0 in set(a):
    result = 0
    
print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    input()
    a=input().split()
    if "0" in a:
        print(0)
        return
    s=1
    for i in a:
        s*=int(i)
        if s>1e+18:
            print("-1")
            return
    else:
        print(s)
    return
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)
    limit = 10**18
    ans = 1
    for ai in a:
        ans *= ai
        if ans > limit:
            print(-1)
            exit(0)
        if ans == 0:
            break
    print(ans)

    


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
ns = list(map(int, input().split()))
if 0 in ns:
    print(0)
    exit()
for i in ns:
    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())) 
ans = 1
if A.count(0) >= 1:
    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 = sorted([int(i) for i in input().split()])

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

else:
    print(ans)

Submission status: Accepted

Solution code:
# 0や1のケースに注意
# index out of range
# 貪欲

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# your code goes here
def solve():
	n = int(input())
	a = input().split()
	a = [int(aa) for aa in a]
	
	for aa in a:
		if aa == 0:
			print(0)
			return 0
	
	ans = 1;
	for aa in a:
		ans *= aa;
		if ans > 1e18:
			print(-1)
			return 0
	print(ans)
	
solve()

Submission status: Accepted

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

import sys
if 0 in A:
  print(0)
  sys.exit()
prod = 1
lim = 10 ** 18
for elem in A:
  prod *= elem
  if prod > lim:
    print(-1)
    sys.exit()
print(prod)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = input()
A = [int(s) for s in input().split()]

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

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

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
getcontext().prec = 400
N=int(input())
A=list(map(int,input().split()))
if 0 in A:
    print(0)
    exit()
i=1
a=10**18
#print(A)
for n in A:
    #print(i,n)
    i*=n
    #print(i)
    if i>a:
        print(-1)
        exit()
print(i)

Submission status: Accepted

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

if min(a) == 0:
    print(0)
    exit()
else:
    ans = a[0]
    for i in range(1, n, 1):
        ans = ans * a[i]
        if ans > 1e+18:
            print(-1)
            exit()
    print(ans)

Submission status: Accepted

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

ans = 1
if as_[0] == 0:
    print(0)
    exit(0)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


t=sorted(s)

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())
A=list(map(int, input().split()))
LIMIT = 10**18
if 0 in A:
  print(0)
  exit(0)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
arr=[int(i) for i in input().split()]
total=1
arr.sort()
if(arr[0]==0):
    print(0)
else:

    for i in range(n):
        if(arr[i]>10**18):
            total=-1
            break
        else:
            total*=arr[i]
            if total>10**18:
                total=-1
                break
    print(total)

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

Submission status: Accepted

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

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

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)