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: Runtime Error

Solution code:

import numpy 

list1 = [] 
  
# number of elemetns as input 
n = int(input()) 
  
# iterating till the range 
for i in range(0, n): 
    ele = int(input()) 
  
    list1.append(ele) 
    result1 = numpy.prod(list1)
    if(result1>1000000000000000000):
        print("-1")
    else:
        print(result1)

Submission status: Runtime Error

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

tar = 1
for i in range(A):
    tar *= i

if tar > 10 ** 18:
    print(-1)
else:
    print(tar)

Submission status: Runtime Error

Solution code:
n=int(input())
list_a=list(map(int,input().split()))
from functools import reduce
print(reduce(lambda x,y :x*y,list_a)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce
n = int(input())
a = list(map(int,input().split()))

if 0 in a:
	print(0)
else:
	M = 10**18
	ans = reduce(mul, a)
	if ans > M:
		print(-1)
		break
	else:
		print(ans)

Submission status: Runtime Error

Solution code:
n = input()
li = list(map(int, input().split()))
a = 1
for x in li:
    a *= x
if a > 10**18:
    print(-1)
elif n > 10**5:
    print(-1)
else:
    print(a)

Submission status: Runtime Error

Solution code:
n = int(input())

sum = 0
i = 0

for i in range(n):
  x = int(input())
  sum *= x
  i += 1
  
  if sum > 10 ** 18:
    print(-1)
    break
  
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

tar = 1
for i in range(A):
    tar *=  i

if tar > 10 ** 18:
    print(-1)
else:
    print(tar)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
value = 1

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

if 0 in A:
  print(0)
else:
  for a in A:
    if np.log10(value * a) > 18:
      value = -1
      break
    else:
      value *= a
  print(value)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = 1
for i in a
  x =*i
  if x > 1000000000000000000
    x = 0
    break
print(x)

Submission status: Runtime Error

Solution code:
import sys
N=int(input())
A=[]
pai=int(1)
hantei=int(0)
A=list(map(int,input().split()))
for i in range(N):
    if A[i]==o:
        print("0")
        sys.exit()
for i in range(N):
    pai=pai*A[i]
    if pai>10**18:
        print("-1")
        hantei=int(1)
        break
if hantei==0:
    print(pai)

Submission status: Runtime Error

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

import numpy as np
arrayA = np.array(A)
p = np.prod(arrayA)

if 0 in A:
  print(0)
else:
  if result > 10**18:
    print(-1)
  else:
    print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from operator import mul

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

print reduce(mul, a[:n])

Submission status: Runtime Error

Solution code:
n = int(inut())
x = [input() for i in range(n)]

ans = 1
for i in x:
  ans = ans*i
  
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}


signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;
  sort(begin(a),end(a));

  __int128_t res = 1;
  __int128_t limit = 1e18;
  rep(i,n){
    if(a[i]==0){
      cout<<0<<endl;
      return 0;
    }
    res *= a[i];
    if(res>limit){
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<(res)<<endl;

}

Submission status: Runtime Error

Solution code:
n = int(input())
ans =int(1)
p = int(0)
p = pow(10,18)
for i in range(0,n):
	print("hello")
	z = int(input())
	if ans!=-1:
		ans = ans*z
	if ans>p:
		ans=-1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
ans=1
for i in range(n):
  a = int(input())
  ans=ans*a
  if ans>1000000000000000000:
    ans=-1
    break
print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(int,input().split()))
B  = [math.log10(x) for x in A]

ans = 1
if sum(B) > 18:
    ans = -1
else:
    for a in A:
        ans *= a

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

Submission status: Runtime Error

Solution code:
a = input()
b = 1
for i in range(1, n):
  c = input()
  b *= c
print(b)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

N = int(input())
A = list(map(int, input().split()))
S = reduce(mul, A)
if A > 10 ** 18:
    print("-1")
else:
    print(S)

Submission status: Runtime Error

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


for i in range(N):
 if(i == 0): ans = A[i]
 else: ans = ans*A[i]
  
ans = '{:.19g}'.format(ans)  
if(ans[1] == 'e'):
  print('-1')
else:
  print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    import numpy as np
    ans = np.prod(list)
    print(ans if ans <= 10**18 else "-1")
