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:
n = int(input())

l = []
ans = 1
z = False
l = input().split(' ')
for x in l:
  x = int(x)
  if x == 0:
    print(0)
    exit(0)
for i in range(n):
  x = int(l[i])
  ans *= x
  if ans > 1e18:
    ans = -1
    break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input().strip())
array = list(map(int, input().strip().split()))
x=1
l=len(array)
a=array.count(0)
if a>=1:
    print(0)
else:
    for i in range (l):
        x*=array[i]
        if x>1000000000000000000:
            x=-1
            break
    print(x)

Submission status: Accepted

Solution code:

def submit():
    n = int(input())
    a = [int(e) for e in input().split()]
    thr = 10 ** 18

    if 0 in a:
        print(0)
        return

    ans = 1
    for e in a:
        ans *= e
        if ans > thr:
            ans = -1
            break
    
    print(ans)


submit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = [int(x) for x in input().split()]
summ = 1
for i in range(a):
    if(b[i]==0):
        summ = 0
for i in range(a):
    summ*=b[i]
    if(summ>1000000000000000000):
        summ=-1
        break
print(summ)

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

Submission status: Accepted

Solution code:
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
a = LIST()
res  = 1
if 0 in a:
    print(0)
    sys.exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

N=int(input())
list = list(map(int, input().split()))
c = collections.Counter(list)
m=10**18

if(c[0]!=0):
  print(0)
else:
  i=0
  res=1
  while(i<N):
    res=res*list[i]
    if(m<res):
      res=-1
      break
    i+=1
  print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math

N=int(input())

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


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

mult=1
for i in range(N):
    mult *= A[i]
    if mult > 1E18:
        print(-1)
        sys.exit(0)

print(mult)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return

    ans = 1
    n = 10 ** 18
    for i in A:
        ans *= i
        if ans > n:
            print(-1)
            return
    print(ans)


main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
t=1
for m in a:
    t*=m
    if t > 1000000000000000000:
        t=-1
    elif t == 0:
        t=0
        break
    elif t<0:
        t=-1
print(t)

Submission status: Accepted

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

Submission status: Accepted

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

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

# if b>1e18:
#     b=-1;
print(b)

Submission status: Accepted

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

a.sort(reverse=True)


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

    for i in a:
        m *= i
        if m > 10 ** 18:
            break

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

Submission status: Accepted

Solution code:
import sys




def solve():
    res = 1
    over = False
    for i in range(len(a)):
        if not over:
            res *= a[i]
            if res > mxn:
                over = True
        else:
            if a[i] == 0:
                print(0)
                return
    if not over:
        print(res)
    else:
        print(-1)
    return


mxn = 10**18
n = int(input())
a = [int(i) for i in input().split()]
solve()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

ans = 1
lim = pow(10, 18)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

n = 1
lim = 10**18
for e in l:
    n *= e
    if n > lim:
        print(0 if 0 in l else -1)
        break
else:
    print(n)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

ans = 1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
arr = list(map(int, input().split()))

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

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

else:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
ng = 0
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:
from math import log10
N = int(input())
A = list(map(int, input().split()))

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

s = 1
for a in A:

    s *= a
    if s > 10 ** 18:
        print('-1')
        exit()
print(s)

Submission status: Accepted

Solution code:
def main() :

    N = int(input())
    N_list = [int(i) for i in input().split()]
    res = 1

    if (N_list.count(0) > 0) :
        print(0)
        return

    for i in range(len(N_list)) :
        res = res * N_list[i]
        if (res > 1000000000000000000) :
            print(-1)
            return
    
    print(res)

main()

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().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 = [int(_) for _ in input().split(' ')]

if any([i == 0 for i in a]):
    print(0)
else:
    ans = a[0]
    for i in range(n - 1):
        ans *= a[i + 1]
        if ans > int(1e18):
            break

    if ans > int(1e18):
        print(-1)
    else:
        print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
flag = 0
ans = 1
n = int(input())
num_list = list(map(int, input().split()))
for num in num_list:
    if num == 0:
        ans = 0
        
for num in num_list:
    ans = ans*num

    if ans > 1000000000000000000:
        print(-1)
        flag = 1
        break;
if flag == 0:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
m = 1
flag = True
try:
    a = A.index(0)
    print(0)
except:

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

    if flag:
        print(m)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split()
result = 1
max_val = 10**18
for a in A:
    if a == '0':
        print(0)
        exit()
for a in A:
    result *= int(a)
    if result > max_val:
        print(-1)
        exit()
print(result)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = collections.Counter(input().split())
if a["0"]:
    print(0)
    exit()
ans = 1
for i in a:
    ans *= int(i) ** a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = int(input())
A = readInts()
ans = 1
if A.count(0):
    print(0)
    exit()
A = sorted(A)
for i in range(n-1,-1,-1):
    ans *= A[i]
    #print(ans)
    if ans > 10**18:
        print(-1)
        exit()
    if ans == 0:
        print(0)
        exit()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
res=1
mod=10**18
a=list(reads())
if 0 in a:
  print("0")
  exit()
for i in range(n):   
    res*=a[i]
    #print(res)
    if res>mod:
        print("-1")
        exit()
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

Submission status: Accepted

Solution code:
N = int(input())
arr = [int(x) for x in input().split()]
found = False
for x in arr:
  if x == 0:
    found = True
