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

Submission status: Accepted

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

ans = 1

for x in a:
    ans *= x
    if ans > 1000000000000000000:
        break

for x in a:
    if x == 0:
        ans = x

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

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

INF = 999999999999999999999999
MOD = 10**9+7

n,*A = get_all_int()

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

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import *


n = int(raw_input())
seq = map(int, raw_input().split())

total = 1

has_zero = False

for x in seq:
    if x == 0:
        has_zero = True


limit = int(10 ** 18)

if has_zero == True:
    print(0)
else:
    big = False
    for x in seq:
        total = total * x
        if total > limit:
            big = True
            break
    if big == True:
        print(-1)
    else:
        print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

total = 1
siki = 10**18
if al.count(0) >= 1:
  print(0)
else:
  for i in al:
    total *= i
    if total > siki:
      print(-1)
      break
  else:
    print(total)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

ans = 1
large = False
for i in nums:
    if i == 0:
        ans = 0
        large = False
    if not large:
        ans = ans * i
        if ans > 10 ** 18:
            large = True
    else:
        pass

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

Submission status: Accepted

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

n = int(input())
a_li = list(map(int, input().split()))
if 0 in a_li:
    print(0)
else:
    res = a_li[0]
    for x in a_li[1:]:
        res *= x
        if res > 10**18:
            print(-1)
            break
    else:
        print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
nums = [int(s) for s in input().split()]
nums.sort()
LIMIT = 10 ** 18

def multiply(nums):
    result = 1
    for num in nums:
        result *= num
        if result > LIMIT:
            print(-1)
            return
    print(result)

multiply(nums)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = input_int()
    a = input_to_int_tuple()

    a_sum = 1
    check = 10 ** 18
    if 0 in a:
        return 0

    for _a in a:
        a_sum *= _a
        if a_sum > check:
            return -1

    return a_sum


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

A = [int(x) for x in input().split(' ')]
res = 1
if 0 in A:
  res = 0
else:
  for a in A:
    res *= a
    if res > 1e18:
      res = -1
      break 

print(res)

Submission status: Accepted

Solution code:
import sys

# 整数1個だけ
N = int(input().strip())

# 別変数の整数複数個
A = [int(x) for x in input().strip().split(" ")]
if 0 in A:
    print(0)
    sys.exit(0)

m = 1
l = pow(10, 18)
for a in A:
    m *= a
    if m > l:
        print("-1")
        sys.exit(0)
print(m)

Submission status: Accepted

Solution code:
n=input()

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


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

num=1

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

print(num)

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
import numpy as np

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

b = np.array(a)
c = np.count_nonzero(b)
if len(b) != c:
    print(0)
    exit()
ans = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    for i in range(N):
        if A[i] == 0:
            print(0)
            sys.exit()
    count = 1
    for i in range(N):
        count *= A[i]
        if count > 10 ** 18:
            print(-1)
            sys.exit()
    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

res = 1
if 0 in A:
    print(0)
    exit()

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

Submission status: Accepted

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

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

    print(ans)

Submission status: Accepted

Solution code:
input()
a = [int(i) for i in input().split()]
 
res = 1
if 0 in a:
    res = 0
else:
    for i in a:
        res *= i
        if res > 10**18:
            res = -1
            break

print(res)

Submission status: Accepted

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

A.sort(reverse=True)

if A[N-1] == 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()))
flag = 0

ans = 1

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

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

Submission status: Accepted

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys, math,os
from io import BytesIO, IOBase
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7


def main():

    n=int(data())
    A=mdata()
    A.sort()
    ans=1
    l=10**18
    for i in A:
        ans*=i
        if ans>l:
            out(-1)
            exit()
    out(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 1
for x in arr:
    ans *= x

    if ans > int(1e18):
        ans = -1
        break

    if ans == 0:
        break

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
pro=1
flag=0
arr.sort()
for i in arr:
    pro *= i
    #print(pro)
    if pro > pow(10,18):
        print(-1)
        flag=1
        break
if flag==0:
    print(pro)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())						# 5
A = list( map(int, input().split()) )	# 1 2 3 4 5 ...

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

p108 = pow(10,18)
ans = A[0]
for a in A[1:]:
  ans *= a
  if ans > p108:
    print(-1)
    exit()

if ans > p108:
  print(-1)
  exit()

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque
inf = 10 ** 18
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
tmp = 1
for i in a:
    if i == 0:
        print(0)
        sys.exit()
