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:
# coding: utf-8
#import numpy as np
import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
from queue import PriorityQueue
import itertools
from copy import deepcopy
import random
import time
import os
import sys
import datetime
from functools import lru_cache
from functools import reduce
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
alphabet="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):
    if b:print("yes")
    else:print("no")
def Yn(b):
    if b:print("Yes")
    else:print("No")
def YN(b):
    if b:print("YES")
    else:print("NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(bbool,ret1,ret2):
    if bbool:return ret1
    else:return  ret2
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def pm(x):
    return x//abs(x)
def inputintlist(): 
    return list(map(int,input().split()))
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])#[cost,x]
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def ruisekiwa(A):
    ret=[0]*(len(A)+1)
    for a in range(len(A)):
        ret[a+1]=ret[a]+A[a]
    return ret
def getmd(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow









######################################################################################################
n=int(input())
A=inputintlist()
ans=1
if A.count(0)>0:
    ans=0
else:
    for a in A:
        ans*=a
        if ans>10**18:
            break
if ans>10**18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(S)

Submission status: Accepted

Solution code:
import sys
n=int(input())
a=[int(x) for x in input().split()]
a=sorted(a, reverse=True)
m=1
if a[-1] == 0:
  print(0)
else:
  for i in a:
    m*=i
    if m > 10**18:
      print('-1')
      sys.exit()
  print(m)

Submission status: Accepted

Solution code:
from sys import stdin
N = stdin.readline().rstrip()
An = [int(x) for x in stdin.readline().rstrip().split()]
W = 1
if any([A == 0 for A in An]):
    print(0)
    exit()
for A in An:
    W = W * A
    if 1000000000000000000 < W:
        print(-1)
        exit()
print(W)

Submission status: Accepted

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

Submission status: Accepted

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

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

if li.count(0) > 0:
    print(0)
    exit()

for i in li:
    ans = 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()))
# print(a)

ok = False
for i in a:
    if i == 0:
        ok = True
if(ok):
    print(0)
    exit()

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

print(ret)

Submission status: Accepted

Solution code:
import sys
# import math

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def main():
    n, *a = map(int, sys.stdin.read().split())
    a.sort()
    res = 1
    for x in a:
        res *= x
        if res > 10**18:
            print(-1)
            return
    print(res)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

if 0 in lst:
    print("0")
    quit()

res = 1
for a in lst:
    res = res*a
    if res > 1000000000000000000:
        print("-1")
        quit()
    else:
        pass

print(res)

Submission status: Accepted

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

s = 1
ten18 = 10**18
over = False

for b in a:
  if not over:
    s *= b
  if s > ten18:
    #print(-1)
    over = True
  if b == 0:
    s = 0
    over = False
    break
  
if over:
  print(-1)
else:
  print(s)

Submission status: Accepted

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

if 0 not in a:

    for i in range(n):
        res = res * a[i]
        
        if res > 1000000000000000000:
            res = -1
            break
else:
    res = 0

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in a:
    ans *= i

    if (ans > 1000000000000000000):
        ans = -1
        break

if(0 in a): print(0)
else: print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split(' ')))
start = 1
maxi = int(1e18)
arr.sort()
for num in arr:
  start *= num
  if start > maxi:
    start = -1
    break
    
print(start)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = A[0]
i = 1
if 0 in A:
    print(0)
else:
    while (i < n) and (ans <= 10**18):
        ans *= A[i]
        i += 1
    if (ans <= 10**18) and i == n:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

Solution code:
N, = [int(x) for x in input().split()]
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:
N = int(input())
A = list(map(int,input().split()))
Ans = 1
for a in A:
    if a == 0:
        print("0")
        break
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_lst = list(map(int, input().split()))
max_ = 10 ** 18

if 0 in a_lst:
    print(0)
    quit()
else:
    res = a_lst[0]
    for a in a_lst[1:]:
        res *= a
        if res > max_:
            print(-1)
            quit()
    print(res)

Submission status: Accepted

Solution code:
import sys

n = int(input())
l = []
l += list(map(int, input().split()))

if l.count(0) >= 1:
    print('0')
    sys.exit()

r = 1
for e in l:
    r = r * e

    if r > 10 **18:
        print('-1')
        sys.exit()
        
