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:
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        print(0)
        return
    x = 1
    for tmp in a:
        x *= tmp
        if x > 1000000000000000000:
            print(-1)
            return
    print(x)

solve()

Submission status: Accepted

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

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

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

print (ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if not ( 2 <= N <= 10**5 ): sys.exit()
if not ( 0 <= min(array) and max(array) <= 10**18): sys.exit()
if 0 in array: print(0); sys.exit()

sum = array[0]
for I in range(1,len(array)):
    sum *= array[I]
    if sum > 10**18: print(-1);sys.exit()
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
if 0 in arr:
    print('0' + '\n')
else:
    mul = 1
    for n in arr:
        mul *= n
        if mul > 10**18:
            print('-1' + '\n')
            break
    else:
        print(str(mul) + '\n')

Submission status: Accepted

Solution code:
n = int(input())

A = list(map(int, input().split()))
A = sorted(A)
total = 1
for i in A:
    total *= i
    if total > 10**18:
        total = -1
        break
print(total)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, A: "List[int]"):
    if min(A) == 0:
        return 0
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            return -1
    return ans


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if 0 in A:
    print(0)
else:
    product = 1
    for Ai in A:
        product *= Ai
        if product > 10 ** 18:
            print(-1)
            exit()

    print(product)

Submission status: Accepted

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

Submission status: Accepted

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




flag = True

if 0 in a:
  print(0)
  flag = False

if flag:
  for i in a:
    ans *= i
    if ans > limit:
      print(-1)
      flag = False
      break

if flag:
  print(ans)

Submission status: Accepted

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()

A=many_int()
A=sorted(A)

out = 10**18
output = 1
for a in A:
    output *= a
    if output>out:
        output=-1
        break
print(output)

Submission status: Accepted

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

p=1

for k in range(N):
    if A[k] == 0:
        p = 0
        break

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

    print(p)

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
lim = 10**18
multi = 1
for x in a:
    multi *= x
    # print(x)
    if multi > lim:
        print(-1)
        exit()

print(multi)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(j) for j in input().split()]
a.sort()
ans = 1
for i in a:
    ans *= i
    if ans > 10 ** 18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

if nums.count(0):
    print(0)
    exit(0)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
for a in A:
    ans *= a

    if ans > 10 ** 18:
        ans = -1
        break

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    A = list(sorted(list(map(int, input().split()))))

    if A[0] == 0:
        print(0)
        return

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

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
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()]

result = 1

if A.count(0) == 0:
    for x in range(N):
        result = result * A[x]
        if result >= 10**18 + 1:
            print(-1)
            exit()
    print(result)
else:
    print(0)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

max = 10**18

mul = 1
for a in A:
    mul *= a
    if mul > max:
        print(-1)
        exit()

print(mul)

Submission status: Accepted

Solution code:
n = int(input())
ans,f=1,0
ls = sorted(map(int,input().split()))
for i in ls:
    ans*=i
    # print(i,end="")
    if ans > 1e18:
        f=1
        break
if f:
    print(-1)
else :
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  if 0 in A:
    print(0)
    return
  prd = 1
  for a in A:
    prd *= a
    if prd > 1000000000000000000:
      print(-1)
      return
  print(prd)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())

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

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

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int,input().split()))
A.sort()
result = 1
for i in range(N):
    result = result * A[i]
    if result > 1e18:
        result = -1
        break
print(result)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr.sort();
x=int(1)
for i in arr:
  x=x*i
  if x>1e18:
    x=-1;
    break;
print(x)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
border=10**18

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    np.set_printoptions(threshold=20)
    N = int(input())
    A = list(map(int, input().rstrip().split()))
    A.sort()
    ans = 1
    for v in A:
        ans *= v
        if ans > pow(10, 18):
            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)
else:
  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()))

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

mult = 1

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

Submission status: Accepted

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

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

    if 0 in A:
        print(0)
    else:
        out = 1
        for n in A:
            out = n * out
            if out > 1000000000000000000:
                break
            else:
                continue
    
        if out > 1000000000000000000:
            print(-1)
        else:
            print(out)


main()

Submission status: Accepted

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

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

else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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 i in range(n):
    result *= a[i]
    if result > (10**18):
      print(-1)
      break
    else:
      continue
  else:
    print(result)

Submission status: Accepted

