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:
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <tuple>

//....................................................................................................................//

using std::cin;
using std::cout;
using std::vector;
using std::list;
using std::unordered_set;
using std::set;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::swap;
using std::stack;
using std::deque;
using std::queue;
using std::ios_base;
using std::ifstream;
using std::ofstream;
using std::string;
using std::tuple;
using std::make_tuple;
using std::get;
using std::upper_bound;
using std::lower_bound;
using std::max_element;
using std::min_element;
using std::multiset;
using std::greater;
using std::priority_queue;
using std::less;

//....................................................................................................................//

typedef long long ll;
typedef unsigned long long ull;

[[maybe_unused]] const string endl = "\n";
[[maybe_unused]] const string sep = " ";
[[maybe_unused]] const string yes = "YES\n";
[[maybe_unused]] const string no = "NO\n";
[[maybe_unused]] const string ng = "NG\n";
[[maybe_unused]] const string ok = "OK\n";
[[maybe_unused]] const double pi = acos(-1);
[[maybe_unused]] const ull modular = 1e9 + 7;

//....................................................................................................................//

template<class T>
T min(const T &a, const T &b, const T &c) {
    return min(a, min(b, c));
}

template<class T>
T max(const T &a, const T &b, const T &c) {
    return max(a, max(b, c));
}

typedef vector<vector<ll>> graph;

vector<ll> lca_h, lca_dfs_list, lca_first, lca_tree;
vector<char> lca_dfs_used;

void lca_dfs(const graph &g, ll v, ll h = 1) {
    lca_dfs_used[v] = true;
    lca_h[v] = h;
    lca_dfs_list.push_back(v);
    for (auto i = g[v].begin(); i != g[v].end(); ++i)
        if (!lca_dfs_used[*i]) {
            lca_dfs(g, *i, h + 1);
            lca_dfs_list.push_back(v);
        }
}

void lca_build_tree(ll i, ll l, ll r) {
    if (l == r)
        lca_tree[i] = lca_dfs_list[l];
    else {
        ll m = (l + r) >> 1;
        lca_build_tree(i + i, l, m);
        lca_build_tree(i + i + 1, m + 1, r);
        if (lca_h[lca_tree[i + i]] < lca_h[lca_tree[i + i + 1]])
            lca_tree[i] = lca_tree[i + i];
        else
            lca_tree[i] = lca_tree[i + i + 1];
    }
}

void lca_prepare(const graph &g, ll root) {
    ll n = (ll) g.size();
    lca_h.resize(n);
    lca_dfs_list.reserve(n * 2);
    lca_dfs_used.assign(n, 0);

    lca_dfs(g, root);

    ll m = (ll) lca_dfs_list.size();
    lca_tree.assign(lca_dfs_list.size() * 4 + 1, -1);
    lca_build_tree(1, 0, m - 1);

    lca_first.assign(n, -1);
    for (ll i = 0; i < m; ++i) {
        ll v = lca_dfs_list[i];
        if (lca_first[v] == -1)
            lca_first[v] = i;
    }
}

ll lca_tree_min(ll i, ll sl, ll sr, ll l, ll r) {
    if (sl == l && sr == r)
        return lca_tree[i];
    ll sm = (sl + sr) >> 1;
    if (r <= sm)
        return lca_tree_min(i + i, sl, sm, l, r);
    if (l > sm)
        return lca_tree_min(i + i + 1, sm + 1, sr, l, r);
    ll ans1 = lca_tree_min(i + i, sl, sm, l, sm);
    ll ans2 = lca_tree_min(i + i + 1, sm + 1, sr, sm + 1, r);
    return lca_h[ans1] < lca_h[ans2] ? ans1 : ans2;
}

ll lca(ll a, ll b) {
    ll left = lca_first[a],
            right = lca_first[b];
    if (left > right) swap(left, right);
    return lca_tree_min(1, 0, (ll) lca_dfs_list.size() - 1, left, right);
}


ll gcd(ll a, ll b) {
    if (a == 0) {
        return b;
    }
    return gcd(b % a, a);
}

ll fast_power(ll a, ll pow) {
    if (pow == 0) {
        return 1;
    }
    if (pow % 2 == 0) {
        auto x = fast_power(a, pow / 2);
        return (x * x);
    } else {
        auto x = fast_power(a, pow - 1);
        return (a * x);
    }
}

