prithivMLmods/Coder-Stat huggingface dataset:
Problem p02653 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int maxn = 5010, P = 1000000007;
int n, A, B, ans, pw[maxn], f[maxn][maxn][2], pre[maxn][maxn][2], h[maxn];

int main() {
  scanf("%d %d %d", &n, &A, &B);
  if (A < B)
    swap(A, B);
  pw[0] = pw[1] = 1;
  for (int i = 2; i <= n; i++) {
    pw[i] = (pw[i - 1] + pw[i - 1]) % P;
  }
  f[0][0][0] = f[0][0][1] = 1, h[0] = 1;
  pre[0][0][0] = pre[0][0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      (f[i][j][0] += pre[i - 1][i - j][1]) %= P;
      (f[i][j][1] += pre[i - B][i - j][0]) %= P;
    }
    for (int j = max(0, i - B + 1); j < i; j++) {
      (f[i][0][1] += h[j]) %= P;
    }
    for (int j = A; j <= i; j++) {
      int s = 1LL * (f[i][j][0] + f[i][j][1]) * pw[n - i] % P;
      (ans += s) %= P, f[i][j][0] = f[i][j][1] = 0;
    }
    for (int j = 0; j <= i; j++) {
      (h[i] += f[i][j][0]) %= P;
      pre[i][i - j][0] = (pre[i - 1][i - j][0] + f[i][j][0]) % P;
      pre[i][i - j][1] = (pre[i - 1][i - j][1] + f[i][j][1]) % P;
    }
  }
  printf("%d\n", (ans + P) % P);
  return 0;
}

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

const int maxn = 5010, P = 1000000007;
int n, A, B, ans, pw[maxn], f[maxn][maxn][2], pre[maxn][maxn][2], h[maxn];

int main() {
  scanf("%d %d %d", &n, &A, &B);
  if (A < B)
    swap(A, B);
  pw[0] = pw[1] = 1;
  for (int i = 2; i <= n; i++) {
    pw[i] = (pw[i - 1] + pw[i - 1]) % P;
  }
  f[0][0][0] = f[0][0][1] = 1, h[0] = 1;
  pre[0][0][0] = pre[0][0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      (f[i][j][0] += pre[i - 1][i - j][1]) %= P;
      if (i >= B)
        (f[i][j][1] += pre[i - B][i - j][0]) %= P;
    }
    for (int j = max(0, i - B + 1); j < i; j++) {
      (f[i][0][1] += h[j]) %= P;
    }
    for (int j = A; j <= i; j++) {
      int s = 1LL * (f[i][j][0] + f[i][j][1]) * pw[n - i] % P;
      (ans += s) %= P, f[i][j][0] = f[i][j][1] = 0;
    }
    for (int j = 0; j <= i; j++) {
      (h[i] += f[i][j][0]) %= P;
      pre[i][i - j][0] = (pre[i - 1][i - j][0] + f[i][j][0]) % P;
      pre[i][i - j][1] = (pre[i - 1][i - j][1] + f[i][j][1]) % P;
    }
  }
  printf("%d\n", (ans + P) % P);
  return 0;
}
Problem p02653 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define mod 1000000007
#define maxn 1010

int n, a, b;
int ksm(int x, int y) {
  int re = 1;
  for (; (y & 1 ? re = 1ll * re * x % mod : 0), y;
       y >>= 1, x = 1ll * x * x % mod)
    ;
  return re;
}
int g[maxn][2], f[maxn][2];
void add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); }