Solution code:
import sys  # sys.exit()を使いたいので

n = int(input())
a = list(map(int, input().split()))
a.sort()  # 0があれば先頭に来ます

cur = 1  # 現在の数値
for x in a:
    cur *= x
    if cur > 10 ** 18:
    # 10**18を超えたので終了します
        print(-1)
        sys.exit()
print(cur)  # 10**18以下なので、出力します

Submission status: Accepted

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

for i in range(len(input)):
  if(input[i]==0):
    print(0)
    exit(0)

multi=1
for i in range(len(input)):    
  multi *= input[i]
  if(multi > (10 ** 18)):
    print(-1)
    exit(0)

print(multi)

Submission status: Accepted

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

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

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

print(c)

Submission status: Accepted

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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys  # sys.exit()を使いたいので

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

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

Submission status: Accepted

Solution code:
def multiplication():
    # 入力
    N = int(input())
    A = list(map(int, input().split()))
    # かける数に0があるか確認
    if 0 in A:
        return 0
    # 計算処理
    multi = 1
    for i in range(N):
        multi = multi * A[i]
        # 10^18比較
        if multi > 10 ** 18:
            return -1
    return multi

result = multiplication()
print(result)

Submission status: Accepted

Solution code:
import sys

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

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

s = 1
for x in a:
  s *= x
  if s > 1000000000000000000:
    break
if s > 1000000000000000000:
  print(-1)
else:
  print(s)

Submission status: Accepted

Solution code:
A= int(input())
B = list(map(int, input().split()))
result = 1
if 0 in B:
    print(0)
    exit()

for S in B:
    result *= S
    if result > 10**18:
        print(-1)
        exit()