resolve()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())),dtype=np.int64)


A = np.array(list(map(int, input().split())),dtype=np.int64)
ans = np.prod(A)
if ans > 10**18:
    print(-1)
elif ans< 0:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
a = input()
b = [int(i) for i in input().split()]
all = 0

for x in b:
  all = all * x
  if all > 10**18:
    all = -1
  	break

print(all)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

vector<long long> vi;

int main(){
    long long sum=1;
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        long long a;
        scanf("%lld",&a);
        vi.push_back(a);
    }
    sort(vi.begin(),vi.end());
    for(int i=0;i<n;i++){
        sum*=vi[i];
        if(sum>pow(10,18)||sum<0){
            sum=-1;
            break;
        }
    }
    printf("%lld",sum);
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
str_list = input().split()

list = [int(k) for k in str_list]

list.sort(reverse=True)

result = 1

if(0 in list):
  print('0')
  return

for i in range(n):
  result = result * list[i]
  if(result >= 1000000000000000000):
    print('-1')
    return

print(result)

Submission status: Runtime Error

Solution code:
import numpy

N = int(input())
A = int(input().split())

B = numpy.prod(A)

if B >= 10**8:
  print(-1)
else:
  print(B)

Submission status: Runtime Error

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

if a[0] == 0:
  print(0)
else:
  ans = 1
  for i in a_list:
    ans *= i
    if i > 10**18:
      ans = -1
      break
  print(ans)

Submission status: Runtime Error

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

if '0' in a:
    s = 0
else:
    for i in range(n):
        s = s * a[i]
    if s > 10 ** 18:
        s = -1
        break
print(s)

Submission status: Runtime Error

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

n=1
for i in  list
    n*=n*list[i]

if(n>1000000000000000000):
    print("-1")
else:
    print(n)

Submission status: Runtime Error

Solution code:
n = int(input())

sum = 0
i = 0

for i in range(n):
  x = int(input())
  sum *= x
  i += 1
  
  if sum > 10 ** 18:
  	print(-1)
  	break
  
print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())
sum = 1
Max = 1000000000000000000
while n:
  sum*=int(input())
  if sum>Max:
    break
  n-=1
if sum<=Max:
  print("%d" % sum)
else :
  print("%d" % -1)

Submission status: Runtime Error

Solution code:
a=1
n=input()

s=input()
for i in range(len(s)):
  if i%2==1:
    continue
  a*=int(s[i])
if a>10**18:
  print(-1)
else:
  print(a)

Submission status: Runtime Error

Solution code:
n=int(input())
mul=1
limit=1000000000000000000
for i in range (n):
  x=int(input())
  mul*=x
if(mul>limit):
  print(-1)
else:
  print(mul)

Submission status: Runtime Error

Solution code:
n = int(raw_input())
A = [int(x) for x in raw_input().split()]
prod = 1
for i in range(n):
  prod *= A[i]
if prod <= 10 ** 18:
  print(prod)
else:
  print(-1)

Submission status: Runtime Error

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

if 10**18 < total:
    print("-1")
else:

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in N:
  Seki = Seki * A

if A > 10**18:
  print(-1)
else:
  print(Seki)

Submission status: Runtime Error

Solution code:
A = int(input())
hoge=list(map(int, input().split()))
  
sum=1
for i in range(A):
  sum = sum*hoge[i]

if sum　> 10**18:
  print(-1)
else:
  print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = input().split()
res = 1
if N > 2 and N < 10**5:
    for x in A:
        if int(x) < 10**8:
            res*= int(x)
        else:
            res = -1
            break
    if res > 10**18:
        res = -1
        break
else:
    res = -1

print(res)

Submission status: Runtime Error

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

a.sort()
ans = 1
above = False
for x in a:
	ans *= x
	if ans > 10**18:
		above = True
		break

if not above:
	print(ans)
else:
	print(-1)

Submission status: Runtime Error

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

ans = 1

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

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

j = 100000000000000000

ans = 1

for i in range(n):
    ans *= An[i]

if ans <= s:
    print(ans)
else :
    print('-1')

Submission status: Runtime Error

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

ans = a[0]*a[1]

for i in range(len(a)-2):
  ans *= a[i+2]
if ans > 1e18:
  print(-1)