int main() {
  scanf("%d %d %d", &n, &a, &b);
  if (a > b)
    swap(a, b);
  g[1][1] = 1;
  for (int i = 2; i < b; i++) {
    g[i][1] = (g[i - 1][0] + g[i - 1][1]) % mod;
    for (int j = a; j < i; j++)
      add(g[i][0], g[i - j][1]);
  }
  f[0][0] = f[0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < min(a, i + 1); j++)
      add(f[i][0], f[i - j][1]);
    for (int j = 1; j < min(b, i + 1); j++) {
      if (i == n)
        add(f[i][0], 1ll * f[i - j][0] * g[j][0] % mod);
      if (i == j)
        add(f[i][1], (g[j][0] + g[j][1]) % mod);
      else
        add(f[i][1], 1ll * f[i - j][0] * g[j][1] % mod);
    }
  }
  printf("%d", (ksm(2, n) - (f[n][0] + f[n][1]) % mod + mod) % mod);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define mod 1000000007
#define maxn 5010

int n, a, b;
int ksm(int x, int y) {
  int re = 1;
  for (; (y & 1 ? re = 1ll * re * x % mod : 0), y;
       y >>= 1, x = 1ll * x * x % mod)
    ;
  return re;
}
int g[maxn][2], f[maxn][2];
void add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); }

int main() {
  scanf("%d %d %d", &n, &a, &b);
  if (a > b)
    swap(a, b);
  g[1][1] = 1;
  for (int i = 2; i < b; i++) {
    g[i][1] = (g[i - 1][0] + g[i - 1][1]) % mod;
    for (int j = a; j < i; j++)
      add(g[i][0], g[i - j][1]);
  }
  f[0][0] = f[0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < min(a, i + 1); j++)
      add(f[i][0], f[i - j][1]);
    for (int j = 1; j < min(b, i + 1); j++) {
      if (i == n)
        add(f[i][0], 1ll * f[i - j][0] * g[j][0] % mod);
      if (i == j)
        add(f[i][1], (g[j][0] + g[j][1]) % mod);
      else
        add(f[i][1], 1ll * f[i - j][0] * g[j][1] % mod);
    }
  }
  printf("%d", (ksm(2, n) - (f[n][0] + f[n][1]) % mod + mod) % mod);
}
Problem p02654 (C++)

Buggy submission (status: Runtime Error):
#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);
}

Fixed submission:
#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);
}
Problem p02654 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02654 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 10000100
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, A, fac[N], inv[N], ans;
int qpow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1LL * ans * a % mod;
    a = 1LL * a * a % mod;
    b >>= 1;
  }
  return ans;
}
int init(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = 1LL * fac[i - 1] * i % mod;
  }
  inv[n] = qpow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; --i) {
    inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
  }
}
inline int C(int n, int m) {
  return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
inline int calc(int a, int b, int c) {
  return !(a + b) ? 0
                  : 1LL * fac[a + b + c] * a % mod * inv[a + b] % mod *
                        fac[a + b - 1] % mod;
}
int main() {
  n = read(), A = read();
  init(n);
  for (int i = 1; i <= A + 1; ++i) {
    for (int j = 0; j < i; ++j) {
      ans = (ans +
             (j & 1 ? -1 : 1) * 1LL * C(i - 1, j) *
                 calc(i - j - 1, n - A, max(0, A - i)) % mod +
             mod) %
            mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 10000100
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, A, fac[N], inv[N], ans;
int qpow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1LL * ans * a % mod;
    a = 1LL * a * a % mod;
    b >>= 1;
  }
  return ans;
}
void init(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = 1LL * fac[i - 1] * i % mod;
  }
  inv[n] = qpow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; --i) {
    inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
  }
}
inline int C(int n, int m) {
  return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
inline int calc(int a, int b, int c) {
  return !(a + b) ? 0
                  : 1LL * fac[a + b + c] * a % mod * inv[a + b] % mod *
                        fac[a + b - 1] % mod;
}
int main() {
  n = read(), A = read();
  init(n);
  for (int i = 1; i <= A + 1; ++i) {
    for (int j = 0; j < i; ++j) {
      ans = (ans +
             (j & 1 ? -1 : 1) * 1LL * C(i - 1, j) *
                 calc(i - j - 1, n - A, max(0, A - i)) % mod +
             mod) %
            mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02657 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input().ssplit())
print(a * b)


Fixed submission:
a, b = map(int, input().split())
print(a * b)
Problem p02657 (Python)

Buggy submission (status: Runtime Error):
def main():
    arg = int(input())
    ans = arg + arg**2 + arg**3
    print(str(ans))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    a, b = (int(i) for i in input().split())
    print(str(a * b))


if __name__ == "__main__":
    main()
Problem p02657 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;

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

  return 0;
}
Problem p02657 (Python)

Buggy submission (status: Runtime Error):
a, t = map(int, input().split())
print(a * t)
a, t = map(int, input().split())
print(a * t)


Fixed submission:
a, t = map(int, input().split())
print(a * t)
Problem p02657 (Python)

Buggy submission (status: Runtime Error):
x, y = input().split()
print(x * y)


Fixed submission:
x, y = map(int, input().split())
print(x * y)
Problem p02657 (Python)

Buggy submission (status: Runtime Error):
val1 = input()
val2 = input()

print(int(val1) * int(val2))


Fixed submission:
val1, val2 = (int(x) for x in input().split())

print(int(val1) * int(val2))
Problem p02657 (Python)

Buggy submission (status: Runtime Error):
a, b = [*map(input().split(" "), int)]
print(a * b)


Fixed submission:
a, b = [*map(int, input().split(" "))]
print(a * b)
Problem p02657 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}


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

Buggy submission (status: 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 A * B;
}

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 0;
}
Problem p02657 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}


