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())
alist=list(map(int, input().split()))
ans=1
for a in alist:
    ans=ans*a
    if ans>10**18:
        ans=-1
        break
if 0 in alist:
    ans=0
print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *
def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1/f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret
def bunsu(n):
    ret = []
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            tmp = 0
            while(True):
                if n % i == 0:
                    tmp += 1
                    n //= i
                else:
                    break
            ret.append((i, tmp))

    ret.append((n, 1))
    return ret

def solve():
    lim = 10 ** 18
    n = getN()
    nums = getList()
    if 0 in nums:
        print(0)
        return
    ans = 1
    for num in nums:
        ans *= num
        if ans > lim:
            print(-1)
            return

    print(ans)
def main():
    # n = getN()
    # for _ in range(n):
    solve()
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
ok = True
for i in a:
  if ok == True:
    ans *= i
  if ans > 1000000000000000000:
    ok = False
  if i == 0:
    print(0)
    exit()
if ok:
  print(ans)
else:
  print(-1)

Submission status: Accepted

Solution code:
# B
n = int(input())

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

  

  

maxa = 10 **18

ans = 1
if min(a) == 0:
  ans = 0

for i in a:
  ans = ans * i
  if ans > maxa:
    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 > 1000000000000000000:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0] * N
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 > 1000000000000000000:
            print(-1)
            break
        if i == N - 1:
            print(ANS)

Submission status: Accepted

Solution code:
import numpy as np
import math
import collections

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if ans <= 1000000000000000000 and not already:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = []

z=False
for x in input().split(' '):
    if x == '0':
        z = True
    arr.append(int(x))
if z == True:
    print(0)

else:
    ans = 1
    for x in arr:
        ans *= x
        if ans > int(1e18):
            print(-1)
            exit(0)
    
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
for j in range (n) :
    if a[j] == 0 :
        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:
def main():
  N = int(input())
  A = list(map(int, input().split()))

  A.sort()

  m = 10 ** 18
  ans = A[0];

  if(A[0] == 0):
    ans = 0;
  else:
    for i in range(1, N):
      ans *= A[i]

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

  print(ans)

if __name__ == "__main__":
  main()

Submission status: Accepted

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

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

for i in A:
  ans = 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:
def intlist(x):
    y = []
    for i in range(len(x)):
        y.append(int(x[i]))
    return y
N = int(input())
A = intlist(input().split())
M = 1

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

if 0 in a:
    s = 0

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

#print(A)

flag = 0
b = 1

for a in A:
  if a == 0:
    flag = 2

if flag == 0:
  for a in A:
    b = b * a
    if(b > 10**18):
      flag = 1
      break

#if(b > 10**18):
#  flag = 1
  
  
if flag == 1:
  print(-1)
elif flag == 0:
  print(b)
else:
  print(0)

Submission status: Accepted

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

b = sorted(a, reverse=True)


ans=1

if min(b) == 0:
    print(0)
    exit(0)

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



print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
big = 10**18
n = int(input())
things = list(map(int, input().split()))
result = 1
good = True
if 0 in things:
	print(0)
else:
	for x in things:
		result *= x
		if result > big:
			print(-1)
			good = False
			break
	if good:
		print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
cnt=1
a=sorted(list(map(int,input().split())))
for it in a:
  cnt*=it
  if cnt>1000000000000000000:
    print(-1)
    exit()
if cnt>1000000000000000000:
  print(-1)
else:
  print(cnt)

Submission status: Accepted

Solution code:
import sys

n = sys.stdin.readline()
l = list(map(int, sys.stdin.readline().split()))
tmp = 1000000000000000000

if 0 in l:
    print(0)
else:
    ans = 1
    for i in l:
        ans *= i
        if 1000000000000000000 < ans:
            break
    if ans <= 1000000000000000000:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

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

count = 1

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    exit()
a.sort(reverse = True)
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 = int(input())
a = [int(x) for x in input().split()]
if 0 in a:
    print(0)
else:

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

Submission status: Accepted

Solution code:
N = int(input())

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

flag = True
ans = 1
if 0 in A:
    print(0)
    flag = False

if flag:
    for i in A:
        ans *= i
        if ans > pow(10,18):
            print(-1)
            flag = False
            break

if flag:
    print(ans)

Submission status: Accepted

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

print(calc())

Submission status: Accepted

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

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

if flag == 1 and (0 not in a):
    ans = -1
if 0 in a:
    ans = 0

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math
import random
from decimal import Decimal
import itertools
import re
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(2147483647)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

def main():
	n = I()
	A = sorted(np.array(LI()))
	product = Decimal('1')
	for a in A:
		ad = Decimal(str(a))
		product *= ad
		if product > Decimal(str(10**18)):
			product = -1
			break
	print(int(product))




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math

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

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

if ( chk_0 == 1 ):
  print(0)
else:
  log10_A = 0
  for i in range(N):
    log10_A += math.log10(A[i])
  #print(log10_A)
  
  if ( log10_A > 18 ):
    print(-1)
  else:
    ans = 1
    for i in range(N):
      ans = ans*A[i]
    if ( ans > 10**18 ):
      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
if ans != 0:
    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=list(map(int,input().split()))

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

Submission status: Accepted

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

pi = 1
for num in a:
    pi*=num
    if pi > 10**18:
        pi = -1
        break;

print(pi)

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return

    result = 1
    # count = 0
    for i in A:
        # l = len(str(i)) - 1
        # if l != 0:
        #     count = count + l
        result = result * i
        if result > 1000000000000000000:
            print(-1)
            return

    print(result)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
alist = [ int(x) for x in input().split() ]
product = 1

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

