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

#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long ans = 1;
  for (int i = 0; i < N; i++) {
    if (INF / A[i] < ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= A[i];
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long long N;
  cin >> N;
  long long ans = 1;
  vector<long long> vec(N);
  for (long long i = 0; i < N; i++) {
    cin >> vec.at(i);
    if (vec.at(i) == 0) {
      cout << 0;
      return 0;
    }
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  if (N < 4) {
    for (int i = 0; i < N; i++) {
      ans *= vec.at(i);
    }
    cout << ans << endl;
    return 0;
  }
  for (long long i = 0; i < N - 2; i++) {
    ans = ans * vec.at(i);
    if (ans > 250000000000000000) {
      cout << -1;
      return 0;
    }
  }
  ans *= vec.at(N) * vec.at(N - 1);
  cout << ans;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define ll long long

using namespace std;

ll a[100010];

int main() {
  int n;
  cin >> n;
  bool x = true;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0)
      x = false;
  }
  ll tar = 1e18;
  ll ans = 1;
  bool f = true;
  for (int i = 0; x && i < n; ++i) {
    if (a[i] > tar / ans) {
      cout << -1 << endl;
      f = false;
      break;
    } else
      ans *= a[i];
  }
  if (f && x)
    cout << ans << endl;
  if (!x)
    cout << 0 << endl;
  return 0;
}

Error: 0

Fixed submission:

// #include<bits/stdc++.h>
#pragma warning(disable : 4996)
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define ll long long

using namespace std;

ll a[100010];

int main() {
  int n;
  cin >> n;
  bool x = true;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0)
      x = false;
  }
  ll tar = 1e18;
  ll ans = 1;
  bool f = true;
  for (int i = 0; i < n; ++i) {
    if (a[i] > tar / ans && x) {
      cout << -1 << endl;
      f = false;
      break;
    } else
      ans *= a[i];
  }
  if (f && x)
    cout << ans << endl;
  if (!x)
    cout << 0 << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main(void) {
  int N;
  long long a[1000000], r = 1;

  cin >> N;

  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 / r) {
      cout << "-1" << endl;
      return 0;
    }

    r *= a[i];

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

  cout << r << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {
  int N;
  long long a[1000000], r = 1;

  cin >> N;
  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) {
      cout << "-1" << endl;
      return 0;
    }

    r *= a[i];
    if (a[i] < 1000000000000000000 / r) {
      cout << "-1" << endl;
      return 0;
    }
  }

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

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

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


Error: 0

Fixed submission:

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

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

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

int main() {
  int n;
  cin >> n;
  bool isOver = false;
  __int128_t a = 1;
  const __int128_t INF = 1e18;
  ll b;
  rep(i, n) {
    cin >> b;
    if (b == 0) {
      cout(0);
      return 0;
    }
    if (!isOver) {
      a *= b;
      if (a > INF)
        isOver = true;
    }
  }
  if (isOver)
    cout(-1);
  else
    cout((ll)a);
}


Error: 0

Fixed submission:

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

