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

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 20000005, M = 1e9 + 7;
int fac[N], inv[N], f[5005][5005], n, m;
inline int ksm(int x, int y) {
  int ans = 1;
  for (; y; y >>= 1, x = x * x % M)
    if (y & 1)
      (ans *= x) %= M;
  return ans;
}
inline int P(int x, int y) {
  if (x > y)
    return 1;
  if (!x)
    return 0;
  return fac[y] * inv[x - 1] % M;
}
inline int C(int x, int y) {
  if (x < 0)
    return 1;
  if (x < y)
    return 0;
  return fac[x] * inv[y] % M * inv[x - y] % M;
}
signed main() {
  scanf("%lld%lld", &n, &m);
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % M;
  inv[N - 1] = ksm(fac[N - 1], M - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % M;
  n -= m;
  int ans = 0;
  for (int i = 1; i <= m + 1; i++)
    for (int j = 0; j <= m; j++)
      f[i][j] = ((!j ? 0 : f[i][j - 1]) + inv[j] * fac[i - 2 + n + j]) % M;
  for (int i = 1; i <= m + 1; i++)
    for (int j = 0; j < i; j++) {
      int s = f[i - j][max(0ll, m - i)];
      if (j & 1)
        (ans += M - C(i - 1, j) * (i - j - 1) % M * (i > m ? 1 : fac[m - i]) %
                        M * s % M) %= M;
      else
        (ans +=
         C(i - 1, j) * (i - j - 1) % M * (i > m ? 1 : fac[m - i]) % M * s) %= M;
    }
  printf("%lld\\n", ans);
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 10000005, M = 1e9 + 7;
int fac[N], inv[N], f[5005][5005], n, m;
inline int ksm(int x, int y) {
  int ans = 1;
  for (; y; y >>= 1, x = x * x % M)
    if (y & 1)
      (ans *= x) %= M;
  return ans;
}
inline int P(int x, int y) {
  if (x > y)
    return 1;
  if (!x)
    return 0;
  return fac[y] * inv[x - 1] % M;
}
inline int C(int x, int y) {
  if (x < 0)
    return 1;
  if (x < y)
    return 0;
  return fac[x] * inv[y] % M * inv[x - y] % M;
}
signed main() {
  scanf("%lld%lld", &n, &m);
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % M;
  inv[N - 1] = ksm(fac[N - 1], M - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % M;
  n -= m;
  int ans = 0;
  for (int i = 1; i <= m + 1; i++)
    for (int j = 0; j <= m; j++)
      f[i][j] = ((!j ? 0 : f[i][j - 1]) + inv[j] * fac[i - 2 + n + j]) % M;
  for (int i = 1; i <= m + 1; i++)
    for (int j = 0; j < i; j++) {
      int s = f[i - j][max(0ll, m - i)];
      if (j & 1)
        (ans += M - C(i - 1, j) * (i - j - 1) % M * (i > m ? 1 : fac[m - i]) %
                        M * s % M) %= M;
      else
        (ans +=
         C(i - 1, j) * (i - j - 1) % M * (i > m ? 1 : fac[m - i]) % M * s) %= M;
    }
  printf("%lld\\n", ans);
}
Problem p02654 (C++) — buggy submission, verdict: Runtime Error

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

const int maxn = 10000010, P = 1000000007;
int n, A, fact[maxn], finv[maxn], inv[maxn];

int main() {
  scanf("%d %d", &n, &A);
  fact[0] = finv[0] = inv[0] = inv[1] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = 1LL * i * fact[i - 1] % P;
    if (i > 1)
      inv[i] = 1LL * (P - P / i) * inv[P % i] % P;
    finv[i] = 1LL * finv[i - 1] * inv[i] % P;
  }
  auto C = [&](int x, int y) {
    return 1LL * fact[x] * finv[y] % P * finv[x - y] % P;
  };
  int ans = 0;
  for (int t = 2; t <= A + 1; t++) {
    int a = t - 1, b = n - A, c = max(0, A - t);
    for (int j = 0; j <= a; j++) {
      int coef = j & 1 ? P - 1 : 1;
      ans = (ans + 1LL * coef * C(a, j) % P * (a - j) % P * inv[a - j + b] % P *
                       fact[a - j + b + c]) %
            P;
    }
  }
  printf("%d\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

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

const int maxn = 5010, P = 998244353;
int n, A, fact[maxn], finv[maxn], inv[maxn];

int main() {
  scanf("%d %d", &n, &A);
  fact[0] = finv[0] = inv[0] = inv[1] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = 1LL * i * fact[i - 1] % P;
    if (i > 1)
      inv[i] = 1LL * (P - P / i) * inv[P % i] % P;
    finv[i] = 1LL * finv[i - 1] * inv[i] % P;
  }
  auto C = [&](int x, int y) {
    return 1LL * fact[x] * finv[y] % P * finv[x - y] % P;
  };
  int ans = 0;
  for (int t = 2; t <= A + 1; t++) {
    int a = t - 1, b = n - A, c = max(0, A - t);
    for (int j = 0; j <= a; j++) {
      int coef = j & 1 ? P - 1 : 1;
      ans = (ans + 1LL * coef * C(a, j) % P * (a - j) % P * inv[a - j + b] % P *
                       fact[a - j + b + c]) %
            P;
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int a, b;

  cin >> a >> b;
  cout << a * b;

  return 0;
}

Error: 1

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long int n, a[100000], result;
  result = 1;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (result == 0) {
      cout << "0";
      return 1;
    } else if (result > 1000000000000000000)
      result = -1;
    else
      result *= a[i];
  }
  cout << result;
  return 1;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B << endl;
}


Error: 10

Fixed submission:

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

int main() {
  int A, B;
  cin >> A >> B;
  return A * B;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;

  return 0;
}


Error: 10

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%d\\n", a * b);
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%n", a * b);
  return 0;
}
Problem p02657 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

vector<bool> test(1024 * 1024 * 1024);

int main() {

  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
}


Error: MLE

Fixed submission:

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

vector<lint> test(1024 * 1024 * 127);

int main() {

  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  cout << a * b << endl;
  return 0;
}

Error: 10

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int A, B;
  scanf("%d * %d = %d\\n", A, B, A * B);
  return 0;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int A, B;
  scanf("%i%i", A, B);
  printf("%i", A * B);
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}


Error: 10

Fixed submission:

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

int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
  return 0;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
}