Fixed submission:
#include <iostream>
using namespace std;

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

Buggy submission (status: 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;

  return A * B;
}

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;

  cout << A * B << endl;
}
Problem p02657 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}

Fixed submission:
#include <iostream>

using namespace std;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B;
  scanf("%i%i", A, B);
  printf("%i", A * B);
}

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

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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  return a * b;
}

Fixed submission:
#include <iostream>
using namespace std;

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

  cout << a * b << endl;
  return 0;
}
Problem p02657 (C++)

Buggy submission (status: Memory Limit Exceeded):
#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;
}


Fixed submission:
#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;
}
Problem p02657 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%n", a * b);
  return 0;
}

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

Buggy submission (status: Runtime Error):
a, b = int(input().split())
print(a * b)


Fixed submission:
a, b = map(int, input().split())
print(a * b)
Problem p02657 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  return A * B;
}

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N;
  unsigned long long ans = 1;
  cin >> N;

  bool zero = false;
  bool ng = false;
  for (long long i = 0; i < N; i++) {
    unsigned long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      zero = true;
    }
    if (!zero && 1000000000000000000 / ans < tmp) {
      ng = true;
    }
    ans *= tmp;
  }

  if (zero) {
    cout << 0 << endl;
  } else if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}

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

int main() {
  long long N;
  unsigned long long ans = 1;
  cin >> N;

  bool zero = false;
  bool ng = false;
  for (long long i = 0; i < N; i++) {
    unsigned long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      zero = true;
    }
    if (!zero && 1000000000000000000 / ans < tmp) {
      ng = true;
    }
    if (!zero && !ng) {
      ans *= tmp;
    }
  }

  if (zero) {
    cout << 0 << endl;
  } else if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> V(n);
  for (int i = 0; i < n; i++)
    cin >> V[i];
  long long product = 1;
  long long val = 1e18;
  sort(V.begin(), V.end());
  for (int i = 0; i < n; i++) {
    if (product == 0) {
      cout << 0;
      return 0;
    }
    if (product <= (val / V[i]))
      product *= V[i];
    else {
      cout << -1;
      return 0;
    }
  }
  cout << product;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> V(n);
  for (int i = 0; i < n; i++)
    cin >> V[i];
  long long product = 1;
  long long val = 1e18;
  sort(V.begin(), V.end());
  for (int i = 0; i < n; i++) {
    if (V[i] == 0) {
      cout << 0;
      return 0;
    }
    if (product <= (val / V[i]))
      product *= V[i];
    else {
      cout << -1;
      return 0;
    }
  }
  cout << product;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
