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

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main(void) {
  int N;
  scanf("%d", &N);
  long long A[100010];
  long long ans = 1;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    if (A[i] == 0) {
      printf("0");
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    // cout << ans << " " << 1000000000000000000 / ans << endl;
    if (1000000000000000000 / ans < A[i]) {
      printf("-1");
      return 0;
    } else {
      ans *= A[i];
    }
  }
  printf("%lld", ans);
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main(void) {
  int N;
  scanf("%d", &N);
  long long A[10010];
  long long ans = 1;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    if (A[i] == 0) {
      printf("0");
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    // cout << ans << " " << 1000000000000000000 / ans << endl;
    if (1000000000000000000 / ans < A[i]) {
      printf("-1");
      return 0;
    } else {
      ans *= A[i];
    }
  }
  printf("%lld", ans);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

long long inf = (1e18);

long long mul(long long a, long long b) {
  if (a == 0 or b == 0) {
    return 0;
  }
  if (inf / a >= b) {
    return a * b;
  } else {
    return inf;
  }
}

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

  int n;
  cin >> n;
  long long ans = 1;
  ++inf;
  while (n--) {
    long long x;
    cin >> x;
    ans = mul(ans, x);
  }
  cout << (ans == inf ? -1 : ans);

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

long long mul(long long a, long long b) {
  if (LLONG_MAX / a > b) {
    return a * b;
  } else {
    return LLONG_MAX;
  }
}

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

  int n;
  long long ans = 1;
  cin >> n;
  while (n--) {
    long long x;
    cin >> x;
    ans = mul(ans, x);
  }
  cout << (ans > 1e18 ? -1 : ans);

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

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef boost::multiprecision::cpp_int ll;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      puts("0");
      return 0;
    }
  }
  ll x = 1;
  ll y = 1'000'000'000'000'000'000LL;
  for (int i = 0; i < N; i++) {
    x *= A[i];
    if (x > y) {
      puts("-1");
      return 0;
    }
  }
  cout << x << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef boost::multiprecision::cpp_int ll;