Error: 10

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;

int main() {

  int A, B;
  cin >> A >> B;

  cout << A * B << endl;
}

Error: 10

Fixed submission:

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;

int main() {

  int A, B;
  cin >> A >> B;

  return A * B;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}


Error: 10

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#define endl '\\n'

using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int A, B;
  cin >> A;
  cin >> B;
  cout << A * B;
  return 0;
}

Error: 10

Fixed submission:

#include "bits/stdc++.h"
#define endl '\\n'

using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int A, B;
  cin >> A;
  cin >> B;
  cout << A * B;
  return A * B;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

// Compiler version g++ 6.3.0

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  cout << n * m;
}

Error: 10

Fixed submission:

#include <iostream>
using namespace std;

// Compiler version g++ 6.3.0

int main() {
  int n, m;
  cin >> n >> m;
  return n * m;
}
Problem p02657 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
const double pi = 3.1415926535897932384626;
inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int a, b;
int main() {
  a = read(), b = read();
  printf("%d\\n", a * b);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
const double pi = 3.1415926535897932384626;
inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e5 + 5;
ll n, x;
int main() {
  n = read();
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    x = read();
    if (x == 0) {
      printf("0\\n");
      return 0;
    }
    if (x > 1000000000000000000 / ans) {
      printf("-1\\n");
      return 0;
    }
    ans *= x;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
const ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

  cout << n * m;
}

Error: 10

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
const ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

  return n * m;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
}