ll fast_power(ll a, ll pow, ll mod) {
    if (pow == 0) {
        return 1;
    }
    if (pow % 2 == 0) {
        auto x = fast_power(a, pow / 2, mod);
        return (x * x) % mod;
    } else {
        auto x = fast_power(a, pow - 1, mod);
        return (a * x) % mod;
    }

}

void getFactorialsModular(const ll n, const ll mod, vector<ll> &F) {
    F.resize(n + 1);
    F[0] = 1;
    for (ll i = 1; i <= n; ++i) {
        F[i] = (F[i - 1] * i) % mod;
    }
}

void getFactorialsAndInverseModular(const ll n, const ll mod, vector<ll> &F, vector<ll> &I) {
    getFactorialsModular(n, mod, F);
    I.resize(n + 1);
    I[0] = 1;
    for (ll i = 1; i <= n; ++i) {
        I[i] = fast_power(F[i], mod - 2, mod);
    }
}

ll CnkMod(ll n, ll k, ll mod, vector<ll> &F, vector<ll> &I) {
    return (((F[n] * I[k]) % mod) * I[n - k]) % mod;
}

ll CnkWithRepetitionMod(ll n, ll k, ll mod, vector<ll> &F, vector<ll> &I) {
    return CnkMod(n + k - 1, k - 1, mod, F, I);
}

