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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <string>
#include <vector>

using namespace std;

int main() {
  using ll = long long;
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll B = 1;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 0) {
      cout << "0" << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (B > 1000000000000000000 / A[i]) {
      cout << "-1" << endl;
      return 0;
    }
    B *= A[i];
    if (A[i] == 0) {
      cout << "0" << endl;
      return 0;
    }
  }
  if (B > 1000000000000000000) {
    cout << -1 << endl;
    return 0;
  }
  cout << B << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <string>
#include <vector>

using namespace std;

int main() {
  using ll = long long;
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll B = 1;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 0) {
      cout << "0" << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    B *= A[i];
    if (A.at(i) > 1000000000000000000 / B && B > 1000000000000000000) {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << B << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const long long INF = 1e18;
int main() {
  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 (flag == 1)
      continue;
    if (INF / temp < ans)
      flag = -1;
    ans *= temp;
  }
  if (flag == 1)
    puts("0");
  else if (flag == -1)
    puts("-1");
  else
    cout << ans << endl;
  return 0;
}


Error: -11

Fixed submission:

// Aaradhya Beri
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) ((long long)x.size())
#define fr(a, b, c) for (int a = b; a <= c; a++)
#define rep(a, b, c) for (int a = b; a < c; a++)
#define trav(a, x) for (auto &a : x)
#define all(con) con.begin(), con.end()
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
// const int mod=998244353;
const int mod = 1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int powm(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(8);
  w(t) {
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    ll total = 0;
    rep(i, 0, n) {
      if (a[i] > k)
        total += abs(a[i] - k);
    }
    cout << total << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

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

  bool over = false;
  bool zero = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      zero = true;
      ans = 0;
      continue;
    }
    if (ans > 1000000000000000000 / a) {
      ans = -1;
      over = true;
    } else {
      ans *= a;
    }

    if (a == 0)
      zero = true;
  }

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

Error: 0

Fixed submission:

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

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

  bool over = false;
  bool zero = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (ans > 1000000000000000000 / a) {
      ans = -1;
      over = true;
    } else {
      ans *= a;
    }

    if (a == 0)
      zero = true;
  }

  if (!zero && over)
    ans = -1;
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

