Problem:


Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0



Sample input:
2
1000000000 1000000000


Sample output:
1000000000000000000

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
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 range(n):
    ans *= A[i]
    if ans > 10**18:
        print("-1")
        exit()

print(ans)

Submission status: Accepted

Solution code:
num = input()
data = input().rstrip().split(" ")
ans = 1
if "0" in data:
    ans = 0
else:
    for i in data:
        ans = ans*int(i)
        if ans > 1000000000000000000:
            ans = -1
            break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input().split()
s = [int(i) for i in s]
mul = 1
flag = 0

if 0 in s:
    print(0)
else:


    for item in s:
        mul *= item
        if flag == 1:
            break

        if mul >  1e18:
            print(-1)
            flag = 1

    if mul <=  1e18:
        print(mul)

Submission status: Accepted

Solution code:
import sys

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

N, *A = map(int, read().split())

ans=1
zero=False
for a in A:
    if a==0:
        zero=True
        break

if zero:
    print(0)
else:
    over=False
    for a in A:
        ans*=a
        if ans>1e18:
            print(-1)
            over=True
            break
    if not over:
        print(ans)

Submission status: Accepted

Solution code:
m = 1000000000000000000

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

# s = a.set()
if 0 in a:
    print(0)
else:


    o = 1

    for i in a:
        if o <= m:
            o = o * i
        else:
            o = -1
            break
        
    if o > m:
        o = -1

    print(o)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().strip().split()))
LIMIT = 10**18

z = False
for x in a:
    if x == 0:
        z = True

if z:
    print(0)
else:
    ans = 1
    for x in a:
        ans = ans * x
        if ans > LIMIT:
            break
    print(ans if ans <= LIMIT else -1)

Submission status: Accepted

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

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

for i in range(n):
    ans *= a_list[i]
    if len(str(ans)) > 19 or ans > 10 ** 18:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

mul = 1
if 0 in A:
    print("0")
else:
    for i in A:
        mul *= i
        if mul >= limit:
            print("-1")
            break
    if mul < limit:
        print(mul)

Submission status: Accepted

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

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

goukei = 1
for i in ls:
  goukei *= i

  if goukei > 1000000000000000000:
    print('-1')
    exit()

print(int(goukei))

Submission status: Accepted

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

Submission status: Accepted

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

product = 1
flag = 0

if 0 in A:
    print(0)
else:
    for i in range(N):
        product *= A[i]
        if product > 1000000000000000000:
            flag += 1
            break
    if flag == 0:
        print(product)
    else:
        print(-1)

Submission status: Accepted

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

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

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

print(s)

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

Solution code:

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

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

if ans <= 10**18:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
upper = 1e18
res = 1
generator = map(int, input().split())
for x in generator:
   res *= x
   if res > upper:
      break

for x in generator:
   if x == 0:
      res = 0
   
print(-1 if res > upper else res)

Submission status: Accepted

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

solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 1
for A in input().split():
    A = int(A)
    if ans == -1 and A == 0:
        ans = 0
        break
    elif ans == -1:
        continue
    else:
        ans *= A
        if ans > 10**18:
            ans = -1
print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a = int(input())
    b = [int(i) for i in input().split()]
    ans = 1
    b.sort(reverse=True)
    if 0 in b:
        ans = 0
    else:
        for i in range(len(b)):
            ans *= b[i]
            if ans > 10 ** 18:
                ans = -1
                break
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = nums[0]

for i in range(N):
    if nums[i] == 0:
        print("0")
        exit()

for x in range(N - 1):
    ans = ans * nums[x + 1]
    if ans > 1000000000000000000:
        print("-1")
        exit()
        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

NList.sort()
result = 1
for i in range(N):
    result *= NList[i]

    if result > 10 ** 18:
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

result = a[0]
p = pow(10,18)

if 0 in a:
    result = 0

else:
    for i in range(n-1):
        result *= a[i+1]
        if result > p:
            result = -1
            break

print(result)

Submission status: Accepted

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

if flag == 0 :
    print(Asum)
else:
    print(-1)

Submission status: Accepted

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

ans = 1
for ll in l:
  ans *= ll
  if ans > 10**18 or ans==0:
    break
  
if ans > 10**18:
  print(-1)
else:
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:



def solve(N, As):
    ans = 1
    for a in sorted(As):
        ans *= a
        if ans == 0:
            return 0
        if ans > 10 ** 18:
            return -1
    return ans


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Submission status: Accepted

Solution code:
N=int(input())

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n=int(input())
a=get_array()
mul=1
flag=0
if 0 in a:
    print(0)
else:
    for i in range(n):
        mul=mul*a[i] 
        if mul>1000000000000000000:
            flag=1 
            break
    if flag==0:
        print(mul)
    else:
        print(-1)

Submission status: Accepted