else:
  print(ans)
提出情報

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(0, N):
    A.append(int(input()))
result = 1
for x in A:
    result = result*x
print(-1 if result>=10**18 else result)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
input = stdin.readline
N = int(input())
A = list(map(int,input().split()))
np_A = np.array(A)
ans = np_A[0]

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


if flag == False:
    print(-1)

else:
    print(ans)

Submission status: Runtime Error

Solution code:
n,m,c=map(int,input().split())
bli = [int(i) for i in input().split()]
ans=0
for i in range(n):
	a = [int(j) for j in input().split()]
	sum=0
	for k in range(m):
		sum += a[k]*bli[k]
	if sum + c > 0:
		ans += 1

print(ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
m = 10**18

res = reduce(lambda x,y: x*y, a)
res = 1
for n in a:
    res *= a
    if res > m:
        print(-1)
        exit()
    
print(res)

Submission status: Runtime Error

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

if a[0] == 0:
  print(0)
else:
  ans = 1
  for i in a_list:
    ans *= i
    if i > 10**18:
      ans = -1
      break
  print(ans)

Submission status: Runtime Error

Solution code:
def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    reduce(lamda x, y: x * y, (list))
    from operator import mul
    ans = reduce(mul, (list))
    print(ans if ans <= 10**18 else "-1")
resolve()

Submission status: Runtime Error

Solution code:
N = int(input())
A = input().split(" ")
K = 1

for i in A:
    K *= int(i)
    if K > 10**18:
        print(-1)
        break
if K =< 10**18:
    print(K)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
from operator import mul
from functools import reduce

t = 10**18

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

re = reduce(mul,li)

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

Submission status: Runtime Error

Solution code:
n = int(inut())
x = [input() for i in range(n)]

ans = 1
for i in x:
  ans*i
  
print(ans)

Submission status: Runtime Error

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

for i in range(N):
    if sum <= 10**18:
        sum = sum * A[i]
    else:
        break:

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

Submission status: Runtime Error

Solution code:
 = int(input())
a = list(map(int, input().split()))
MAX = 10**18

ret = 1
for i in range(n):
	if(ret <= MAX):
		ret = ret*a[i]
	if(a[i] == 0):
		ret = 0
		break


if(ret > 10**18):
	print(-1)
else:
	print(ret)

Submission status: Runtime Error

Solution code:
N = input()
a_list = [a for a in input().split()]
ans = 1
for n in a_list:
    ans *=n
if ans < 10**18:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import sys

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

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

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

else : print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

str_list = list(input().split())

ans = np.prod(str_list)

print(ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import collections
import numpy

def main():
    max_n = 10**18
    n = int(input())
    a = input_list()
    if 0 in a:
        print(0)
        exit()

    ans = numpy.prod(a)
    if ans > max_n:
        print(-1)
    else:
        print(int(ans))

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
arr = []

z=False
for x in input().split(' '):
    if x == 0:
        z = True
    arr.append(x)
if z == True:
    print(0)

else:
    ans = 1
    for x in arr:
        ans *= x
        if ans > int(1e18):
            print(-1)
    else:
        print(ans)

Submission status: Runtime Error

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

ans = l_a[0]
if(0 in l_a):
    ans = 0
else:
    for i in range(n-1):
        ans = l_a[i+1] * ans
if(ans > 10**18):
    print(-1)
else:
    print(ans)
~

Submission status: Runtime Error

Solution code:
N = int(input())
Alist = []
p = 1
flag = True
for i in range(N):
    Alist.append(int(input()))

for i in Alist:
    p *= i
    if p >= 10**18:
        flag = False
        break
    else:
        continue
    
if flag:
    print(p)
else:
    print("-1")

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
res = np.prod(a)
if res > (10**18):
    print(-1)
else:
    print(res)

Submission status: Runtime Error

Solution code:
n = int(input())

sum = 0
i = 0

for i in range(n):
  x = int(input())
  sum *= x
  i += 1
  
  if sum > 10 ** 18:
  print(-1)
  break
  
print(sum)

Submission status: Runtime Error

Solution code:
N = input()
nums = [int(e) for e in input().split()]
ret = 1
for i in nums:
    ret = ret * i
        break
if ret > 1e18:
    ret = -1
print(ret)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = input().split()
m = 1
k = a.index(“B”)
if k == 0:
    print("0")
else:
    for i in range(n):
        m = m * int(a[i])
        if m > 10**18:
        break
    if m > 10**18:
        print("-1")
    else:
        print(m)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(raw_input()) 

arr = [int(x) for x in raw_input().split()] 
  
ans = 1

for x in arr: 
    ans*=x
    
    if ans>1000000000000000000:
       ans = -1
    
    if ans!=-1:
        ans*=x
      
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

__int128 mul = 1;

int n;
long long a[100010];

__int128 read() {
	__int128 x = 0;
	int ch, f;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return f ? -x : x;
}

void write(__int128 x) {
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) write(x / 10);
	putchar(x % 10 + '0');
}

int main() {
	n = read();
	for(int i = 1; i <= n; ++i) {
		a[i] = read();
		mul *= a[i];
	}
	if(mul > 1e18) puts("-1");
	else write(mul);
	return 0;
}

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

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

if ans :
    for i in range(n):
        ans = ans * a[i];
        if ans > 1000000000000000000 :
            ans = -1
            break
        
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())
sum = 1
for x in a:
  sum *= a
  if sum > 1e18:
    sum = -1
    break
