Problem p02658 (python)

Fixed submission:
n = int(input())
arr = list(map(int,input().split()))
res = 1
flag = 1
arr.sort()
inf = int(1e18)
for i in range(n):
  res = res*arr[i]
  if(res > inf):
    flag = 0
    break
 
if(flag == 0):
  print(-1)
else:
  print(res)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'



int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//     int t;
//      cin >> t;

//      while(t--){



// }
     int linf = 1e18;
  	int n;
  	cin >> n;
  	int arr[n];
  	fo(i,0,n)cin >> arr[i];
  	sort(arr,arr+n);
  	uint64_t res = 1;
  	int flag = 1;
  	fo(i,0,n){
  		if(res*arr[i] > linf){
  			flag = 0;
  			break;
  		}
  		res = res*arr[i];
  	}
  	if(flag)cout << res << endl;
  	else cout << -1 << endl;


return 0;
}

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'



int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//     int t;
//      cin >> t;

//      while(t--){



// }
     uint64_t linf = 1e18;
  	int n;
  	cin >> n;
  	int arr[n];
  	fo(i,0,n)cin >> arr[i];
  	sort(arr,arr+n);
  	uint64_t res = 1;
  	int flag = 1;
  	fo(i,0,n){
  		if(res*arr[i] > linf){
  			flag = 0;
  			break;
  		}
  		res = res*arr[i];
  	}
  	if(flag)cout << res << endl;
  	else cout << -1 << endl;


return 0;
}

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'



int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//     int t;
//      cin >> t;

//      while(t--){



// }
     uint64_t linf = 1e18;
  	int n;
  	cin >> n;
  	int arr[n];
  	fo(i,0,n)cin >> arr[i];
  	sort(arr,arr+n);
  	uint64_t res = 1;
  	int flag = 1;
  	fo(i,0,n){
  		if(res*arr[i] > linf){
  			flag = 0;
  			break;
  		}
  		res = res*arr[i];
  	}
  	if(flag)cout << res << endl;
  	else cout << -1 << endl;


return 0;
}