Solution code:
def keisan(numlist):
  ans=1
  if "0" in numlist:
    return "0"
  for i in numlist:
    ans *= int(i)
    if ans > max:
      return "-1"
  return ans

  
  

num = input()
numlist = input().split()

max=10**18
print(keisan(numlist))

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

Submission status: Accepted

Solution code:
N = int(input())

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

l.sort(reverse=True)

if l[-1] == 0:
	print(0)
else:
	ans = 1
	for x in l:
		if x*ans > 10**18:
			print(-1)
			exit()
		else:
			ans = x*ans
	print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N = ni()
A = nl()
L = 10 ** 18


def solve():
    ans = 1
    for a in A:
        if a == 0:
            ans = 0
            break
        if ans > 0:
            ans *= a
        if ans > L:
            ans = -1
    return ans


print(solve())

Submission status: Accepted

Solution code:

def main():
  _n = int(input())
  ans = 1
  for num in map(int, input().split()):
    if num == 0:
      print(0)
      return

    if ans <= 10**18:
      ans *= num

  print(ans if ans <= 10**18 else -1)

main()

Submission status: Accepted

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

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

print("{}".format(ret))

Submission status: Accepted

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

INF = 10 ** 18
ans = 1
if any([n == 0 for n in a]):
    print(0)
    exit()

for n in a:
    ans *= n
    if ans > INF:
        ans = -1
        break
print(ans)

Submission status: Accepted

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

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

if min(a)==0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
arr = sorted(map(int, input().split()))
INF = 10 ** 18
ans = 1
for num in arr:
    ans *= num
    if num > 0 and ans > INF:
        ans = -1
        break
    elif ans == 0:
        break

print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(input())
h = list(map(int, input().split()))
c = 1
if 0 in h:
    print(0)
    sys.exit()
for i in range(0, len(h)):
    c *= h[i]
    if c > 10**18:
        print(-1)
        sys.exit()
print(c)

Submission status: Accepted

Solution code:
import math
import sys

N = int(input())
A = list(map(int, input().split()))
if min(A) == 0:
    print(0)
else:
    k = 1
    flag = True
    for a in sorted(A, reverse=True):
        k *= a
        if k > math.pow(10, 18):
            print(-1)
            flag = False
            break

    if flag:
        print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

res = 1
exceeded = False
thresh = 10 ** 18
for a in [int(v) for v in input().split()]:
    if not exceeded:
        res *= a
        if res > thresh:
            exceeded = True
    elif a == 0:
        res = 0
        exceeded = False

if exceeded:
    print(-1)
else:
    print(res)

Submission status: Accepted

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

ans=1

flag=1
zero=0

for i in range(0,N):
    if A[i]==0:
        zero=1


for i in range(0,N):
    ans*=A[i]
    if ans>1000000000000000000:
        flag=0
        break;

if zero==1:
    print(0)
elif flag==0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
 
import sys
import math
from collections import Counter
import itertools
import fractions
#import numpy as np
#from functools import reduce
 
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()
 
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
 
# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")
 
# ###########################################
n=II()
A=LI()
 
ans = 1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p = 10 ** 18

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

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

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


print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(input().split(' '))
arr = map(int, sorted(arr))
ans = 1
for i in arr:
    ans *= i
    if ans > 1e18:
        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 > pow(10,18):
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A = list(map(int, input().split()))
result=1
limit=10**18
flg0=0
flg=0
for i in range(n):
  if A[i] == 0:
    flg0=1
    print('0')
for i in range(n):
  if flg0 == 1:
    break
  result *= A[i]
  if result > limit:
    print('-1')
    flg=1
    break
if flg != 1 and flg0 != 1:
  print(result)

Submission status: Accepted

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

for one in a:
    now *= one
    if now > 1e18:
        print("-1")
        exit()

print(now)

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3.5 -tt

import random
import sys

if __name__ == '__main__':
    def _(f):
        for l in f:
            for i in l.split():
                yield(int(i))

    g = _(sys.stdin)

    N = next(g)

    a = []

    for i in range(N):
        a.append(next(g))

    a.sort()

    S = 1

    for i in a:
        S *= i

        if S == 0:
            print(0)
            sys.exit(0)
        elif S > 10 ** 18:
            print(-1)
            sys.exit(0)

    print(S)

Submission status: Accepted

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

for x in a:
    b *= x
    if b > 10**18:
        ans = -1
        break
    else:
        ans = b

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from functools import reduce
from operator import mul
sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, sys.stdin.readline().split(' ')))
def In(): return int(sys.stdin.readline())
def InS(): return sys.stdin.readline()

N = In()
A = InMap()

A.sort()
if A[0] == 0:
    print(0)
    sys.exit()
res = 1
for i in A:
    res *= i
    if res > 1000000000000000000:
        print(-1)
        sys.exit()
print(res)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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()
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MAX_NUM = 10 ** 18