print(r)

Submission status: Accepted

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

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

ans = 1

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

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


print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
ans = 1

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

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

Submission status: Accepted

Solution code:
n = input()

ls = list(map(int,input().split()))
inf = 10**18
ans = 1

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

Submission status: Accepted

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

a0 = a[0]
a_else = a[1:]
th = 10**18
for ai in sorted(a_else):
    a0 *= ai
    if a0 > th:
        print('-1')
        exit()

print(a0)

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


print(ans)

Submission status: Accepted

Solution code:
import sys
import math
 
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
 
def main():
  K = int(input())
  s = list(map(int, input().split()))
  prod = 1
  a = 10 ** 18
  if 0 in s:
    print(0)
    sys.exit()
  for k in range(K):
    prod = prod * s[k]
    if prod > a:
      print(-1)
      sys.exit()
  
  print(prod)

if __name__ == '__main__':
  main()

Submission status: Accepted

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

for i in li:
    if i == 0:
        print(0)
        exit()
    if (ans > 1000000000000000000):
        overflg = True
    else:
        ans *= i

if (ans > 1000000000000000000):
        overflg = True

if overflg:
    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()
limit = 10**18
for i in a:
    ans*=i
    if ans > limit:
        print(-1)
        exit()
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:
def main():
    n = int(input())

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


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

    ret = 1

    for a in A:
        ret *= a
        if ret > 1000000000000000000:
            print(-1)
            return;

    print(ret)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
s = list(set(a))
if s[0] == 0:
    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()))
if 0 in a:
  print(0)
else:
  ans=1
  a.sort(reverse=True)
  for i in range(n):
    ans*=a[i]
    if ans>10**18:
      ans=-1
      break
  print(ans)

Submission status: Accepted

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

if a > 0:
    print(a)

Submission status: Accepted

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

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

print(mul)

Submission status: Accepted

Solution code:
import sys

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


def multiple(l):
    ans = 1
    if 0 in l:
        return 0
    for i in l:
        if ans * i > 10 ** 18:
            return -1
        else:
            ans *= i
    return ans


print(multiple(a))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
k=list(map(int,input().split()))
res=1
k.sort()
for x in k:
  res*=x
  if(res>10**18):
    print(-1)
    break
else:
  print(res)

Submission status: Accepted

Solution code:
N=int(input())
M=[int(_) for _ in input().split()]
M.sort(reverse=True)
a=1
if M[-1]==0:
    print(0)
    exit()

else:
    for s in M:
        a=a*s
        if a>10**18:
            print(-1)
            exit()
print(a)

Submission status: Accepted

Solution code:
import sys
n = int(input())
A = list(map(int,input().split()))
ans = 10**18
tmp = 1

if 0 in A:
    print(0)
else:
    for i in range(n):
        tmp *= A[i]
        if tmp > ans:
            print(-1)
            sys.exit()
    print(tmp)

Submission status: Accepted

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
answer=1
for a in A:
    answer*=a
    if answer>pow(10,18):
        answer=-1
        break
if 0 in A:
    print(0)
else:
    print(answer)

Submission status: Accepted

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

if 0 in a_list:
    print(0)
else:
    result = 1
    for a in a_list:
        result = result * a
        if result > 10 ** 18:
            print(-1)
            break
    else:
        print(result)

Submission status: Accepted

Solution code:

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

chk = A[0]

i = 1




while i < N:
    chk = chk * A[i]
    if chk > 1000000000000000000:
        chk = -1
        break
    i+=1

i = 0
while i < N:
    if A[i] == 0:
        chk = 0
    i+=1

print(chk)

Submission status: Accepted

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

Submission status: Accepted

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

c = set(a)

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

print(ans)

Submission status: Accepted

Solution code:
def solve(N, As):
    ans = 1
    _As = sorted(As)
    border = 10 ** 18
    for a in _As:
        ans *= a
        if ans > border:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    N = int(input())
    As = [int(i) for i in input().split()]
    solve(N, As)

Submission status: Accepted

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

ans = 1
if 0 in l:
  print(0)
else:
  for i in l:
    ans *= i
    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()))
A = sorted(A)
ANS = 1

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