int main() {
  int n;
  ll result = 1;
  vector<ll> b(n);
  cin >> n;
  rep(i, n) {
    cin >> b[i];
    if (b[i] == 0) {
      cout(0);
      return 0;
    }
  }
  rep(i, n) {
    result *= b[i];
    if (result > 1000000000000000000ll || result < 0) {
      cout(-1);
      return 0;
    }
  }
  cout(result);
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d", x)
#define plld(x) printf("%lld", x)
#define pds(x) printf("%d ", x)
#define pllds(x) printf("%lld ", x)
#define pdn(x) printf("%d\\n", x)
#define plldn(x) printf("%lld\\n", x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base, ll exponent, ll mod) { // with mod < 1e9
  ll ans = 1;
  while (exponent) {
    if (exponent & 1)
      ans = (ans * base) % mod;
    base = (base * base) % mod;
    exponent /= 2;
  }
  return ans;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
const int upperlimit = 1e6 + 1;
const int mod = 998244353;
int main() {
  //	freopen(".in","r",stdin);freopen(".out","w",stdout);
  ll gg = 1000000000000000000, ans = 1, inp;
  bool is0 = false;
  int n;
  sd(n);
  for (int i = 1; i <= n; i++) {
    slld(inp);
    ans *= inp;
    if (inp)
      gg /= inp;
    else
      is0 = true;
  }
  if (is0)
    pd(0);
  else if (!gg)
    pd(-1);
  else
    plld(ans);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d", x)
#define plld(x) printf("%lld", x)
#define pds(x) printf("%d ", x)
#define pllds(x) printf("%lld ", x)
#define pdn(x) printf("%d\\n", x)
#define plldn(x) printf("%lld\\n", x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base, ll exponent, ll mod) { // with mod < 1e9
  ll ans = 1;
  while (exponent) {
    if (exponent & 1)
      ans = (ans * base) % mod;
    base = (base * base) % mod;
    exponent /= 2;
  }
  return ans;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
const int upperlimit = 1e6 + 1;
const int mod = 998244353;
ll a[upperlimit];
int main() {
  //	freopen(".in","r",stdin);freopen(".out","w",stdout);
  ll gg = 1000000000000000000, ans = 1;
  int n;
  sd(n);
  for (int i = 1; i <= n; i++) {
    slld(a[i]);
    ans *= a[i];
    gg /= a[i];
  }
  if (!gg)
    pd(-1);
  else
    plld(ans);
  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;

long long int pow_num(int n, int p) {
  long long int sum = 1;
  rep(i, p) sum *= n;
  return sum;
}

int main() {
  int N;
  cin >> N;
  long long int A[N];
  long long int ans = 1;
  int flag = 0;
  rep(i, N) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << "0" << endl;
      return 0;
    }
    int num_A = 0;
    int num_ans = 0;
    int A_sub = A[i];
    while (true) {
      A_sub /= 10;
      num_A++;
      if (A_sub < 10)
        break;
    }
    int ans_sub = ans;
    while (true) {
      ans_sub /= 10;
      num_ans++;
      if (ans_sub < 10)
        break;
    }

    if (1000000000000000000 / ans < A[i]) {
      ans = -1;
      flag = 1;
    } else if (num_A + num_ans > 17 && A_sub * ans_sub >= 10) {
      ans = -1;
      flag = 1;
    } else if (ans * A[i] > pow_num(10, 18)) {
      ans = -1;
      flag = 1;
    }
    if (flag == 0)
      ans = A[i] * ans;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

long long int pow_num(int n, int p) {
  long long int sum = 1;
  rep(i, p) sum *= n;
  return sum;
}

int main() {
  int N;
  cin >> N;
  long long int A[N];
  long long int ans = 1;
  int flag = 0;
  rep(i, N) {
    cin >> A[i];
    if (A[i] == 0) {
      ans = 0;
      flag = 1;
    }
    int num_A = 0;
    int num_ans = 0;
    int A_sub = A[i];
    while (true) {
      A_sub /= 10;
      num_A++;
      if (A_sub < 10)
        break;
    }
    int ans_sub = ans;
    while (true) {
      ans_sub /= 10;
      num_ans++;
      if (ans_sub < 10)
        break;
    }

    if (1000000000000000000 / ans < A[i] && ans != 0) {
      ans = -1;
      flag = 1;
    } else if (num_A + num_ans > 17 && A_sub * ans_sub >= 10) {
      ans = -1;
      flag = 1;
    } else if (ans * A[i] > pow_num(10, 18)) {
      ans = -1;
      flag = 1;
    }
    if (flag == 0)
      ans = A[i] * ans;
  }

  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 mult = 1;
  bool can = true;
  bool zero = false;
  long long arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  sort(arr, arr + n);
  for (int i = 0; i < n; i++) {
    if (!arr[i]) {
      zero = true;
      break;
    }
    if (can && mult > ((long long)1e18 + arr[i] - 1) / arr[i]) {
      can = false;
      break;
    }
    if (can) {
      mult *= arr[i];
    }
  }

  if (zero) {
    cout << 0 << endl;
  } else {
    if (!can || mult > (long long)1e18) {
      cout << -1 << endl;
      ;
    } else {
      cout << mult << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long mult = 1;
  bool can = true;
  bool zero = false;
  long long arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  sort(arr, arr + n);
  for (int i = 0; i < n; i++) {
    if (can && mult > ((long long)1e18 + arr[i] - 1) / arr[i]) {
      can = false;
      break;
    }
    if (can) {
      mult *= arr[i];
    }
    if (!arr[i]) {
      zero = true;
      break;
    }
  }

  if (zero) {
    cout << 0 << endl;
  } else {
    if (!can || mult > (long long)1e18) {
      cout << -1 << endl;
      ;
    } else {
      cout << mult << 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 Z = 1, A = 0;
  int64_t K = 1000000000000000000;
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    if (1 + (K - 1) / Z < a && a != 0) {
      A++;
    } else {
      Z *= a;
    }
    if (Z == 0) {
      break;
    }
  }
  if ((A == 0 && Z <= K) || Z == 0) {
    cout << Z << endl;
  } else {
    cout << "-1" << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int64_t Z = 1, A = 0;
  int64_t K = 1000000000000000000;
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    if (1 + (K - 1) / Z < a && a != 0) {
      A++;
    } else {
      Z *= a;
    }
  }
  if ((A == 0 && Z <= K) || Z == 0) {
    cout << Z << endl;
  } else {
    cout << "-1" << 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 < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()

int main() {
  int N;
  cin >> N;
  uint64_t ans = 1;
  vector<string> a(N);
  rep(i, N) cin >> a[i];

  rep(i, N) {
    if (a[i] == "0") {
      ans = 0;
      cout << ans << endl;
      return 0;
    }
  }
  rep(i, N) {
    if (a[i].size() > 18 && a[i] != "1000000000000000000") {
      cout << "-1" << endl;
      return 0;
    }
  }

  rep(i, N) {
    if (to_string(ans).size() + a[i].size() >= 20 &&
        !(ans == 1000000000 && a[i] == "1000000000")) {
      cout << "-1" << endl;
      return 0;
    }
    ans *= stoull(a[i]);
  }
  if (ans > 1000000000000000000ULL) {
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  uint64_t ans = 1;
  vector<string> a(N);
  rep(i, N) cin >> a[i];

  rep(i, N) {
    if (a[i] == "0") {
      ans = 0;
      cout << ans << endl;
      return 0;
    }
  }
  rep(i, N) {
    if (a[i].size() > 18 && a[i] != "1000000000000000000") {
      ans = -1;
      cout << ans << endl;
      return 0;
    }
  }

  rep(i, N) {
    if (to_string(ans).size() + a[i].size() > 20) {
      ans = -1;
      break;
    }
    ans *= stoi(a[i]);
  }

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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
lint inf = 1E18L + 1;
int main() {
  int n;
  lint out = 1, a;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (out < 1L)
      continue;
    if (inf / out + 1 < a)
      out = inf;
    else
      out *= a;
  }
  if (out >= inf)
    cout << -1 << endl;
  else
    cout << out << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
lint inf = 1E18L + 1;
int main() {
  int n;
  lint out = 1, a;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (inf / out + 1 < a)
      out = inf;
    else
      out *= a;
  }
  if (out >= inf)
    cout << -1 << endl;
  else
    cout << out << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\\n'
#define pb push_back
#define mp make_pair
#define SPEED                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define MOD 1000000007
#define INF 1e18
#define M 1000000009
#define pi 3.14159265358979323846264338327950
typedef pair<int, int> pr;
#define N 1000002
signed main() {
  SPEED;
  int n;
  cin >> n;
  int a[n], ans = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (a[0] == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (ans > (1000000000000000000 / a[i])) {
      cout << -1;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\\n'
#define pb push_back
#define mp make_pair
#define SPEED                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define MOD 1000000007
#define INF 1e18
#define M 1000000009
#define pi 3.14159265358979323846264338327950
typedef pair<int, int> pr;
#define N 1000002
signed main() {
  SPEED;
  int n;
  cin >> n;
  int a[n], ans = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; ++i) {
    if (ans > (1000000000000000000 / a[i])) {
      cout << -1;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

const ll MX = 1e18;

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

Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool flag0 = false;
  bool inf = false;
  ll m = 1;
  rep(i, 18) { m *= 10; }
  rep(i, n) {
    ll a;
    cin >> a;
    // ll cnt = ans;
    double f = (double)(m / ans);
    if (a > f)
      inf = true;
    if (a == 0) {
      flag0 = true;
      break;
    }
    ans *= a;
  }

  if (flag0) {
    cout << 0 << endl;
  } else if (inf) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

const ll MX = 1e18;

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

Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool flag = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (MX / ans < a)
      flag = true;
    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;
using ll = unsigned long long;
const ll mx = 1000000000000000000;

bool is_ok(ll a, ll b) { return (mx / a < b ? 0 : 1); }

int main() {
  int n, i;
  cin >> n;
  ll arr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  // cout<<arr[0]*arr[1]<<"\\n";
  ll ans = 1;
  bool ok = 1;
  sort(arr, arr + n);
  if (arr[0] != 0)
    for (i = 0; i < n; i++) {
      if (!is_ok(ans, arr[i])) {
        ok = 0;
        break;
      }
      ans *= arr[i];
      if (ans > mx)
        ok = 0;
    }
  else
    ans = 0;
  if (ok)
    cout << (ll)ans;
  else
    cout << -1;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = unsigned long long;
const ll mx = 1000000000000000000;

bool is_ok(ll a, ll b) { return (mx / a <= b ? 0 : 1); }

int main() {
  int n, i;
  cin >> n;
  ll arr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  // cout<<arr[0]*arr[1]<<"\\n";
  ll ans = 1;
  bool ok = 1;
  sort(arr, arr + n);
  for (i = 0; i < n; i++) {
    if (!is_ok(ans, arr[i])) {
      ok = 0;
      break;
    }
    ans *= arr[i];
    if (ans > mx)
      ok = 0;
  }
  if (ok)
    cout << (ll)ans;
  else
    cout << -1;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int N;
  cin >> N;
  long A[N];
  long long result = 1;
  long long thre = 1000000000000000000;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  if (A[0] == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = N - 1; i >= 0; i--) {
      if (A[i] <= thre / result) {
        result *= A[i];
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << result << endl;

  return 0;
}


Error: WA

Fixed submission:

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

int main(void) {
  int N;
  cin >> N;
  long A[N];
  long long result = 1;
  long long thre = 1000000000000000000;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  if (A[0] == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = N - 1; i >= 0; i--) {
      result *= A[i];
      if (thre / result > 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << result << endl;

  return 0;
}