for index in range(len(alist)):
    product = product * alist[index]
    if product > 10**18:
        print(-1)
        sys.exit()

print(product)

Submission status: Accepted

Solution code:
n = int(input())

p = 1

flag = False
zero = False
n = input().split()
for i in n:
    x = int(i)
    p = p * x
    if p == 0:
        zero = True

    if p > 1000000000000000000:
        flag = True
        p = 1

if zero:
    print(0)
else:
    if flag:
        print(-1)
    else:
        print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 a.count(0) > 0:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)
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 = sorted(list(map(int, input().split())), reverse=True)
if A[-1] == 0:
    print(0)
    exit()
ans = 1
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()))
tot = a[0]

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

for i in range(1,n):
  if (tot > 1e18):
    print(-1)
    exit()
  tot *= a[i]
  
if (tot > 1e18):
  print(-1)
  exit()

print(tot)

Submission status: Accepted

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

sum = 1

if 0 in A:
    sum = 0

else:
    for i in range(len(A)):
        sum *= A[i]
        if sum > 1000000000000000000:
            break
    
if sum > 1000000000000000000:
    sum = -1

print(sum)

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

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    *A, = map(int, input().split())
    a = 1
    if 0 in A:
        print(0)
    else :
        for i in A:
            a*=i
            if a > 10**18:
                print(-1)
                break
        else :
            print(a)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

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

answer = 1
for Ai in A:
    answer *= Ai
    if answer > 10 ** 18:
        answer = -1
        break

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
#print(a)
ans = 1
if a.count(0):
    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
flag=True
if 0 in A:
    print(0)
else:
    for j in A:
        ans*=j
        if ans>10**18:
            print(-1)
            flag=False
            break
    if flag:
        print(ans)

Submission status: Accepted

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

if A.count(0) != 0:
    print(0)
else:
    result = 1
    for e in A:
        result *= e
        if result > 10**18:
            break

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

if min(an) == 0:
    print(0)
else:
    calc = 1
    is_ok = True
    for i in sorted(an, reverse=True):
        calc *= i
        if calc >10 ** 18:
            is_ok = False
            break
    if is_ok:
        print(calc)        
    else:
        print(-1)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
if A[0]==0:
    print(0)
else:
    ok=bool(True)
    ans=int(1)
    for i in A:
        ans*=i
        if ans>1000000000000000000:
            ans=0
            ok=False
    if ok:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

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

A.sort()
B = list(set(A))

total = 1
flag = 9
for i in range(len(B)):
  total *= B[i]**A.count(B[i])
  if total > 10**18:
    flag = 0
    break
  elif min(A) == 0:
    flag = 1
    break
  
if flag == 0:
  print(-1)
elif flag == 1:
  print(0)
else:
  print(total)

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in a:
    ans = 0
else:
    for i in range(1, n):
        if ans <= 10 ** 18:
            ans *= a[i]
        else:
            break

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

Submission status: Accepted

Solution code:
n=int(input())
arr=[int(i) for i in input().split()]
ans=1
if 0 in arr:
    print(0)
else:
    for i in arr:
        ans=ans*i
        boo=True
        if ans>1000000000000000000:
            print(-1)
            boo=False
            break
    if boo:
        print(ans)

Submission status: Accepted

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

ans = A[0]

if 0 in A:
    ans = 0
else:
    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 = [int(a) for a in input().split()]
if min(A) == 0:
    print(0)
else:
    ans = 1
    M = 10**18
    for i in A:
        ans *= i
        if ans > M:
            print(-1)
            break
    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:
        print(0)
        exit()
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        break
if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

limit = 10 ** 18
res = A[0]

if 0 in A:
    print(0)
    exit(0)
else:
    for i in range(1, N):
        res *= A[i]
        if res > limit:
            print(-1)
            exit(0)

print(res)

Submission status: Accepted

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

INF=1000000000000000000
if 0 in A:
    print(0)
else:
    ans=1
    for n in range(N):
        ans*=A[n]
        if ans>INF:
            break

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(dp[n])

Submission status: Accepted

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

Submission status: Accepted

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


if flag==1:
    print(-1)
elif flag ==2:
    print(0)
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 ans > 10**18+1:
        break
    else:
        ans = ans * A[i]

if 0 in A:
    print(0)
elif ans > 10**18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 1
    for ai in a:
        ans *= ai
        if ans == 0:
            print(0)
            exit()
        elif ans > 10 ** 18:
            print(-1)
            exit()
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC169 B Multiplication 2

from collections import deque

n = int(input())

a_list = [int(x) for x in input().split()]

if min(a_list) == 0:
    print("0")
else:
    a_dq = deque(a_list)
    ans = 1
    for i in range(n):
        ans *= a_dq.popleft()
        if ans > 10**18:
            break

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

Submission status: Accepted

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

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

ans = 1
for i in a:
    ans *= 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()))
a = 1

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

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

else : print(a)

Submission status: Accepted

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

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

EL = 1
for i in range(N):
    EL = EL * As[i]
    if EL > 1e+18:
        print(-1)
        exit(0)
print(EL)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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


  ans = 1
  f = False

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

  if not f:
    print(ans)

Submission status: Accepted

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

if 0 in l:
    print('0')
    sys.exit()
    
for e in l:
    ans *= e
    if ans > 10 ** 18:
        print('-1')
        sys.exit()

print(str(ans))

Submission status: Accepted

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


def f():

    for i in range(n):
        a = int(A[i])
        if(a == 0):
            return 0

    ans = 1

    for i in range(n):
        a = int(A[i])
        if(a == 0):
            return 0
        elif(ans*a > 1000000000000000000):

            return -1
        ans *= a

    return ans


print(f())