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

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
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()

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):
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()  

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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):



from math import *
from copy import *                    
from heapq import *                    
from string import *                
from random import *                
from bisect import *                
from sys import stdin                
from sys import maxsize                
from operator import *                
from itertools import *                
from collections import Counter        
from collections import defaultdict 

'''

'''

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)

Solution (Python):


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))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):
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


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)

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
ans = 1
if 0 in lis:
  print(0)
  exit()
for num in lis:
  ans *= num
  if ans > 10 ** 18:
    print(-1)
    exit()
print(ans)