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:
input()
a = list(map(int, input().split()))
a.sort()
b = 1
for i in a:
    b *= i
    if b > 1e18:
        print(-1)
        exit()
print(b)

Submission status: Accepted

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

Submission status: Accepted

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

if any([a == 0 for a in A]):
    print(0)
    exit()

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

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

"""
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_b && sh testp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_b && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_b && sh submitp.sh
"""

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = [ int(x) for x in input().split(" ")]
a.sort()
ans = 1
for x in a:
  if x==10**18 and ans>1:
    ans = -1
    break
  else:
    ans *= x
    if ans>10**18:
      ans = -1
      break
print(ans)

Submission status: Accepted

Solution code:

n = int(input())
An = [int(x) for x in input().split()]
An.sort(reverse=True)

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

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

if ans > j :
    print(-1)
    
else :
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = 1
if 0 in a:
  b = 0
else:
  for i in range(N):
    b = b * a[i]
    if b > 10 ** 18:
      b = 'out'
      break

if b == 'out':
  print(-1)
else:
  print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = int(input().strip())
arr = list(map(int, input().strip().split()))
arr.sort()

ans = 1

for num in arr:
    ans *= num

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = input().split()

if "0" in A:
    print(0)

else:
    ans = 1
        
    for n in range(N):
        ans = ans*int(A[n])

        if ans>10**18:
            print(-1)
            sys.exit()
            
    if ans<=10**18:
        print(ans)

Submission status: Accepted

Solution code:
import copy

def main():
    n = int(input())
    a = list( map( int, input().split()))
    sum = 1
    if 0 in a:
        print(0)
    else:
        for i in a:
            sum = sum * i
            if sum > 1000000000000000000:
                print(-1)
                exit()
        print(sum)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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


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

print(int(sum))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
judge = True
ans = 1
for i in a:
    ans *= i
    if (ans > 1000000000000000000):
        judge = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

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


if 0 in a:
    print(0)
else:
    ans=1
    i=0
    while ans<=10**18 and i<n:
        ans*=a[i]
        i+=1

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

Submission status: Accepted

Solution code:
import sys 
n = int(input())
arr = input()
ans = 1
arr = list(map(int,arr.split(' ')))
arr.sort()
for i in range(n):
    t = arr[i]
    ans *= t
    if (ans > 1000000000000000000):
        print(-1)
        sys.exit()
print(ans)

Submission status: Accepted

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

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

x=a[0]

if 0 not in a:
    for i in range (1,n):
        x=x*a[i]
        if x > pow(10,18):
            print(-1)
            exit()           
    print(x)         
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = 1
L = list(map(int, input().split()))
L.sort()
for i in L:
    a *= i
    if (a > 1e18):
        break

print(-1 if a > 1e18 else a)

Submission status: Accepted

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

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:

n = map(int, input())
data = list(map(int, input().split()))
INF = 1e18
ans = 1

for d in data:
  ans = ans * d
  if ans > INF:
    ans = -1
    break

if 0 in data:
  ans = 0

print(ans)

Submission status: Accepted

Solution code:
# from operator import mul
# from functools import reduce

n=int(input())
a=list(map(int, input().split()))
# limit=10**18

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

ans = 1
# ans = reduce(mul, a) #=> 1320

for i in range(n):
  ans *= a[i]
  if ans > 10 ** 18:
  # if a[i] == 0:
  #   break
  # elif (ans*a[i]) > limit:
    ans = -1
    break

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

# if ans > limit:
#   print(-1)
# else:
print(ans)

Submission status: Accepted

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy


def main():
    n = int(input())
    a_list = tuple(map(int, input().split()))
    num = 1e18
    ans = 1
    if (0 in a_list):
        print(0)
        sys.exit()
    for i in range(n):
        ans *= a_list[i]
        if ans > num:
            print(-1)
            sys.exit()

    
    if ans <= num:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

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

sum = a[0]


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

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

print(sum)

Submission status: Accepted

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

if 0 in l:
    r=0
else:
    r = 1
    for x in range(n):
        r = r * l[x]
        if r > 10**18:
            r=-1
            break
  
print(r)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
A_list = list(map(int,input().split()))
border = 10**18

if 0 in A_list:
  print(0)
  sys.exit()
else:
  A_list.sort(reverse=True)
  pro = 1
  for i in range(N):
    pro *= A_list[i]
    if pro > 10**18:
      print('-1')
      sys.exit()
    else:
      pass

print(pro)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=1
for i in A:
  B*=i
  if(B>10**18):
    B=-1
    break
print(B)

Submission status: Accepted

Solution code:
#import numpy
import math
import sys