def main():
    import math
    N = int(input())
    A = list(map(int, input().split()))
    A_set = set(A)
    log_sum = 0
    if(0 in A_set):
        print("0")
        return
    
    A_log = [0] * N
    ans = 1
    for i in range(N):
        log_sum += math.log10(A[i])
        if(log_sum > 18):
            ans = -1
            break
        else:
            ans = ans * A[i]
            if(ans > MAX_NUM):
                ans = -1
                break
    print(ans)



main()

Submission status: Accepted

Solution code:
n=int(input())
ans=1;
i = []
for a in input().split():
    i.append( int(a) )
    if (int(a)==0):
        print(0)
        exit(0)
for l in i:
    ans*=l
    if (ans>1000*1000*1000*1000*1000*1000):
        print(-1)
        exit(0)
print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(input())
a = list(map(int, input().split()))
cur = 1
for x in a:
    if ( x == 0 ):
        print(0)
        exit()

for x in a:
    cur = cur * x
    if ( cur > 1000000000000000000 ):
        print(-1)
        exit()
print(cur)

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:
    ans = -1
    break
  else:
    ans *= x
    if ans>10**18:
      ans = -1
      break
print(ans)

Submission status: Accepted

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

ans = 1

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

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

Submission status: Accepted

Solution code:

n = int(input())

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

if n != 0 :
    ans = a_list[0]
else :
    ans = 0

if 0 in a_list :
    ans = 0

for i in range(1, n):
    ans = ans * a_list[i]

    if 10**18 < ans :
        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
    flag = False
    for i in range(n):
        ans = ans * a[i]
        if ans > 10**18:
            flag = True
            break

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    a_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    b = 10**18

    if 0 in a_list:
        print(0)
        return

    a = 1
    for _a in a_list:
        a *= _a
        if a > b:
            print(-1)
            return

    print(a)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1000000000 1000000000"""
        output = """1000000000000000000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
101 9901 999999000001"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """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"""
        output = """0"""
        self.assertIO(input, output)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
_ = input()
l = list(map(int, input().split()))
 
res = 1
for i in l:
    if i == 0:
        res *= i
        break
    if res == -1:
        continue
    res *= i
    if res > 1e18:
        res = -1
 
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
from functools import cmp_to_key
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = map(int, readline().split())
A = map(int, readline().split())
A = sorted(A)

ret = 1
for num in A:
    ret *= num
    if(ret > 1000000000000000000):
        print(-1)
        exit(0)
print(ret)
exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

num = list(input().split())
ans = 1
if '0' in num :
    ans = 0
else:
    for i in num:
        ans *= int(i)
        if ans  > 10**18:
            break

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

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())
k = list(map(int, input().split()))
import collections
c = collections.Counter(k)
re = 1
if c[0] == 0:
  for i in range(n):
    re = re * k[i]
    if re > 10**18:
      print(-1)
      exit()
  print(re)
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
if 0 in c:
    print('0')
    exit()

for i in range(n):
    ans *= c[i]
    if ans > 1000000000000000000:
        print('-1')
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1

p = 10 ** 18

for a in A_list:
    ans *= a
    if ans > p:
        ans = -1
        break

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

Submission status: Accepted

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

ans = 1
flag = False
A.sort()
for i in range(N):
  ans *= A[i]
  if(ans>1000000000000000000):
    flag = True
    break

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

Submission status: Accepted

Solution code:
n = int(input())
alist = list(map(int, input().split()))
num = 1

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

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

print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int, input().split()))
#入力される数値には０が入っていることがあり、その場合積は当然０になる
result = 1
hantei = True
zero = False
if 0 in L:
    zero = True
else:
    for i in L:
        result *= i
        if result > 10**18:
            hantei = False
            break
if zero:
    print(0)
elif hantei:
    print(result)
else:
    print("-1")

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in A:
    print(0)
else:
    A.sort()
    A.reverse()

    i = 1
    res = A[0]
    while (res <= (10 ** 18)) and (i < len(A)):
        res = res * A[i]
        i += 1
    if res <= (10 ** 18):
        print(res)
    else:
        print("-1")

Submission status: Accepted

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

#n=3
#A=[101,9901,999999000001]
cum=1
p=A.count(0)
#print(p)
if p>0:
  cum=0

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

print(cum)

Submission status: Accepted

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

if A.count(0) > 0:
    print(0)
else:
    ans = A[0]
    for i in range(1, N):
        ans = 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 a.count(0) > 0:
  ans = 0
else:
  ans = 1

for i in a:
  ans *= i
  if ans > (10 ** 18):
    break

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

Submission status: Accepted

Solution code:
import sys
n = int(input())

strs = input().split()
sum = 1
out_range = False
for i in range(n):
  v = int(strs[i])
  if(not out_range):
    sum *= v
    if(sum > 1000000000000000000):
      out_range = True

  if(v == 0):
    print(0)
    sys.exit()
    
if(not out_range):
  print(sum)
else:
  print(-1)