Language: C++

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>  
using namespace std;

#define ff 	 		first	
#define ss 	 		second
#define pb 	 		push_back
#define pf 	 		push_front
#define pob 		pop_back
#define pof 		pop_front
#define mp 	 		make_pair
#define ins 		insert
#define ll 	 		long long int
#define ld 	 		long double
#define ull 		unsigned long long
#define loop(i,n) 	for(ll i=0;i<n;i++)
#define loop1(i,n) 	for(ll i=1;i<=n;i++)
#define rev(i,n) 	for(ll i=n-1;i>=0;i--)
#define rev1(i,n) 	for(ll i=n;i>=1;i--)
#define test(t) 	int t;cin>>t;while(t--)
#define endl 		'\n'
#define all(c) 	 	(c).begin(), (c).end()
#define tr(c,it) 	for(auto it=(c).begin(); it!=(c).end(); it++)
#define rtr(c,it) 	for(auto it=(c).rbegin(); it!=(c).rend(); it++)
#define sz(c) 	 	(c).size()
// Define mod as per requirement
const ll MOD =1000000007;
//const ll MOD= 998244353; 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll; 
struct Order1{bool operator()(pll const& a,pll const& b)const{return (a.ss < b.ss || (a.ss == b.ss && a.ff < b.ff));}};
struct Order2{bool operator()(pll const& a,pll const& b)const{return (a.ff < b.ff || (a.ff == b.ff && a.ss < b.ss));}};
typedef priority_queue <ll> maxpq;// maximum priority_queue
typedef priority_queue <ll, vector<ll>, greater<ll> > minpq; //minimum priority_queue
typedef priority_queue <pll> maxpq_pair_f;// maximum priority_queue for pairs with maximum ff
typedef priority_queue <pll,vector<pll>, Order2 > max_pq_s; // maximum priority_queue for pairs with maximum ss
typedef priority_queue< pll, vector<pll>, greater<pll> > minpq_pair_f; //minimum priority_queue for pairs with the smallest ff
typedef priority_queue< pll, vector<pll>, Order1 > minpq_pair_s; //minimum priority_queue for pairs with the smallest ss

long long min(long long a,long long b){if(b<=a)return b;return a;}
long long max(long long a,long long b){if(a>=b)return a;return b;}
long long add(long long x, long long y){x += y;while(x >= MOD) x -= MOD;while(x < 0) x += MOD;return x;}
long long multiply(long long x, long long y){return (x * 1ll * y) % MOD;}
long long power(long long x, long long y){long long z = 1;while(y){if(y & 1) z = multiply(z, x);x = multiply(x, x);y >>= 1;}return z;}
long long modInverse(long long x){return power(x, MOD - 2);}
long long divide(long long x, long long y){return multiply(x, modInverse(y));}
long long gcd(long long a,long long b) { if(a == 0)return b;return gcd(b % a, a);}
long long lcm(long long a,long long b){long long val=max(a,b)/gcd(a,b);val*=min(a,b);return val;} 
const long long N=200050; // can be changed as per constraints
long long fact[N]; // array to store values of factorial
void cal_factorial(){fact[0] = 1;for(long long i = 1; i < N; i++)fact[i] = multiply(fact[i - 1], i);}// function to calculate factorial upto N
long long nCr(long long n, long long k){return divide(fact[n], multiply(fact[k], fact[n - k]));}
void BOOST(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
bool inc(long long x,long long y){return x<=y;}// for increasing order
bool dec(long long x,long long y){return x>=y;}// for decreasing order
// For union and intersection of vectors
vector<int>Intersection(vi &v1,vi&v2){vi v3;sort(all(v1));sort(all(v2));set_intersection(all(v1),all(v2),back_inserter(v3));return v3;}
vector<int>Union(vi &v1,vi&v2){vi v3;sort(all(v1));sort(all(v2));set_union(all(v1),all(v2),back_inserter(v3));return v3;}


int main(){
	BOOST();
	int n;cin>>n;
  	ull prod=1;
  	for(int i=0;i<n;i++){
    ull ai;cin>>ai;if(ai>1LL*1e18){cout<<-1<<endl;return 0;}
    prod*=ai;
     if(prod>1LL*1e18){cout<<-1<<endl;return 0;}
      
    }
  cout<<prod;

}


Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:6:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~