Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9 + 7;
ll MOD = 998244353;
typedef pair<ll, ll> ii;
#define iii pair<ii, ll>
#define f(i, a, b) for (long long i = a; i < b; i++)
#define rf(i, a, b) for (long long i = a; i >= b; i--)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define w(t) while (t--)
#define c(n)                                                                   \\
  ;                                                                            \\
  cin >> n;
#define p(n) cout << n;
#define pl(n) cout << n << "\\n";
#define ps(n)                                                                  \\
  ;                                                                            \\
  cout << n << " ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld double
#define arrin(a, n)                                                            \\
  f(i, 0, n) { cin >> a[i]; }
#define arrout(a, n)                                                           \\
  f(i, 0, n) { cout << a[i] << " "; }
#define printclock                                                             \\
  cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\\n";
#define PI (2 * acos(0))
#define EPS 1e-18
/// I hope I will get uprating and don't make mistakes
/// I will never stop programming
/// sqrt(-1) Love C++
/// Please don't hack me
///@TheofanisOrfanou Theo830
/// Training
int main(void) {
  fastio;
  ll n;
  cin >> n;
  ll arr[n];
  f(i, 0, n) { cin >> arr[i]; }
  ll ans = 1;
  sort(arr, arr + n);
  if (arr[0] == 0) {
    cout << 0;
    return 0;
  }
  f(i, 0, n) {
    if (1000000000000000000 / ans < arr[i]) {
      ans = -1;
      break;
    }
    ans *= arr[i];
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9 + 7;
ll MOD = 998244353;
typedef pair<ll, ll> ii;
#define iii pair<ii, ll>
#define f(i, a, b) for (long long i = a; i < b; i++)
#define rf(i, a, b) for (long long i = a; i >= b; i--)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define w(t) while (t--)
#define c(n)                                                                   \\
  ;                                                                            \\
  cin >> n;
#define p(n) cout << n;
#define pl(n) cout << n << "\\n";
#define ps(n)                                                                  \\
  ;                                                                            \\
  cout << n << " ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld double
#define arrin(a, n)                                                            \\
  f(i, 0, n) { cin >> a[i]; }
#define arrout(a, n)                                                           \\
  f(i, 0, n) { cout << a[i] << " "; }
#define printclock                                                             \\
  cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\\n";
#define PI (2 * acos(0))
#define EPS 1e-18
/// I hope I will get uprating and don't make mistakes
/// I will never stop programming
/// sqrt(-1) Love C++
/// Please don't hack me
///@TheofanisOrfanou Theo830
/// Training
int main(void) {
  fastio;
  ll n;
  cin >> n;
  ll arr[n];
  f(i, 0, n) { cin >> arr[i]; }
  ll ans = 1;
  sort(arr, arr + n);
  if (arr[0] == 0) {
    cout << 0;
    return 0;
  }
  f(i, 0, n) {
    ans *= arr[i];
    if (1000000000000000000 / ans >= arr[i]) {
      ans = -1;
      break;
    }
  }
  cout << ans;
}