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 in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)


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

typedef long long ll;
typedef double db;
typedef long double ld;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int>>  vvi ;
typedef vector<vc> vvc;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi ;

#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define rall(x) x.rbegin(), x.rend()
#define F first 
#define S second
#define pb push_back 
#define mp make_pair
#define ar array
#define lb lower_bound
#define ub upper_bound
#define FIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mem(X,val) memset(X, val, sizeof((X)))
#define FOR(i, n) for(int i = 0 ; i < (int) n ; ++i)
#define UNQ(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define P(x) cout << x <<'\n';
#define W(x) cout << x;
#define llu unsigned long long int
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const db PI = acos(-1);
const ll mod = 1e9+7;
template <typename A, typename B>istream& operator>>(istream& input,pair<A,B>& x) {input>>x.F>>x.S;return input;}
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
template<class T> void _R(T &x) { cin >> x; } void R() {}template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...);}
template <class T>void smax(T& x,T y){ if(x<y)x=y;}
template <class T>void smin(T& x,T y){ if(x>y)x=y;}
template<typename T1, typename T2> T1 powz(T1 A, T2 B);
template <typename T1, typename T2>T1 ADD(T1,T2);
template <typename T1, typename T2>void ADDZ(T1&,T2);
template<class T1, class T2> T1 mul(T1 A, T2 B);
template<typename T1, typename T2> T1 GCD(T1 A,T2 B);
template<typename T1> T1 MOD(T1 A){return (A%mod + mod)%mod;}
/***************************************************main code**************************************************************/
const int MXN=1e6+5;
const ll INF = 9e18+200;
const int inf = 1e9+100;
const int mxn = 2e5+20;

void test_case()
{
	int n; R(n);
	
	vl a(n); R(a);
	sort(all(a));
	unsigned long long int s=1llu;
	for(auto x : a){
		s *=(x+0ll);
		debug(s);
		if(s==0LL){
			W(s);return;
		}
		if( s > 1000000000000000000LL){
			W(-1);return;
		}
	}
	W(s);
	
	
}

/*************----------------------------******************/
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int Tests = 1;
	//cin >> Tests;
	
	for(int tc = 1; tc <= Tests; ++tc){
		//cout <<"Case #"<<tc<<": ";
		test_case();
		cout<<'\n';
	}
		
}
template <typename T1, typename T2> 
T1 ADD(T1 A, T2 B)
{
	ll res = (A+B)%mod;
	if(res<0)res+=mod;
	return res;
}
template <typename T1, typename T2> 
void ADDZ(T1& A, T2 B)
{
	ll res = (A+B)%mod;
	if(res<0)res+=mod;
	A = res;
}
template<typename T1, typename T2>
T1 powz(T1 X,T2 B)
{
	ll A = X;
	ll res=1;
		A%=mod; 
		assert(B>=0); 
	for( ; B ; B>>=1){
		if(B&1)res=res*A%mod;
		A= A*A%mod;
	}
	return res;
}
template<typename T1, typename T2> 
T1 GCD(T1 A,T2 B)
{
	 return B?GCD(B,A%B):A;
}
template <class T1 , class T2> 
T1 mul(T1 A, T2 B)
{
	ll res = 1;
	res = (1LL * A%mod * B%mod )%mod;
	return res;
}