alexjercan/bugnet huggingface dataset:
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <cstdint>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

int main() {
  int N;
  string tmp;
  Bint ans = 1;
  Bint lim("1000000000000000000");

  vector<Bint> vec;

  cin >> N;

  for (int i = 0; i < N; ++i) {
    cin >> tmp;
    vec.push_back(Bint(tmp));
  }

  sort(vec.begin(), vec.end(), greater<Bint>());

  if (vec.back() == 0) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = 0; i < N; ++i) {
    ans *= vec[i];

    if (ans > lim) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <boost/multiprecision/cpp_int.hpp>
#include <cstdint>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

int main() {
  int N;
  string tmp;
  Bint ans = 1;
  Bint lim("1000000000000000000");

  cin >> N;

  for (int i = 0; i < N; ++i) {
    cin >> tmp;
    Bint val(tmp);
    ans *= val;
  }

  if (ans > lim) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
#define pi acos(-1)
int main() {
  int n;
  cin >> n;
  ll arr[n + 5];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  ll m = 1e18;
  if (arr[0] == 0)
    cout << "0" << endl;
  else {
    ll ans = 1;
    for (int i = 0; i < n; i++) {
      if (arr[i] <= m / ans)
        ans *= arr[i];
      else {
        cout << "-1" << endl;
        return 0;
      }
    }
    cout << ans << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define pp 1000000000000000000
int main() {
  ll t;
  vector<ll> v;
  cin >> t;
  for (ll i = 0; i < t; i++) {
    ll k;
    cin >> k;
    v.push_back(k);
  }
  sort(v.begin(), v.end());

  ll ans = 1;
  for (int i = 0; i < t; i++) {
    ans *= v[i];
    if (pp / ans > v[0]) {
      cout << -1 << endl;
      return 0;
    }
    if (ans == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  // if(ans-pp>0){cout<<-1<<endl; }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> a(n);
  int check = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      check = 2;
      cout << 0 << endl;
    }
  }
  unsigned long long sum = 1;
  if (check != 2) {
    for (int i = 0; i < n; i++) {
      if (a[i] <= 1000000000000000000 / sum) {
        sum *= a[i];
      } else {
        check = -1;
        cout << -1 << endl;
        break;
      }
    }
    if (check != -1) {
      cout << sum << endl;
    }
  }
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
    }
  }
  int check = 0;
  unsigned long long sum = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / sum) {
      sum *= a[i];
    } else {
      check = -1;
      cout << -1 << endl;
    }
  }
  if (check != -1) {
    cout << sum << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
const long double PI = 3.14159265358979;
const ll MAX = 0;

int main() {
  ll N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = 1;
  sort(A, A + N);
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      ans = 0;
      break;
    }
    if (ans > 1000000000000000000 / A[i]) {
      ans = -1;
      break;
    }
    ans *= A[i];
    if (ans > 1000000000000000000) {
      ans = -1;
      break;
    }
    if (ans < 0) {
      ans = -1;
      break;
    }
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
const long double PI = 3.14159265358979;
const ll MAX = 0;

int main() {
  ll N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = 1;
  sort(A, A + N);
  for (int i = 0; i < N; i++) {
    if (ans > 1000000000000000000 / A[i]) {
      ans = -1;
      break;
    }
    ans *= A[i];
    if (ans > 1000000000000000000) {
      ans = -1;
      break;
    }
    if (ans < 0) {
      ans = -1;
      break;
    }
  }
  cout << ans;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

void Main() {
  int64_t N;
  cin >> N;

  vector<uint64_t> A(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return;
    }
  }

  uint64_t result = 1;
  for (int64_t i = 0; i < N; ++i) {
    uint64_t threashold = 1000000000000000000 / A[i];
    if (result > threashold) {
      cout << -1 << endl;
      return;
    }
    result *= A[i];
  }

  cout << result << endl;
}

int main() { Main(); }


Error: -11

Fixed submission:

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

void Main() {
  int64_t N;
  cin >> N;

  vector<uint64_t> A;
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return;
    }
  }

  uint64_t result = 1;
  uint64_t threashold = pow(10, 18);
  for (auto a : A) {
    result *= a;
    if (result > threashold) {
      cout << "-1" << endl;
      return;
    }
  }

  cout << result << endl;
}