/*
  Reference:-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int, int>
#define all(vec) vec.begin(), vec.end()
ll mod = 1000000007;
const int N = 2e5 + 5;
ll power(ll n, ll k) {
  ll ans = 1;
  while (k) {
    if (k & 1)
      ans = (ans * n) % mod;
    k /= 2;
    n = (n * n) % mod;
  }
  // ans=(ans-1+mod)%mod;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll ans = 1;
  ll ar[n];
  forn(i, n) {
    cin >> ar[i];
    if (ar[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  ll che = 1000000000000000000;
  forn(i, n) {
    // ans*=ar[i];
    // cout<<ans<<endl;
    if (ar[i] > che / ans) {
      cout << -1;
      return 0;
    }
    ans *= ar[i];
  }
  // if(ans>che)ans=-1;
  cout << ans;

  return 0;
}


Error: WA

Fixed submission:

/*
  Reference:-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int, int>
#define all(vec) vec.begin(), vec.end()
ll mod = 1000000007;
const int N = 2e5 + 5;
ll power(ll n, ll k) {
  ll ans = 1;
  while (k) {
    if (k & 1)
      ans = (ans * n) % mod;
    k /= 2;
    n = (n * n) % mod;
  }
  // ans=(ans-1+mod)%mod;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll ans = 1;
  ll ar[n];
  forn(i, n) {
    cin >> ar[i];
    if (ar[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  ll che = 1e18;
  forn(i, n) {
    ans *= ar[i];
    // cout<<ans<<endl;
    if (ar[i] <= che / ans) {
      cout << -1;
      return 0;
    }
    ans *= ar[i];
  }
  if (ans > che)
    ans = -1;
  cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
unsigned long long N, tmp, BIG = 1000000000000000000;
bool lebih = false;
int main() {
  cin >> N;
  unsigned long long total = 1;
  for (unsigned long long i = 0; i < N; i++) {
    cin >> tmp;
    if (total != 0 && tmp <= (BIG / total)) {
      total = total * tmp;
    } else if (total != 0) {
      lebih = true;
    }
    if (tmp == 0) {
      total = 0;
      lebih = false;
    }
  }
  if (lebih) {
    cout << -1 << '\\n';
  } else {
    cout << total << '\\n';
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
unsigned long long N, tmp, BIG = 1000000000000000000;
bool lebih = false;
int main() {
  cin >> N;
  unsigned long long total = 1;
  for (unsigned long long i = 0; i < N; i++) {
    cin >> tmp;
    if (tmp > (BIG / total)) {
      lebih = true;
    } else {
      total *= tmp;
    }
    if (tmp == 0) {
      total = 0;
    }
  }
  if (lebih) {
    cout << -1 << '\\n';
  } else {
    cout << total << '\\n';
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
long long a[100010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  int zero = 0;

  for (int i = 0; i < n; i++)
    if (a[i] == 0)
      zero++;
  if (zero > 0) {
    // a[i] contains 0
    printf("0\\n");
    return 0;
  }
  long long prod = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / prod) {
      // This condition is equivalent to prod*a[i] <=10ˆ18
      prod *= a[i];
    } else {
      printf("-1\\n");
      return 0;
    }
  }
  printf("%lld\\n", prod);
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a[n], m = 1, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    m = m * a[i];
  }
  if (m <= pow(10, 18))
    cout << m;
  else {
    cout << -1;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n, i, j, sum, flg = 0, cnt = 0, c = 1000000000000000000;
  cin >> n;
  ll ar[n + 1];
  for (i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] == 0)
      cnt = 1;
  }
  sum = ar[0];
  if (cnt == 1)
    cout << 0 << endl;
  else {
    for (i = 1; i < n; i++) {
      if (ar[i] <= c / sum)
        sum = sum * ar[i];
      else {
        flg = 1;
        break;
      }
    }
    if (flg == 1)
      cout << -1 << endl;
    else
      cout << sum << endl;
  }
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
long long int a[10000], ans = 1;
int main() { // long long int a[1000000000000000000],ans=1;
  long int n, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    ans *= a[i];
  }
  if (ans > 1000000000000000000) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

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

Error: WA

Fixed submission:

#include <stdio.h>
int main() {
  // soal F
  long long int N;             // test case
  long long int f;             // mencari 0 atau >10^18
  long long int g = 1;         // buat hasil perkalian
  long long int h[10000] = {}; // array buat menampung angka
  scanf("%lld", &N);
  getchar();
  for (long long int i = 0; i < N; i++) {
    scanf("%lld", &h[i]);
    // printf("number = %lld\\n", h[i]);
    if (h[i] == 0) {
      f = 0;
      break;
    } else if (h[i] > 1000000000000000000) {
      f = -1;
      break;
    } else {
      g *= h[i];
      //	printf("numbers multiplied = %lld\\n", g);
      if (g > 1000000000000000000) {
        f = -1;
        break;
      }
    }
  }

  if (f == 0) {
    printf("0");
  } else if (f == -1) {
    printf("-1");
  } else {
    printf("%lld", g);
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

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

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

  (zero) ? 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;
    }
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>

int main() {

  int Tc;
  scanf("%d", &Tc);
  long long int data[Tc] = {};
  long long int Tot = 1;

  for (int i = 0; i < Tc; i++) {
    scanf("%lld", &data[i]);
  }

  for (int j = 0; j < Tc; j++) {
    if (data[j] == 0) {
      printf("0");
      return 0;
    }
  }
  for (int k = 0; k < Tc; k++) {
    if (data[k] > 1000000000000000000 / Tot) {
      printf("-1");
      return 0;
    } else {
      Tot *= data[k];
    }
  }
  printf("%lld", Tot);
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
#include <string.h>

int main() {

  int Num;
  scanf("%d", &Num);
  long long int Data[Num],
      MS = 0, Tot = 1, ZS = 0,
      max = 1000000000000000000; // Minus Switch, Total, and Zero Switch

  for (int i = 0; i < Num; i++) {
    scanf("%d", Data[i]);
    (Tot > max / Tot) ? MS++ : 1;
    (Tot == ZS) ? ZS++ : 1;
    Tot *= Data[i];
  }
  (MS > 0) ? printf("-1\\n") : ((ZS > 0) ? printf("0\\n") : printf("%lld", Tot));

  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, res = 1, check = 0, zero = 0;

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

  (zero) ? printf("0\\n") : ((check) ? printf("-1\\n") : printf("%lld\\n", res));
  return 0;
}


Error: WA

Fixed submission:


#include <stdio.h>
int main() {

  int n;
  scanf("%d ", &n);

  long long int data[100] = {0};
  long long int total = 1;

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

#include <stdio.h>

int main() {
  long long int t;
  scanf("%lld", &t);
  long long int num[t] = {0};
  long long int hasil = 1;
  for (long long int i = 0; i < t; i++) {
    scanf("%lld", &num[i]);
  }
  for (long long int i = 0; i < t; i++) {

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

Error: WA

Fixed submission:

#include <stdio.h>
int main() {
  long long int N;
  unsigned int sum = 1;

  scanf("%d", &N);

  long long int A[N];

  for (int i = 0; i < N; i++) {
    scanf("%llu", &A[i]);
    if (A[i] == 0) {
      printf("0");
      return 0;
    }
    for (int i = 0; i < N; i++) {
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] <= 1000000000000000000 / sum) {
      sum *= A[i];

    } else {
      printf("-1");
      return 0;
    }
  }
  printf("%lld", sum);

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

#include <stdio.h>
int main() {
  long long int t;
  scanf("%lld", &t);
  long long int number[t] = {0};
  long long int hasil = 1;

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

Error: WA

Fixed submission:

#include <stdio.h>

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

#include <stdio.h>

int main() {
  int N, i, j, test;
  unsigned long long mul;
  long long A[100001], tt = 1000000000000000000;

  scanf("%d", &N);

  mul = 1;
  test = 1;
  for (i = 1; i <= N; i++) {
    scanf("%lld", &A[i]);
  }
  for (i = 1; i <= N; i++) {
    if (A[i] == 0) {
      test = 0;
      break;
    }

    if (tt / mul >= A[i]) {
      mul *= A[i];
    } else
      test = 2;
  }

  if (test == 0)
    printf("0\\n");
  else if (test == 1)
    printf("%llu\\n", mul);
  else if (test == 2)
    printf("-1\\n");

  return 0;
}


Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  long long int N, A[10000], M = 1, max = 1e18, flag = 0;
  scanf("%d", &N);
  if (N >= 2 && N <= 10000) {
    for (int i = 0; i < N; i++) {
      scanf("%d", &A[i]);
      if (A[i] > 1e18) {
        flag += 1;
      } else if (A[i] > max) {
        flag += 1;
      }
      max /= A[i];
      M *= A[i];
    }
    (flag >= 1) ? printf("%d", -1) : printf("%lld", M);
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>  // sort, lower_bound, heap, min, next_permutation
#include <bitset>     // bitset
#include <cmath>      // sin, exp, log, pow, sqrt
#include <cstdio>     // fopen, printf, scanf, puts
#include <ctime>      // clock
#include <functional> // greater, less
#include <iomanip>    // setfill, setbase
#include <iostream>   // cin, cout
#include <list>       // list
#include <map>        // map
#include <queue>      // queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, stoi, to_string
#include <tuple>      // tuple
#include <vector>     // vector

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps = 1e-14;
const int mod = 1e9 + 7;
const int inf = ((1 << 30));
const long long linf = (1LL << 60);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  long long ans = 1;
  bool ok = true;
  long long A[n];
  for (int i = 0; i < n; i++)
    cin >> A[i];
  sort(A, A + n);
  for (int i = 0; i < n; i++) {
    if (A[i] == 0) {
      ans = 0;
      break;
    } else if (ans <= 1000000000000000000 / A[i]) {
      ans *= A[i];
    } else {
      ok = false;
      break;
    }
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>  // sort, lower_bound, heap, min, next_permutation
#include <bitset>     // bitset
#include <cmath>      // sin, exp, log, pow, sqrt
#include <cstdio>     // fopen, printf, scanf, puts
#include <ctime>      // clock
#include <functional> // greater, less
#include <iomanip>    // setfill, setbase
#include <iostream>   // cin, cout
#include <list>       // list
#include <map>        // map
#include <queue>      // queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, stoi, to_string
#include <tuple>      // tuple
#include <vector>     // vector

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps = 1e-14;
const int mod = 1e9 + 7;
const int inf = ((1 << 30));
const long long linf = (1LL << 60);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  long long ans = 1;
  bool ok = true;
  long long A[n];
  for (int i = 0; i < n; i++)
    cin >> A[i];
  sort(A, A + n);
  for (int i = 0; i < n; i++) {
    if (ans <= 1000000000000000000 / A[i]) {
      ans *= A[i];
    } else {
      ok = false;
      break;
    }
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i, s, f) for (ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

int32_t main() {
  FAST int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  int res = 1;
  for (int i = 0; i < n; i++) {
    if (1000000000000000000LL / res >= arr[i]) {
      res *= arr[i];
    } else {
      cout << -1;
      return 0;
    }
  }
  cout << res;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i, s, f) for (ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

int32_t main() {
  FAST int n;
  cin >> n;
  int res = 1;
  bool ok = 1;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      cout << 0;
      return 0;
    }
    res *= a;
    if (a > 1000000000000000000 / res || res > 1000000000000000000) {
      ok = 0;
    }
  }
  if (!ok) {
    cout << -1;
    return 0;
  }
  cout << res;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX 1000000000000000000

int main() {
  long long a[100005], ans = 1;
  bool flag = false, zero = false;
  int N;
  cin >> N;

  rep(i, N) {
    cin >> a[i];
    if (a[i] == 0)
      zero = true;
  }
  if (!zero) {
    rep(i, N) {
      if (MAX / ans < a[i]) {
        flag = true;
        break;
      }
      ans *= a[i];
    }
  }

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

Error: 0

Fixed submission:

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

#define MAX 1000000000000000000

int main() {
  long long a[100005], ans = 1;
  bool flag = false, zero = false;
  int N;
  cin >> N;

  rep(i, N) {
    cin >> a[i];
    if (a[i] == 0)
      zero = true;
  }
  if (!zero) {
    rep(i, N) {
      if (MAX / ans < a[i])
        flag = true;

      ans *= a[i];
    }
  }

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