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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
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)
        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()

INF = 10 ** 18 + 1
ans = 1
for e in a:
    ans *= e
    ans = min(ans, INF)

if ans == INF:
    ans = -1

print(ans)

Submission status: Accepted

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

ans=1
INF = pow(10,18)
if 0 in L:
    print(0)
    exit()
for l in L:
    ans*=l
    if ans>INF:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
INF = 10**18
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 > INF:
      ans = -1
      break
  
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = li()
ans = 1
for num in A:
    ans *= num
    if ans > 10**18:
        if 0 in A:
            print(0)
        else:
            print(-1)
        exit()

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().rstrip())

A = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

INF = 10 ** 19

answer = 1

for x in A:
	answer *= x
	if answer > INF:
		answer = INF

print(-1 if answer > (10 ** 18) else answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
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:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

ans = nums[0]
if 0 in nums:
	ans = 0
else:
	for x in nums[1:]:
		ans *= x
		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()))
    A.sort()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def main():
    n = int(input())
    A = list(map(int, input().split()))
    co = 10**18

    ans = 1

    if 0 in A:
        print(0)
        return

    for i_A in A:
        ans *= i_A
        if ans > co:
            print(-1)
            return
    
    print(ans)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(hoge) for hoge in input().split()]
if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        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=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()))
A = sorted(A)
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 bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, or_

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

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

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

def read_float():
    return float(input())

def read_float_n():
    return list(map(float, input().split()))

def read_str():
    return input().strip()

def read_str_n():
    return list(map(str, input().split()))

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



def main():
    n = read_int()
    a = read_int_n()
    a.sort()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
r = 1
f = False
for i in A:
    r *= i
    if r > 1000000000000000000:
        f = True
        break
if 0 in A:
    print(0)
elif f:
    print(-1)
else:
    print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
A = [int(i) for i in input().split()]
if 0 in A:
    print(0)
else:
    for i in range(n):
        ans *= A[i]
        if ans > 1e18:
            print(-1)
            exit()
    print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    n = int(sys.stdin.readline())
    N = list(map(int,sys.stdin.readline().split()))
    if 0 in N:
        print('0')
        return 0
    ans = 1
    for i in N:
        ans *= i
        if ans > 10**18:
            print('-1')
            return 0
    print(ans)
    return 0

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = eval(input())
A = [int(v) for v in input().strip().split(" ")]

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

    print(result)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, (input().split())))
A.sort()
ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        ans = -1
        break
    elif ans == 0:
        break
print(ans)

Submission status: Accepted

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

    print(curr_ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

def main(A):
    ans = 1
    if 0 in A:
        return 0
    for a in A:
        ans *= a
        if ans > 10**18:
            return -1
    return ans

print(main(A))

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
if min(a) == 0:
    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:
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    N = int(input())
    A = list(map(int, readline().split()))
    ans = 1
    if 0 in set(A):
        print(0)
        return
    for a in A:
        ans *= a
        if ans > pow(10,18):
            print(-1)
            return
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N = I()
    A = LI()
    ans = 1
    LIMIT = 10 ** 18

    if not all(A):
        print(0)
        return

    for i in range(N):
        ans *= A[i]
        if ans > LIMIT:
            print(-1)
            return

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
if 0 in arr:
  print(0)
else:
  for i in range(N):
    ans *= arr[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.sort()
MOD = 10**18
ans = 1
if a[0] == 0:
    print(0);exit()
for A in a:
    ans *= A
    if ans > MOD:
        print(-1);exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
n = int(input())
#a, b = map(int, sys.stdin.readline().split())
#n = input()
a = list(map(int, sys.stdin.readline().split()))

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
if 0 in A:
    print(0)
else:
    ans = 1
    for 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()))
ans = 1
if 0 not in a:
    for i in a:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
elif 0 in a:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
# Contest No.: ABC169
# Problem No.: B
# Solver:      JEMINI
# Date:        20200531

import sys
import heapq

def main():
    n = int(input())
    nums = list(map(int, sys.stdin.readline().split()))
    ans = 1
    for i in nums:
        if i == 0:
            ans = 0
            break
        if ans > 10 ** 18:
            continue
        ans *= i
    if ans > 10 ** 18:
        print(-1)
    else:
        print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])
