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 sys
n = int(input())
A = list(map(int,input().split()))
ANS = 1
for i in range(n):
    ANS *= A[i]
    if ANS > 10**18:
        print(-1)
        sys.exit(1)
print(ANS)

Submission status: Runtime Error

Solution code:
n = int(input())
a = input().split()
sum = 1
for i in a:
  sum*=i
if sum > 10**18:
  print(-1)
else:
  print(sum)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    rep(i, 0, N) {
        if (!A[i]) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    rep(i, 0, N) {
        if (ans > 1000000000000000000LL / A[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
    }
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = input()
A = list(input().split())
num = 0
for i in A:
  num *= i
if num <= 1000000000000000000:
  print(-1)
else:
  print(num)

Submission status: Runtime Error

Solution code:
n=int(input())
p=1;
for i in range(n):
	x=int(input())
  	p=p*x;
if(p>int(1e18)):
	print("-1")
else:
  print(p)

Submission status: Runtime Error

Solution code:
_ = input()
l = list(map(int, input().split(" ")))

ans = functools.reduce(lambda x, y : x* y, l, 1)

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

Submission status: Runtime Error

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    a = sorterd(a)
    limit = 10**18
    ans = 1
    for ai in a:
        ans *= ai
        if ans > limit:
            print(-1)
            exit(0)
        if ans == 0:
            break
    print(ans)

    


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans = 1
for i in a:
    ans *= i
    if ans > 10**18: 
        ans = '-1'
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
res = 1
exc = False
for i in a:
	res *= i
	if res > 10**18:
      exc = True
      print(-1)
if not exc:
  print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = int(input())
b = []
n = 1
for i in range(a):
  b.append(int(input()))
  
for i in range(a):
  n = n * b[i]

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = 1
for _ in range(N):
    A = A * int(input())

print(A)

Submission status: Runtime Error

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

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

    if flag == True:
        print(cnt)
    else:
        print(-1)


resolve()

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 1
for i in range(N):
    ans *= int(input())
if ans <= 10**18:
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

Solution code:

a=int(input())
b=list(map(int, input().split()))
c=1
if 0 in b:
    d=1
for i in range(a):
    c*=b[i]
    if d!=1 and c>10**18:
        print(-1)
        exit()


print(c)

Submission status: Runtime Error

Solution code:
N=int(input())
A=1
for i in range(N):
   A=A*int(input())
print(A if len(A)<=18 else -1)

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 > 1000000000000000000:
  print(-1)
else:
  print(res)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n=input()
ans=eval(input().replace(" ","*"))
if ans>10**18:
  print(-1)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
import prod
l1=list(map(int,input().split()))
a=math.prod(l1)
if a>=10**18:
  print("-1")
esle:
  print(a)

Submission status: Runtime Error

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

ans = 1
for x in arr:
	ans *= x
    if ans > 10**18:
    	ans = 10**19

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

Submission status: Runtime Error

Solution code:
/*
Author: Qaseem Hasan alias Mikepayne14(Codeforces,Atcoder) 
                           qaseem_hasan_ (Codechef,HackerRank,HackerEarth)
*/


//---------------------------------------------------------
//#pragma GCC optimize "trapv"

#include <bits/stdc++.h>
using namespace std;
//---------------------------------------------------------

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<pair<int,int>>> vvpii;
typedef set<int> seti;
typedef unordered_set<int> us;
typedef unordered_set<int,greater<int>> usrev;
typedef priority_queue <int, vector<int>, greater<int>> revpq;

const int INF = (int)1e9;
const int EPS = 1e-8;
const int MOD  = 1000000007;
const ld PI = 3.14159265359;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

#define acc accumulate
#define eb emplace_back
#define mii map <int,int>
#define F first
#define S second
#define MP make_pair
#define mid(s,e) (s+(e-s)/2)
#define fil(v,x) fill(all(v),x)
#define filcon(v,x) iota(all(v),x)
#define repi(n) for(int i=0;i<n;++i)
#define repj(n) for(int j=0;j<n;++j)
#define repr(n) for(int i=n-1;i>=0;--i)
#define erase(v,e) v.erase(std::remove(v.begin(), v.end(), e), v.end())
#define sqr(x) ((x)*(x))
#define MEM(a,b) memset(a, b, sizeof(a))
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define inrange(i,a,b) ((i>=min(a,b)) && (i<=max(a,b)))
#define FLSH fflush(stdout)
// #define min_all(a,b,c,d,...) min({a,b,c,d,...})
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define make_unique(v) sort(all(v)); v.erase(unique(all(v)), v.end());
#define readfull(s) getline(cin,s)
#define printv(v) for(auto i:v) cout << i << " "
#define trace(x) cout<<#x<<" = { "<<x<<" }\n";
#define khatam '\n'
#define test int t; cin >> t; repi(t) {solve(); cout << khatam;}
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
for ( \
    auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
    blockTime.second; \
    debug("%s: %ld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
)

//--------------------------------------------------------
inline bool grid_inside(int x, int y, int n, int m) {return x >= 1 && x <= n && y >= 1 && y <= m;}

template<typename T>
T lcm(T a,T b)
{
    return (a*b)/__gcd(a,b);
}

template<typename ForwardIterator,typename T>
T first_val(ForwardIterator first,ForwardIterator last,T value)
{
    auto it = std::lower_bound(first,last,value);
    return (it!=last)?(it - first) : -1;
}

template<typename ForwardIterator,typename T>
T last_val(ForwardIterator first,ForwardIterator last,T value)
{
    auto it = std::upper_bound(first,last,value);
    return ((it!=last)?((it - first)-1) : -1);
}

template <typename T> T Dis(T x1,T y1,T x2, T y2)
{return sqrt(sqr(x1-x2) + sqr(y1-y2));}

template <typename T> T Angle(T x1,T y1,T x2, T y2)
{return atan((db)(y1-y2) / (db)(x1-x2));}

int Set(int N,int pos){ return N=N | (1<<pos);}
int Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Check(int N,int pos){return (bool)(N & (1<<pos));}
template< class T, class X > inline T togglebit(T a, X i) { T t=1;return (a^(t<<i));}

//--------------------------------------------------------

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.F < j.F;
}

int doubleCompare(double x, double y) {
    if (fabs(x-y) <= EPS)
        return 0;
    if(x < y)
        return -1;
    return 1;
}

int LSOne(int x)
{
    return ((x)&(-x));
}

int rangeClear(int n,int i,int j){
    int ones = ~0;
    int a = ones << (j+1);
    int b = (i<<2)-1;
    int mask = a|b;
    int ans = n&mask;
    return ans;
}

int countSetBits(int n)
{
    int count=0;
    while(n>0)
    {
        count += (n&1);
        n = n>>1;
    }
    return count;
}

int getPosBit(int n,int k)
{
    return (n&(1<<k))!=0?1:0;
}

void setPosBit(int &n,int k)
{
    n = n|(1<<k);
}

ll fast_power(int a,int x)
{
    if(x==0)
        return 1;
    else if(x==1)
        return a;
    else
    {
        ll R = fast_power(a,x>>1);
        if(!(x&1))
            return R*R;
        else
            return R*a*R;
    }
}

ll fast_power_unlocked(ll a,ll n,ll mod)
{
    ll res = 1;
    while(n > 0)
    {
        if(n&1)
        {
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        n = n >> 1;
    }
    return res;
}

ll modInverse(ll A,ll M)
{
    return fast_power_unlocked(A,M-2,M);
}

/* DSU
vi par(MAX_N,0);
vi rnk(MAX_N,0);

int find(int x)
{
    if(x==par[x])
        return x;
    return par[x] = find(par[x]);
}

void Union(int x,int y)
{
    int par_x = find(x);
    int par_y = find(y);

    if(par_x == par_y) return;

    if(rnk[par_x] < rnk[par_y])
        swap(par_x,par_y)
    par[par_y] = par_x;

    if(rnk[par_x] == rnk[par_y])
        rnk[par_x]++;
    }
}
*/

bool checkPrime(int n)
{
    int cnt=0;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i == 0)
        {
            if(n/i == i)
                cnt++;
            else
                cnt += 2;
        }
    }
    if(cnt == 2)
        return true;
    else
        return false;
}

/*
const int mx = 1e5;
bool isPrime[mx];
void createSieve()
{
    MEM(isPrime,true);
    for(int i=2;i*i<=mx;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=mx;j+=i)
            {
                isPrime[j] = false;
            }
        }
    }
}*/

/*vll f;
vll invf;
void init(){
    f.resize(MAX_N, 1);
    invf.resize(MAX_N, 1);
    repi(MAX_N) f[i] = (f[i-1]*i)%MOD;
    repi(MAX_N) invf[i] = modInverse(f[i],MOD);
}

ll ncr(ll n, ll r){
    return invf[n-r] * ( f[n] * invf[r] % MOD ) % MOD;
}*/

const ll MAX_N = 1e18;

void solve()
{
    int n;
    cin >> n;
    ull val;
    ull ans=1;
    repi(n) {cin >> val; ans *= val; if(ans > MAX_N) {cout << -1; return;}}
    cout << ans;
}

int main()
{
    FAST_IO;

//-------------------------------------------------------
    time__("Time Taken"){
        solve();
    }
}

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
a=1
for i in range(n):
  b=int(input())
  l.append(b)
  a=a*b
print(a)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int, input().split()))
dap=1
nodap=0
for i in range(n):
    dap*=l[i]
    if dap>1000000000000000000:
        nodap++
        break
