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

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

int N;

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

Error: 0

Fixed submission:

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

int N;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll n;
  cin >> n;
  ll row[n];
  ll result = 1;
  for (int i = 0; i < n; i++) {
    cin >> row[i];
    if (row[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (row[i] <= 1000000000000000000 / result) {
      result *= row[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << result << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll n;
  ll row[n];
  ll result = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> row[i];
  }
  for (int i = 0; i < n; i++) {
    result *= row[i];
    if (result > 1000000000000000000) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << result << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <cassert>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

//< in.txt > out.txt
using namespace std;
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
const long long MOD = 1000000007;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  LL N;
  cin >> N;
  VLL A(N);
  for (LL n = 0; n < N; n++) {
    cin >> A[n];
    if (A[n] == 0) {
      cout << 0 << "\\n";
      return 0;
    }
  }
  bigint res(A[0]);
  bigint cri(1e18);
  for (LL n = 1; n < N; n++) {
    bigint temp(A[n]);
    res *= temp;
    if (res > cri) {
      cout << -1 << "\\n";
      return 0;
    }
  }
  cout << res << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <cassert>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

//< in.txt > out.txt
using namespace std;
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
const long long MOD = 1000000007;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  LL N;
  cin >> N;
  LL A;
  cin >> A;
  bigint res(A);
  bigint cri(1e18);
  for (LL n = 1; n < N; n++) {
    cin >> A;
    bigint temp(A);
    res *= temp;
  }
  if (res > cri) {
    cout << -1 << "\\n";
  } else {
    cout << res << "\\n";
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

const long long INF = 1000000000000000000LL;

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

  bool over = false;
  bool zero = false;
  long long res = 1;
  for (int i = 0; i < N; i++) {
    long long A;
    std::cin >> A;
    if (A == 0) {
      zero = true;
    } else if (INF / res < A) {
      over = true;
      res = 1;
    } else {
      res *= A;
    }
  }

  if (zero == true) {
    std::cout << 0 << "\\n";
  } else if (over == false || zero == true) {
    std::cout << res << "\\n";
  } else {
    std::cout << "-1\\n";
  }
}

Error: 0

Fixed submission:

#include <iostream>

const long long INF = 1000000000000000000LL;

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

  bool over = false;
  long long res = 1;
  for (int i = 0; i < N; i++) {
    long long A;
    std::cin >> A;
    if (INF / res < A) {
      over = true;
      res = 1;
    } else {
      res *= A;
    }
  }

  if (over == false || res == 0) {
    std::cout << res << "\\n";
  } else {
    std::cout << "-1\\n";
  }
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using ll = mp::cpp_int;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define REP3(i, x, n) for (ll i = x; i > (n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();

int main() {
  int N;
  ll ans = 1;
  cin >> N;
  ll A[N];

  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << "0" << endl;
      return 0;
    }
    A[i] = a;
  }
  for (int i = 0; i < N; i++) {

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

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using ll = mp::cpp_int;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define REP3(i, x, n) for (ll i = x; i > (n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();

int main() {
  long long N;
  ll ans = 1;
  cin >> N;
  vector<ll> A(N);

  for (ll i = 0; i < N; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << "0" << endl;
      return 0;
    }
    ans *= a;
  }
  if (ans > 1000000000000000000) {
    cout << "-1" << endl;
    return 0;
  }

  cout << ans << endl;

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

#include <iostream>

using namespace std;

#define ll long long

const ll int MAX = 1e18;

int main() {

  int i;
  ll int ans = 1;
  int fover = 0;
  int zerocnt = 0;
  cin >> i;

  ll int j[100000];
  for (int cnt = 0; cnt < i; cnt++) {
    cin >> j[cnt];
    if (j[cnt] == 0) {
      zerocnt++;
    }
  }
  if (zerocnt == 0) {

    for (int cnt = 0; cnt < i; cnt++) {

      if (j[cnt] <= MAX / ans) {
        ans *= j[cnt];
      } else {
        fover++;
        break;
      }
    }
  }

  if (fover > 0) {
    ans = -1;
  }
  if (zerocnt > 0) {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

#define ll long long
#define endl '\\n'
#define PI 3.1415926535897932384
using namespace std;

const ll int N = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ar[10000], ans = 1, zero = 0;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] == 0) {
      zero++;
    }
  }
  if (zero > 0)
    ans = 0;
  else {
    for (int i = 0; i < n; i++) {
      if (ar[i] <= N / ans)
        ans *= ar[i];
      else {
        ans = -1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  long long N;
  scanf("%lld", &N);
  long long A[N], sum = 1;

  for (long long i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }

  for (long long i = 0; i < N; i++) {
    if (A[i] == 0) {
      printf("0\\n");
      return 0;
    }
  }

  for (long long i = 0; i < N; i++) {
    if (A[i] <= (1000000000000000000 / sum)) {
      sum *= A[i];
    } else {
      printf("-1\\n");
      return 0;
    }
  }

  printf("%lld\\n", sum);

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int N, janganprint = 0;
  scanf("%d", &N);
  long long A[N], temp, sb, sum = 1;

  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    if (A[i] == 0) {
      printf("0");
      janganprint++;
      break;
    }
    if (A[i] > 1000000000000000000) {
      printf("-1");
      janganprint++;
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    temp = A[i];
    sb = 1000000000000000000 / temp;
    if (A[i + 1] > sb) {
      printf("-1");
      janganprint++;
      break;
    }
  }

  for (int i = 0; i < N; i++) {
    sum = sum * A[i];
  }

  if (janganprint == 0) {
    printf("%lld\\n", sum);
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back
#define inf 10000000000

// nestedcode

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, i, s, fl = 0, a;
  s = 1;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      fl = 2;
      continue;
    }
    if ((1000000000000000000 % a == 0) && (1000000000000000000 / a < s)) {
      fl = 1;
    }
    if ((1000000000000000000 % a != 0) && ((1000000000000000000 / a) + 1 < s)) {
      fl = 1;
    }
    s *= a;
  }
  if (fl == 1 || s > 1000000000000000000)
    cout << -1;
  else if (fl == 2)
    cout << 0 << endl;
  else
    cout << s;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back
#define inf 10000000000

// nestedcode

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, i, s, fl = 0, a;
  s = 1;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    if (1000000000000000000 % a == 0 && 1000000000000000000 / a > s) {
      fl = 1;
    }
    if (1000000000000000000 % a != 0 && 1000000000000000000 / a + 1 > s) {
      fl = 1;
    }
    s *= a;
  }
  if (fl)
    cout << -1;
  else
    cout << s;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\\n'
#define main() int main()
#define ff1(i, n) for (int i = 1; i <= n; ++i)
#define ff0(i, n) for (int i = 0; i < n; ++i)
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x) & (-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define fir first
#define sec second
#define debug(x) cout << x << '\\n'
#define sa(a) scanf("%d", &a)
#define sab(a, b) scanf("%d%d", &a, &b)
#define pa(a) printf("%d", a)
#define pab(a, b) printf("%d%d", a, b)
#define pii pair<int, int>
using namespace std;

#define maxn 200005
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll powmod(ll a, ll b) {
  ll ans = 1, pow = a % mod;
  while (b) {
    if (b & 1)
      ans = (ans * pow) % mod;
    pow = (pow * pow) % mod;
    b >>= 1;
  }
  return ans % mod;
}
ull a[maxn];
const ll maxx = 1e18;
bool judge(ull a, ull b) {
  if (maxx / a < b) {
    return true;
  }
  return false;
}
main() {
  int n;
  cin >> n;
  int f = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      f = 0;
  }
  if (f == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    if (judge(ans, a[i])) {
      cout << "-1" << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 101;
const ll inf = 1e18;
ll fast_mul(
    ll a, ll b,
    ll mod) { // 快速乘法a*b%mod，因为在代码里面运算时，乘法会炸long long
  ll ans = 0;
  ll flag = 1;
  if (a < 0)
    a *= -1, flag *= -1;
  if (b < 0)
    b *= -1, flag *= -1;
  while (b) {
    if (b & 1)
      ans = (ans + a) % mod;
    a = (a + a) % mod;
    b >>= 1;
  }
  if (flag == -1)
    return -ans;
  else
    return ans;
}
int main() {
  ll n;
  scanf("%lld", &n);
  ll ans = 1;
  ll flag0 = 0;
  ll exd = 0;
  for (ll i = 1; i <= n; ++i) {
    ll x;
    scanf("%lld", &x);
    if (x == 0)
      flag0 = 1;
    if (inf / ans < x)
      exd = 1;
    else
      ans *= x;
  }
  if (flag0) {
    puts("0");
  } else if (exd) {
    puts("-1");
  } else {
    printf("%lld\\n", ans);
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  long long sum = 1;
  int flag = 0;

  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (sum > 1000000000000000000 / A[i]) {
      flag = 1;
    }
    sum = sum * A[i];
  }
  if (flag == 1) {
    cout << -1 << endl;
    return 0;
  }

  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  long long sum = 1;
  int flag = 0;

  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (sum > 1000000000000000000 / A[i]) {
      flag = 1;
    }
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    sum = sum * A[i];
  }
  if (flag == 1) {
    cout << -1 << endl;
    return 0;
  }

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

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

#define pb push_back
#define sf(x) scanf("%d", &x)
#define sfl(x) scanf("%lld", &x)
#define pf(x) printf("%d\\n", x)
#define pfl(x) printf("%lld\\n", x)
#define endl '\\n'
#define pii pair<int, int>
#define mapii map<int, int>
#define mapll map<ll, ll>
#define mapci map<char, int>
#define mapcl map<char, ll>
#define mapsi map<string, int>
#define mapsl map<string, ll>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double, double>
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define mp make_pair
#define ftc(x) cerr << #x << ": " << x << " " << endl;
#define PI acos(-1)
#define lcm(a, b) ((a * b) / __gcd(a, b))
#define optimize                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define sqr(a) ((a) * (a))
const ll MAx = 1000000000000000000;
int main() {
  ll n, i, j, k, l = 1ll, m;

  cin >> n;

  ll ar[n + 10];

  for (i = 0; i < n; i++) {
    cin >> ar[i];
  }

  sort(ar, ar + n);

  for (i = 0; i < n; i++) {
    if (ar[i] == 0) {
      l = 0;
      break;
    }
    ll fuk = MAx / l;

    if (ar[i] > fuk)
      return cout << -1 << endl, 0;
    //  if((l*ar[i]) > MAx)return cout << -1<< endl,0;
    l = l * ar[i];
  }

  cout << l << endl;
}


Error: 0

Fixed submission:

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

#define pb push_back
#define sf(x) scanf("%d", &x)
#define sfl(x) scanf("%lld", &x)
#define pf(x) printf("%d\\n", x)
#define pfl(x) printf("%lld\\n", x)
#define endl '\\n'
#define pii pair<int, int>
#define mapii map<int, int>
#define mapll map<ll, ll>
#define mapci map<char, int>
#define mapcl map<char, ll>
#define mapsi map<string, int>
#define mapsl map<string, ll>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double, double>
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define mp make_pair
#define ftc(x) cerr << #x << ": " << x << " " << endl;
#define PI acos(-1)
#define lcm(a, b) ((a * b) / __gcd(a, b))
#define optimize                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define sqr(a) ((a) * (a))
const ll MAx = 1000000000000000000;
int main() {
  ll n, i, j, k, l = 1ll, m;

  cin >> n;

  ll ar[n + 10];

  for (i = 0; i < n; i++) {
    cin >> ar[i];
  }

  sort(ar, ar + n);

  for (i = 0; i < n; i++) {
    ll fuk = MAx / l;

    if (ar[i] > fuk)
      return cout << -1 << endl, 0;
    if ((l * ar[i]) > MAx)
      return cout << -1 << endl, 0;
    l = l * ar[i];
  }

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

#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2)                                                   \\
  freopen((string(s) + "." + end1).c_str(), "r", stdin),                       \\
      freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i : x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int MAX = 4e18 + 5, MAX2 = 1e18;
int mul(int a, int b) {
  if (a == 0 || b == 0)
    return 0;
  if (a > MAX / b)
    return MAX;
  return a * b;
}
signed main() {
#ifdef BLU
  in("blu.inp");
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 1;
  cin >> n;
  fw(i, 0, n) {
    int x;
    cin >> x;
    ans = mul(ans, x);
  }
  if (ans > MAX2)
    cout << "-1";
  else
    cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2)                                                   \\
  freopen((string(s) + "." + end1).c_str(), "r", stdin),                       \\
      freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i : x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int MAX = 4e18 + 5, MAX2 = 1e18;
int mul(int a, int b) {
  if (a > MAX / b)
    return MAX;
  return a * b;
}
signed main() {
#ifdef BLU
  in("blu.inp");
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 1;
  cin >> n;
  fw(i, 0, n) {
    int x;
    cin >> x;
    ans = mul(ans, x);
  }
  if (ans > MAX2)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define LIMIT 1000000000000000000

using namespace std;

int main() {
  int n;
  unsigned long long a, ans = 1;
  bool overflow = false;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (!a || !ans || a <= LIMIT / ans) {
      ans *= a;
    } else {
      overflow = true;
    }
  }

  if (!overflow || ans == 0) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#define LIMIT 1000000000000000000

using namespace std;

int main() {
  int n;
  unsigned long long a, ans = 1;
  bool overflow = false;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (!a || a <= LIMIT / ans) {
      ans *= a;
    } else {
      overflow = true;
    }
  }

  if (!overflow || ans == 0) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}
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;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = a[0];
  const ll INF = 1e18;
  for (int i = 1; i < n; i++) {
    if (a[i] > INF / ans) {
      cout << -1 << endl;
      return 0;
    } else {
      ans *= a[i];
    }
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

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

int main() {
  int n;
  const ll max = 1e18;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[n];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = a[0];
  for (int i = 1; i < n; i++) {
    if (a[i] > max / ans) {
      cout << -1 << endl;
      return 0;
    } else {
      ans *= a[i];
    }
  }
  cout << ans << endl;
}