int main() {
  int N;
  cin >> N;
  ll x = 1;
  for (int i = 0; i < N; i++) {
    long long A;
    cin >> A;
    x *= A;
  }
  ll y = 1'000'000'000'000'000'000LL;
  if (x > y)
    puts("-1");
  else
    cout << x << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>

using namespace std;
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      // 1e4
#define base10_5 100000     // 1e5
#define base10_6 1000000    // 1e6
#define base10_7 10000000   // 1e7
#define base10_8 100000000  // 1e8
#define base10_9 1000000000 // 1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

// #include <stack>
// #include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

vll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;
ll ans = 1;
ll llmin(ll a, ll b) {
  if (a >= b)
    return b;
  return a;
}
ll llmax(ll a, ll b) {
  if (a <= b)
    return b;
  return a;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> N;
  rep(ni, N) {
    cin >> ltmp;
    A.push_back(ltmp);
  }
  sort(A.begin(), A.end());

  ll ni = 0;
  while (ni < N) {
    ll Amax = base10_9;
    Amax = Amax * base10_9 / ans;
    if (A[ni] == 0) {
      ans = 0;
      break;
    }
    if (Amax < A[ni]) {
      ans = -1;
      break;
    }
    ans *= A[ni];

    ni++;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>

using namespace std;
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      // 1e4
#define base10_5 100000     // 1e5
#define base10_6 1000000    // 1e6
#define base10_7 10000000   // 1e7
#define base10_8 100000000  // 1e8
#define base10_9 1000000000 // 1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

// #include <stack>
// #include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

vll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;
ll ans = 1;
ll llmin(ll a, ll b) {
  if (a >= b)
    return b;
  return a;
}
ll llmax(ll a, ll b) {
  if (a <= b)
    return b;
  return a;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> N;
  rep(ni, N) {
    cin >> ltmp;
    A.push_back(ltmp);
  }
  sort(A.begin(), A.end());

  ll ni = 0;
  while (ni < N) {
    ll Amax = base10_9;
    Amax = Amax * base10_9 / ans;
    if (Amax < A[ni]) {
      ans = -1;
      break;
    }
    ans *= A[ni];
    ni++;
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<long long int> a(n);
  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;
    }
  }

  bool x = true;

  long long int ans = 1;
  for (int i = 0; i < n; i++) {
    if (ans > 1000000000000000000 || 1000000000000000000 / ans < a.at(i)) {
      x = false;
      break;
    }
    ans = ans * a.at(i);
  }

  if (x == false) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<long long int> a(n);
  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;
    }
  }

  bool x = true;

  long long int ans = 1;
  for (int i = 0; i < n; i++) {
    if (1000000000000000000 / ans < a.at(i)) {
      x = false;
    }
    ans = ans * a.at(i);
  }

  if (x == false) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int k = 1, i;
  long long p = 1, c = 1e18, d, q[n];
  for (i = 1; i <= n; i++) {
    cin >> q[i - 1];
    if (q[i - 1] == 0)
      k = 0;
  }
  if (k == 0) {
    cout << "0\\n";
    return 0;
  }
  for (i = 0; i < n; i++) {
    d = c / p;
    if (q[i] > d) {
      cout << "-1\\n";
      return 0;
    }
    p *= q[i];
  }
  cout << p << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int k = 1, i;
  long long a, p = 1, c = 1e18, d;
  for (i = 1; i <= n; i++) {
    cin >> a;
    if (a == 0) {
      cout << "0\\n";
      k = 2;
      break;
    }
    d = c / p;
    if (a > d) {
      k = 0;
    }
    p *= a;
    if (p > c) {
      k = 0;
    }
  }
  if (k == 1)
    cout << p << endl;
  else if (k == 0)
    cout << "-1\\n";
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Y cout << "YES\\n"
#define N cout << "NO\\n"
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define R(i, n) for (int i = 0; i < n; i++)
#define RE(i, a, b) for (int i = a; i >= b; i--)

int main() {
  ll mod, n, x, a[100010], ans = 1, flag = 0;
  cin >> n;
  mod = 1000000000000000000;
  R(i, n) { cin >> a[i]; }
  sort(a, a + n);
  R(i, n) {
    if (ans == 0) {
      break;
    }
    x = (mod / ans);
    if (a[i] > x) {
      flag = 1;
      cout << "-1\\n";
      break;
    }
    ans *= a[i];
  }
  if (flag == 0) {
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Y cout << "YES\\n"
#define N cout << "NO\\n"
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define R(i, n) for (int i = 0; i < n; i++)
#define RE(i, a, b) for (int i = a; i >= b; i--)

int main() {
  ll mod, n, x, ans = 1, flag = 0;
  cin >> n;
  mod = 1000000000000000000;
  R(i, n) {
    cin >> x;
    mod /= ans;
    if (x > mod) {
      flag = 1;
      cout << "-1\\n";
    } else {
      ans = x * ans;
    }
  }
  if (flag == 0) {
    cout << ans << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const long long maxt = 1e18;
int main() {
  ll n, a[100005], b, ans = 1;
  cin >> 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 ((maxt / ans) < a[i]) {
      cout << -1;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ll n, a[10005], b, ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  while (n--) {
    ans *= a[n];
    if (ans > 1e18) {
      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;
#define pii pair<int, int>
#define ff first
#define ss second
#define md 1000000000000000000

int main() {
  int n;
  cin >> n;
  ll mult = 1;
  bool flag = true;
  while (n--) {
    ll x;
    cin >> x;
    if (x == 0) {
      cout << 0;
      return 0;
    } else if (x > md / mult)
      flag = false;
    else
      mult *= x;
  }
  if (flag)
    cout << mult;
  else
    cout << -1;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  unsigned long long int n, i, b, x, y, s = 1, a[99999];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s *= a[i];
  }
  x = (pow(10, 18));
  if (s > x) {
    cout << "-1" << endl;
  } else
    cout << s << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

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() {
  int n;
  long long a[100001];
  long long max = 1000000000000000000;
  long long mul = 1;

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

  for (int i = 0; i < n; i++) {
    if (a[i] > max) {
      printf("-1");
      return 0;
    }
    mul *= a[i];
    max /= a[i];
  }
  printf("%lld", mul);
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  long long int b[35];
  long long int c = 1;
  int a, i;
  scanf("%d", &a);
  for (i = 0; i < a; i++) {
    scanf("%lld", &b[i]);
  }
  for (i = 0; i < a; i++) {
    c = c * b[i];
  }
  if (c >= 1000000000000000000) {

    printf("-1");
  } else {
    printf("%lld", c);
  }

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

#include <stdio.h>
int main() {
  long long int t;
  scanf("%lld", &t);
  long long input[t];

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

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  long long int b[35], c = 1;
  int a, i;
  scanf("%d", &a);
  for (i = 0; i < a; i++) {
    scanf("%lld", &b[i]);
    c = c * b[i];
  }
  c > 1000000000000000000 ? printf("-1") : printf("%d", c);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {

  long long int tc;
  long long int temp = 1;

  scanf("%lld", &tc);
  long long int input[100005];
  bool printtemp = false;
  bool nextloop = true;
  for (long long int i = 0; i < tc; i++) {
    scanf("%lld", &input[i]);
    if (input[i] == 0) {
      printf("0\\n");
      nextloop = false;
      break;
    }
  }
  if (nextloop) {
    for (long long int i = 0; i < tc; i++) {
      if (1000000000000000000 / temp < input[i]) {
        printf("-1\\n");
        break;
      }
      temp *= input[i];
      // printf("Temp [%d] : %lld\\n",i,temp);
      if (i >= tc - 1) {
        printtemp = true;
      }
    }
  }

  if (printtemp)
    printf("%lld\\n", temp);

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  long long N;
  scanf("%d", &N);
  long long A, sum = 1;

  for (int i = 1; i <= N; i++) {
    scanf("%lld", &A);
    sum = sum * A;
  }
  sum > 1000000000000000000 ? printf("-1\\n") : printf("%lld\\n", sum);

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

#include <stdio.h>

int main() {
  long long n;
  long long ctr = 1;
  scanf("%lld", &n);
  long long num[n];

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

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

Error: WA

Fixed submission:

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

  long long int N; // test case
  long long int f;
  long long int g = 1;
  long long int h[10000] = {};
  scanf("%d", &N);
  getchar();
  for (long long int i = 0; i < N; i++) {
    scanf("%d", &h[i]);
  }
  for (long long int j = 0; j < N; j++) {
    if (h[j] == 0) {
      printf("0");
      return 0;
    } else if (h[j] > 10000000000000000) {
      printf("-1");
      return 0;
    }
  }
  for (long long int k = 0; k < N; k++) {
    g *= h[k];
  }
  g <= 10000000000000000 ? printf("%d", g) : printf("-1");
  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)
const int INF = 1001001001;
using ll = long long;
using Edge = pair<ll, ll>;
using Graph = vector<vector<int>>;
ll inf = 1e18;

int main() {
  __int128 ans = 1;
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n) {
    ll a;
    cin >> a;
    v[i] = a;
  }
  sort(v.begin(), v.end());
  if (v[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, n) {
    ans *= v[i];
    if (inf < ans) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (inf < ans)
    cout << -1 << endl;
  else
    cout << (ll)ans << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int INF = 1001001001;
using ll = long long;
using Edge = pair<ll, ll>;
using Graph = vector<vector<int>>;
ll inf = 1e18;

int main() {
  __int128_t ans = 1;
  int n;
  cin >> n;
  vector<ll> v;
  rep(i, n) {
    ll a;
    cin >> a;
    v[i] = a;
  }
  sort(v.begin(), v.end());
  if (v[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, n) {
    ans *= v[i];
    if (inf < (ll)ans) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (inf < (ll)ans)
    cout << -1 << endl;
  else
    cout << (ll)ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  long long int tc;
  scanf("%lld", &tc);
  long long int n[tc], tot = 1;
  for (long long int i = 0; i < tc; i++) {
    //		tot<1000000000000000000
    scanf("%lld", &n[i]);
    if (n[i] == 0) {
      tot = 0;
      printf("%lld\\n", tot);
      break;
    }
  }
  if (tot > 0) {
    for (long long int i = tc - 1; i >= 0; i--) {
      if (tot > 1000000000 && n[i] > 1000000000) {
        tot = 0;
        printf("-1\\n");
        break;
      } else if (tot * n[i] > 1000000000000000000) {
        tot = 0;
        printf("-1\\n");
      } else {
        tot *= n[i];
      }
    }
  }
  if (tot > 0) {
    printf("%lld\\n", tot);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  long long N;
  scanf("%d", &N);
  long long A, sum = 1;

  for (int i = 0; i < N; i++) {
    scanf("%11d", &A);
    sum = sum + A;
  }
  sum > 1000000000000000000 ? printf("-1\\n") : printf("%11d\\n", sum);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

  long long int berapaKali;
  scanf("%lld", &berapaKali);
  long long int a1[berapaKali];
  long long int a2 = 1;
  long long int max = 1000000000000000000;
  long long int hasil;

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

  for (int h = 0; h < berapaKali; h++) {

    if (a1[h] == 0) {
      printf("0\\n");
      return 0;
    }
  }
  for (int i = 0; i < berapaKali; i++) {
    if (a1[i] <= max / a2) {
      a2 *= a1[i];
    } else {
      printf("-1\\n");
      return 0;
    }
  }
  hasil = a2;
  printf("%lld\\n", hasil);

  return 0;
}

Error: WA

Fixed submission:

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

  long long int berapaKali;
  scanf("%lld", &berapaKali);
  long long int a1[berapaKali];
  long long int a2 = 1;
  long long int max = 1000000000000000000;
  long long int hasil;

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

  for (int h = 0; h < berapaKali; h++) {

    if (a1[h] == 0) {
      printf("0");
      return 0;
    }
  }
  for (int i = 0; i < berapaKali; i++) {
    a2 *= a1[i];
  }
  hasil = a2;
  if (a1[1] <= max / a2) {
    printf("%lld", hasil);
    return 0;
  } else {
    printf("-1\\n");
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

  scanf("%lld", &N);
  long long int A[N];

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

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

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {

  long long int brpkali;
  long long int hasil = 1;
  scanf("%d", &brpkali);
  long long int arr[10000000000] = {};
  for (long long int i = 0; i < brpkali; i++) {
    scanf("%lld", &arr[i]);
  }
  for (long long int i = 0; i < brpkali; i++) {

    if (arr[i] == 0) {
      printf("0\\n");
      return 0;
    }
  }
  for (long long int i = 0; i < brpkali; i++) {
    if (arr[i] <= 10000000000000000000 / hasil) {
      hasil = hasil * arr[i];
    } else {
      printf("-1\\n");
      return 0;
    }
  }
  printf("%lld", hasil);
  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, zero = 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] : zero = 1;
  }

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

Error: 0

Fixed submission:

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

using ll = long long;
using pll = pair<ll, ll>;

ll n, a, ans = 1;
bool flag, zero;

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

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    zero |= (a == 0);
    a <= (ll)round(1e18) / ans ? ans *= a : flag = 1;
  }
  cout << (flag ? -1 : ans) * (1 - zero) << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  long long int a;
  long long int number[100000];
  scanf("%lld", &a);
  for (long long int i = 0; i < a; i++) {
    scanf("%lld", &number[i]);
  }
  for (long long int i = 0; i < a; i++) {
    if (number[i] == 0) {
      printf("0\\n");
      return (0);
    }
  }
  long long int ans = 1;
  for (int i = 0; i < a; i++) {
    if (number[i] <= (1000000000000000000 / ans)) {
      ans = ans * number[i];

    } else {
      printf("-1\\n");
      return (0);
    }
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: -11

Fixed submission:

#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 = 1; 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;
}