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:
a = int(input())
b = list(map(int,input().split()))
b.sort()
c  = 1
yon = 10**18
for i in b:
    c *= i
    if c > yon :
     print(-1)
     exit()
print(c)

Submission status: Accepted

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

zero = 0
if zero in A:
    print("0")
else:
    for i in range(n):
    
        temp = A[i]
        if i ==0:
            kakeru = temp
        else:
            kakeru = kakeru*temp
        if kakeru >10**18:
            kakeru = -1
            break
    
    print(kakeru)

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
input()
l = 10**18
a = 1
*b, = map(int, input().split())
if 0 in b:
    a = 0
else:
    for i in b:
        a *= i
        if a > l:
            a = -1
            break
print(a)

Submission status: Accepted

Solution code:
n = int(input());

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

ok = True;
ans = 1;
a.sort();
for val in a:
    ans *= val;
    if(ans > 1e18):
        ok = False;
        break;
    elif(ans == 0):
        break;

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
if 0 in a: print(0)
else:
    m = 1
    flag = 0
    for i in a:
        m *= i
        if m > 1e+18:
            print(-1)
            flag = 1
            break
    if flag == 0: print(m)

Submission status: Accepted

Solution code:
import numpy as np

N=int(input())
A=np.ones(N)
a=np.ones(N)

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


a=sorted(A,reverse=True)

a_product=1
flag_1e18=False
flag_0=False

if a[N-1]==0:
  flag_0=True

for i in range(0,N,1):
  a_product=a_product*a[i]
  if a_product>1e18:
    flag_1e18=True
    break
  else:
    continue
    
if flag_1e18==True and flag_0==False:
  print(-1)
elif flag_0==True:
  print(0)
else:
  print(a_product)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

ans=1
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())
l = list(map(int, input().split()))
l.sort()

v_max = 10 ** 18

result = 1
for v in l:
    # print(v)
    result *= v
    # print(result)
    if result > v_max:
        result = -1
        break
    
print(result)

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 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()))
is_zero = False
for i in a:
  if i == 0:
    is_zero = True
    break
if is_zero:
  print(0)
else:
  p = 1
  for i in a:
    p = p*i
    if p > 10**18:
      break
  if p > 10**18:
    p = -1
  print(p)

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 A:
  ans *= i
  if ans > 10 ** 18:
    print(-1)
    exit(0)
print(ans)

Submission status: Accepted

Solution code:

n = int(input())
list_a=list(map(int, input().split()))  #リスト入力
list_a.sort(reverse=True)
# list_a = sort(list_a)
result = 1
if list_a[-1] == 0 :
    print(0)
else:
    for i in list_a:
        result = result * i
        if result > 1000000000000000000:
            print(-1)
            break

    if result <= 1000000000000000000:
        print(result)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input()); c=0
a=[int(x) for x in input().split()]
if 0 in a: 
    print(0)
else:
    p=1; m=10**18
    for i in a:
        if(p*i>m):
            c=1;break
        else: 
            p*=i
    if(c==0):
        print(p)
    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)
    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
ok = True
for a in A:
    if a == 0:
        ans = 0
        break
    if ok:
        ans *= a
        if ans > 10 ** 18:
            ans = -1
            ok = False
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import sys

n = stdin.readline().rstrip().split()
a = stdin.readline().rstrip().split()

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

total = 1
for i in a:
    total = total*int(i)

    if(total > 1000000000000000000):
        print(-1)
        sys.exit()

print(total)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
a.sort()
# print(a)

max_x = 10 ** 18

result = 1
for x in a:
    result *= int(x)
    if result == 0 or result > max_x:
        break

if result > max_x:
    print(-1)
else:
    print(result)

Submission status: Accepted

Solution code:
N    = int(input())
A    = [int(x) for x in input().split()]
Pro  = 1
PrF  = 1
PrFF = 1

if 0 in A:
    print('0')
    PrF = 0
    
if PrF:
    for T in range(0,len(A)):
        Pro = Pro*A[T]
        if Pro > pow(10,18):
            PrFF = 0
            print('-1')
            break