print(ANS)

Submission status: Accepted

Solution code:
'''     ##     ##  #######  # #  ######
        ##     ##  ##   ##  ###    ##
        ##     ##  ##    #  # #    ##
        #########  #######  # #    ##    '''

import sys
import math
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMOD = 998244353;

if __name__ == "__main__":
    # sys.stdin = open("input.txt","r")  # <<<  ^o^  Comment this line  ^_^  >>>
    n = int(input())
    ans = 1
    li = get_array()
    maxii = int(1e18)
    flag = flag2 = False
    for i in li:
        if not flag2:
            ans *= i
        if i == 0:
            flag = True
        if ans > maxii:
            flag2 = True
            ans = -1
        # printchk(ans)
    if flag:
        ans = 0
    print(ans)


# #############################################################################
'''
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
>>> DO NOT PLAGIARISE.
TESTCASES:
'''

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

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

Submission status: Accepted

Solution code:
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    sys.exit()
#A = [int(input()) for _ in range(N)]
A1 = 1
for i in A:
    A1 *= i
    if A1 > 10**18:
        print("-1")
        sys.exit()

print(A1)
#cnt = 0
#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')

Submission status: Accepted

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
ans=int(1)
aaa=True
if 0 in l:
    aaa = False
    print(0)
else:
    for j in range(n):
        ans = ans*l[j]
        if ans > 10**18:
            print(-1)
            aaa=False
            break
if aaa:print(ans)

Submission status: Accepted

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

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

for i in range(n):
    ans *= a[i]
    if ans > m:
        ans = -1
        break 

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# from typing import *
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def solve(N, A):
    for i in range(N):
        if A[i] == 0:
            print(0)
            return
    ans =1
    for i in range(N):
        if A[i] > math.pow(10,18):
            print(-1)
            return
        ans *= A[i]
        if ans > math.pow(10,18):
            print(-1)
            return
    print(ans)



def main():
    import sys
    tokens = iter(sys.stdin.read().split())
    N = int(next(tokens))
    A = [None for _ in range(N)]
    for i in range(N):
        A[i] = int(next(tokens))
    assert next(tokens, None) is None
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
v = []
v = [int(x) for x in input().split()]
v.sort()
for x in v:
	ans = ans*x
	if ans > 1e18:
		break
if ans > 1e18:
	print(-1)
else :
	print(ans)

Submission status: Accepted

Solution code:
# Nの入力
N = int(input())

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

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

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a = [int(i) for i in input().split() if i!="1"]

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

Submission status: Accepted

Solution code:
import sys
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    ans = 1

    for i in range(n):
        if a[i] == 0:
            print(0)
            sys.exit(0)

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))
    #print(A_list)
    A_list.sort()
    #print(A_list)
    ans = 1
    for a in A_list :
        ans = ans * a
        if ans == 0 :
            break
        elif ans > 10 ** 18 :
            ans = -1
            break

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

n = int(input())

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

k = 1

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

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

t = 1

for i in range(n):
    if a[i] == 0:
        print("0")
        exit()

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

print(t)

Submission status: Accepted

Solution code:
N = int(input())

A = list(map(int,input().split()))
#print(A)
result = 1
for i in A:
    result = result * i
    if result > 1000000000000000000:
        break

for j in A:
    if j == 0:
        result = 0
    



if result <= 1000000000000000000:
    print(result)
else:
    print(-1)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int, input().split()))
res = 1
for i in range(n):
    if( nums[i] == 0):
        res = 0
if(res != 0):
    for i in range(n):
        res *= nums[i]
        if(res > 1000000000000000000):
            break
if res <= 1000000000000000000:
    print(res)
else:
    print(-1)

Submission status: Accepted

Solution code:
n = int(input())
a=[int(i) for i in input().split()]
ans=1
flag=0
for i in range(n):
    ans = ans*a[i]
    if a[i]==0:
        flag=1
    if ans>pow(10,18):
        ans=0
if ans==0 and flag==0:
    print("-1")
elif ans==0 and flag==1:
    print("0")
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = list(map(int,input().split()))
ans = 1
if 0 in A:
  print(0)
  sys.exit()

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

Submission status: Accepted

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