def main():
    n = int(input())
    a = sorted(input_list())
    max_n = 10 ** 18
    ans = 1
    for v in a:
        ans *= v
        if ans > max_n:
            ans = -1
            break
        if ans == 0:
            break
    print(ans)


def yogen(a, b, angle):
    coss = math.cos((angle/180)*math.pi)
    return math.sqrt(a**2 + b**2 - 2*a*b*coss)


def get_angle(hour, minute):
    h = (hour * 360) / 12 + (minute * 360) / (12 * 60)
    m = (minute * 360) / 60
    angle = abs(h-m)
    return min(angle, 360-angle)

def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

def input_list():
    return list(map(int, sys.stdin.readline().split()))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

    if flag!=1:
        print(m)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

if l[0] == 0:
  print(0)
  exit()
res = 1

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

Submission status: Accepted

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

if A.count(0) > 0:
  print(0)
else:
  ans = A[0]
  flag = 0
  for i in range(1,N):
    ans *= A[i]
    if ans > 10 ** 18:
      print(-1)
      flag += 1
      break
  if flag == 0:
    print(ans)

Submission status: Accepted

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

def ans(a):
    if 0 in a:
        return 0
    n = 1
    for i in a:
        n *= i
        if n > 10**18:
            return -1
    return n

print(ans(a))

Submission status: Accepted

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

ans = 1
t = 1e18
if 0 in a:
    print(0)
    exit(0)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_,a=open(0)
t=1
for b in sorted(a.split()):
 t*=int(b)
 if t>1e18:t=-1;break
print(t)

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int,input().split())]
A.sort()
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
N=int(input())
A=[int(i) for i in input().split()]
p=1
for i in A:
  if i==0:
    print(0)
    sys.exit()
for i in A:
  p=p*i
  if p>1000000000000000000:
    print(-1)
    sys.exit()
print(p)

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)
            exit()
    print(ans)

Submission status: Accepted

Solution code:
_=input()
A=sorted(list(map(int,input().split())))
B=1
for a in A:
    B*=a
    if B>10**18:
        B=-1
        break
print(B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
result=1
for i in a:
    result*=i
    if 10**18<result:
        result=-1
        break
print(result)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
result = 1
for i in range(len(a)):
  result = result*a[i]
  if result == 0:
    break
  elif result > 1000000000000000000:
    break

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

Submission status: Accepted

Solution code:
def main():
    _ = input()
    lst = list(map(int, input().split()))
    ans = 1

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
over_value = 10 ** 18
total = 1
cnt = 0
while cnt < N:
    total *= A[cnt]
    if total > over_value:
        total = -1
        break
    cnt += 1
    
for i in range(N):
    if A[i] == 0:
        total = 0
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  A = input()
  v = 1;
  for a in A.split(' '):
      d = int(a)
      if d == 0:
          print(0)
          return

  for a in A.split(' '):
      d = int(a)
      v *= d
      if (v > 1e18):
          print(-1)
          return
  print(v)

main()

Submission status: Accepted

Solution code:
import sys
def main():

    n=int(input())
    p=list(map(int,input().split()))
    s=1
    p=sorted(p)
    for i in p:
        s*=i
        if i==0:
            print(0)
            sys.exit()
        elif s>=10**18+1:
            print(-1)
            sys.exit()
    print(s)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
mult = 1
for i in range(n):
    mult *= a[i]
    if mult > 1e+18:
        mult = -1
        break
        
for i in range(n):
    if a[i] == 0:
        mult = 0

print(mult)

Submission status: Accepted

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

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

for i in range(n):
    b *= a[i]
    if b > 10 ** 18:
        b = -1
        break

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

print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def main():
  N = int(input())
  P = sys.stdin.readline().rstrip().split()
  if '0' in P:
    print(0)
    return
  ans = 1
  for a in P:
    ans *= int(a)
    if ans > 1000000000000000000:
      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
a.sort()
if a[0] == 0:
    ans = 0
    print(ans)
    exit()

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

print(ans)

Submission status: Accepted

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

ans = 1

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

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
 
n = int(input())
a = list(map(int,input().split()))
ans = 1

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

print(ans)

Submission status: Accepted

Solution code:

N = int(input()) 
A = list(map(int, input().split()))
S = set(A)
if 0 in S:
  print(0)
  exit()
 
upp = 10**18
ans = 1
#print(A)
for a in A:
  ans *= a
  if ans > upp:
    ans = -1
    break
 
print(ans)

Submission status: Accepted

Solution code:
def ans(lst):
  if 0 in lst:
    return 0
  n = 1
  for i in lst:
    n *= i
    if n > 10**18:
      return -1
  return n
input()
A = input().split(' ')
A = [int(x) for x in A]
print(ans(A))

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:
n=int(input())
a=input().split()
a=list(map(int,a))
ans=1
if(0 in a):
    print(0)
    exit()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = A[0]

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

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()))
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:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