if PrF & PrFF:
    print(Pro)

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  arr = list(map(int, input().split()))
  
  
  if 0 in arr:
    print(0)
    return 0
  res = arr[0]
  for a in arr[1:]:
    res *= a
    if res > 1000000000000000000:
      print("-1")
      return 0

  print(res)

main()

Submission status: Accepted

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

    if a.count(0)>=1:
        print(0)
        return

    for i in range(N):
        cal*=a[i]
        if cal>10**18:
            print("-1")
            return

    print(cal)
    return


main()

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = sorted(a)
    if a[0] == 0:
        return "0"
    ans = 1
    for _a in a[::-1]:
        ans *= _a
        if ans > 10**18:
            return "-1"
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = sorted(a)
    ans = 1
    for _a in a:
        ans *= _a
        if ans > 10**18:
            return "-1"
        if ans == 0:
            return "0"
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = sorted(map(int,input().split()))
ans = 1
if a[0] == 0:
  print(0)
else:
  for i in a:
    ans *= i
    if 1000000000000000000<ans:
      print(-1)
      sys.exit()
  print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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())
alist = list(map(int,input().split()))
alist.sort()
mx = 10**18

ans = 1
for a in alist:
    ans *= a
    if ans > mx:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    result = 1
    if 0 in a:
        print(0)
        return
    for number in a:
        result *= number
        if result > 10 ** 18:
            print(-1)
            return
    print(result)

main()

Submission status: Accepted

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

for i in a:
    result = result * i

    # result = np.prod(a)

    if (result > pow(10, 18)):
        result = -1
        break

print(result)

Submission status: Accepted

Solution code:
N = int(input())

nums = list(map(int,input().split(" ")))
s = 1
limit = 10**18
flag = False
for num in nums:
    s = s * num
    if s > limit:
        flag = True
        break

if flag:
    if 0 not in nums:
        print(-1)
    else:
        print(0)
else:
    print(s)

Submission status: Accepted

Solution code:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n = int(rl())
	ans = 1
	lim = 10**18
	flag = False
	for a in rli():
		if flag:
			if a == 0:
				ans = 0
				print(0)
				return
			continue
		ans *= a
		if ans > lim:
			flag = True
	print(ans if not flag else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

temp=1
seki=0
for i in range(N):
    temp*=A[i]
    seki*=A[i]
    seki+=(temp//10**9)
    temp%=10**9
    
    if seki*10**9+temp>10**18:
        print(-1)
        exit()
    

print(seki*10**9+temp)

Submission status: Accepted

Solution code:
n = int(input())
m = list(map(int, input().split()))
ans = 1
if min(m) == 0:
    print(0)
else:
    m.sort(reverse=True)
    for i in m:
        ans *= i
        if ans > 1000000000000000000:
            ans = -1
            break
    print(ans)

Submission status: Accepted

Solution code:
input()
s=1
for a in map(int,input().split()):
  if a==0:s=0;break
  if s>0:s*=a
  if s>1e18:s=-1
print(s)

Submission status: Accepted

Solution code:
# B - Multiplication 2
def main():
    _, *A = open(0).read().split()
    if "0" in A:
        print(0)
        return
    prod = 1
    LIM = 10 ** 18
    for i in A:
        prod *= int(i)
        if prod > LIM:
            print(-1)
            return
    print(prod)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# B - Multiplication 2
def main():
    _, *A = map(int, open(0).read().split())
    if 0 in A:
        print(0)
        return 
    prod = 1
    LIM = 10 ** 18
    for i in A:
        prod *= i
        if prod > LIM:
            print(-1)
            return
    print(prod)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    m = list(map(int, input().split()))
    ans = 1
    if min(m) == 0:
        print(0)
    else:
        m.sort(reverse=True)
        for i in m:
            ans *= i
            if ans > 1000000000000000000:
                ans = -1
                break
        print(ans) 
if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 1
if 0 in a_lis:
    ans = 0
    
else:
    for i in a_lis:
        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()))
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 = input()
A = input().split()
if '0' in A:
  print(0)