mt19937_64 rng(58);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  long long ans = 1;
  bool larger = false;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    cerr << (1000000000000000001ll) / ans << '\n';
    if (a >=
        (1000000000000000001ll) / ans + (1000000000000000001ll % ans > 0)) {
      larger = true;
    } else {
      ans *= a;
    }
  }
  if (ans != 0 && larger) {
    cout << -1 << '\n';
  } else {
    cout << ans << '\n';
  }
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
mt19937_64 rng(58);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  long long ans = 1;
  bool larger = false;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (ans && a >= (1000000000000000001ll) / ans +
                        (1000000000000000001ll % ans > 0)) {
      larger = true;
    } else {
      ans *= a;
    }
  }
  if (ans != 0 && larger) {
    cout << -1 << '\n';
  } else {
    cout << ans << '\n';
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
using namespace std;
using ll = long long;

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

  ll INF = pow(10, 18);

  ll A, ans = 1;
  bool zero = false, overflow = false;
  rep(i, 0, N - 1) {
    cin >> A;
    if (A == 0)
      zero = true;
    if (INF / A < ans)
      overflow = true;
    ans *= A;
  }

  if (zero)
    cout << 0 << endl;
  else if (overflow)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}


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

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

  ll INF = pow(10, 18);

  ll A, ans = 1;
  bool zero = false, overflow = false;
  rep(i, 0, N - 1) {
    cin >> A;
    if (A == 0)
      zero = true;
    else if (INF / A < ans)
      overflow = true;
    ans *= A;
  }

  if (zero)
    cout << 0 << endl;
  else if (overflow)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x << endl;
using namespace std;

// int _;

int n;
long long ans = 1, a[100050];

int main() {
  // for(scanf("%d",&_);_;_--)
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    if (!a[i]) {
      puts("0");
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (1000000000000000000 / ans >= a[i] && 1000000000000000000 % ans != 0) {
      puts("-1");
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x << endl;
using namespace std;

// int _;

int n;
long long ans = 1, a[100050];

int main() {
  // for(scanf("%d",&_);_;_--)
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    if (!a[i]) {
      puts("0");
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (1000000000000000000 / ans < a[i]) {
      puts("-1");
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
// #include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
typedef unsigned long long ll;
typedef unsigned char Byte;
using namespace std;

bool isZero = true;

// string ans = "Yes";
ll ans = 1;
int N;
vector<ll> A;
int main() {
  cin >> N;

  ll stdd = 1;
  rep(_i, 18) stdd *= 10;

  rep(i, N) {
    ll tmp;
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }
    A.push_back(tmp);
  }

  rep(i, N) {
    ll recAns = ans;
    ans *= A[i];
    if (ans > stdd || recAns != ans / A[i]) {
      cout << -1 << endl;
      return -1;
    }
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
// #include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
typedef unsigned long long ll;
typedef unsigned char Byte;
using namespace std;

bool isZero = true;

// string ans = "Yes";
ll ans = 1;
int N;
vector<ll> A;
int main() {
  cin >> N;

  ll stdd = 1;
  rep(_i, 18) stdd *= 10;

  rep(i, N) {
    ll tmp;
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }
    A.push_back(tmp);
  }

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

  cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 1e18;
const int MB = 20;
const int MOD = 998244353;
const int maxN = 1e6;

void solve() {
  int n;
  cin >> n;
  int res = 1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (INF / res < x) {
      res = INF + 1;
    } else {
      res *= x;
    }
  }
  cout << (res > INF ? -1 : res);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed;
  cout.precision(12);
  srand(time(0));
  int t = 1;
  // int t;
  // cin >> t;
  while (t--)
    solve();
}

Fixed submission:
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 1e18;
const int MB = 20;
const int MOD = 998244353;
const int maxN = 1e6;

void solve() {
  int n;
  cin >> n;
  int res = 1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (res && INF / res < x) {
      res = INF + 1;
    } else {
      res *= x;
    }
  }
  cout << (res > INF ? -1 : res);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed;
  cout.precision(12);
  srand(time(0));
  int t = 1;
  // int t;
  // cin >> t;
  while (t--)
    solve();
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
long long a[10001];

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0\n";
      return 0;
    }
  }

  long long prod = 1;
  rep(i, n) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      prod = -1;
      break;
    }
  }

  cout << prod;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
long long a[100010];

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0\n";
      return 0;
    }
  }

  long long prod = 1;
  rep(i, n) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      prod = -1;
      break;
    }
  }

  cout << prod;

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define ll long long

