alexjercan/bugnet huggingface dataset:
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
  int a, over = 0;
  long long int total = 1;
  cin >> a;
  for (int k = 0; k < a; k++) {
    long long int b;
    cin >> b;
    if (b != 0 && total > 1000000000000000000ll / b) {
      over++;
    } else if (b == 0) {
      cout << 0;
      return 0;
    } else {
      total *= b;
    }
  }
  if (over > 0) {
    cout << -1;
  } else {
    cout << total;
  }
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
  int a, over = 0;
  long long int total = 1;
  cin >> a;
  for (int k = 0; k < a; k++) {
    long long int b;
    cin >> b;
    if (total > 1000000000000000000ll / b) {
      over++;
    } else if (b == 0) {
      cout << 0;
      return 0;
    } else {
      total *= b;
    }
  }
  if (over > 0) {
    cout << -1;
  } else {
    cout << total;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
namespace mp = boost::multiprecision;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

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

  sort(all(A));

  mp::cpp_int ans = 1;

  rep(i, N) {
    ans *= A[i];
    if (ans > 1000000000000000000) {
      cout << -1 << endl;
      return 0;
    }
    if (ans == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
namespace mp = boost::multiprecision;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

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

  mp::cpp_int ans = 1;

  rep(i, N) {
    mp::cpp_int a;
    cin >> a;
    ans *= a;
  }

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

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

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  bool flag = true, zero = false;
  ll a[n], ans = 1, maxi = 1e18;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (ans != 0 && a[i] > maxi / ans) {
      flag = false;
    }
    if (a[i] == 0) {
      zero = true;
    }
    ans = ans * a[i];
  }
  if (flag && !zero) {
    cout << ans << "\\n";
  } else if (zero) {
    cout << "0\\n";
  } else {
    cout << "-1\\n";
  }
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  bool flag = true, zero = false;
  ll a[n], ans = 1, maxi = 1e18;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (!zero && a[i] > maxi / ans) {
      flag = false;
    }
    if (a[i] == 0) {
      zero = true;
    }
    ans = ans * a[i];
  }
  if (flag && !zero) {
    cout << ans << "\\n";
  } else if (zero) {
    cout << "0\\n";
  } else {
    cout << "-1\\n";
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  vector<long long> b(n);
  b = a;
  sort(b.begin(), b.end());
  if (b.at(0) == 0) {
    cout << 0 << endl;
  } else {
    long long ans = 1;
    for (int i = 0; i < n; i++) {
      if (a.at(i) <= 1000000000000000000 / ans) {
        ans = a.at(i) * ans;
      } else {
        ans = -1;
        break;
      }
    }
    cout << ans << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {
  int n;
  vector<long long> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  vector<long long> b(n);
  b = a;
  sort(b.begin(), b.end());
  if (b.at(0) == 0) {
    cout << 0 << endl;
  } else {
    long long ans;
    for (int i = 0; i < n; i++) {
      if (a.at(i) <= 1000000000000000000 / ans) {
        ans = a.at(i) * ans;
      } else {
        ans = -1;
        break;
      }
    }
    cout << ans << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
#define LOCAL
const ll MX = 1e18;

int main() {
  int n;
  ll ans = 1;
  cin >> n;
  bool ng = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || MX / ans < a) {
      ng = true;
    }
    ans *= a;
  }
  if (ng)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
const ll MAXN = 1e18;
#define LOCAL

ull a;

int main() {
  ios::sync_with_stdio(false);
  cout.tie(0), cin.tie(0);
  int t;
  cin >> t;
  ull ans = 1;
  int flag = 0;
  // int flag = 0, flag2 = 0;
  for (int i = 0; i < t; i++) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (MAXN / ans < a) {
      flag = 1;
    }
    ans *= a;
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
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)
using ll = long long;
using P = pair<int, int>;

using namespace std;

int N;
string s;
unsigned long long a[100005];

int main() {
  cin >> N;
  // 0 除外
  unsigned long long prod = 1;
  unsigned long long tmp;
  rep(i, N) {
    cin >> tmp;
    if (tmp == 0) {
      cout << "0";
      return 0;
    }
    a[i] = tmp;
  }
  unsigned long long max_;
  rep(i, N) {
    max_ = 1000000000000000000 / prod;
    if (a[i] > max_) {
      cout << "-1";
      return 0;
    }
    prod *= a[i];
  }
  cout << prod;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

using namespace std;

int N;
string s;
unsigned long long a[10005];

int main() {
  cin >> N;
  unsigned long long prod = 1;
  unsigned long long tmp;
  rep(i, N) {
    cin >> tmp;
    if (tmp == 0) {
      cout << "0";
      return 0;
    }
    a[i] = tmp;
  }
  rep(i, N) {
    unsigned long long max_ = 1000000000000000000 / prod;
    if (a[i] > max_) {
      cout << "-1";
      return 0;
    }
    prod *= a[i];
  }
  cout << prod;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define faster                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define f(i, a, b) for (ll i = a; i < b; i++)
#define r(i, a, b) for (ll i = a; i > b; i--)
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1000000000000000000;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool tr = false;
  f(i, 0, n) {
    ll a;
    cin >> a;

    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (tr || INF / ans < a) {
      tr = true;
    }

    ans *= a;
  }
  if (tr) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define faster                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define f(i, a, b) for (ll i = a; i < b; i++)
#define r(i, a, b) for (ll i = a; i > b; i--)
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1000000000000000000;

int main() {
  ll n;
  cin >> n;

  bool tr = false;
  ll ans = 1;

  f(i, 0, n) {

    ll a;
    cin >> a;
    if (a == 0) {
      cout << "0" << endl;
      return 0;
    }

    if ((INF / ans < a) || tr) {
      tr = true;
    }

    ans *= a;
  }

  if (tr) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define faster                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define f(i, a, b) for (ll i = a; i < b; i++)
#define r(i, a, b) for (ll i = a; i > b; i--)
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1000000000000000000;

int main() {
  ll n;
  cin >> n;

  bool tr = false;
  ll ans = 1;

  f(i, 0, n) {

    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (tr || (INF / ans < a)) {
      tr = true;
    }

    ans *= a;
  }

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

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define faster                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define f(i, a, b) for (ll i = a; i < b; i++)
#define r(i, a, b) for (ll i = a; i > b; i--)
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1000000000000000000;

int main() {
  ll n;
  cin >> n;

  bool tr = false;
  ll ans = 1;

  f(i, 0, n) {

    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }

    if ((INF / ans < a) || tr) {
      tr = true;
    }

    ans *= a;
  }

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

  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
namespace mp = boost::multiprecision;

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

  vector<long long> vec(n);
  rep(i, n) { cin >> vec.at(i); }
  bool zero = false;
  rep(i, n) {
    if (vec.at(i) == 0) {
      zero = true;
    }
  }

  if (zero == false) {
    mp::int256_t seki = 1;
    rep(i, n) {
      seki *= vec.at(i);
      if (seki > 1000000000000000000) {
        seki = -1;

        break;
      }
    }

    cout << seki;
  }

  else {
    cout << 0;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

namespace mp = boost::multiprecision;

int main() {
  int N;
  cin >> N;
  vector<mp::cpp_int> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  mp::cpp_int s = 1;

  for (int i = 0; i < N; i++) {
    s *= a.at(i);
  }

  if (s > 1000000000000000000) {
    cout << -1;
  } else {
    cout << s;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int N;
  long long A[100000];
  long long ans = 1;

  cin >> N;
  rep(i, N) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

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

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int N;
  long long A[100000];
  long long ans = 1;

  cin >> N;
  rep(i, N) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0;
      exit(0);
    }
  }

  rep(i, N) {
    if (ans > 1000000000000000000.0 / A[i]) {
      cout << -1;
      exit(1);
    }
    ans *= A[i];
  }
  cout << ans;

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

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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for (uint64_t i = start; i < end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) { return (m * n) / gcd(m, n); }

void comb(vector<vector<uint64_t>> &v) {
  for (uint64_t i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (uint64_t k = 1; k < v.size(); k++) {
    for (uint64_t j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
    }
  }
}

bool is_product_overflow(uint64_t a, uint64_t b) {

  uint64_t prod = a * b;

  return (prod / b != a);
}

signed main() {
  uint64_t n;
  cin >> n;

  uint64_t aMax = 1000000000000000000;
  uint64_t a = 0;
  uint64_t aMul = 1;
  bool isOver = false;
  bool doesZeroExist = false;
  REP(i, n) {
    cin >> a;
    if (a == 0)
      doesZeroExist = true;
    if (!isOver && aMax / a < aMul) {
      isOver = true;
    } else {
      aMul *= a;
    }
  }
  if (doesZeroExist) {
    cout << "0" << endl;
    return 0;
  }
  if (isOver) {
    cout << "-1" << endl;
    return 0;
  }
  cout << aMul << endl;
  return 0;
}

Error: WA

Fixed submission:

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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for (int64_t i = start; i < end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) { return (m * n) / gcd(m, n); }

void comb(vector<vector<uint64_t>> &v) {
  for (uint64_t i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (uint64_t k = 1; k < v.size(); k++) {
    for (uint64_t j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
    }
  }
}

bool is_product_overflow(uint64_t a, uint64_t b) {

  uint64_t prod = a * b;

  return (prod / b != a);
}

signed main() {
  uint64_t n;
  cin >> n;

  uint64_t aMax = 1000000000000000000;
  uint64_t a = 0;
  uint64_t aMul = 1;
  bool isOverflow = false;
  bool doesZeroExist = false;
  REP(i, n) {
    cin >> a;
    if (a == 0)
      doesZeroExist = true;
    isOverflow = is_product_overflow(a, aMul);
    if (!isOverflow) {
      aMul *= a;
    }
  }
  if (doesZeroExist) {
    cout << "0" << endl;
    return 0;
  }
  if (aMul > aMax || !isOverflow) {
    cout << "-1" << endl;
    return 0;
  }
  cout << aMul << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\\n'
int main() {
  int N;
  cin >> N;
  vector<lli> A(N + 10);
  rep(i, 0, N) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  lli res = 1;
  const lli limit = 1000000000000000000;
  rep(i, 0, N) {
    if (A[i] > limit / res) {
      res = -1;
      break;
    }
    res *= A[i];
  }
  cout << res << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\\n'
int main() {
  int N;
  cin >> N;
  vector<lli> A(N + 10);
  rep(i, 0, N) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  lli res = 1;
  const lli limit = 1000000000000000000;
  rep(i, 0, N) {
    res *= A[i];
    if (limit / res == 0) {
      res = -1;
      break;
    }
  }
  cout << res << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a;
  long long ans1 = 1000000000000000000, ans2 = 1;
  int flag = 0;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a);
    if (a != 0)
      ans1 /= a;
    if (a == 0)
      flag = 1;
    ans2 *= a;
  }
  if (flag)
    printf("0\\n");
  else if (ans1 == 0)
    printf("-1\\n");
  else
    printf("%lld\\n", ans2);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  long long count = 1;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  sort(a, a + n);
  int i;
  for (i = 0; i < n; i++) {
    if (count > 1000000000000000000 / a[i])
      break;
    else
      count = count * a[i];
  }
  if (i < n)
    printf("-1\\n");
  else
    printf("%lld\\n", count);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <map>
#include <string>
typedef unsigned long long ll;
const ll inf = 1e18;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1, temp, t;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (temp == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (inf / temp < ans)
      flag = 1;
    else
      ans *= temp;
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <string>
typedef unsigned long long ll;
const ll inf = 1e18;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1, temp, t;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (inf / temp < ans)
      flag = 1;
    else
      ans *= temp;
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;

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

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

int main() {
  long long int n, m = 1;
  cin >> n;
  long long int a[n + 2];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      exit(0);
    }
  }
  for (int i = 0; i < n; i++) {
    if (1000000000000000000 / a[i] < m || m < 0) {
      cout << -1 << endl;
      exit(0);
    }

    m *= a[i];
  }
  cout << m << endl;
}

Error: -11

Fixed submission:

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

int main() {
  long long int n, m = 1, a[n + 2];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      exit(0);
    }
  }
  for (int i = 0; i < n; i++) {
    m *= a[i];
    if (1000000000000000000 < m || m < 0) {
      cout << -1 << endl;
      exit(0);
    }
  }
  cout << m << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
// vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main() {
  long long int n;
  long long tmp;
  cin >> n;
  long long int res = 1;
  vector<int> a(n);
  int flag_zero = 0;
  int flag_18 = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp == 0) {
      flag_zero = 1;
      break;
    }
    if (tmp <= 1000000000000000000 / res) {
      res = res * tmp;
    } else {
      flag_18 = 1;
    }
  }

  // flag++;
  // cout << flag << endl;
  // cout << res << endl;

  if (flag_zero == 1) {
    cout << 0 << endl;
  } else if (flag_18 == 1) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
}
// 1000000000000000000
// 9223372036854775807
// 1000000000000000001

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main() {
  long long int n;
  long long tmp;
  cin >> n;
  long long int res = 1;
  vector<int> a(n);
  int flag_zero = 0;
  int flag_18 = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp == 0) {
      flag_zero = 1;
    }
    if (tmp <= 1000000000000000000 / res) {
      res = res * tmp;
    } else {
      flag_18 = 1;
    }
  }

  // flag++;
  // cout << flag << endl;
  // cout << res << endl;

  if (flag_zero == 1) {
    cout << 0 << endl;
  } else if (flag_18 == 1) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
}
// 1000000000000000000
// 9223372036854775807
// 1000000000000000001