print("%d"%result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

final = 1

if 0 in a:
    print(0)
    
else:
    for i in a:
        final *= i
        if final > 1000000000000000000:
            break
    if final > 1000000000000000000:
        print(-1)
    else:
        print(final)

Submission status: Accepted

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

        else:
            ans=D
        

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

prod = 1

A.sort()
if A[0] == 0:
    prod = 0

A.sort(reverse=True)


for i in range(N):
    prod *= A[i]
    if prod > 1e18:
        prod = -1
        break
    if prod == 0:
        break

print(prod)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def line_to_int(): return int(sys.stdin.readline())
def line_to_each_int(): return map(int, sys.stdin.readline().split())
def line_to_list(): return list(map(int, sys.stdin.readline().split()))
def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
# def dp(init, i, j): return [[init]*i for i2 in range(j)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #A = [0]+list(accumulate(A))
# import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a)

n = line_to_int()
a = line_to_list()

# from functools import reduce, partial
# from operator import mul

# prod = partial(reduce, mul)

# if 0 in a:
#     print(0)
# else:
#     if prod(a) <= 10**18:
#         print(prod(a))
#     else:
#         print(-1)
ans = a[0]
limit = 10**18
if 0 in a:
    print(0)
else:
    for i in range(1,n):
        if ans <= limit:
            ans = ans * a[i]
        else:
            print(-1)
            exit()
    if ans <= limit:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

Solution code:
def b169(n, alist):

    ans = 1
    for i in alist:
        if i == 0:
            return 0

    for i in alist:
        ans *= i
        if ans > 10**18:
            return -1

    return ans

def main():
    n = int(input())
    alist = list(map(int, input().split()))
    print(b169(n, alist))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=int(input())
List = list(map(int, input().split()))
res =1
List.sort()
for i in range(a):
  res = res *List[i]
  if res > 1000000000000000000:
    res = -1
    break
  elif res == 0:
    break
  else:
    pass
print(res)

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:
        if  ans * i > 10**18:
            ans = -1
            break
        else:
            ans *= i

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    output = 0
    
else:

    output = 1

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

Submission status: Accepted

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

temp = 1

if 0 in a:
    print(0)

else:
    for i in a:
        temp *= i
        if temp > 10**18:
            print(-1)
            sys.exit()
    print(temp)

Submission status: Accepted

Solution code:
n = input()
n = int(n)
a = input().split()
b = 1
if '0' in a:
    print ("0")
else:
    for i in a:
        b *= int(i)
        if (b > 1000000000000000000):
            print ("-1")
            break
    if (b <= 1000000000000000000):
        print (b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main(numbers: list):
    result = 1
    numbers.sort()
    for num in numbers:
        result *= num
        if result > 10 ** 18:
            print(-1)
            return

    print(result)


N = int(input())
line = list(map(int, input().split()))
main(line)

Submission status: Accepted

Solution code:
MX = 10**18
def fun(a,n):
	if max(a) > MX:
		return -1
	if 0 in a:
		return 0
	res = a[0]
	for i in range(1,n):
		res = res * a[i]
		if res > MX:
			return -1
	return res

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
res = 1
if 0 in a:
  print(0)
  exit()
for a in a:
  res *= a
  if res > 1e18:
    res = -1
    break
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    al = list(map(int,input().split()))
    al_p = 1

    if 0 in al:
        print(0)
        return

    for i in range(n):
        al_p *= al[i]
        if al_p > 10**18:
            print(-1)
            return
        
    print(al_p)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = 1
ok1 = True
_n = int(input())
a = list(map(int,input().split()))
ok2 = False
if 0 in a:
    ok2 = True

for i in a:
    ans *= i
    if ans > 1e18:
        ok1 = False
        break

if ok2:
    print(0)
elif ok1:
    print(ans)
else :
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
a = [int(i) for i in input().split(" ")]
p = 1
for i in a:
 p *= i
 if(p > 10**18): p = 10**18 + 1
if(p > 10**18):
 print(-1)
else:
 print(p)

Submission status: Accepted

Solution code:
import math

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

ans = 1
for num in range(N):
    ans *= A[num]
    if ans > math.pow(10, 18):
        ans = -1
        break

if 0 in A:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a = k()
b = l()
b.sort()
ans = 1
for i in b:
    if i == 0:
        print(0)
        sys.exit()
    else:
        ans *= i
    if ans > 10**18:
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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



for ai in A:
  if ai == 0 :
    print('0')
    exit()
	    
ans = A[0]      
for i in range(1,N):
  
  ans *= A[i]
  
  ansCp = ans
  ansCnt = 1
  while ansCp >= 10:
    ansCp /= 10
    ansCnt += 1
    
  if (ansCnt > 19) or ( ansCnt == 19 and ans%10 > 0 ) :
    print("-1")
    exit()
  
  
      
print(str(ans))

Submission status: Accepted

Solution code:
import sys

if __name__ == "__main__":
    a = int(input())
    n = list(map(int, input().strip().split(' ')))
    ans = 1
    n.sort()
    for i in n:
      ans *= i
      if ans > 10**18:
          break
    if ans > 10**18:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

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

flag = 1
if 0 in num:
  print(0)
  flag=0

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

if flag==1:
  print(ans)

Submission status: Accepted

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


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


def main():
    N = II()
    A = LI()

    ans = 1
    index = 0
    A_set = set(A)
    if 0 in A_set:
        print(0)
        return
    while index < N:
        ans *= A[index]
        index += 1
        if ans > 10**18:
            break

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


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()

Submission status: Accepted

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

a.sort()
sum_num = 1
std_num = 1000000000000000000
if(a[-1] == 0):
    sum_num = 0
else:
    for i in range(n):
        sum_num = a[i]*sum_num
        if(sum_num > std_num):
            sum_num = -1
            break;
print(sum_num)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    X=input().split()
    if "0" in X:
        print(0)
        return
    ans=1
    for i in X:
        ans = int(i) * ans
        if 1000000000000000000<ans:
            print(-1)
            return
    print(ans)
main()

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    X=input().split()
    if "0" in X:
        print(0)
        return
    ans=1
    for i in X:
        ans = int(i) * ans
        if 1e18<ans:
            print(-1)
            return
    print(ans)
main()

Submission status: Accepted

Solution code:
N=int(input())
X=input().split()

ans=1
if "0" in X:
    print(0)
else:
    for i in X:
        ans = int(i) * ans
        if 1e18<ans:
            print(-1)
            break
    else:
        print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=1
if 0 in X:
    print(0)
else:
    X.sort()
    for i in X:
        ans *= i
        if 1e18<ans:
            print(-1)
            break
    else:
        print(ans)

Submission status: Accepted

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

ans=1
if 0 in X:
    print(0)
else:
    X.sort()
    for i in range(N):
        ans *= X[i]
        if 10**18<ans:
            print(-1)
            break
    else:
        print(ans)