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,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
 
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()


class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def __str__(self):
        return  str(self.edges)
 
    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        #self.st=SegTree(self.size*2-1,self.ETdepth,function=min,ide=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]

## Tested by EduFor 88 D
## https://codeforces.com/contest/1359/problem/D

class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    # return boundary index of r such that func({table[i]} =< x , i in [pos,r]
    def right_bound(self,pos,x):
        k=(self.size-pos).bit_length()
        for j in range(k)[::-1]:
            nx=pos+(1<<j)
            if nx<n and self.query(pos,nx+1)<=x:
                pos+=(1<<j)
        return pos
    
    # return boundary index of l such that func({table[i]} =< x , i in [l,pos]
    def left_bound(self,pos,x):
        k=pos.bit_length()
        for j in range(k)[::-1]:
            nx=pos-(1<<j)
            if 0<=nx and self.query(nx,pos+1)<=x:
                pos-=(1<<j)
        return pos

    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)
 

## return prime factors of N as dictionary {prime p:power of p}
## within 2 sec for N = 2*10**20+7
def primeFactor(N):
    i,n=2,N
    ret={}
    d,sq=2,99
    while i<=sq:
        k=0
        while n%i==0:
            n,k,ret[i]=n//i,k+1,k+1
        if k>0 or i==97:
            sq=int(n**(1/2)+0.5)
        if i<4:
            i=i*2-1
        else:
            i,d=i+d,d^6
    if n>1:
        ret[n]=1
    return ret


## return the list of prime numbers in [2,N], using eratosthenes sieve
## within 2sec for N = 1.2*10**7
def PrimeNumSet(N):
    Max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList:
        if seachList[0] <= Max:
            break
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

## retrun LCM of numbers in list b
## within 2sec for no of B = 10*5  and  Bi < 10**6
def LCM(b,mo=10**9+7):
    prs=PrimeNumSet(max(b))
    M=dict(zip(prs,[0]*len(prs)))
    for i in b:
        dc=primeFactor(i)
        for j,k in dc.items():
            M[j]=max(M[j],k)
    
    r=1
    for j,k in M.items():
        if k!=0:
            r*=pow(j,k,mo)
            r%=mo
    return r

 
show_flg=False
show_flg=True
ans=0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
def main():
    if c[0] >0:
        print(0)
        return

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

Submission status: Accepted

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

s = 1
mod = pow(10, 18)

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

for i in a:
    s = s*i
    if s > mod:
        print(-1)
        exit()
else:
    print(s)

Submission status: Accepted

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

"""

"""

tot = 1
n = int(input())
arr = map(int, input().split())

for v in arr:
    if v == 0:
        tot = 0
        break
    if tot <= 10**18:
        tot *= v
    

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

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


for i in range(n):
    ans *= A[i]

    if ans > 1e18:
        ans = -1
        break


print(ans)

Submission status: Accepted

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

MAX = int(1e18)
tmp = 0 if 0 in A else 1
flag = False

for a in A:
    tmp *= a
    if tmp > MAX:
        flag = True
        break

if flag:
    print(-1)
else:
    print(tmp)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
  N=int(input())
  A=list(map(int,input().split()))
  A.sort(reverse=True)
  ans=1
  if A[-1]!=0:
    for a in A:
      ans*=a
      if ans > 10**18:
        ans=-1
        break
  else:ans=0
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n=int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x  = int(input())

line  = [int(y) for y in input().split()]
line.sort()

yeet  = 1
solved  = False

if line[0] == 0:
    print(0)
else:
    for i in range(0,x):
        yeet = yeet*line[i]
        if yeet > 10**18:
            solved = True
            print(-1)
            break

    if solved == False:
        print(yeet)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
n=int(input())
a=[int(x) for x in input().rstrip().split()]
a.sort()
if a[0]==0:
  print(0)
else:
  ans=1
  for i in a:
    ans*=i
    if 10**18<ans:
      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)
    exit()
for i in range(n):
    if i==0:
        ans=a[i]
    else:
        ans*=a[i]
        if ans>10**18:
            print(-1)
            exit()
print(ans)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
 
def main():
    n = inp()
    a = inpl()
    ans = 1
    a.sort()
    for i in range(n):
        if a[i] == 0:
            print(0)
            return
        ans *= a[i]
        if ans > 10**18:
            print(-1)
            return
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul
N = int(input())
A = [int(c) for c in input().split()]
ans = 1
if 0 in A:
  print(0)
  import sys
  sys.exit()
for c in A:
  ans *= c
  if ans>10**18:
    print(-1)
    break
else:
  print(ans)

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
def main():
    _ = input()
    A = list(map(int, input().split()))
    cnt = 1 
    mi = min(A)
    if mi == 0:
        print(0)
    else:
        for a in A:
            cnt *= a 
            if cnt > 1e18 and mi > 0:
                print(-1)
                break
        else:
            if cnt < 0:
                print(-1)
            else:
                print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

