Problem:


Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0



Sample input:
2
1000000000 1000000000


Sample output:
1000000000000000000

Submission status: Accepted

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


main()

Submission status: Accepted

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

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(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:
            break
    if ans > 10 ** 18:
        print(-1)
    else:
        print(ans)

Submission status: Accepted

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

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


ans=1
for i in A:
    ans*=i
    if ans>M:
        ans=-1
        break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
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:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a = 1
    m = 10**18
    A.sort()
    for i in A:
        a *= i
        if a > 10**18:
            return -1
        elif a == 0:
            return 0
    return a
print(main())

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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 = sys.stdin.readline

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

INF = 10**18

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
a = [int(item) for item in input().split()]
if 0 in a:
    print(0)
    exit()
ans = 1
for item in a:
    ans *= item
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

res = 1
n = ni()
a = nl()
a.sort()
for x in a:
    res *= x
    if res > 10**18:
        print(-1)
        exit()
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
if 0 in a:
	print(0)
	exit()
x=1
for y in a:
	x*=y
	if x>10**18:
		print(-1)
		exit()
print(x)

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 math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()
  l.sort()

  ans=l[0]
  for x in l[1:]:
    ans*=x

    if ans>10**18:
      return -1

  return ans

# main()
print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

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

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

print(result)

Submission status: Accepted

Solution code:
N = int(input())
A = tuple(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)
        break
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 18

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 *= A[i]
        if ans > INF:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
A = LIST()

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 = 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:
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62



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


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:
def examA():
    A, B = LI()
    ans = A*B
    print(ans)
    return

def examB():
    N = I()
    A = LI()
    for a in A:
        if a==0:
            print(0)
            return
    ans = 1
    for a in A:
        ans *= a
        if ans>10**18:
            print(-1)
            return
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<60
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

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

Submission status: Accepted

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

print(c)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    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)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

res = 1

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

    else:
        print(res)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    if 0 in A:
        print(0)
        return
    cur = 1
    for a in A:
        cur *= a
        if cur > 10**18:
            print(-1)
            return
    print(cur)

main()

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

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

    print(ans)
    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0 if 0 in A else 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()))

res = 1
if min(a) == 0:
    res = 0
for i in a:
    res *= i
    if res > 10 ** 18:
        res = -1
        break

print(res)

Submission status: Accepted

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

    a.sort()

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

if 0 in A:
	print(0)
	exit()
	
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 = sorted(list(map(int, input().split())))
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()))
A.sort()

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

Submission status: Accepted

Solution code:
th = 10**18

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

res = 1

for v in A:
    res *= v
    if res > th:
        print(-1)
        quit()
print(res)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    if 0 in A:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10 ** 18:
            print(-1)
            return
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    # print('YNEOS'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    MAX = 10 ** 18
    res = 1
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return

    for a in A:
        res *= a
        if res > MAX:
            print(-1)
            return
    print(res)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(m)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    if 0 in A:
        print(0)
        return 
    ans = 1
    for a in A:
        ans *= a
        if(ans > 10**18):
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
x = 1
for v in a:
    x = x * v
    if x > 1000000000000000000:
        x = 1000000000000000001
if x > 1000000000000000000:
    print(-1)
else:
    print(x)

Submission status: Accepted

Solution code:
N=int(input())
A=sorted([int(i) for i in input().split()])
ans=1
for i in range(N):
    ans=ans*A[i]
    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()))
A.sort()

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *                    # ll = deepcopy(l)
from heapq import *                    # heappush(hp,x)
from string import *                # alpha = ascii_lowercase
from random import *                # l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *                # bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin                # bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize                # minn = -maxsize
from operator import *                # d = sorted(d.items(), key=itemgetter(1))
from itertools import *                # pre = [0] + list(accumulate(l))
from collections import Counter        # d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	n = len(l)
	p = 1
	if(0 in l):
		return 0
	for i in l:
		p *= i
		if(p > 10**18):
			return -1
	return p
	

N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
print(ans)

Submission status: Accepted

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

import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]"):
    ret = 1
    A.sort()
    for a in A:
        ret *= a
        if ret > 10 ** 18:
            print(-1)
            return -1
    print(ret)
    return

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:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

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

if(A.index(0) >= 0):
    print(0)
    sys.exit(0)

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

print(prod)

Submission status: Runtime Error

Solution code:
dontt_use = input()
n = map(int,list(input().split()))
total = 1
for number in n:
    total = total * number
    if total > 10**18:
        print('-1')
        return
print(total)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=1
for i in[*open(0)][1].split():a*=int(i);a=[-1,a][-1<a<1e18]
print(a)1

Submission status: Runtime Error

Solution code:
input();l=input().split();x=1
for j in sorted(l):
  x:=x*int(j)if x>1e18or x<0else-1
print(x)

Submission status: Runtime Error

Solution code:
input();l=input().split();x=not'0'in l
for j in l:
  x=x*int(j)if x>1e18or x<0
print(x)

Submission status: Runtime Error

Solution code:
input();l=input().split();x=1
for j in sorted(l):x*=int(j)
  if x>1e18:x=-1;break
print(x)

Submission status: Runtime Error

Solution code:
input();l=input().split();x=not'0'in l
for j in l:
  x*=int(j);if x>1e18:x=-1;break
print(x)

Submission status: Runtime Error

Solution code:
i=input;i();l=i().split();x=1-('0'in l)
for j in l:
  x*=int(j);if x>1e18:x=-1;break
print(x)

Submission status: Runtime Error

Solution code:
a,b=open(0);print([x:=eval(b.replace(*' *')),-1][x>10**18or len(b)>=99])

Submission status: Runtime Error

Solution code:
i=input;i();l=i().split();x=1-('0'in l)
for j in l:
  x*=j-48
  if x>1e18:
    print(-1);quit()
print(x)

Submission status: Runtime Error

Solution code:
input();a=1
for i in input().split():a*=int(i);a=[-1,a][1=<a<=eval('1'+'0'*18)]
print(a)

Submission status: Runtime Error

Solution code:
a,b=open(0);c=1;
for i in range(int(a)):c*=int(b[2*i])
if c>10**18:print(-1);exit()
print(c)

Submission status: Runtime Error

Solution code:
a,b=open(0);print([x:=eval(b.replace(*' *')),-1][x>10**18])

Submission status: Runtime Error

Solution code:
def check() -> int:
    n = int(input())
    n_l = list(map(int, input().split()))
    VORDER = 10 ** 18
    ans = 1
    
    if 0 in n_l:
        ans = 0
        break
    else:
        for i in n_l:
            ans = i * ans
            if  ans > VORDER:
                ans = -1
                break
    return ans
if __name__ == '__main__':
    print(check())

Submission status: Runtime Error

Solution code:
N = int(input())
A = reversed(sorted(map(int, input().split())))
assert len(A) == N
mul = 1
for a in A:
  mul *= a
  if mul >= 10 ** 18:
    print(-1)
    break
else:
  print(mul)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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