signed main() {
  int n;
  cin >> n;
  ll num = 1, a;

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

    if (a > 0 && 1000000000000000000 / num >= a) {
      num *= a;
    }

    else if (a == 0) {
      num = 0;
    }

    else {
      num = -1;
    }
  }

  cout << num;
}

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

#define ll long long

signed main() {
  int n;
  cin >> n;
  ll num = 1, a;

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

    if (a > 0 && 1000000000000000000 / num >= a) {
      num *= a;
    }

    else if (a == 0) {
      num = 0;
      break;
    }

    else {
      num = -1;
    }
  }

  cout << num;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  long long a[N], b[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a[i] > 1e18) {
      cout << -1 << endl;
      return 0;
    }
    if (a[i] != 1)
      b[i] = a[i] - 1;
  }
  long long ans = a[0], ans2 = a[0] + 1;
  for (int i = 1; i < N; i++) {
    ans2 *= b[i];
    if (ans2 < 0 || ans2 > 1000000000000000000 || ans2 % b[i] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i < N; i++) {
    ans *= a[i];
    if (ans < 0 || ans > 1000000000000000000 || ans % a[i] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  long long a[N], b[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a[i] > 1e18) {
      cout << -1 << endl;
      return 0;
    }
    if (a[i] != 1)
      b[i] = a[i] - 1;
    else
      b[i] = a[i];
  }
  long long ans = a[0], ans2 = a[0] + 1;
  for (int i = 1; i < N; i++) {
    ans2 *= b[i];
    if (ans2 < 0 || ans2 > 1000000000000000000 || ans2 % b[i] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i < N; i++) {
    ans *= a[i];
    if (ans < 0 || ans > 1000000000000000000 || ans % a[i] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(i, a, n) for (int i = a; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

// int in() { int x; scanf("%d", &x); return x; }
// ll lin() { ll x; scanf("%lld", &x); return x; }
// void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const ll MAX = 1e18;

int main(void) {
  std::ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  ll ans = 1;
  bool ng = false;
  FOR(i, n) {
    ll tmp;
    cin >> tmp;

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

    if ((MAX + 1) / ans < tmp || ans * tmp > MAX) {
      ng = true;
    }

    ans *= tmp;
  }

  if (ng)
    cout << -1 << endl;
  else
    cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(i, a, n) for (int i = a; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

// int in() { int x; scanf("%d", &x); return x; }
// ll lin() { ll x; scanf("%lld", &x); return x; }
// void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const ll MAX = 1e18;

int main(void) {
  std::ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  ll ans = 1;
  bool ng = false;
  FOR(i, n) {
    ll tmp;
    cin >> tmp;

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

    if (ng || (MAX + 1) / ans < tmp || ans * tmp > MAX) {
      ng = true;
    }

    ans *= tmp;
  }

  if (ng)
    cout << -1 << endl;
  else
    cout << ans;

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

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

  int64_t sum = 1;
  bool over = false;
  for (int64_t i = 0; i < N; ++i) {
    int64_t A;
    std::cin >> A;
    if (A == 0) {
      sum = 0;
      over = false;
      break;
    }

    if (A > 1000000000000000000 / sum)
      over = true;

    sum *= A;
  }

  if (over)
    std::cout << -1;
  else
    std::cout << sum;
}

Fixed submission:
#include <iostream>

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

  int64_t sum = 1;
  bool over = false;
  for (int64_t i = 0; i < N; ++i) {
    int64_t A;
    std::cin >> A;
    if (A == 0) {
      sum = 0;
      over = false;
      break;
    }

    if (sum > 1000000000000000000 / A)
      over = true;

    sum *= A;
  }

  if (over)
    std::cout << -1;
  else
    std::cout << sum;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int main() {
  int n;
  cin >> n;
  ll aux, ans = 1;
  bool sw = 0, sw2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> aux;
    if (aux == 0)
      sw = 1;
    if (ans > (1000000000000000000 / aux) || ans < 0)
      sw2 = 1;
    ans *= aux;
  }
  if (sw) {
    cout << "0\n";
    return 0;
  } else if (sw2) {
    cout << "-1\n";
    return 0;
  }
  cout << ans << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int main() {
  int n;
  cin >> n;
  ll aux, ans = 1;
  bool sw = 0, sw2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> aux;
    if (aux == 0)
      sw = 1;
    else if (ans > (1000000000000000000 / aux) || ans < 0)
      sw2 = 1;
    ans *= aux;
  }
  if (sw) {
    cout << "0\n";
    return 0;
  } else if (sw2) {
    cout << "-1\n";
    return 0;
  }
  cout << ans << "\n";

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

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

  int n;
  cin >> n;

  constexpr ll M = (ll)1e+18;
  ll r = 1;
  int b = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;

    if (a == 0) {
      cout << 0 << endl;
      exit(0);
    }
    if (a > (M + r - 1) / r)
      b = 1;
    r *= a;
    if (r > M)
      b = 1;
  }

  if (b) {
    cout << -1 << endl;
  } else {
    cout << r << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

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

  int n;
  cin >> n;

  constexpr ll M = (ll)1e+18;
  ll r = 1;
  int b = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;

    if (a == 0) {
      cout << 0 << endl;
      exit(0);
    }
    if (!b && a > (M + r - 1) / r)
      b = 1;
    r *= a;
    if (r > M)
      b = 1;
  }

  if (b) {
    cout << -1 << endl;
  } else {
    cout << r << endl;
  }

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  int N;
  cin >> N;
  long A[100005];
  REP(i, N) cin >> A[i];
  long ans = 1l;
  long sai = 1000000000000000000;
  bool ok = true;
  sort(A, A + N);
  REP(i, N) {
    if (A[i] == 0l) {
      ans = 0l;
      break;
    }
    if (sai / ans < A[i]) {
      ok = false;
    }
    ans *= A[i];
    // cout << ans << endl;
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  long A[100005];
  REP(i, N) cin >> A[i];
  long ans = 1l;
  long sai = 1000000000000000000;
  bool ok = true;
  sort(A, A + N);
  REP(i, N) {
    if (A[i] == 0l) {
      ans = 0l;
      break;
    }
    if (sai / ans < A[i]) {
      ok = false;
      break;
    }
    ans *= A[i];
    // cout << ans << endl;
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> a;
  ll ans = 1;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    ll b;
    cin >> b;
    a.push_back(b);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a[i] > 1000000000000000000 / ans) {
      flag = false;
      break;
    }
    ans *= a[i];
  }
  if (flag) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a;
  ll ans = 1;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    ll b;
    cin >> b;
    a.push_back(b);
    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a[i] > 1000000000000000000 / ans) {
      flag = false;
      break;
    }
    ans *= a[i];
  }
  if (flag) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
  long long a, b, c, h, i, j, k, l, m, n, x, y;
  long long ans = 1;
  double aa, aans = 1.0;
  string s;
  cin >> n;
  // vector<ll>	aa(n);
  bool flag = true, zero = false;
  for (i = 0; i < n; i++) {
    cin >> a;
    c = 1000000000000000000ull / ans;
    if (c < a)
      flag = false;
    ans *= a;
    aa = a;
    // aans *= aa;
    // if (aans > 1000000000000000000.0) flag = false;
    // if (ans > 1000000000000000000ull) flag = false;
    if (a == 0) {
      zero = true;
    }
  }

  if (flag == false && zero == false)
    ans = -1;

  // vector<ll>	dp(n+1,INFL);
  // vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));

  cout << ans << endl;
  return 0;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
  long long a, b, c, h, i, j, k, l, m, n, x, y;
  long long ans = 1;
  double aa, aans = 1.0;
  string s;
  cin >> n;
  // vector<ll>	aa(n);
  bool flag = true, zero = false;
  for (i = 0; i < n; i++) {
    cin >> a;
    if (ans != 0) {
      c = 1000000000000000000ull / ans;
      if (c < a)
        flag = false;
    }
    ans *= a;
    aa = a;
    // aans *= aa;
    // if (aans > 1000000000000000000.0) flag = false;
    // if (ans > 1000000000000000000ull) flag = false;
    if (a == 0) {
      zero = true;
    }
  }

  if (flag == false && zero == false)
    ans = -1;

  // vector<ll>	dp(n+1,INFL);
  // vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));

  cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  const long long lim = 2000000000000000000ll;

  int N;
  scanf("%d", &N);
  long long A = 1;
  while (N--) {
    long long a;
    scanf("%lld", &a);
    if (A > lim / a)
      A = lim;
    else
      A *= a;
    if (A > lim)
      A = lim;
  }
  if (A > lim / 2)
    A = -1;
  printf("%lld\n", A);
  return 0;
}


Fixed submission:
#include <stdio.h>

int main() {
  const long long lim = 2000000000000000000ll;

  int N;
  scanf("%d", &N);
  long long A = 1;
  while (N--) {
    long long a;
    scanf("%lld", &a);
    if (a && A > lim / a)
      A = lim;
    else
      A *= a;
    if (A > lim)
      A = lim;
  }
  if (A > lim / 2)
    A = -1;
  printf("%lld\n", A);
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <limits.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
// const ll LLMAX = LLONG_MAX;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll answer = 1;

  // a.sort(a.begin(), a.end());
  rep(i, n) {
    if (a[i] > INF / answer) {
      answer = INF + 1;
    } else
      answer *= a[i];
  }
  if (answer > INF)
    cout << -1 << endl;
  else
    cout << answer << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <limits.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
// const ll LLMAX = LLONG_MAX;
#define rep(i, n) for (int i = 0; i < n; i++)

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 answer = 1;

  // a.sort(a.begin(), a.end());
  rep(i, n) {
    if (a[i] > INF / answer) {
      answer = INF + 1;
    } else
      answer *= a[i];
  }
  if (answer > INF)
    cout << -1 << endl;
  else
    cout << answer << endl;

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// Author: Ezio Sam
/* Shorthands */
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second
#define po(x) x *x
/* STL */
#define vi vector<int> v
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mem(a, n) memset(a, n, sizeof(a));
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mx(v) *max_element(v.begin(), v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(), a.end())
/* loops */
#define fr(i, n) for (__typeof(n) i = 0; i < (n); i++)
#define fn(i, n) for (__typeof(n) i = 1; i <= (n); i++)
#define fa(i, a, n) for (__typeof(a) i = (a); i <= (b); i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
#define db(something) cerr << #something << " - " << something << "\n";
int main() {

  Ezio
      /*Variables*/
      /*Code*/
      ll n,
      x;
  vector<ll> v;
  ll ans = 1;
  const ll m = 1e18;
  int i;
  cin >> n;

  fr(i, n) {
    cin >> x;
    v.pb(x);
  }

  sort(all(v));

  fr(i, n) {
    if (ans <= m / v[i])
      ans *= v[i];

    else {
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// Author: Ezio Sam
/* Shorthands */
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second
#define po(x) x *x
/* STL */
#define vi vector<int> v
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mem(a, n) memset(a, n, sizeof(a));
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mx(v) *max_element(v.begin(), v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(), a.end())
/* loops */
#define fr(i, n) for (__typeof(n) i = 0; i < (n); i++)
#define fn(i, n) for (__typeof(n) i = 1; i <= (n); i++)
#define fa(i, a, n) for (__typeof(a) i = (a); i <= (b); i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
#define db(something) cerr << #something << " - " << something << "\n";
int main() {

  Ezio
      /*Variables*/
      /*Code*/
      ll n,
      x;
  vector<ll> v;
  ll ans = 1;
  const ll m = 1e18;
  int i;
  cin >> n;

  fr(i, n) {
    cin >> x;
    if (x == 0) {
      cout << 0;
      return 0;
    }
    v.pb(x);
  }

  sort(all(v));

  fr(i, n) {
    if (ans <= m / v[i])
      ans *= v[i];

    else {
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;

long long n, a, m = 1, e = 1e18, fl;
int main() {
  cin >> n;
  while (n--) {
    cin >> a;
    if (a <= e / m)
      m *= a;
    else
      fl = 1;
  }
  if (m == 0)
    cout << 0;
  else if (fl)
    cout << -1;
  else
    cout << m;
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;

long long n, a, m = 1, e = 1e18, fl;
int main() {
  cin >> n;
  while (n--) {
    cin >> a;
    if (a <= e / m)
      m *= a;
    else
      fl = 1;
    if (m == 0)
      break;
  }
  if (m == 0)
    cout << 0;
  else if (fl)
    cout << -1;
  else
    cout << m;
  return 0;
}
Problem p02658 (C++)

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

const ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool over = false;

  rep(i, n) {
    ll a;
    cin >> a;

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

    if ((mx + 1) / ans < a || a * ans > mx || over) {
      over = true;
    }

    ans *= a;
  }

  if (over)
    ans = -1;
  cout << ans << endl;
}

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

const ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool over = false;

  rep(i, n) {
    ll a;
    cin >> a;

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

    if (over || (mx + 1) / ans < a || a * ans > mx) {
      over = true;
    }

    ans *= a;
  }

  if (over)
    ans = -1;
  cout << ans << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll limit = 1000000000000000000;

int main() {
  // 入力
  ll N;
  cin >> N;
  vector<ll> vec(N);
  for (ll i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  ll ans = 1;
  for (ll i = 0; i < N; i++) {
    if (vec.at(i) <= limit / ans) {
      ans *= vec.at(i);
    } else {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll limit = 1000000000000000000;

int main() {
  // 入力
  ll N;
  cin >> N;
  vector<ll> vec(N);
  for (ll i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  ll ans = 1;
  for (ll i = 0; i < N; i++) {
    if (vec.at(i) <= limit / ans) {
      ans *= vec.at(i);
    } else {
      ans = -1;
      break;
    }
    if (ans == 0) {
      break;
    }
  }

  cout << ans << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  long long count = 1;
  for (int i = 0; i < n; i++) {
    if (count > 0) {
      if (count <= 1000000000000000000 / a[i])
        count *= a[i];
      else
        count = -1;
    }
  }
  cout << count << endl;
}

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

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  long long count = 1;
  for (int i = 0; i < n; i++) {
    if (count != -1) {
      if (a[i] == 0)
        count = 0;
      else if (count <= 1000000000000000000 / a[i])
        count *= a[i];
      else
        count = -1;
    }
  }
  cout << count << endl;
}