Error: 10

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}
Problem p02657 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll a;
  ld b;
  cin >> a >> b;
  cout << ll(a * (b * 100) / 100) << "\\n";
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n;
  ll tmp, res = 1, max = 1000000000000000000;
  cin >> n;
  bool ng = true;
  bool zero = false;

  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    if (tmp == 0) {
      zero = true;
      cout << 0 << "\\n";
      return 0;
    }
    if (tmp > max / res) {
      ng = false;
    }
    res *= tmp;
  }

  cout << (zero ? 0 : ng ? res : -1) << "\\n";
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {

  int berapaKali;
  long long a1[100001];
  long long a2 = 1;
  long long max = 1000000000000000000;

  scanf("%d", &berapaKali);

  for (int j = 0; j < berapaKali; j++) {
    scanf("%lld", &a1[j]);
    if (a1[j] == 0) {
      printf("0");
      return 0;
    }
  }

  for (int i = 0; i < berapaKali; i++) {
    if (a1[i] > max) {
      printf("-1");
      return 0;
    }
    a2 *= a1[i];
    max /= a1[i];
  }

  printf("%lld", a2);

  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {

  int berapaKali;
  long long a1[10001];
  long long a2 = 1;
  long long max = 1000000000000000000;

  scanf("%d", &berapaKali);

  for (int j = 0; j < berapaKali; j++) {
    scanf("%lld", &a1[j]);
    if (a1[j] == 0) {
      printf("0");
      return 0;
    }
  }

  for (int i = 0; i < berapaKali; i++) {
    if (a1[i] > max) {
      printf("-1");
      return 0;
    }
    a2 *= a1[i];
    max /= a1[i];
  }

  printf("%lld", a2);

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

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

constexpr uint64_t THRESHOLD = 1000000000000000000;

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

  vector<uint64_t> values(N, 0);

  for (size_t i = 0; i < N; ++i) {
    cin >> values[i];
    if (values[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  uint64_t prod = 1;
  for (size_t i = 0; i < N; ++i) {
    double capacity = THRESHOLD / prod;
    if (capacity < values[i]) {
      cout << "-1" << endl;
      return 0;
    }
    prod *= values[i];
  }

  cout << prod << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

constexpr uint64_t THRESHOLD = 1000000000000000000;

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

  uint64_t prod = 1;
  bool is_zero = false;
  bool overflow = false;

  for (size_t i = 0; i < N; ++i) {
    uint64_t x;
    cin >> x;

    if (x == 0) {
      is_zero = true;
      break;
    }

    if (THRESHOLD / prod < x) {
      overflow = true;
      // is_zeroはoverflow後に発生しうるのでbreakしない
    }
    prod *= x;
  }

  if (is_zero) {
    cout << 0 << endl;
    return 0;
  }
  if (overflow) {
    cout << "-1" << endl;
    return 0;
  }

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

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using ll = long long;
using P = pair<int, int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll INF = 1LL << 60;

int main() {
  int N;
  cin >> N;
  ll ans = 1;
  bool ng = false;
  bool zero = false;
  rep(i, N) {
    ll A;
    cin >> A;
    if (A == 0 || ans == 0) {
      zero = true;
      continue;
    }
    if (1000000000000000000LL / ans < A) {
      ng = true;
      continue;
    }
    if (i == 0)
      ans = A;
    else
      ans *= A;
  }

  if (ng)
    ans = -1;
  if (zero)
    ans = 0;

  cout << ans << endl;

  return 0;
}
// Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using ll = long long;
using P = pair<int, int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll INF = 1LL << 60;

int main() {
  int N;
  cin >> N;
  ll ans = 1;
  bool ng = false;
  bool zero = false;
  rep(i, N) {
    ll A;
    cin >> A;
    if (A == 0 || ans == 0) {
      zero = true;
      continue;
    }
    if (1000000000000000000LL / ans < A)
      ng = true;
    if (i == 0)
      ans = A;
    else
      ans *= A;
  }

  if (ng)
    ans = -1;
  if (zero)
    ans = 0;

  cout << ans << endl;

  return 0;
}
// Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

void solve() {
  // cout << log(10000) << endl;
  int n;
  cin >> n;
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (ans == 0 || a == 0) {
      cout << 0;
      return;
    }
    if (ans > ll(2e18) / a) {
      ans = 2e18;
    } else
      ans *= a;
  }
  if (ans > ll(1e18)) {
    cout << -1;
    return;
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // int t; cin >> t;
  // while (t--)
  solve();
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

void solve() {
  // cout << log(10000) << endl;
  int n;
  cin >> n;
  ll ans = 1;
  long double cur = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (ans > ll(2e18) / a) {
      ans = 2e18;
    } else
      ans *= a;
  }
  if (ans > ll(1e18)) {
    cout << -1;
    return;
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // int t; cin >> t;
  // while (t--)
  solve();
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
#define ll long long
int main() {
  ll N, ans = 1;
  cin >> N;
  vector<ll> A(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 / ans) {
      ans *= A[i];
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
#define ll long long
int main() {
  ll N, ans;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ans = A[0];
  for (int i = 1; i < N; i++) {
    if (A[i] < 1000000000000000000 / ans) {
      ans = -1;
      break;
    }
    ans *= A[i];
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long p = 1;
  bool isOver = false;
  while (N--) {
    long long A;
    cin >> A;
    if (A == 0) {
      puts("0");
      return 0;
    }
    if (!isOver and 1000000000000000000LL / p < A) {
      isOver = true;
    }
    p *= A;
  }
  cout << (isOver ? -1 : p) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long p = 1;
  bool isOver = false;
  while (N--) {
    long long A;
    cin >> A;
    if (p == 0) {
      puts("0");
      return 0;
    }
    if (1000000000000000000 / p < A) {
      isOver = true;
    }
    if (A == 0) {
      puts("0");
      return 0;
    }
    p *= A;
  }
  cout << (isOver ? -1 : p) << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>

#define XX first
#define YY second
#define PB push_back
#define MP make_pair

#define NEWLINE cerr << "\\n";
#define HOISE cerr << "hoise " << __LINE__ << "\\n"
#define PAUSE system("pause")
#define DEBUG(x) cerr << #x << " = " << x << "\\n"
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

int32_t main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (!a[i]) {
      cout << 0;
      return 0;
    }
  }
  ll p = 1;
  ll lmt = 1000000000000000000;
  for (int i = 0; i < n; i++) {
    if (a[i] > lmt / p or a[i] > lmt) {
      cout << "-1";
      return 0;
    }
    p *= a[i];
  }
  cout << p;

  return 0;
}

Error: -8

Fixed submission:

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

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>

#define XX first
#define YY second
#define PB push_back
#define MP make_pair

#define NEWLINE cerr << "\\n";
#define HOISE cerr << "hoise " << __LINE__ << "\\n"
#define PAUSE system("pause")
#define DEBUG(x) cerr << #x << " = " << x << "\\n"
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

int32_t main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll p = 1;
  ll lmt = 1e18;
  for (int i = 0; i < n; i++) {
    if (a[i] > lmt / p or a[i] > lmt) {
      cout << "-1";
      return 0;
    }
    p *= a[i];
  }
  cout << p;

  return 0;
}