if found:
  print(0)
  exit(0)
res = 1
MAX = 10 ** 18
for x in arr:
  res *= x
  if res > MAX:
    print(-1)
    exit(0)
print(res)

Submission status: Accepted

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

for x in l:
    ans *= x

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    max_lim = 10 ** 18
    _ = int(input())
    A = [int(x) for x in input().split()]
    now = A[0]
    for a in A[1:]:
        if now != -1:
            now *= a
        if a == 0:
            print(0)
            return
        if now > max_lim:
            now = -1
    print(now)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
n  = int(input())
#  = map(int, input().split())
a  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

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

ans = a[0]
for a_ in a[1:]:
    if ans * a_ <= 10 ** 18:
        ans *= a_
    else:
        print(-1)
        break
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys


#torf = [[None for _ in range(m)]for _ in range(n)]
#print(torf)
#print(torf[0][0])
#print(torf[1][0])

n = int(input())

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

#ans = a[0]


a = sorted(a)
ans = a[0]

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
ju = 0
j = 0
if 0 in a:
    ju=1

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

if ju==1:
    print(0)
elif j==1:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 1
if 0 in A:
    print(0)
    exit()
for i in 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 min(A) == 0:
    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())
l=list(map(int, input().split()))
m=1
for i in range(n):
    m*=l[i]
    if m>10**18:
        if 0 in l:
            print(0)
            exit()
        print(-1)
        exit()

print(m)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    n = int(input())
    l = list(map(int,input().split()))
    if 0 in l :
        print("0")
    else :
        flag = 1
        prod = 1
        for i in range(n) :
            prod = prod * l[i]
            if prod > int(math.pow(10,18)) :
                flag = 0 
                break 
        if flag == 0 :
            print("-1")
        else :
            print(prod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 21:01:14 2020

@author: NEC-PCuser
"""

N = int(input())
A = list(map(int, input().split()))
MAX = 10 ** 18
ans = 1
zero_flg = False
for i in A:
    if (i == 0):
        print(0)
        zero_flg = True
        break
    
if (zero_flg == False):
    for i in A:
        ans *= i
        if (ans > MAX):
            print(-1)
            break
    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)
else:
    for i in a:
        ans *= i
        if ans > 1000000000000000000:
            print(-1)
            exit()

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(A):
    if 0 in A:
        return 0

    x = 1

    for a in A:
        x *= a
        if x > 10**18:
            return -1

    return x

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 1

for a in sorted(input().split()):
    ans *= int(a)
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

Solution code:
def intMap(): return map(int,input().split())
def intList(): return list(map(int, input().split())) #横並びの場合
def intListVertical(): [int(input()) for _ in range(N)] #縦並びの場合

#s = input()
n = int(input())
#s,t = input().split()
#n,m = intMap()
a = intList()
#w = intListVertical()

ans = 1
limit = 1000 * 1000 * 1000 * 1000 * 1000 * 1000

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 1
dekai = False
for a in A:
    ans *= a
    if ans > (10 ** 18):
        dekai = True
        break

if 0 in A:
    print(0)
elif dekai:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
#sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


N=l()[0]
A=l()
ans=1
if(0 in A):
    ans=0
    print(ans)
    exit()
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:
import sys
 
N = int(input())
A = list(map(int, input().split()))
Ans = 1

for j in range(N):
  if A[j] == 0:
    Ans = 0
    print(Ans)
    sys.exit()    

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


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

    if (0 in A):
        print("0")
        sys.exit()

    for a in A:
        res = res * a
        if res > pow(10, 18):
            print("-1")
            sys.exit()
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

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

Submission status: Accepted

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

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

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

    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve(a):
    if 0 in a:
        return 0
    ans = 1
    for i in a:
        ans *= i
        if ans > 10**18:
            return -1
    else:
        return ans

if __name__ == '__main__':
    n = int(input())
    a = list(map(int,input().split()))
    print(solve(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 range(n):
        ans *= a[i]
        if 10**18 < ans:
            ans = -1
            break

print(ans)

Submission status: Accepted

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

def main(A):
    a = 1
    for x in A:
        if x == 0:
            return 0
    for x in A:
        a *= x
        if a > U:
            return -1
    return a

print(main(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    def solve():
        if 0 in a:
            return 0
        ans = 1
        for aa in a:
            ans *= aa
            if ans >10**18:
                return -1
        return ans
    print(solve())
        
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    As = list(map(int, input().split()))

    ans = 1
    if 0 in As:
        print(0)
        exit()

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
alist = [int(s) for s in input().split(" ")]
alist.sort()

if alist[0] == 0:
  print(0)
else:
  ans = 1
  ok = True
  for a in reversed(alist):
    ans *= a
    if ans > 1e18:
      ok = False
      break
  if ok:
    print(ans)
  else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
ans = 1
for i in a:
  if i=='0':
    ans = 0
    break
for i in a:
  ans = ans * int(i)
  if ans>1000000000000000000:
    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)
    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()))
a.sort()
ans = 1
for i in a:
  ans *= i
  if ans > 10**18:
    ans = -1
    break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

res = 1

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

for e in nums:
    if res == -1:
        if e == 0:
            res = 0

        continue
    res *= e
    if res > 10 ** 18:
        res = -1


print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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


print(ans)