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

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back

const ll MAX = 1e18;

int main() {
  int n;
  cin >> n;
  vll a(100010);
  ll ans = 1;
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (ans <= MAX / a[i]) {
      ans *= a[i];
    } else {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back

const ll MAX = 1e18;

int main() {
  int n;
  cin >> n;
  vll a(10010);
  ll ans = 1;
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (ans <= MAX / a[i]) {
      ans *= a[i];
    } else {
      ans = -1;
      break;
    }
  }
  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 < (int)(n); i++)
#include <math.h>
#include <set>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));

int main() {
  long long int MX = 1e18;
  int n;
  cin >> n;
  long long int a;
  long long int ans = 1;
  bool ng = false;
  rep(i, n) {
    cin >> a;
    if (a == 0) {
      cout << '0';
      return 0;
    }

    if (ng || (MX + 1) / ans < a || ans * a > MX) {
      ng = true;
    }
    ans *= a;
  }
  if (ng)
    cout << "-1";
  else
    cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <math.h>
#include <set>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));

int main() {
  long long int MX = 1e18;
  int n;
  cin >> n;
  long long int a;
  long long int ans = 1;
  bool ng = false;
  rep(i, n) {
    cin >> a;
    if (a == 0) {
      cout << '0';
      return 0;
    }

    if ((MX + 1) / ans < a || ans * a > MX) {
      ng = true;
    }
    ans *= a;
  }
  if (ng)
    cout << "-1";
  else
    cout << ans;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int n;
long long t = 1;
long long a[100000];

int main() {
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];

    if (a[i] == 0)
      t = 0;
  }

  if (t != 0) {

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

      if (t <= 1000000000000000000 / a[i])
        t *= a[i];
      else {
        t = -1;
        break;
      }
    }
  }

  cout << t << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int n;
long long t = 1, a;
const long long M = 1e18;

int main() {
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a;

    if (a == 0 || (t >= 0 && t < M / t + 1 && a * t <= M))
      t *= a;
    else
      t = -1;
  }

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

#include <bits/stdc++.h>

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

using ll = long long int;
const ll MOD = 1e9 + 7;

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

  ll ans = 1;
  ll T = 1000000000000000000LL;
  bool over = false;
  rep(i, N) {
    ll A;
    std::cin >> A;
    if (A == 0) {
      std::cout << 0 << '\\n';
      return 0;
    }

    if (ans <= 0 || A > T / ans) {
      over = true;
    }
    ans *= A;
  }

  std::cout << (over ? -1LL : ans) << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

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

using ll = long long int;
const ll MOD = 1e9 + 7;

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

  ll ans = 1;
  ll T = 1000000000000000000LL;
  bool over = false;
  rep(i, N) {
    ll A;
    std::cin >> A;
    if (A == 0) {
      std::cout << 0 << '\\n';
      return 0;
    }

    if (A > T / ans) {
      over = true;
    }
    ans *= A;
  }

  std::cout << (over ? -1LL : ans) << '\\n';
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
constexpr int MOD = 1000000007;
// constexpr int MOD=998244353;
#define INF (1 << 30)
#define LINF (lint)(1LL << 56)
#define endl "\\n"
#define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
#define plint pair<lint, lint>
#define fi first
#define se second
typedef long long lint;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAX_N = 2e5 + 5;

using Bint = mp::cpp_int;

int main(void) {
  lint N;
  cin >> N;
  lint A[N];
  rep(i, N) cin >> A[i];
  Bint mul = 1;
  bool che = false;
  rep(i, N) if (A[i] == 0) che = true;
  if (che) {
    cout << 0 << endl;
    return 0;
  }
  lint cmp = 1e18;
  rep(i, N) {
    mul *= A[i];
    if (mul > cmp) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (mul > cmp)
    cout << -1 << endl;
  else
    cout << mul << endl;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
constexpr int MOD = 1000000007;
// constexpr int MOD=998244353;
#define INF (1 << 30)
#define LINF (lint)(1LL << 56)
#define endl "\\n"
#define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
#define plint pair<lint, lint>
#define fi first
#define se second
typedef long long lint;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAX_N = 2e5 + 5;

using Bint = mp::cpp_int;

int main(void) {
  lint N;
  cin >> N;
  lint A[N];
  rep(i, N) cin >> A[i];
  Bint mul = 1;
  rep(i, N) { mul *= A[i]; }
  lint cmp = 1e18;
  if (mul > cmp)
    cout << -1 << endl;
  else
    cout << mul << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  ll pdt = 1;
  bool ex = 0, zero = 0;
  FOR(i, 1, n) {
    ll t;
    scanf("%lld", &t);
    if (t == 0)
      zero = 1;
    if (pdt > 0 && t > llinf / pdt)
      ex = 1;
    pdt *= t;
  }
  if (zero)
    printf("0\\n");
  else if (ex)
    printf("-1\\n");
  else
    printf("%lld\\n", pdt);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  ll pdt = 1;
  bool ex = 0;
  FOR(i, 1, n) {
    ll t;
    scanf("%lld", &t);
    if (t == 0) {
      printf("0\\n");
      return 0;
    }
    if (t > llinf / pdt)
      ex = 1;
    pdt *= t;
  }
  if (ex)
    printf("-1\\n");
  else
    printf("%lld\\n", pdt);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll lim = 1;
  for (int i = 0; i < 18; i++) {
    lim *= 10;
  }

  ll ans = 1;
  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (ans == 0) {
      break;
    }

    if (a[i] > (lim / ans)) {
      ans = -1;
      ok = false;
    }

    ans *= a[i];
  }

  if (ans == 0) {
    cout << ans << ln;
  } else {
    cout << (ok ? ans : -1) << ln;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll lim = 1;
  for (int i = 0; i < 18; i++) {
    lim *= 10;
  }

  ll ans = 1;
  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (a[i] > (lim / ans)) {
      ans = -1;
      ok = false;
    }

    ans *= a[i];
  }

  if (ans == 0) {
    cout << ans << ln;
  } else {
    cout << (ok ? ans : -1) << ln;
  }

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

#include <bits/stdc++.h>
using ll = long long;

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
long long INF = 1.0e-18;

int main() {
  ll a[200000];
  ll n;
  ll ans = 1;
  bool zero = false;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0)
      zero = true;
  }
  if (zero) {
    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>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
long long INF = 1.0e-18;

int main() {
  int N;
  cin >> N;
  ll sum = 1;
  ll a;
  bool is = false;
  rep(i, N) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (INF / sum < a) {
      is = true;
    }
    sum = sum * a;
  }

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

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back

const ll MAX = 1e18;
vll a(100010);

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (ans > MAX / a[i]) {
      ans = -1;
      break;
    } else
      ans *= a[i];
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back

const ll MAX = 1e18;

int main() {
  int n;
  cin >> n;
  vll a(10010);
  ll ans = 1;
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (ans > MAX / a[i])
      ans = -1;
    else
      ans *= a[i];
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  long long int a[100000];
  int n, i;
  int flag = 1;

  long long int ans = 1;
  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }

  for (i = 0; i < n; i++) {
    if (a[i] == 0) {
      printf("0");
      return 0;
    }
  }

  for (i = 0; i < n; i++) {
    if (ans == 0)
      return printf("-1");
    if (a[i] > 1000000000000000000 / ans) {
      printf("-1");
      return 0;
    }
    ans *= a[i];
  }

  printf("%lld", ans);
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  long long int a[100000];
  int n, i;
  int flag = 1;
  int flag2 = 1;
  long long int ans = 1;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }

  for (i = 0; i < n; i++) {
    if (a[i] == 0) {
      return printf("0");
    }
  }

  for (i = 0; i < n; i++) {
    if (ans == 0)
      return printf("-1");
    ;
    if (a[i] > 1000000000000000000 / ans)
      return printf("-1");
    ans *= a[i];
  }

  printf("%lld", 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;

int main() {
  long long n;
  cin >> n;
  long long sum = 1;
  bool ok = true;
  long long a[n];
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    if (a[i] == 0)
      sum = 0;
  }

  if (sum == 1) {
    rep(i, n) {
      if (a[i] > (1000000000000000000 / sum)) {
        cout << -1 << endl;
        ok = false;
        break;
      }
      sum *= a[i];
    }
  }

  if (ok)
    cout << sum << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  long long sum = 1;
  bool ok = true;
  long long a[10010];
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    if (a[i] == 0)
      sum = 0;
  }

  if (sum == 1) {
    rep(i, n) {
      sum *= a[i];
      if (sum > 1000000000000000000) {
        ok = false;
        break;
      }
    }
  }

  if (ok)
    cout << sum << endl;
  else
    cout << -1 << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

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

  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }

  ll ans = 1;
  int ansm = 0;
  sort(ALL(a));
  for (int i = 0; i < n; i++) {

    if (a[i] == 0) {
      ans = 0;
      break;
    }
    if (ans > 1000000000000000000 / a[i]) {
      ansm = -1;
      break;
    } else {
      ans *= a[i];
    }
  }

  if (ansm == -1) {
    cout << ansm << "\\n";
  } else {
    cout << ans << "\\n";
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

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

  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }

  ll ans = 1;
  int ansm = 0;
  sort(ALL(a));
  for (int i = 0; i < n; i++) {
    if (ans > 1000000000000000000 / a[i]) {
      ansm = -1;
      break;
    } else {
      ans *= a[i];
    }
  }

  if (ansm == -1) {
    cout << ansm << "\\n";
  } else {
    cout << ans << "\\n";
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int 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 res = 1;
  for (int i = 0; i < n; i++) {
    if (1000000000000000000 / res < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    res *= a[i];
  }

  cout << res << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long res = 1;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    // ゼロ判定
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (1000000000000000001 / res < a[i]) {
      flag = true;
    }
    res *= a[i];
  }
  if (flag) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
typedef long double ld;

#define REP(i, s, n) for (ll i = s; i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
  ll N;
  ll a[100010];
  int zero = 0;
  ll prod = 1;
  ll max = 1000000000000000000;
  cin >> N;
  rep(i, N) { cin >> a[i]; }
  rep(i, N) if (a[i] == 0) zero++;
  if (0 < zero) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, N) {
    if (a[i] <= max / prod) {
      prod *= a[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << prod << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
typedef long double ld;

#define REP(i, s, n) for (ll i = s; i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
  ll N;
  ll a[100010];
  int zero = 0;
  ll prod = 1;
  bool flg = true;
  ll max = pow(10, 18);
  cin >> N;
  rep(i, N) {
    cin >> a[i];
    if (a[i] == 0)
      zero++;
    if (a[i] <= max / prod) {
      prod *= a[i];
    } else {
      flg = false;
    }
  }
  if (0 < zero) {
    cout << 0 << endl;
  } else if (flg) {
    cout << prod << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const long long MAX = pow(10, 18);
int main() {

  long long N, answer = 1;
  cin >> N;
  long long num;
  bool ng = false;
  for (long long i = 0; i < N; i++) {
    cin >> num;
    if (num == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (__int128(answer) * num > MAX) {
      ng = true;
    }
    answer *= num;
  }
  if (ng)
    cout << -1 << endl;
  else
    cout << answer << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long N, answer;
  long long MX = 1000000000000000000;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  answer = A[0];
  for (long long i = 1; i < N; i++) {
    answer *= A[i];
    // cout<<answer<<endl;
    if (A[i] <= MX / answer) {
      answer *= A[i];
    } else {
      cout << -1 << endl;
      return 0;
    } /*
   if(answer>1000000000000000000||answer<0){
                     cout<<-1<<endl;
             ///cout<<"a"<<Endl
             return 0;
             }*/
  }
  cout << answer << endl;

  return 0;
}