for i in a:
    if i > inf:
        print(-1)
        sys.exit()
    tmp = tmp*i
    if tmp > inf:
        print(-1)
        sys.exit()
print(tmp)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
if a.count(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()))
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:
import sys

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

if As.count(0) > 0:
    print(0)
    sys.exit()

ans = 1
for A in As:
    ans *= A
    if ans > 10**18:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int,input().split())
# list(map(int,input().split()))
# [input() for _ in range(n)]

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

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

if 0 in a:
  ans = 0

print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())
li = list(map(int, input().split(" ")))

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

ans = li[0]
del li[0]

for i in li:
    ans *= i
    if ans > 1000000000000000000:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()
    a.sort()

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ls = [int(u) for u in input().split()]

ls.sort()
ans = 1

for i in ls:
    ans *= i;
    if ans>1000000000000000000:
        print(-1)
        exit(0)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int, readline().split()))
    a.sort()
    
    cur = 1
    for x in a:
        cur *= x
        if cur > 10 ** 18:
            print(-1)
            sys.exit()

    print(cur)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

if 0 in a_ls:
	ans=0

print(ans)


# 2darray [[0] * 4 for i in range(3)]

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))
n=n_in()
A=l_in()

res = 1

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


for a in A:
    res *= a


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

Submission status: Accepted

Solution code:
N = int(input())
arr = [int(x) for x in input().strip().split()]
ans = 1

if 0 in arr:
    ans = 0
else:
    for x in arr:
        ans *= x
        if ans > 1e18:
            ans = -1
            break

print(ans)

Submission status: Accepted

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

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

# output
print(ans)

Submission status: Accepted

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

lim = pow(10,18)

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    a.sort()
    ans = 1
    for ai in a:
        ans *= ai
        if ans > 10 ** 18:
            print(-1)
            return
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

ans = 1
if A.count(0) > 0:
    ans = 0
else:
    for n in range(N):
        ans *= A[n]
        if ans > 10**18:
            ans = -1
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
ans = 1
p = pow(10, 18)
list_A.sort()
for num in list_A:
    ans *= num
    if ans > p:
        ans = -1
        break

print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

inf=10**18
ans=1
if 0 in a:
    print(0)
    sys.exit()


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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
if 0 in a:
    print(0)
else:
    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
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=1
    if 0 in A:
        print(0)
        exit()
    for a in A:
        ans*=a
        if ans>10**18:
            print(-1)
            exit()
        
    print(ans)




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<29
lINF = 1<<35

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

def main():
    n = int(input())
    a = readInt()
    a.sort()
    if a[0]==0:
        print(0)
        return
    ans = a[0]
    for i in range(1,n):
        ans *= a[i]
        if ans>int(1e18):
            print(-1)
            return
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
ar=list(map(int,input().split()))
s=1
ex=1e18
z=1
for i in ar:
    s*=i
    if s>ex:
        z=0
        break
if ar.count(0)>0: print(0)
elif z: print(s)
else: print(-1)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *A = map(int, read().split())
    ans = 1
    lim = pow(10,18)
    
    try:
        zero = A.index(0)
        print(0)
        return
    except:
        pass
    
    for a in A:
        ans *= a
        if ans > lim:
            print(-1)
            return
            
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    result = 1
    if 0 in A:
        print(0)
        return
    for n in range(N):
        result *= A[n]
        if result > (10 ** 18):
            print('-1')
            return
    print(result)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    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]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
INF = 10 ** 18


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

    if 0 in A:
        ans = 0
    else:
        ans = 1
        for a in A:
            ans *= a
            if ans > INF:
                ans = -1
                break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque
import sys

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
li = list(map(int, input().split()))
li.sort()

ans = 1
for i in li:
    ans *= i
    if (ans > int(1e18)):
        print(-1)
        sys.exit(0)

if ans > int(1e18):
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
input = raw_input

n = int(input())
As = map(int, input().split(" "))

if 0 in As:
    out = 0
else:
    m = 10 ** 18 
    for i, a in enumerate(As):
        if a > m:
            out = -1
            break

        if i == 0:
            out = a
        else:
            out *= a

        if out > m:
            out = -1
            break

print(out)

Submission status: Accepted

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

###
# main
if(__name__ == '__main__'):
    # input
    n = int(input())
    a_list = list(map(int, input().split(" ")))
    a_list.sort()

    ans = 1

    for elem in a_list:
        ans *= elem
        if ans > 10**18:
            ans = -1
            break

    print(ans)

# else:
    # do nothing