if nodap:
    print("-1")
else:
    print(dap)

Submission status: Runtime Error

Solution code:
#B
import numpy as np
n = int(input())
A = np.array(list(map(int,input().split())))
ans = 1
for i in A:
    ans *= i
if ans > 10**18:
    ans = -1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
list_a=list(int(input()))
result=1
for a in list_a:
  result = result*a
  
if result > 10**18:
  print('-1')
else:
  print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
t=int(1)
for i in range (0,n):
  a=input()
  t=int(t*a)
if t>1000000000000000000:
  print(-1)
else:
  print(t)

Submission status: Runtime Error

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

ans = 1
var = pow(10,18)
for i in range(len(A)):
    ans *= A[i]
    if ans > tmp:
        ans = -1
        break

print(ans)

Submission status: Runtime Error

Solution code:
ans = 0
for i in range(N):
    ans = ans * A[i]
print(ans)

Submission status: Runtime Error

Solution code:
cumul = 1
n = int(raw_input())
ais = map(int, raw_input().split(' '))
while(i < len(ais) and cumul < 10 ** 18):
  cumul *= ais[i]
  i+=1
print cumul if cumul < 10 ** 18 else -1

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <CodeforcesSolutions.h>
#include <ONLINE_JUDGE <solution.cf(contestID = "1359",problemID = "C",method = "GET")>.h>
"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    n = inp()
    a = inlt()
    q = -1
    for i in range(n):
        q = q * a[i]
        if q > 10 ** 18:
            q = -1
            break
    print(q)
                
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    t = inp()
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
    sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))