else:
  a = 1
  for i in A:
    a *= int(i)
    if a > 10**18:
        print(-1)
        exit()
  else:
    print(a)

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
# coding: utf-8
n = input()
hairu = input()
kita = hairu.split(" ")
seki = 1

for c in kita:
    if c == "0":
        kita[0] = "0"

for c in kita:
    seki = seki * int(c)
    if seki > 10**18:
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''
Fuad Ashraful Mehmet
University of Asia Pacific,Bangladesh
Date:2nd june 2020
'''

def Solve():
    n=int(input())
    ar=[int(x) for x in input().split()]
    if 0 in ar:
        print(0)
        exit()
    ans=1
    for x in ar:
        ans=ans*x
        if ans>10**18:
            print("-1")
            return
    print(ans)
Solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
num = int(input())
s = list(map(int,input().split()))
res = 1
for i in s:
    res *= i
    if res >= 10 ** 18:
        break

if 0 in s:
    print(0)
elif res <= 10 ** 18:    
    print(res)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
a = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 1
for i in range(a):
  ans = ans * l[i]
  if 10**18 < ans:
    ans = -1
    break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
int_list = list(map(int, input().split()))
max_num = 10**18
ans = 1

if 0 in int_list:
    print(0)
    exit()
  
for i in int_list:
    ans *= i
    if ans > max_num:
        print(-1)
        break
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1

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

print(ans)

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return
    
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    
    print(prod)
    return

main()

Submission status: Accepted

Solution code:
import math
import re
import copy
import sys

n = int(input())
a = list(map(int,input().split()))
ceil = 10 ** 18
ans = 1
if all([b > 0 for b in a]):
    for i in range(n):
        ans *= a[i]
        if ans > ceil:
            break
if any([b == 0 for b in a]):
    print(0)
elif ans > ceil:
    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:
  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()))

seki = 1
if 0 in a:
  print(0)
else:

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

Submission status: Accepted

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

	prod = 1 
	for a in A:
		prod *= a
		if prod > 1000000000000000000:
			print(-1)
			return

	print(prod)


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in a:
    print(0)
else:
    for elem in a:
        ans *= elem
        if 10 ** 18 < ans:
            print(-1)
            exit()
    print(ans)

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


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


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

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

print(num)

Submission status: Accepted

Solution code:
n = int(input())

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

if 0 in n_list:
    print(0)

else:

    product = 1
    for num in n_list:
        product = product * num

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


    print(product)

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
dec = 10**18
Ans = 1
# print(len(L))
if(0 in L):
    print(0)
else:
    for i in L:
        Ans = Ans * i
        if dec < Ans:
            print(-1)
            break
    else:
        print(Ans)

Submission status: Accepted

Solution code:
N = int(input())
A=list(map(int, input().split()))
 
ans=1
c=0
 
while c<N:
    if A[c]==0:
        ans=0
    elif ans*A[c]>1000000000000000000:
        ans=1000000000000000001
    else :
        ans=ans*A[c]
    
    c+=1
    
if ans>1000000000000000000: print(-1)
else: print(ans)

Submission status: Accepted

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

    if 0 in a:
        print(0)
        return

    mul = 1
    for ai in a:
        mul *= ai
        if mul > 1000000000000000000:
            print(-1)
            return

    print(mul)

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
from math import log10
from functools import reduce

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
log = 0.0
for a in A:
    if a == 0:
        print(0); exit()
    log += log10(a)

if log > 18:
    print(-1); exit()

answer = reduce(lambda x, y: x*y, A)
print(answer if answer <= 10 ** 18 else -1)

Submission status: Accepted

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

if min(A)==0:
    print(0)
else:
    ans=1
    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())
nums = input().split()
mul = int(nums[0])
if str(0) in nums:
    mul = 0
else:
    for i in nums[1:]:
        mul *= int(i)
        if len(str(mul)) >= 19 and str(mul) != "1000000000000000000":
            mul = -1
            break
print(mul)

Submission status: Accepted

Solution code:
input()
ans = 1
n = int(1e18)
a = list(map(int, input().strip().split()))
for i in a:
    ans *= i
    if ans > n:
        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()))
MX = 10**18
ans = 1
a.sort()
for x in a:
    if x == 0:
        print(0)
        exit(0)
    else:
        ans *= x
        if ans > MX:
            print(-1)
            exit(0)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve():
    e = 10 ** 18
    n = int(input())
    arr = [int(i) for i in input().split()]
    ans, flag = [1,1]
    if 0 in arr:
      	return 0
    for i in arr:
        ans = ans * i
        if ans > e:
            return -1
    return ans
print(solve())

Submission status: Accepted

Solution code:
import math
n = int(input())
A = list(map(int, input().split(" ")))
A.sort()
ans = 1
ok = True
for i in A:
    ans = ans * i
    if(ans > math.pow(10, 18)):
        ok = False
        break

print(ans if ok else -1)

Submission status: Accepted

Solution code:
n = int(input())
a_array = sorted([int(x) for x in input().split()])
s = a_array[0]
for a in a_array[1:]:
    s *= a
    if s > 10**18:
        s = -1
        break
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul

n = int(input())

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

a = sorted(a)
ans = 1
for x in a:
    ans = ans * x
    if (ans > 1e18):
        ans = -1
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def Mul(data,start = 0 ,end = None):
    if end == None:
        end = len(data)-1
    if start == end:
        return data[start]
    else:
        mid = (start+end)//2
        A = Mul(data,start,mid)
        B = Mul(data,mid+1,end)
        return A*B
n = int(input())
data = list(map(int,input().split()))
X = Mul(data)
if X>10**18:
  print(-1)
else:
  print(X)

Submission status: Accepted

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
A = LIST()

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

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

Submission status: Accepted

Solution code:
import math
N=int(input())
risuto=list(map(int,input().split()))
ans=1
kari=0
if 0 in risuto:
    print(0)
else:
    for j in range(N):
        kari+=math.log10(risuto[j])

    if kari<18:
        for i in range(N):
            ans*=risuto[i]
        print(ans) 
    elif kari==18:
        for i in range(N):
            ans*=risuto[i]
        if ans>10**18:
            print(-1)
        else:
            print(ans)
    else:
        print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

    
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
L = sorted(list(map(int, input().split())), reverse=True)
ret = 1
if L[-1] == 0:
    print(0)
else:
    for i in L:
        ret *= i
        if ret > 10**18:
            ret = -1
            break
    print(ret)

Submission status: Accepted

Solution code:
#!/usr/bin/python

import sys
import math 

#Input Functions
#===============

input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

#===============

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

def main() :
	run_test()

if __name__ == '__main__' :
	main()

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    
    A.sort()
    x =1
    for i in A:
        x *= i
        if x==0:
            print(0)
            return
        if x > 10**18:
            print(-1)
            return
    print(x)
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

s = 1
for i in a:
    s = s*i
    s = min(s,10**18+1)
if s == 10**18+1:
    print('-1')
else:
    print(s)

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
from heapq import*;p=heappop;heapify(l)
while len(l)>1:heappush(l,p(l)*p(l))
print([l[0],-1][l[0]>10**18])

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
from heapq import*
p=heappop
heapify(l)
while len(l)>1: heappush(l,p(l)*p(l))
print([l[0],-1][l[0]>10**18])

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
from heapq import*;heapify(l)
while len(l)>1:heappush(l,heappop(l)*heappop(l))
print([l[0],-1][l[0]>10**18])

Submission status: Accepted

Solution code:
"""
pythonはオーバーフローしないが、桁数がデカい整数の計算をすると、計算が間に合わなくなる。
O（N^2)とかになる。

0のときは0を答えないとダメなので、0があったら0とするでよい。

"""


import sys

N = int(input())

An = [int(_) for _ in input().split()]
An.sort()

ans = 1

for val in An:
    # 0がきたらすぐに抜ける
    if(int(val) == 0):
        print(0)
        sys.exit()
    ans *= val
    # ansが10^18を超えた時点で-1にする
    if(ans > 10 **18):
        print(-1)
        sys.exit()

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

limit = 10**18

result = 1
for value in A:
    result *= value
    if result > limit:
        result = -1
        break

print(result)

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

MX = 10**18
n=ni()
a = sorted(nl())



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