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

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

typedef long long ll;
#define nl "\\n"
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define bs binary_search
#define pll pair<ll, ll>
#define ppll pair<ll, pll>
#define sll stack<ll>
#define qll queue<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define vc vector<char>
#define vvll vector<vector<ll>>
#define all(x) x.begin(), x.end()
#define loop(i, s, n) for (ll i = s; i < n; i++)
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
ll mod = 1000000007;
double pi = 3.1415926535;

void solve() {
  ll n;
  cin >> n;
  ll ans = 1, d, flg = 0, p = 0;
  while (n--) {
    cin >> d;
    if (((double)1000000000000000000 / ans) < d)
      flg = 1;
    ans *= d;
    // cout<<ans<<nl;
    if (!d)
      p = 1;
    if (ans > 1000000000000000000 || ans < 0) {
      flg = 1;
    }
  }
  // ll k=1000000000000000000*;
  // cout<<k<<nl;
  if (p)
    cout << "0";
  else if (flg)
    cout << "-1";
  else
    cout << ans;
}

int main() {
  fast_io;

  solve();
  return 0;
}


Error: WA

Fixed submission:

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

typedef long long ll;
#define nl "\\n"
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define bs binary_search
#define pll pair<ll, ll>
#define ppll pair<ll, pll>
#define sll stack<ll>
#define qll queue<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define vc vector<char>
#define vvll vector<vector<ll>>
#define all(x) x.begin(), x.end()
#define loop(i, s, n) for (ll i = s; i < n; i++)
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
ll mod = 1000000007;
double pi = 3.1415926535;

void solve() {
  ll n;
  cin >> n;
  ll ans = 1, d, flg = 0, p = 0;
  while (n--) {
    cin >> d;
    if (floor(1000000000000000000 / ans) < d)
      flg = 1;
    ans *= d;
    // cout<<ans<<nl;
    if (!d)
      p = 1;
    if (ans > 1000000000000000000 || ans < 0) {
      flg = 1;
    }
  }
  // ll k=1000000000000000000*;
  // cout<<k<<nl;
  if (p)
    cout << "0";
  else if (flg)
    cout << "-1";
  else
    cout << ans;
}