f=1
c=0
for i in l:
    f*=i
    if f > 10**18:
        c=1
        break
    
if 0 in l:
    print(0)
elif c==1:
    print(-1)
else:
    print(f)

Submission status: Accepted

Solution code:
# B - Multiplication 2

import sys
readline = sys.stdin.readline

N = int(readline())
A = list(int(x) for x in readline().split())
A.sort()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

n = int(readline())
p = list(map(int, input().split()))
ma = int(1e18)

for p_ in p:
    if p_ == 0:
        print(0)
        exit()

ans = 1
for p_ in p:
    ans *= p_
    if ans > ma:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

OUT = 1 + 10 ** 18

ans = 1
for i, Ai in enumerate(A):
    if ans == 0: break
    #
    Ai_end = (OUT + ans - 1) // ans
    if Ai >= Ai_end:
        ans = -1
        break
    else:
        ans *= Ai

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
MAX = 10**18
if A[0] == 0:
    print(0)
    exit()
ans = 1
for i in reversed(range(N)):
    ans *= A[i]
    if ans > MAX:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=int(input())
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    a=list(map(int,sys.stdin.readline().split(' ')))
    ams=1

    if 0 in a:
        print(0)
        continue
        
    for x in a:
        ams*=x
        if ams> 1000000000000000000:
            ams=-1
            break

    print(ams)
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

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

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

print(mul)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
a = RI()

a.sort(reverse=True)

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

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

print(ans)

Submission status: Accepted

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

ans = 1
a.sort()

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

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

Submission status: Accepted

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

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

res = 1
for aa in a:
    res *= aa
    if(res > 1000000000000000000):
        print(-1)
        exit()

print(res)

Submission status: Accepted

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

ans = 1

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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


def solve(nums):
  if any(not n for n in nums):
      return 0

  i = 1
  for n in nums:
      i *= n
      if i > 10 ** 18:
        return -1
  return i

print(solve(nums))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*a = map(int,read().split())
x = 1
INF = 10**18

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


for i in a:
    x *= i
    if x > INF:
        print(-1)
        break
else:
    print(x)

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
prod = 1
if 0 in lis:
    print(0)
    exit(0)
for i in lis:
    if(prod>1000000000000000000):
        print(-1)
        exit(0)
    prod=prod*i
print(prod) if(prod<=1000000000000000000) else print(-1)

Submission status: Accepted

Solution code:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n = inp()
x = ip()
ele = 10**18
prod = 1
if 0 in x:
    print(0)
    exit()
for i in x:
    prod *= i
    if prod > ele:
        print(-1)
        exit()
print(prod)

Submission status: Accepted

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

ans = 1
for x in a:
	if ans == 0 or ans == -1:
		break
	ans = ans * x
	if ans > 1000000000000000000:
		ans = -1

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

s = input().split()
A = []
for i in range(N):
  A.append(int(s[i]))

result = 1

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

print(result)

Submission status: Accepted

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

ans = 1

if 0 in A:
    print(0)
else:
    flag = 0

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

    if flag == 0:
        print(ans)

Submission status: Accepted

Solution code:
input()
r = 1
for x in input().split():
  r = max(-1, r * int(x))
  if r > 1e18:
    r = -1
print(r)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    ans = 0
    limit = 10 ** 18
    if 0 in A:
        print(0)
        return
    for i, v in enumerate(A):
        if i == 0:
            ans = v 
            continue
        ans *= v
        if ans > limit:
            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:
#!python3

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

# input
N = int(input())
A = LI()


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


def solve(data):
    ans = 1
    if 0 in data:
        return 0
    for d in data:
        ans *= d
        if ans > 10 ** 18:
            return -1
    return ans


if __name__ == '__main__':
    n = int(input())
    data = list(map(int, input().split()))
    ans = solve(data)
    #print('ans') # debug
    print(ans)

    #print('\33[32m' + 'end' + '\033[0m') # debug

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
N = int(input())
A = list(map(int, input().split()))

# 求解処理
result = 1
if 0 in A:
    result = 0
else:
    sorted_A = list(reversed(sorted(A)))
    for A_n in sorted_A:
        result *= A_n
        if result > pow(10, 18):
            result = -1
            break

# 結果出力
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
nums = map(int, input().split(' '))

sum = 1

for num in sorted(nums):
    sum *= num
    if sum > 1e18:
        print(-1)
        exit()

print(sum)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    INF = 10 ** 18
    ans = 1
    is_INF = False
    for a in A:
        ans *= a
        if ans > INF:
            is_INF = True
            break
    if is_INF:
        if 0 in A:
            print(0)
        else:
            print(-1)
    else:
        print(ans)
if __name__ == "__main__":
    main()