/*
MIT License
Copyright (c) 2019 ouuan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

// for further information and bug tracking,
// please visit https://github.com/ouuan/segmentTree


template<typename valueType, typename tagType>
class segmentTreeNode {
public:
    int id, left, right;
    valueType val;
    tagType tag;
};

template<typename valueType,
        typename tagType,
        valueType (*merge)(valueType, valueType),
        void (*update)(segmentTreeNode<valueType, tagType> &, tagType)>
class segmentTree {
private:
    std::vector<segmentTreeNode<valueType, tagType> > nodes;
    int leftRange, rightRange;
    valueType valueZero;
    tagType tagZero;

    void push_up(int cur) {
        nodes[cur].val = merge(nodes[cur << 1].val, nodes[cur << 1 | 1].val);
    }

    void push_down(int cur) {
        update(nodes[cur << 1], nodes[cur].tag);
        update(nodes[cur << 1 | 1], nodes[cur].tag);
        nodes[cur].tag = tagZero;
    }

    void build(int cur, int l, int r, const std::vector<valueType> &initValue) {
        nodes[cur].id = cur;
        nodes[cur].left = l;
        nodes[cur].right = r;
        nodes[cur].tag = tagZero;
        if (l == r - 1) nodes[cur].val = initValue[l - leftRange];
        else {
            build(cur << 1, l, (l + r) >> 1, initValue);
            build(cur << 1 | 1, (l + r) >> 1, r, initValue);
            push_up(cur);
        }
    }

    void init(const std::vector<valueType> &_initValue,
              const valueType &_valueZero,
              const tagType &_tagZero) {
        valueZero = _valueZero;
        tagZero = _tagZero;
        nodes.resize((rightRange - leftRange) << 2);
        build(1, leftRange, rightRange, _initValue);
    }

    void modify(int cur, int l, int r, int L, int R, const tagType &tag) {
        if (l >= R || r <= L) return;
        if (L <= l && r <= R) update(nodes[cur], tag);
        else {
            push_down(cur);
            modify(cur << 1, l, (l + r) >> 1, L, R, tag);
            modify(cur << 1 | 1, (l + r) >> 1, r, L, R, tag);
            push_up(cur);
        }
    }

    valueType query(int cur, int l, int r, int L, int R) {
        if (l >= R || r <= L) return valueZero;
        if (L <= l && r <= R) return nodes[cur].val;
        push_down(cur);
        return merge(query(cur << 1, l, (l + r) >> 1, L, R),
                     query(cur << 1 | 1, (l + r) >> 1, r, L, R));
    }

public:
    segmentTree() {}

    segmentTree(int _leftRange,
                int _rightRange,
                const std::vector<valueType> &_initValue,
                const valueType &_valueZero,
                const tagType &_tagZero) {
        leftRange = _leftRange;
        rightRange = _rightRange;
        init(_initValue, _valueZero, _tagZero);
    }

    segmentTree(int size,
                const std::vector<valueType> &_initValue,
                const valueType &_valueZero,
                const tagType &_tagZero) {
        leftRange = 1;
        rightRange = size + 1;
        init(_initValue, _valueZero, _tagZero);
    }

    void modify(int l, int r, const tagType &tag) {
        modify(1, leftRange, rightRange, l, r, tag);
    }

    void modify(int p, const tagType &tag) {
        modify(p, p + 1, tag);
    }

    valueType query(int l, int r) {
        return query(1, leftRange, rightRange, l, r);
    }

    valueType query(int p) {
        return query(p, p + 1);
    }
};

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout.precision(15);
    ll n;
    cin >> n;
    ll res = 1;

    for (int i = 0; i < n; ++i) {
        if (res != -1) {
            ll a;
            cin >> a;
            res *= a;
            if (res > (long long) (1e18) || res < a) {
                res = -1;
            }
        } else {
            ll a;
            cin >> a;
            if (a == 0) {
                res = 0;
                break;
            }
        }
    }

    cout << res;
}

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import numpy as np
n = int(input()) 
A = list(map(int, input().split()))
i = 10 ** 18
ans = np.prod(A)
elif ans > i:
    print(-1)
else:
    print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
sum = 1
'''
for i in range(N):
    sum = sum * A[i]  
    
if sum > 10**18:
    print(-1)
else:
    print(sum)   
'''
def suq(A, N):
    if N == 1:
        return 1
    else:
        return A[N-1] * suq(A, N-1)

print(suq(A, N))

Submission status: Runtime Error

Solution code:
N = int(input())
a = [int(i) for i in input().strip.split(" ")]
res=1
xx=1**18
for i in a:
    res*=i
if res>xx:
    print(-1)
else:
    print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy
n= int(input())
Number=list(map(int,input().split())
print(numpy.prod(Number)

Submission status: Runtime Error

Solution code:
N=int(input())
if N>=2 and N<=10**5:
    array=list(map(int,input().strip().split()))
    if array[0]>=0 and array[-1]<=10**18:
        multipul=1
        for i in len(array-1):
            multipul=multipul*array[i]
        print(multipul)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int N;
  cin >> N;
  long long int B =1;
   long long int C=1;
  for(long long int i=0;i<18;i++){
    C*=10;
  }
  
  vector<long long int> A(N);
  for(long long int i=0;i<N;i++){
    cin >> A[i];
    B*=A[i];
    if(B>C){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << B << endl;
}

Submission status: Runtime Error

Solution code:
X,Y=input().split()

N=int(input())
 
X=list(map(int,input().split()))
for i in X:
  if i==0:
    print(0)
    exit(0)

result=1
for i in X:
  result*=i
  if result>10**18:
    result=-1
    break
 
print(result)

Submission status: Runtime Error

Solution code:
# your code goes here
n = int(raw_input())
nums = raw_input().split()
nums1 = []
for i in nums:
	nums1.append(int(i))
nums1.sort()
ans = 1
flag = 0
for i in range(len(nums1)):
	if nums1[i]!=0:
		if nums1[i]>1e18 or ans>1e18/nums1[i]:
			flag=1
			break
	ans = ans*nums1[i]
	if ans==0:
		break
if flag==1:
	print(-1)
else:
	print(ans)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
const ll m = 1e18;
int main(int argc, const char** argv) {
    ll n,k,i;
    cin>>n;
    ll x;
    ll prod = 1;
    ll arr[n];
    for(i=0;i<n;++i){
        cin>>arr[i];
    }
    for(i=0;i<n;++i){
        if(arr[i] == 0){
            cout<<"0\n";
            return 0;
        }
    }
    for(i=0;i<n;++i){
        if(prod > 1e9 && arr[i] >1e9){
            cout<<"-1";
            return 0;
        }
        prod *= arr[i];
        if(prod > m){
            cout<<"-1";
            return 0;
        }
    }
    cout<<prod<<"\n";
    return 0;

}

Submission status: Runtime Error

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

Submission status: Runtime Error

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


def multiplyList(myList):
    result = 1
    for x in myList:
        result = result * x
    if results <= 1000000000000000000
        return result
    else:
        return -1


print(multiplyList(results))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i< (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    ll ans = 1;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i]==0){
            ans = 0;
        }
    }
    rep(i,n){
        ans *= a[i];
        if(ans>1000000000000000000 || ans < 0){
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
c=list(map(int, input().split()))
t1=np.prod(c)
for i in range(1,n):
    t1*=c[i]
if t1>1e18:
    print(-1)
else:
     print(t1)

Submission status: Runtime Error

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;


int main() {
    int n; cin >> n;
    ll a[n]; rep(i,0,n) cin >> a[i];
    sort(a,a+n);
    ll ans = a[0];
    bool f = false;
    rep(i,1,n){
        if(ans*a[i] != 1000000000000000000 && ans > 0 && a[i] > 0 && 
          (int)(to_string(ans).size())*(int)(to_string(a[i]).size()) >= 18){
            f = true;
        }else if(ans * a[i] > 1000000000000000000)
        {f = true;}
        else{
            ans *= a[i];
        }
    }
    if(f || ans > 1000000000000000000) cout << -1 << "\n";
    else cout << ans << "\n";
}

Submission status: Runtime Error

Solution code:
n = int(input())
strr = list(input())

ans = 1

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = (int(x) for x in input().split())
sum  = 1
for i in A:
    sum = sum * i
    if(i == 0):
        print(0)
        break
    if(sum > (10**18)):
        print(-1)
        break
    elif(len(A) == N):
        print(sum)
        break

Submission status: Runtime Error

Solution code:
n = input()
s = input().split(" ")
ans = 1
for i in s:
  ans *= i
print(ans)

Submission status: Runtime Error

Solution code:
import  numpy as mul
import math

N=int(input())
A=[]
for i in range(N):
	A.append(list(map(int,input().split())))


ans=mul.prod(pyA)


if int(math.log10(ans)) > 17:
	print("-1")
	
else:
	print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 1
for x in range(0, n):
    sk = int(input())
    ans = ans * sk
if ans > 1e18:
    print(-1)
else: print(ans)

Submission status: Runtime Error

Solution code:
a = [0]*n
a = input().split()
n0 = a.count('0')
sum = int(a[0])
if n0 == 0:
  for k in range(len(a)-1):
    sum =sum*int(a[k+1])
    if sum >1000000000000000000:
      print(-1)
      break
  if sum >1000000000000000000:
    print(-1)
  else:
    print(sum)
else:
  print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
arr = list(map(int,input().split()))
mul = eval('*'.join([str(n) for n in arr]))
print("-1" if mul > (10**18) else mul)

Submission status: Runtime Error

Solution code:
n = int(input())
b = [int(x) for x in input().split()]
a = 1
max = 10**18

for i in b:
  a *= i
  
a = -1 if a > max else a
print(r)

Submission status: Runtime Error

Solution code:
a=1
b=[]
n=int(input())
for i in range(n):
    b.append(int(input()))
    a*=b[i]
if a>10000000000000000:
    print(-1)
else:
    print(a)

Submission status: Runtime Error

Solution code:
N = int(input())
lst = list(map(int, input().split()))
output = 1
if 0 in lst:
    print(0)
    quit()
for i in ls:
    output *= i
    if output > 10**18:
        print(-1)
        quit()
print(output)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
max=1000000000000000000
pro=1
flag=0
for i in range(0,len(a)):
  pro=pro*a[i]
  if(pro>max):
     print(-1)
      flag=1
      break
if(flag==0):
  print(pro)

Submission status: Runtime Error

Solution code:
スコード
m
1
import numpy
2
n = int(input())
3
m = list(map(int,input().split()))
4
s = 1
5
a = 0
6
if 0 in m:
7
  print(0)
8
  a =1
9
else:
10
  for i in range(n):
11
    s=s*m[i-1]
12
    if s>10**18:
13
      print(-1)
14
      a = 1
15
      break
16
if a == 0:
17
  print(s)
※ 512 KiB まで

Submission status: Runtime Error

Solution code:
ans=1
n=int(input())
for i in range n:
  a=int(input())
  if(a==0) 
  	ans=0
  ans*=a
  if(ans!=0&&ans>1000000000000000000) 
  	print(-1)
if(ans==0) 
	print(0)
else if(ans<=1000000000000000000) 
	print(ans)

Submission status: Runtime Error

Solution code:
N =int(input())
B = 1
for i in range(N):
    A =list( map(int,input().split()))
    for i in A:
        B = B * i
        #print(B)
    
#print(B)
C = 10 ** 18
#print(C)
if B > C:
    print(-1)
else:
    print(B)

Submission status: Runtime Error

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = 1
for i in b:
    c *= i
if c > 10**18
    print('-1')
print(c)

Submission status: Runtime Error

Solution code:
#include <iostream>

using namespace std;

unsigned long long int overflow = 1e+18, ip;
long long int res=1;

int main() {
    int n;  cin>>n;
    int flag=1;
    
    for(int i=0; i<n; i++){
        cin>>ip;
        if(ip==0){
            res = 0;
            break;
        }
        res=ip*res;
    }
    
    if(res>overflow || flag==-1){
        cout<<"-1";
    }
    else if(res<0){
        cout<<"-1";
    }
    else{
        cout<<res;
    }
    
    return 0;
}

Submission status: Runtime Error

Solution code:
n =int(input())
h = 1
m = 10**18
c = -1
for i in range(n):
    a = int(input())
    h *= a
if h > m :
    print(c)
else:
    print(h)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(int(input().split())
 
ans = 1
for i in x:
  ans = ans*i
  
if ans > 1000000000000000000:
  ans = -1
print(ans)

Submission status: Runtime Error

Solution code:
# your code goes here
n = int(raw_input())
nums = raw_input().split()
nums1 = []
for i in nums:
	nums1.append(int(i))
nums1.sort()
ans = 1
flag = 0
for i in range(len(nums1)):
	if nums1[i]!=0:
		if ans>1e18/nums1[i]:
			flag=1
			break
	ans = ans*nums1[i]
	if ans==0:
		break
if flag==1:
	print(-1)
else:
	print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
alis=sorted(list(map(int,input().split())))
p=alis[0]
if p==0:
  print(0)
  exit()
for i in range(1,n):
  p*=alis[i]
  if len(list(str(p)))>18:
  sa=list(map(int,list(str(p))))
    
  if sum(sa)!=1:
    print(-1)
    exit()
print(p)

Submission status: Runtime Error

Solution code:
N = int(input())
A = (int(x) for x in input().split())
sum  = 1
for i in A:
    sum = sum * i
    if(i == 0):
        print(0)
        break
    if(sum > (10**18)):
        print(-1)
        break
    elif(len(A) == N)
        print(sum)
        break

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
using namespace std;

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
x = 1
y = 10**18

x = np.prod(A)
if x > y:
    print("-1")
else:
    print(x)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import operator
num = int(input())
a = list(map(int, input().split()))
result = reduce(operator.mul,a)
if result > 1000000000000000000:
    print(-1)
else:
    print(result)

Submission status: Runtime Error

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

for i in range(N):
    ans = ans*A[i]

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.array(A, dtype=np.float256)

MAX = pow(10, 18)

ans = A[0]


for i in range(1, N):
    ans *= A[i]


if ans > MAX:
    ans = -1


ans = int(ans)



print(str(ans))

Submission status: Runtime Error

Solution code:
k=int(input()
mal=1
a=[]      
for i in range(1,k+1):
      n=int(input()
      a.append(n)      
for i in range(0,len(a)-1):
            mal=mal*a[i]
if(mal<=10**18):
            print(mal)
else:
     print(-1)

Submission status: Runtime Error

Solution code:
import math,numpy, collections
n = int(input())
A = numpy.array(list(map(int,input().split())))
an = A.prod()


print(an if an

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  if (a[i] == 0):
    print(0)
    sys.exit()

sum = 1
for i in range(n):
  sum *= a[i]

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

Submission status: Runtime Error

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

def calc(i, y):
  if i==n-1:
    return y
  elif y>10**18:
    return "-1"
  else:
    return calc(i+1, lis[i+1])*y
result=calc(0, lis[0])

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

Submission status: Runtime Error

Solution code:
n = int(input()) 
  
# Below line read inputs from user using map() function  
a = list(map(int,input().strip().split()))[:n] 
zero = 0
for i in range(n):
	if(a[i] == 0):
		zero = zero + 1
# print(zero)
if(zero > 0):
	print(0)
	exit(1)
ans = 1
for i in range(n):
	ans = ans * a[i]
	if(ans > 1000000000000000000):
		print(-1)
		exit(1)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

import math


def main():
    N = int(input())
    A = [int(arg) for arg in input().split()]
    ans = 1
    for i in range(N+1):
        ans *= A[i]
        if ans > pow(10, 18) and i == N:
            ans = "-1"
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
product =1
vals = list(map(int,input().split()))

for i in vals:
	if i = 0:
		product = 0
		break
	product *= i;

if product >= 1000000000000000001:
	print(-1,end=" ")
else:
	print(product,end=" ")

Submission status: Runtime Error

Solution code:
#include<iostream>
using namespace std;
int main(){
	long t;
	long long x,res=1;
	cin>>t;
	while(t--){
		cin>>x;
		res = res*x;
		if(res == 0){
			break;
		}
	}
	if(res > 1000000000000000000){
		cout<<-1<<endl;
	}else{
		cout<<res<<endl;
	}
	
	return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 1
a = [long(n) for n in input().split()]
for e in a:
    ans*=a
if ans>1000000000000000000:
    print("-1")
else:
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
list = list(map(int, input().split()))
no = 0
non = 0
ans = 1
lens = 0
if list.count("0") >= 1:
  print("0")
  exit()
for i in range(N):
  lens = lens + len(list[non])
  non += 1
if non >= 19:
  print("-1")
  exit()
for j in range(N):
  ans = ans * list[no]
  no += 1
print(ans if ans <= 10**18 else "-1")

Submission status: Runtime Error

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

for i in range(n):
  b *= a[i]

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int, input().split())
if N > len(A):
  print(0)
else:
  tmp = 1
  for i in range(N):
    tmp *= A[i]
  if np.log(tmp) > 18:
    print(tmp)
  else:
    print(-1)

Submission status: Runtime Error

Solution code:
a=int(input())
l=[]
for x in range(a):
    b=int(input())
    l.append(b)
ans=1
for i in l:
    ans*=i
if ans>10**18:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import functools
import operator

def calc(n):
    return n / 1000000

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

#z = functools.partial(functools.reduce, operator.mul)
#count = z(A)

count = np.prod(A)

#print(count)

count = count * 1000000 ** len(A)

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = input().split()
i = 0
while i <= n-1:
  b = int(a[i]) * int(a[i+1])
  i += 1
if b > 10**18
  b = -1
print(b)

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout
n=stdin.readline()
l=list(map(int,sys.stdin.readline().strip().split()))
k=1
for i in l:
  k=k*i
if(k>1000000000000000000):
  print(-1)
else:
  print(k)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
x = [int(input().split()) for i in range(n)]
 
ans = 1
for i in x:
  ans = ans*i
  
if ans > 1000000000000000000:
  ans = -1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

sum = 0
i = 0

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.array(A, dtype=np.float128)

MAX = pow(10, 18)

ans = A[0]


for i in range(1, N):
    ans *= A[i]

ans = int(ans)

if ans > MAX:
    ans = -1


print(str(ans))

Submission status: Runtime Error

Solution code:
import math

if __name__ == "__main__":

    N = int(input())

    P = (map(int,input().split()))

    mult = 1
    for i in P:
        mult *= i

    if(math.log10(mult) > 18):
        print(-1)
    else:
        print(mult)

Submission status: Runtime Error

Solution code:
_ = input()
A = list(map(int, input().split()))
b = np.prod(A)
b = b if b < 10 ** 18 else -1
print(b)

Submission status: Runtime Error

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

temp_sum = 1
flag = False
flag_0 = False

if 0 in list_A:
    flag_0 = True
    break
else:
    for i in range(N):
        temp_sum *= list_A[i]
        if temp_sum >= 10**18:
            flag = True
            break
        else:
            continue

if flag_0:
    print(0)
elif (flag_0 == False) and flag:
    print(-1)
else:
    print(temp_sum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = input()
a = A.split()
sum = 1
if "0" in a :
    print(0)
else:
    for i in range(N):
        sum *= int(a[i])
        if sum > 10**18:
            print(-1)
            flag = 1
            break
    if flag == 0:
        print(sum)

Submission status: Runtime Error

Solution code:
#include <iostream>
#define INF 1000000000000000000LL
using namespace std;
using ll = long long;

int main()
{
  int n;
  cin >> n;
  ll a[n];
  ll ans = 1;
  for(int i=0; i<n; ++i) {
    cin >> a[i];
  }

  for(int i=0; i<n; ++i){
    ans *= a[i];
  }
  if(ans>INF){
    cout <<  "-1" << endl;;
  }else{
    cout << ans << endl; 
  }

  return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
def main():
    n = int(input())
    A = np.array(list(map(int, input().split())))
    limit = 10 ** 18

    if np.any(A=0):
        print(0)
    else:
        ans = 1
        for i in range(n):
            ans *= A[i]
            if ans > limit:
                print(-1)
                exit()

        print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.array(A, dtype=np.float128)

MAX = pow(10, 18)

ans = A[0]


for i in range(1, N):
    ans *= A[i]

if ans > MAX:
    ans = -1

ans = int(ans)

print(str(ans))

Submission status: Runtime Error

Solution code:
n =int(input())
h = 1
m = 10**18
for i in range(n):
    a = int(input())
    h *= a
if h > m:
    print('-1')
else:
    print(h)