bb = 10**18

def main():
    n = ii()
    a = li()
    ans = 1

    if 0 in a:
        print(0)
        return

    for i in range(len(a)):
        ans *= a[i]
        if ans > bb:
            print(-1)
            break
    else:
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce

def m(l):
    result = 1
    for num in l:
        result *= num
        if result == 0:
            return 0
        elif result > 10**18:
            return -1
    return result

if __name__ == "__main__":
    input()
    aList = list(map(int, input().split()))
    aList.sort()
    print(m(aList))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int, input().split()))
ans = 1
 
for n in range(N):
 ans = L[n]*ans
 if ans >= 1000000000000000001: ans = -1
 if ans == -1: break
 
for n in range(N):
 if L[n] == 0: ans = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
result = 1
flag = 0
zero_flag = 0
for a in A:
    if a == 0:
        zero_flag = 1
        result = 0
        break
    else:
        result = result * a
        if result > pow(10, 18):
            flag = 1
            result = 0
if flag == 1 and zero_flag != 1:
    print(-1)
else:
    print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
_=input()
val=1
t=10**18

for i in map(int,input().split()):
  if i==0:
    val*=i
    break
  if val>=t: continue
  val*=i

if val>t:
  print(-1)
  exit()

print(val)

Submission status: Accepted

Solution code:
n = int(input())
s = sorted(map(int,input().split()))
M = 10 ** 18
ans = 1
for ss in s:
	ans *= ss
	if ans > M:
		ans = -1
		break
	elif ans == 0:
		break
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
L = list(map(int, input().split()))
ans = 1

for n in range(N):
 ans = L[n]*ans
 if ans >= 1000000000000000001: ans = -1
 if ans == -1: break

for n in range(N):
 if L[n] == 0: ans = 0
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x = list(map(int, input().split()))
val=1
length=range(n)
zflag=0
flag=0
for i in length:
    if x[i]==0:
        zflag=1;
if zflag==1:
    print(0)
else:
    for i in length:
        val=val*x[i];
        if val>1000000000000000000:
            print(-1)
            flag=1
            break
    if flag==0:
        print(val)

Submission status: Accepted

Solution code:
a=int(input())
b=input().split(" ")
sum1=1

if "0" in b:
	print("0")
else:
	for i in range(a):
		sum1=sum1*int(b[i])
		if sum1>10**18:
			sum1=-1
			break
	print(sum1)

Submission status: Accepted

Solution code:
def mul(m) : 
      
    # Multiply elements one by one 
    res = 1
    for x in m: 
        res = res * x
        if res == 0:
             return 0 
        if res > 10**18:
             return -1
    return res
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
z = mul(a)
print(z)

Submission status: Accepted

Solution code:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))

    #output
    A = sorted(A, reverse = True)
    if A[-1] == 0:
        print(0)
        exit()
        
    answer = 1
    limit = pow(10, 18)
    for i in range(N):
        answer *= A[i]
        if answer > limit:
            print(-1)
            exit()
        else:
            continue

    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
_ = int(input())
A = [ int(i) for i in input().strip().split(' ')]
a = 1
if min(A) == 0:
    print(0)
else:
    for Ai in A:
        a *= Ai
        if a > 10**18:
            print('-1')
            break
    else:
        print(a)

Submission status: Accepted

Solution code:
n = input()
x = list(map(int,input().split()))
x.sort()
sum = 1
done = False



for i in x:

    # if 0 sum must be 0
    if i == 0:
        sum = 0
        break

    sum = sum * i

    if sum > 10**18:
        break

    



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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

total = 1
li.sort()
for a in li:
    if a == 0:
        total = 0
        break
    total *= a
    if 10 ** 18 < total:
        total = -1
        break
print(total)

Submission status: Accepted

Solution code:
a = int(input())
li = list(map(int,input().split()))
total = 1
i = 1
for i in range(a):
    total = total*li[i]
    if total > 1000000000000000000:
        total = -1
        break
for i in range(a):
    if li[i] == 0:
        total = 0

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

B = set(A)
Answer = 1
if 0 in B:
    print(0)
    exit()
for i in range(N):
    Answer *= A[i]
    if Answer > 1000000000000000000:
        print(-1)
        exit()
print(Answer)

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 a:
    ans*=i
    if ans > 10**18:
      print(-1)
      exit()
  print(ans)