int main() { Main(); }
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  ll ans = 1;
  SORT(a);
  if (a[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, N) {
    if (a[i] > (ll)1e18 / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}


Error: -8

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  ll ans = 1;
  SORT(a);
  if (a[0] = 0) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, N) {
    if (a[i] > (ll)1e18 / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      ans = 0;
      cout << ans << endl;
      return 0;
    } else if (a <= 1000000000000000000 / ans) {
      ans = ans * a;
    } else {
      ans = -1;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      ans = 0;
    } else if (a <= 1000000000000000000 / ans) {
      ans = ans * a;
    } else {
      ans = -1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
#define ll long long
using namespace std;
const int MAX = 100;
int main() {
  ll a;
  int n;
  cin >> n;
  ll ans = 1;
  priority_queue<ll> Q;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (a == 0) {
      cout << 0;
      return 0;
    } else if (a > 1e18) {
      cout << -1;
      return 0;
    } else
      Q.push(a);
  }
  for (int i = 0; i < n; i++) {
    if (!Q.empty()) {
      a = Q.top();
      Q.pop();
      if (ans > (ll)1e18 / a || ans < 0) {
        cout << -1;
        return 0;
      }
      ans *= a;
      if (ans > (ll)1e18 || ans < 0) {
        cout << -1;
        return 0;
      }
    }
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
#define ll long long
using namespace std;
const int MAX = 100;
int main() {
  unsigned ll a;
  int n;
  cin >> n;
  unsigned ll ans = 1;
  priority_queue<ll, vector<ll>, greater<ll>> Q;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (a != 1)
      Q.push(a);
    else if (a == 0) {
      cout << 0;
      return 0;
    } else if (a > 1e18) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    a = Q.top();
    Q.pop();
    ans *= a;
    if (ans > (long long)1e18) {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
ll M = 1e18;
ll a[210000];
int main() {
  int n;
  ll sum = 1, y;
  int flag = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      sum = 0;
      ;
    }
  }
  if (sum == 0) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (sum <= M / a[i] && M / a[i] >= 1) {
      sum *= a[i];
      flag = 0;
    } else {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << "-1" << endl;
  else
    cout << sum << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
ll M = 1e18;
int main() {
  int n;
  ll sum = 1, y;
  int flag = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> y;
    //	cout<<sum<<endl;
    if (sum != 0) {
      if (sum <= M / y) {
        sum *= y;
        flag = 0;
      } else {
        flag = 1;
      }
    }
  }
  if (flag)
    cout << "-1" << endl;
  else
    cout << sum << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
  if (x >= 0)
    return;
  else
    x = -x;
  return;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll INF = 1LL << 60;

int N;

// DPテーブル
vector<ll> dp(100010);

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) { cin >> a.at(i); }
  sort(a.begin(), a.end());
  ll ans = 1;
  if (a.at(0) == 0) {
    ans = 0;
  } else {
    rep(i, n) {
      if (a.at(i) > 1000000000000000000 / ans) {
        ans = -1;
        break;
      } else {
        ans *= a.at(i);
      }
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
  if (x >= 0)
    return;
  else
    x = -x;
  return;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll INF = 1LL << 60;

int N;

// DPテーブル
vector<ll> dp(100010);

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a.at(i);
    if (a.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    ll judge = 1000000000000000000;
    judge /= ans * a.at(i);
    if (judge == 0) {
      ans = -1;
      break;
    }
    ans *= a.at(i);
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main() {

  long long S = 1;
  int n;

  cin >> n;
  vector<long long> A(n);

  rep(i, n) { cin >> A.at(i); }

  rep(i, n) {
    if (A.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (A.at(i) <= 1000000000000000000 / S) {
      S *= A.at(i);
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << S << endl;
}


Error: 0

Fixed submission:

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main() {

  long long S = 1;
  int n;

  cin >> n;
  vector<long> A(n);

  rep(i, n) {
    cin >> A.at(i);
    if (A.at(i) <= 1000000000000000000 / S) {
      S *= A.at(i);
    } else {
      cout << -1 << endl;
      exit(1);
    }
  }
  cout << S << endl;
}

//    long long K = pow(10,18);

//    cout << K << endl;
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll unsigned long long int
/* run this program using the console pauser or add your own getch,
 * system("pause") or input loop */
using namespace std;

const ll lim = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1;
  bool fail{false}, abs = false;
  while (n--) {
    ll term;
    cin >> term;
    if (term == 0) {
      abs = true;
    }
    if (term != 0 && ans > lim / term) {
      fail = true;
    }
    ans *= term;
  }
  if (abs) {
    cout << 0;
  } else if (fail) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll unsigned long long int
/* run this program using the console pauser or add your own getch,
 * system("pause") or input loop */
using namespace std;

const ll lim = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1;
  bool fail{false}, abs = false;
  while (n--) {
    ll term;
    cin >> term;
    if (term == 0) {
      abs = true;
    }
    if (ans > lim / term) {
      fail = true;
    }
    ans *= term;
  }
  if (abs) {
    cout << 0;
  } else if (fail) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18) + 1;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  unsigned long long result = 1;
  bool flag = false;
  vector<ll> an(n);
  rep(i, n) cin >> an[i];
  rep(i, n) {

    if (an[i] == 0)
      flag = false;
    else {
      if (result != result * an[i] / an[i] || result * an[i] > ll(1e18))
        flag = true;
    }
    result *= an[i];
  }
  if (flag)
    cout << -1;
  else
    cout << result;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18) + 1;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  unsigned long long result = 1;
  bool flag = false;
  vector<ll> an(n);
  rep(i, n) cin >> an[i];
  rep(i, n) {
    if (result != result * an[i] / an[i] || result * an[i] > ll(1e18))
      flag = true;
    if (an[i] == 0)
      flag = false;
    result *= an[i];
  }
  if (flag)
    cout << -1;
  else
    cout << result;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[100010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int zero = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      zero++;
    }
  }
  if (zero > 0) {
    cout << 0 << endl;
    return 0;
  }
  long long prod = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << prod << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  long long a[100010];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int z = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      z++;
    }
  }
  if (z > 0) {
    cout << '0' << endl;
  }
  long long prod = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      cout << "-1" << endl;
    }
  }
  cout << prod << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;

  int64_t b = 1;
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    if (b != -1) {
      int64_t c = 1000000000000000000 / b;
      if (a > c)
        b = -1;
      else
        b *= a;
    } else if (a == 0) {
      b = 0;
      break;
    }
  }

  cout << b << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;

  int64_t b = 1;
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    if (b != -1) {
      if (a > 1000000000000000000 / b)
        b = -1;
      else
        b *= a;
    } else if (a == 0)
      b = 0;
  }

  cout << b << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, ans = 1;
  bool zeros = false, o = false;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0)
      zeros = true;
  }
  if (!zeros) {
    for (ll i = 0; i < n; i++) {
      if (ans > 1000000000000000000 / a[i]) {
        o = true;
      } else {
        ans *= a[i];
      }
    }
  }
  if (zeros)
    cout << 0 << endl;
  else if (o)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, ans = 1;
  bool zeros = false, o = false;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0)
      zeros = true;
  }
  for (ll i = 0; i < n; i++) {
    if (ans > 1000000000000000000 / a[i]) {
      o = true;
    } else {
      ans *= a[i];
    }
  }
  if (zeros)
    cout << 0 << endl;
  else if (o)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll ans = 1;
  bool is_zero = false;
  vll a(n);
  REP(i, n) {
    cin >> a[i];
    if (a[i] == 0)
      is_zero = true;
  }
  // zero
  if (is_zero == true) {
    cout << "0\\n";
    return 0;
  }

  // not zero
  REP(i, n) {
    if (a[i] <= (ll)1e18 / ans) {
      ans *= a[i];
    } else {
      cout << "-1\\n";
      return 0;
    }
  }
  cout << ans << "\\n";
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll ans = 1;
  bool is_zero = false;
  vll a(n);
  REP(i, n) {
    cin >> a[i];
    if (a[i] == 0)
      is_zero = true;
  }
  // zero
  if (is_zero == true) {
    cout << "0\\n";
    return 0;
  }

  // not zero
  bool is_overflow = false;
  REP(i, n) {
    ans *= a[i];
    if (a[i] <= (ll)1e18 / ans) {
      is_overflow = true;
      break;
    }
  }
  if (is_overflow == true) {
    cout << "-1\\n";
    return 0;
  }
  cout << ans << "\\n";
  return 0;
}