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())
A = list(map(int, input().split()))
num = 1
A.sort()
for i in range(N):
    num *= A[i]
    if num > 10 ** 18:
        num = -1
        break
print(num)

Submission status: Accepted

Solution code:
from sys import exit

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

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

print(tmp)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
List = list(map(int, input().split()))
List=sorted(List)
List=List[::-1]
#print(List)
if List.count(0)!=0:
    print(0)
    quit()
ANS=List[0]
i=1
while i<N:
    ANS=ANS*List[i]
    if ANS>1000000000000000000:
        print(-1)
        quit()
    i+=1

print(ANS)

Submission status: Accepted

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

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

ans = a[0]
for i in range(1, len(a)):
    ans *= a[i]
    if ans > 1000000000000000000:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import numpy as np
import bisect
import sys
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

#n=int(input())z
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))



n=int(input())
#n,m=input_list()
a=input_list()
ans=1
if 0 in a:
    print(0)
    exit()
for i in a:
    ans*=i
    if ans>10**18:
        print(-1)
        exit()



print(ans)

Submission status: Accepted

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

print(use)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N = I()
A = LI()

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

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

print(ans if not 0 in A else 0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
t = 10**18
l = list(map(int, input().split(' ')))
ans = 1

for i in l:
	ans *= i
	if(ans > t):
		ans = -1
		break
if(0 in l):
	ans = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

is0 = 0
for i in range(0, n):
    if a[i] == 0:
        is0 = 1

if is0 == 1:
    print(0)
else:
    for i in range(0, n):
        if ok:
            ans = ans * a[i]

        if ans > 1000000000000000000:
            ok = 0

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

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:
      continue
  else:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

a = sorted(a);

ans = 1

for i in a:
    ans *= i
    if ans > 1000000000000000000:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

lim = 10**18

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

T = 1
for i in A:
    T *= i
    
    if T > lim:
        print(-1)
        exit()

print(T)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 1
for i in range(N):
    if (ans > 10 ** 18):
        break
    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
if 0 in a:
    print(0)
    exit()
for i in a:
    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()))

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

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

print(res)

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    A = read_ints()
    maximum = 10**18
    if 0 in A:
        return 0
    ans = 1
    for a in A:
        ans *= a
        if ans > maximum:
            return -1
    return ans


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

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

    print(ans)



if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    if a.count(0) > 0:
        ret = 0
    else:
        ret = 1
        for i in a:
            ret *= i
            if ret > 1e18:
                ret = -1
                break
    print(ret)

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)

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

print(result)

Submission status: Accepted

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

ans=1

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().strip().split()))[:n]
limit=10**18
mul=1
if(0 in arr):
	print(0)
else:
	for i in arr:
		mul*=i
		if(mul > limit):
			print(-1)
			break
	if(mul <= limit):
		print(mul)

Submission status: Accepted

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

n = input()
line = input()
res = 1
data = []
for x in line.split(' '):
    data.append(int(x))
    if int(x) == 0:
        res = 0
for x in data:
    res = res * int(x)
    if pow(10, 18) < res:
        res = -1
        break
print(res)

Submission status: Accepted

Solution code:
num = int(input())
numbers = input().split(" ")
if "0" in numbers:
  print(0)
else:
  ans = 1
  for number in numbers:
    kake = int(number)
    ans *= kake
    if ans > 10**18:
      print(-1)
      break
  else:
    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
    for i in range(n):
        ans *= a[i]
        if ans > 10**18:
            print(-1)
            break
    else:
      print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    for i in a:
        if i == 0:
            print(0)
            return
    ans = 1
    INF = int(1e18)
    for i in a:
        ans *= i
        if ans > INF:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
if 0 in A:
    ans = 0
else:
    for i in 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()))

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

Submission status: Accepted

Solution code:
#! env/bin/local python3

import sys

n = int(input())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x)

result = 1

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

Submission status: Accepted

Solution code:
n=int(input())

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

sum=1

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    MAX = 10**18
    if 0 in set(a):
        print(0)
    else:
        ans = a[0]
        for ai in a[1:]:
            ans *= ai
            if ans > MAX:
                print(-1)
                return
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

# print('input >>')
N = int(input())
As = list(map(int,(input().split())))

INF = 10 ** 18

ans = 1

over = False

for A in As:
    if A == 0:
        print(0)
        sys.exit()

for A in As:
    ans *= A
    if ans > INF:
        print(-1)
        sys.exit()
        
# print('-----output-----')
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
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:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n = ni()
a = sorted(nl())
ans = 1
for ele in a:
    ans *= ele
    if ans > 10 ** 18:
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
cumul = 1
n = int(raw_input())
ais = map(int, raw_input().split(' '))
i = 0
ais.sort(key = lambda x:-x)
if ais[-1] == 0:
	cumul = 0
while(i < len(ais) and cumul <= 10 ** 18):
  cumul *= ais[i]
  i +=1
  if cumul == 0:
  	break

print cumul if cumul <= 10 ** 18 else -1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
A = list(map(int,input().split()))
A.sort()
if A[0] == 0:
    print(0)
    exit()
elif A[-1]*A[-2] > 10**18:
    print(-1)
    exit()
from collections import defaultdict
d = defaultdict(int)
for a in A:
    d[a] += 1
for k in d:
    ans *= k**d[k]
if ans > 10**18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in alist:
    result=0
else:
    result=1
    for a in alist:
        result*= a
        if result > 10**18:
            result = -1
            break

