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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

al = sorted(al)

ans = 1

ok = 1

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

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    if 0 in a:
        print(0)
        return
    ans = 1
    for i in a:
        ans *= i
        if ans > 10**18:
            print(-1)
            return
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())

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

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

d = 1
for x in A:
    d *= x
    if d > 1000000000000000000:
        print(-1)
        exit()

print(d)

Submission status: Accepted

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

    MAX = 10 ** 18
    for a in A:
        res *= a
        if res > MAX:
            return -1
    return res


print(main())

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

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

Submission status: Accepted

Solution code:
import sys
N = int(input())

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

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


for i in a:
    ans *= i

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

print (ans)

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, 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:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))
MAX = 10**18

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

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().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")
            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 i in a:
    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())))

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

Submission status: Accepted

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

Submission status: Accepted

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

base = 1
flag = True
for i in range(n):
    base *= arr[i]
    if base > 10**18:
        flag = False
        break

if flag:
    print(base)
else:
    if 0 in arr:
        print(0)
    else:
        print(-1)

Submission status: Accepted

Solution code:
n=int(input())
alist = list(map(int, input().split()))
alist=sorted(alist)
answer=1
ng=0
for i in range(n):
    if ng==0:
        answer*=alist[i]
        if answer>10**18:
            ng=1

if ng==1:
    print(-1)
else:
    print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
ans = 1
if 0 in Alist:
    print(0)
    exit()
for a in Alist:
    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 num in a:
    if num==0:
        print(0)
        exit()

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_n) for _n in input().split()]
A.sort(reverse=True)
if 0 in A:
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
def main():

    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A: return 0
    A.sort()
    u = 1
    bound = pow(10, 18)
    for v in A:
        u *= v
        if u > bound:
            return -1
    return u

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

Submission status: Accepted

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

max_val = 10 ** 18

val = 1

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

for item in a:
    val *= item
    if val > max_val:
        print(-1)
        exit()

print(val)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

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

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

    print(ans)

Submission status: Accepted

Solution code:
N=int(input())
m=10**18
A=sorted(list(map(int,input().split())))
ans=1
for a in A:
    ans*=a

    if ans>m:
        print('-1')
        exit(0)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
from collections import defaultdict

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

def solve():
    n, = input_ints()
    a = input_ints()
    ans = 1
    for x in a:
        ans = (ans * x)
        ans = min(10 ** 18 + 1, ans)
    if ans > 10 ** 18:
        ans = -1
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

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

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

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    current = 1
    MAX = 10**18
    if 0 in A:
        print(0)
        exit()
    for a in A:
        current*=a
        if current > MAX:
            print(-1)
            exit()
    print(current)
    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:
import sys
import math
import itertools
n = int(input())
a = list(map(int, input().split()))
MAX=10**18
ans = 1
if 0 in a:
    print(0)
    sys.exit()
for i in a:
    ans *= i
    if (ans > MAX):
        print(-1)
        sys.exit()
print(ans)

Submission status: Accepted

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

ans = 1
for i in range(len(aa)):
    if aa[i] == 0:
        ans = 0
        break

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

print(ans)

Submission status: Accepted

Solution code:
N, *X = map(int, open(0).read().split())
X.sort()
ans = 1
for v in X:
    ans *= v
    if ans > 10 ** 18:
        ans = -1
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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


def solve(N, K, A):
    tmp = K
    ret = 0
    for a in A:
        # print(a, tmp)
        if a != tmp:
            tmp = K

        if a == tmp:
            tmp -= 1

        if tmp == 0:
            ret += 1
            tmp = K
    return ret


def main():

    N = int(input())
    A = inpl()
    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)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = A.pop(0)
for i in range(len(A)):
    a=a*A[i]
    if a>mod:
        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 a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import math
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    a=LIST()
    ans=1
    a=sorted(a)
    for i in a:
        ans*=i
        if ans>10**18:
            ans=-1
            break
    print(ans)
if __name__ == '__main__':
    do()

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from itertools import accumulate
def main():
    t = 10**18
    n = int(input())
    A=[int(i) for i in input().split()]
    A.sort()
    tmp = 1
    for i in A:
        tmp*=i
        if tmp>t:
            print(-1)
            exit()

    print(tmp)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    f = False
    for v in a:
        if v == 0:
            f = True
    if f:
        print(0)
    else:
        ans = 1
        for v in a:
            ans *= v
            if ans > 10**18:
                break
        if ans <= 10**18:
            print(ans)
        else:
            print(-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

A = tuple(map(int,input().split()))
if 0 in A:
    print(0)
else:
    p = 1
    for a in A:
        p *= a
        if p > 10**18:
            p = -1
            break

    print(p)

Submission status: Accepted

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

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

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

print(total)

Submission status: Accepted

Solution code:
# coding: utf-8
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:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    a = list(map(int, input().split()))
    for i in a:
        if i == 0:
            print(0)
            return

    s = 1
    for i in a:
        s *= i
        if s > int(1e18):
            print(-1)
            return
    print(s)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

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

Submission status: Accepted

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

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
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


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

INF = 2**62-1


def read_int():
    return int(buff_readline())


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


def read_float():
    return float(buff_readline())


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


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


def read_str_n():
    return readline().strip().split()

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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 1
    l = 10**18
    A.sort()
    for a in A:
        ans *= a
        if ans > l:
            return -1
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
n = int(input())

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

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

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:
N = int(input())
a = list(map(int,input().split()))

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

print(base)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
ans=1
c=a.count(0)
if c>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:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    if 0 in A: print(0)
    else:
        ans = 1
        for i, a in enumerate(A):
            ans *= a
            if ans > 10 ** 18:
                print(-1)
                break
        else:
            print(ans)
        

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul

mod = 10 ** 9 + 7
INF = 10 ** 13
sys.setrecursionlimit(2147483647)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n = I()
A = LI()
ret = 1
for i in range(n):
    if A[i] == 0:
        print(0)
        exit()

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

print(ret)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

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:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    MAX = int(1e18)
    ans = 1
    for a in A:
        ans *= a
        if ans > MAX:
            print(-1)
            return
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()

A.sort()

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

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

Submission status: Accepted

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

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n = readint()
a = readints()
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:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

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

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(n):
    ans *= a[i]
    if ans > MAX:
        ans = -1
        break

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a =list(map(int,input().split()))
    ans = 1
    tmp = 10 ** 18
    a.sort()
    for i, aa in enumerate(a):
        ans *= aa
        if ans > tmp:
            print(-1)
            return
    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)
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:
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    exit()
limit = 10 ** 18
res = 1
for a in A:
    res *= a
    if res > limit:
        print(-1)
        break
else:
    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:
        ans = -1
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
for i in a:
    ans *= i
    if ans > pow(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]"):
    tmp = 1
    th = 10 ** 18
    if 0 in A:
        return 0
    for a in A:
        tmp *= a
        if tmp > th:
            return -1
    return tmp


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))

INF = 10**18
if 0 in lst1:
    print(0)
    exit()
ans = 1
for i in range(n):
    ans *= lst1[i]
    if ans > INF:
        print(-1)
        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 :
  ret = 1
  for i in range(N) :
    ret *= A[i]
    if ret > 10 ** 18 :
      print(-1)
      break
  else :
    print(ret)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 1
    for ai in a:
        ans *= ai
        if ans > 10 ** 18:
            print(-1)
            exit()
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


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

    if 0 in As:
        return 0

    ans = 1
    for a in As:
        ans *= a
        if ans > 10 ** 18:
            return -1

    return ans


def main():
    print(solve())


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

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