#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
a=1
for i in range(n):
  b=int(int(input())
  l.append(b)
  a=a*b
print(a)

Submission status: Runtime Error

Solution code:

n=int(input())
ar=list(map(int,raw_input().split()))

x=1
for y in ar:
	x=x*y;
if(x>1000000000000000000):
	print(-1)
else:
	print(x)

Submission status: Runtime Error

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
prod=1
for i in range(0,N):
  prod=prod*A[i]
  if(prod>1000000000000000000):
    prod=-1
    break
print(prod)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int N;
  cin >> N;
  ll sum = 1;
  REP(i, N) {
    ll a;
    cin >> a;
    sum *= a;
    if(sum>(ll)1e18){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;

  return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
p = 1
b = 1
for i in rane(n):
  p *= int(input())
  if p > 1e18:
    b = 0
    p = 0
if b:
  print(p)
else:
  print(-1)

Submission status: Runtime Error

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    limit = 10**18
    ans = 1
    for i in A:
        if A == 0:
            print(0)
            return
        if ans > limit:
            print(-1)
            return
        ans *= A[i]
    print(ans)

main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
INF = 10**18
N = int(input())
sum = 1
for _ in range(N):
  sum = sum*int(input())
  if sum > INF:
    print(-1)
    import sys
    sys.exit()

print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans = reduce(mul, A)
print(ans if ans <= 10**18 else -1)

Submission status: Runtime Error

Solution code:
N = int(input())

result = 1
for i in range(N):
    result *= int(input())

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
ans=1
for i in range(n):
  ans*=int(input())
print(ans)

Submission status: Runtime Error

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