ans=1
ok=True
for i in a:
    ans*=i
    if ans>10**18:
        ok=False
        break
if ok:
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

A.sort()
ans = 1
for a in A:
    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 = 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
flg = True
z_flg = False
for i in range(N):
    if A[i] == 0:
        z_flg = True

if z_flg:
    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())
A = list(map(int, input().split()))

def Main(N, A):
    if 0 in A:
        return 0
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            return -1
    return ans
    
res = Main(N, A)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(input())

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

ans = 1
MAX = 10**18

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

for x in A:
    ans *= x
    if ans > MAX:
        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 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()))
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:
        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()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a = list(map(int,input().split()))
a.sort()
max = 10**18
ans = 1
for i in range(len(a)):
    ans = 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()))

for a in A:
    if(a == 0):
        print(0)
        quit()

acc = 1
for a in A:
    acc *= a
    if acc > (1e18):
        print(-1)
        quit()

print(acc)

Submission status: Accepted

Solution code:
n = int(input())

ans = 1

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

for x in s:
    ans *= x
    if ans > int(1e18):
        break

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
for i in sorted(map(int, input().split())):
    ans *= i
    if ans>1e18:
        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)
else:
    ans = 1
    x = 10 ** 18
    for ai in a:
        ans *= ai
        if ans > x:
            print(-1)
            break
    else:
        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)
    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(' ')))
mul = 1
zero = False
for i in a:
  if i == 0:
    zero = True
    break
if zero:
  print(0)
else:
  early = False
  for i in a:
    mul *= i
    if mul > int(1e18):
      print(-1)
      early = True
      break
  if not early:
    print(mul)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    A = list(map(int, input().split()))
    lim = 10**18

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(a):
    max_val = pow(10, 18)
    result = 1
    if 0 in a:
        return 0
    for item in a:
        result *= item
        if result > max_val:
            return -1
    return result


if __name__ == "__main__":
    n = int_in()
    a = arr_in()
    out(solve(a))

Submission status: Accepted

Solution code:
b = 10**18
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 > b:
    ans = -1
    break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
result = 1
for i in A:
    result *= i
    if result > 10**18:
        if 0 in A:
            result = 0
        else:
            result = -1
        break
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 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()))
A.sort()

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

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    A=[int(_) for _ in 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)

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(K)

Submission status: Accepted

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

    if 0 in A:
        print(0)
        return

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
k = int(input())
ary = list(map(int, input().split()))
result=1
if ary.count(0)>0:
    print(0)
    exit()
for i in ary:
    result*=i
    if result > 1000000000000000000:
        print(-1)
        exit()
print(result)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in A:
    if i == 0:
        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:
import sys

sys.setrecursionlimit(10**7)

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    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:
import sys
sys.setrecursionlimit(10000000)
import numpy as np
from heapq import heapify, heappop, heappush
import copy
from math import gcd, ceil
from collections import deque
# queueとして使う場合 push, popleftを使う
from bisect import bisect_left, bisect_right
# bisect_left: 配列の順序関係が崩れない条件で挿入することができる一番左の点
# bisect_right: 配列の順序関係が崩れない条件で挿入することができる一番右の点
# A = [1, 1, 1, 2, 2, 2, 4]
# print(bisect_left(A, 2))  # 3
# print(bisect_right(A, 2))  # 6
# print(bisect_left(A, 3))  # 6
# print(bisect_right(A, 3))  # 6


def main():
    N = int(input())
    A = [int(c) for c in input().split()]
    count = 1
    for i in range(len(A)):
        count *= A[i]
        if count > 10 ** 18:
            count = 10 ** 18 + 1
    if count > 10 ** 18:
        print(-1)
        sys.exit()
    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve () :
    n = int(input())
    arr = list(map(int, input().split(" ")))
    arr.sort()
    limit = 1e18
    if arr[0] == 0 :
        return 0
    else :
        cur = 1
        for a in arr :
            cur*=a 
            if cur >limit :
                return -1
    return cur 
    
print(solve())

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in 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:

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

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

res = 1
for a in A_list:
    res *= a

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

print(res)