print(sum)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main() {
    int N;
    cin >> N;
    long long k;
    long long ans = 1;
    for (int i = 0; i<N; i++ ){
        cin >>k;
        // cout << i << endl;
        ans *= k;
    } 
    if(ans > pow(10,18)){
        cout << -1;
    }else{
        cout << ans;
    }

    return 0;
}

Submission status: Runtime Error

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

list.sort(reverse=True)

result = 1

if(0 in list):
  print('0')
  return

for i in range(n):
  result = result * list[i]
  if(result >= 1000000000000000000):
    print('-1')
    return

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
arr = []
for _ in range(n):
    arr.append(int(input())   
val =1
x=-1

for i in arr:
    val = val*i

if val>1000000000000000000:
    print(x)
else :
    print(val)

Submission status: Runtime Error

Solution code:
n = int(input())
sum = 1
Max = 1000000000000000000
while n:
  sum*=int(input())
  n--
if sum<=Max:
  print("%d" % sum)
else :
  print("%d" % -1)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}

ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}

int main(){
    ll n;
    cin >> n;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans=1;
    for (ll i=0;i<n;i++){
        ans*=a[i];
        if (ans>1000000000000000000){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

struct expand_type {
    template <typename... T>
    expand_type (T&&...) {}
};
template <typename... ArgTypes>
void print (ArgTypes... args) {
    expand_type {0, (cerr << args << ", ", 0)...};
    cerr << "\b\b \n";
}
#define printv(x) cerr << "["; for(auto i : (x)) cerr << i << ", "; cerr << "\b\b]\n";
#define __lcm(a,b) a * b / __gcd(a, b)

typedef unsigned long long ull;
typedef long double ld;


ull m = (ull)1e18;

int main () {
    std::ios::sync_with_stdio (false);
    cin.tie (nullptr);
    cout.tie (nullptr);
    int n;
    cin >> n;
    ull p = 1;
    bool f = true;
    for (int i = 0; i < n; i++) {
        ull in;
        cin >> in;
        if ((ull)(m / p) < in) {
            f = false;
            p = 0;
        } else {
            p *= in;
        }
    }
    if (f) {
        cout << p << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Submission status: Runtime Error

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

ans=1

for i in a:
  ans*=i


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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import prod
n = int(input())
arr = list(map(int,input().split()))
a = prod(arr)
if a > 10**18:
  print(-1)
else:
  print(a)

Submission status: Runtime Error

Solution code:
def resolve():
    from operator import add
    N = int(input())
    list = list(map(int, input().split()))
    ans = reduce(add, (list))
    print(ans if ans <= 10**18 else "-1")
resolve()

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
nums = list(map(int, input().split(' ')))

output = 1

if 0 in nums:
  print(0)
  
else:
  for x in nums:
    output *= x

    if output > 10**18
      print('-1')
      sys.exit()

  print(output)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

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

if ANS>10**18:
    print(-1)
else:
    print(ANS)

Submission status: Runtime Error

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

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