int main() {
  fast_io;

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

#include <iostream>
using namespace std;

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

  long long a[n];

  long long res = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      res = 0;
  }

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

  for (int i = 0; i < n; i++) {
    if (a[i] <= (long long)1e18 / res)
      res *= a[i];
    else {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << res << endl;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long n;
  long long a[n];
  cin >> n;

  long long res = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      res = 0;
  }

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

  for (int i = 0; i < n; i++) {
    res = res * a[i];
    if (res > (long long)1e18) {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << res << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int m = 1;
  bool q = false;
  for (int x = 1; x <= n; ++x) {
    long long int v;
    cin >> v;
    if (v <= 1000000000000000000 / m) {
      m *= v;
    } else {
      q = true;
    }
    if (m == 0) {
      break;
    }
  }
  if (q && m != 0) {
    m = -1;
  }
  cout << m << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int m = 1;
  bool q = false;
  for (int x = 1; x <= n; ++x) {
    long long int v;
    cin >> v;
    if (v <= 1000000000000000000 / m) {
      m *= v;
    } else {
      q = true;
    }
  }
  if (q && m != 0) {
    m = -1;
  }
  cout << m << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1, temp;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (temp == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (inf / temp < ans)
      flag = 1;
    else
      ans *= temp;
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <string>
typedef unsigned long long ll;
const ll inf = 1e18;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1, temp;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (temp == 0)
      flag = 1;
    if (inf / temp < ans)
      flag = 2;
    else
      ans *= temp;
  }
  if (flag == 1)
    cout << 0 << endl;
  else if (flag == 2)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;
double pi = 3.14159265358979;

ll r(ll x, ll y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return r(x, y / 2) * r(x, y / 2) % mod;
  else
    return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod;
}

int main() {
  ll n;
  cin >> n;
  ll sum = 1;
  bool f = 1;
  ll p = 1000000000000000000;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      sum = 0;
    } else if (p / a < sum) {
      f = 0;
    } else
      sum = sum * a;
  }
  if (f || sum == 0)
    printf("%lld\\n", sum);
  else
    cout << -1 << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;
double pi = 3.14159265358979;

ll r(ll x, ll y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return r(x, y / 2) * r(x, y / 2) % mod;
  else
    return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod;
}

int main() {
  ll n;
  cin >> n;
  ll sum = 1;
  bool f = 1;
  ll p = 1000000000000000000;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      sum = 0;
    } else if (p / sum < a) {
      f = 0;
    } else
      sum = sum * a;
  }
  if (f || sum == 0)
    printf("%lld\\n", sum);
  else
    cout << -1 << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::multiprecision::cpp_int;
int main() {
  int n;
  cin >> n;
  long long int a[n];
  cpp_int ans = 1;
  int zero = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      zero++;
  }
  if (zero > 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = 0; i < n; i++) {
      ans *= a[i];
      if (ans > 1000000000000000000) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::multiprecision::cpp_int;
int main() {
  int n;
  cin >> n;
  cpp_int a;
  cpp_int ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    ans *= a;
  }
  if (ans > 1000000000000000000)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  long long int t, sum = 1;
  scanf("%lld", &t);

  long long int n[t];
  for (int i = 0; i < t; i++) {
    scanf("%lld", &n[i]);
  }
  for (int i = 0; i < t; i++) {
    if (n[i] == 0) {
      printf("0");
      return 0;
    }
  }
  for (int i = 0; i < t; i++) {
    if (n[i] <= 1000000000000000000 / sum) {
      sum *= n[i];
    } else {
      printf("-1");
      return 0;
    }
  }
  printf("%lld", sum);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  long long int t, sum = 1;
  scanf("%lld", &t);

  long long int n[t];
  for (int i = 0; i, t; i++) {
    scanf("%lld", &n[i]);
  }

  for (int i = 0; i < t; i++) {
    if (n[i] == 0) {
      printf("0");
      return 0;
    }
  }
  for (int i = 0; i < t; i++) {
    if (n[i] <= 1000000000000000000 / sum) {
      sum *= n[1];
    } else {
      printf("-1");
      return 0;
    }
  }
  printf("%lld", sum);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;

  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\\n", prod));
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int t;
  long long u = 1;
  long long s = 1000000000000000000;
  long long a[100005];
  scanf("%d", &t);

  for (int i = 0; i < t; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0) {
      printf("%d\\n", 0);
      return 0;
    }
  }
  for (int i = 0; i < t; i++) {
    u *= a[i];
    if ((s / u < 1)) {
      printf("%d\\n", -1);
      return 0;
    } else if (i == (t - 1)) {
      printf("%lld\\n", u);
    }
  }

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

#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, product = 1, flag = 0, zero = 0;

  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    product *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\\n", product));
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  int N, A[10];
  double M = 1;
  scanf("%d", &N);
  if (N >= 2 && N <= 10e5) {
    for (int i = 0; i < N; i++) {
      scanf("%d", &A[i]);
      M *= A[i];
    }
  } else {
    return 0;
  }
  (M < 0 || M > 10e18) ? printf("%d", -1) : printf("%.0lf", M);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const long long MAX_A = 1000000000000000000LL;

int main(void) {
  int N;
  cin >> N;
  vector<unsigned long long> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    if (A[i] <= MAX_A / ans) {
      ans *= A[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
int main(void) {
  mp::cpp_int ANS = 1;

  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    mp::cpp_int A;
    cin >> A;
    ANS *= A;
  }

  if (ANS > 1000000000000000000) {
    std::cout << -1;
  } else {
    std::cout << ANS;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long N, ans = 1;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  for (int i = 0; i < N; ++i) {
    if (A[i] > 1000000000000000000 / ans) {
      cout << -1;
      return 0;
    }
    ans *= A[i];
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long N, ans = 1;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++N)
    cin >> A[i];
  for (int i = 0; i < N; ++i) {
    if (A[i] == 0) {
      cout << 0;
      return 0;
    }
    if (A[i] <= 1000000000000000000 / ans)
      ans *= A[i];
    else {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#define ll long long
using namespace std;

int main() {

  int N;
  cin >> N;
  ll A[N];
  ll multi = 1;

  bool can = false;
  ll cant = pow(10, 18);
  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 (cant / A[i] < multi) {
      can = true;
      break;
    }
    multi *= A[i];
  }

  if (can)
    cout << "-1" << endl;
  else
    cout << multi << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#define ll long long
using namespace std;

int main() {

  int N;
  cin >> N;
  ll A;
  ll multi = 1;

  bool can = true;
  ll cant = pow(10, 18);
  for (int i = 0; i < N; i++) {
    cin >> A;
    multi *= A;
    if (cant / A < multi)
      can = false;
  }
  /*
  ll multi = A[0];
  for (int i=1; i<N; i++){
    multi *= A[i];
  }
  bool can = true;
  ll cant = pow(10,18);
  if (cant < multi) can = false;
  */

  if (can)
    cout << multi << endl;
  else
    cout << "-1" << endl;

  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string.h>
using namespace std;
#define ll long long
#define maxn 500000
int c[maxn], a[maxn];
char s[40];
int b[40];
int k = 1, p;
int mul(int a[], int b[]) {
  int lenx = k;
  int leny = p;
  int t = 0;
  for (int i = 1; i <= lenx; i++) {
    t = 0;
    for (int j = 1; j <= leny; j++) {
      c[i + j - 1] += a[i] * b[j] + t;
      t = c[i + j - 1] / 10;
      c[i + j - 1] %= 10;
    }
    c[i + leny] = t;
  }
  int lenc = lenx + leny;
  while (c[lenc] == 0 && lenc > 1)
    lenc--;
  return lenc;
}
int main() {
  int n;
  cin >> n;
  c[1] = 1;
  int ans = 1;
  while (n--) {
    scanf("%s", s);
    // printf("%s\\n",s);
    if (s[0] == '0')
      ans = 0;
    if (ans == 0) {
      k = 0;
      continue;
    }
    if (k > 19)
      continue;
    for (int i = 1; i <= k; i++) {
      a[i] = c[i];
      c[i] = 0;
    }
    p = strlen(s);
    // cout<<"ssa"<<p<<endl;
    for (int i = 1; i <= p; i++) {
      b[i] = s[p - i] - '0';
    }
    // cout<<endl;
    k = mul(a, b);
  }
  /* for(int i=k;i>=1;i--)
  cout<<c[i];
  cout<<endl;*/
  if (ans == 0)
    cout << 0;
  else {
    if (k > 19)
      cout << -1;
    else if (k == 19) {
      int flag = 1;
      for (int i = 1; i <= 18; i++)
        if (c[i] != 0) {
          flag = 0;
          break;
        }
      if (c[19] != 1)
        flag = 0;
      if (flag) {
        for (int i = k; i >= 1; i--)
          printf("%d", c[i]);

      } else
        printf("-1");
    } else {
      for (int i = k; i >= 1; i--)
        cout << c[i];
    }
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;
#define ll long long
#define maxn 500000
int c[maxn], a[maxn];
char s[40];
int b[40];
int k = 1, p;
int mul(int a[], int b[]) {
  int lenx = k;
  int leny = p;
  int t = 0;
  for (int i = 1; i <= lenx; i++) {
    t = 0;
    for (int j = 1; j <= leny; j++) {
      c[i + j - 1] += a[i] * b[j] + t;
      t = c[i + j - 1] / 10;
      c[i + j - 1] %= 10;
    }
    c[i + leny] = t;
  }
  int lenc = lenx + leny;
  while (c[lenc] == 0 && lenc > 1)
    lenc--;
  return lenc;
}
int main() {
  int n;
  cin >> n;
  c[1] = 1;
  while (n--) {
    scanf("%s", s);
    // printf("%s\\n",s);
    for (int i = 1; i <= k; i++) {
      a[i] = c[i];
      c[i] = 0;
    }
    p = strlen(s);
    // cout<<"ssa"<<p<<endl;
    for (int i = 1; i <= p; i++) {
      b[i] = s[p - i] - '0';
    }
    // cout<<endl;
    k = mul(a, b);
  }
  /* for(int i=k;i>=1;i--)
  cout<<c[i];
  cout<<endl;*/
  if (k > 19)
    cout << -1;
  else if (k == 19) {
    int flag = 1;
    for (int i = 1; i <= 18; i++)
      if (c[i] != 0) {
        flag = 0;
        break;
      }
    if (c[19] != 1)
      flag = 0;
    if (flag) {
      for (int i = k; i >= 1; i--)
        printf("%d", c[i]);

    } else
      printf("-1");
  } else {
    for (int i = k; i >= 1; i--)
      cout << c[i];
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

long long MAX = 1e18;

int main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int N;

  cin >> N;
  long long A[N];
  long long sum = 1;
  bool overflow = false;
  bool hasZero = false;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0)
      hasZero = true;
    if (!overflow && A[i] > MAX / sum) {
      overflow = true;
    } else {
      sum *= A[i];
    }
    // if(overflow) break;
  }

  if (hasZero) {
    cout << "0\\n";
  } else if (overflow) {
    cout << "-1\\n";
  } else {
    cout << sum << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

long long MAX = 1e18;

int main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int N;

  cin >> N;
  long long A[N];
  long long sum = 1;
  bool overflow = false;
  bool hasZero = false;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0)
      hasZero = true;
    if (A[i] > MAX / sum) {
      overflow = true;
    } else {
      sum *= A[i];
    }
    // if(overflow) break;
  }

  if (hasZero) {
    cout << "0\\n";
  } else if (overflow) {
    cout << "-1\\n";
  } else {
    cout << sum << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define go ios::sync_with_stdio(0)
ll inf = 1e18;
bool zero, over;
int main() {
  go;
  int n;
  cin >> n;
  ll x;
  cin >> x;
  if (!x)
    zero = 1;
  for (int i = 0; i < n - 1; i++) {
    ll y;
    cin >> y;
    if (!y)
      zero = 1;
    if (inf / x < y) {
      over = 1;
      continue;
    }
    if (over)
      continue;
    if (zero)
      continue;
    x *= y;
  }
  if (zero)
    cout << 0;
  else if (over)
    cout << -1;
  else
    cout << x;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define go ios::sync_with_stdio(0)
ll inf = 1e18;
bool zero, over;
int main() {
  go;
  int n;
  cin >> n;
  ll x;
  cin >> x;
  if (!x)
    zero = 1;
  for (int i = 0; i < n - 1; i++) {
    ll y;
    cin >> y;
    if (!y)
      zero = 1;
    if (inf / x < y) {
      over = 1;
      continue;
    }
    x *= y;
  }
  if (zero)
    cout << 0;
  else if (over)
    cout << -1;
  else
    cout << x;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int a;
  scanf("%d", &a);
  long long int arr[a], max = 1e18, prod = 1, flag = 0, kosong = 0;

  for (int i = 0; i < a; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : kosong = 1;
  }

  (kosong) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\\n", prod));
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  int a, flag = 0;
  long long arr[100001];
  long long last = 1;

  scanf("%d", &a);

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

    scanf("%lld", &arr[i]);
  }

  for (int i = 0; i < a; i++) {
    if (arr[i] == 0) {
      printf("0\\n");

      return 0;
    }
  }

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

    last = last * arr[i];
  }
  for (int i = 0; i < a; i++) {
    if (arr[i] <= 1000000000000000000 / last) {
      printf("%lld", last);
      return 0;
    }

    else {

      printf("-1\\n");
      return 0;
    }
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  ll a[n], ans = 1, inv;
  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++) {
    inv = (ll)1e18 / ans;
    if (a[i] > inv) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << (ans > (ll)1e18 ? -1 : ans) << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  ll a, ans = 1, inv;
  bool flg = false;
  for (int i = 0; i < n; i++) {
    inv = (ll)1e18 / ans;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a > inv + 1)
      flg = true;
    ans *= a;
  }
  cout << ((ans > (ll)1e18 || flg) ? -1 : ans) << endl;
}