print(result)

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_c = num_list.count(0)

    if zero_c >= 1:
        print(0)
        exit()

    ans = 1

    max_num = 10**18

    for num in num_list:
        ans *= num
        if ans > max_num:
            print(-1)
            exit()

    print(ans)
            
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    A = sorted(A)
    cnt = 1
    flag = True
    for i in range(n):
        cnt *= A[i]
        #print(cnt)
        if cnt > 10**18:
            flag = False
            break

    if flag == True:
        print(cnt)
    else:
        print(-1)


resolve()

Submission status: Accepted

Solution code:
n = input()
 
nums = list(map(int, input().split()))
 
MAX = 10**18

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

ans = 1
for num in nums:
    ans = ans*num 
    if ans > MAX:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

e = 10**18
ans = a[0]
if 0 in a:
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
th = pow(10, 18)
a = list(map(int, input().split()))

ans = 1
over = False

for i in a:
    ans *= i
    if ans > th:
        over = True
        ans %= th
    
    if i == 0:
        ans = 0
        over = False
        break

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

Submission status: Accepted

Solution code:
x=int(input())
s=list(map(int,input().split()))
s.sort()
res=1
for n in s:
	res*=n
	
	if res>1e18:
		res=-1
		print(-1)
		exit(0)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(val)

Submission status: Accepted

Solution code:
def main():
    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 0 in a:
        ans = 0

    print (ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = [int(i) for i in 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()))
MOD = 10**18
if 0 in A:
    print(0)
else:
    ans = 1
    flag = True
    for a in A:
        ans *= a
        if ans > MOD:
            print(-1)
            flag = False
            break
    
    if flag:
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

isZero = False
for l in L:
    if (l == 0):
        isZero = True

if (isZero):
    print(0)
else:
    a = 1
    maxV = 1e+18
    for l in L:
        a *= l
        if (a > maxV):
            print(-1)
            sys.exit()

    print(a)

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

limit = pow(10, 18)
N, *A = map(int, read().split())
A = sorted(A)

ans = 1
for a in A:
    ans *= a
    if ans > limit:
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

l = 10**18

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

ans = 1
for ai in a:
    ans *= ai
    if ans > l:
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
import sys 

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

if min(A)==0:
  print("0")
  sys.exit()
if max(A) > 10**18:
  print("-1")
  sys.exit()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
max_ans = 10**18

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

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

print(ans)

Submission status: Accepted

Solution code:

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

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

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

res = 1
for v in a:
    res *= v
    if res > 10 ** 18:
        print(-1)
        sys.exit()

print(res)

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

U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1

if p > U:
    print(-1)
else:
    print(p)

Submission status: Accepted

Solution code:
import sys
n=int(input())
A = [int(x) for x in input().split()]
bar = 10**18
ans =A[0]
if 0 in A:
    print(0)
    sys.exit()
    
for i in A[1:]:
    ans = ans * i
    if ans > bar:
        print(-1)
        sys.exit()
        
print(ans)

Submission status: Accepted

Solution code:
# abc169_b.py
N = int(input())
A = list(map(int,input().split()))
ans =1
A.sort()
for i in A:
    if i == 0 :
        ans = 0
        break
    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()))
ans = a[0]

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

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

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 > 10**18:
        print(-1)
        quit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

LIMIT = 10 ** 18
result = 1


for a_i in sorted(list(a_n)):
    result = result * a_i

    if result > LIMIT:
        result = -1
        break
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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

maxn = 10**18
ans = 1
for k in a:
    ans *= k
    if ans > maxn:
        ans = -1
        break


print(ans)

Submission status: Accepted

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

s = 1
l=10**18

for i in a:
    s *= i
    if s > l:
        print(-1)
        exit()
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = int(input())
a = list(map(int, input().split()))
upper = 10 ** 18
res = 1

a.sort()
a.reverse()

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

for aa in a:
    res *= aa
    if res > upper:
        print(-1)
        exit(0)

print(res)

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    A = list(iim())
    mx = 10**18
    A.sort()

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

    ans = 1
    for i, a in enumerate(A):
        ans *= a
        if ans > mx:
            print(-1)
            return

    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
if A[0] == 0:
    print(0)
    exit()

ans = 1
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:
import sys
# sys.setrecursionlimit(10**10)
N = int(sys.stdin.readline().rstrip())
# S = sys.stdin.readline().rstrip()
# N, K = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))

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

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

Submission status: Accepted

Solution code:
n, *A = map(int, open(0).read().split())
A.sort()
s = 1
for a in A:
    s *= a
    if s > 10**18:
        print(-1)
        break
    elif s == 0:
        print(0)
        break
else:
    print(s)

Submission status: Accepted

Solution code:
# coding: utf-8

import math
import re
import numpy as np

N = int(input())
An = input().split(" ")

over = False

ans = 1

if "0" in An:
    ans = 0

else:
    for i in range(N):
        Ai = int(An[i])
        if (ans != 0 and Ai > 1000000000000000000) or ans > 1000000000000000000:
            over = True
            break

        ans *= Ai

if ans > 1000000000000000000:
    over = True

if not over:
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

tot=A[0]
b=True
if (0 in A)==True:
    print(0)
    b=False
a=True
if b==True:
    for i in range(1,N):
        tot=tot*A[i]
        if tot>10**18:
            print(-1)
            a=False
            break
    if a==True:
        print(tot)

Submission status: Accepted

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

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