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

#include <assert.h>
#include <bits/stdc++.h>
#include <errno.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
long long m[100010];
int main() {
  int u;
  cin >> u;
  for (int p = 0; p < u; p++) {
    cin >> m[p];
  }
  int c = 0;
  for (int p = 0; p < u; p++) {
    if (m[p] == 0) {
      c += 1;
    }
  }
  if (c > 0) {
    cout << 0 << "\\n";
    return 0;
  }
  long long i = 1;
  for (int p = 0; p < u; p++) {
    if (m[p] <= 1000000000000000000 / i) {
      i *= m[p];
    } else {
      cout << -1 << "\\n";
      return 0;
    }
  }
  cout << i << "\\n";
}

Error: 0

Fixed submission:

#include <assert.h>
#include <bits/stdc++.h>
#include <errno.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
long long m[100010];
int main() {
  int u;
  cin >> u;
  for (int p = 0; p < u; p++) {
    cin >> m[p];
  }
  int c = 0;
  for (int p = 0; p < u; p++) {
    if (m[p] == 0) {
      c += 1;
    }
  }
  if (c > 0) {
    cout << 0 << "\\n";
  }
  long long i = 1;
  for (int p = 0; p < u; p++) {
    if (m[p] <= 1000000000000000000 / i) {
      i *= m[p];
    } else {
      cout << -1 << "\\n";
    }
  }
  cout << i << "\\n";
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

/**
 *    author:  velengel
 *    created: 12.06.2020 17:09:20
 *    to run & test the code, type below command.
 *    cptest abc000_a
 **/

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

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

  int n;
  cin >> n;
  ll ans = 1;
  bool f = false;
  ll ikichi = 1000000000000000000;

  ll a[1000001];

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

  rep(i, n) {
    if (a[i] > ikichi || (ikichi + 1) / ans < a[i]) {
      f = true;
      cout << -1 << endl;
      return 0;
    }

    if (!f) {
      ans *= a[i];
    }

    if (ans > ikichi) {
      f = true;
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

/**
 *    author:  velengel
 *    created: 12.06.2020 17:09:20
 *    to run & test the code, type below command.
 *    cptest abc000_a
 **/

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

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

  int n;
  cin >> n;
  ll ans = 1;
  bool f = false;
  ll ikichi = 1000000000000000000;

  ll a[1000001];

  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0)
      ans = 0;
  }

  rep(i, n) {
    if (a[i] > ikichi || (ikichi + 1) / ans < a[i]) {
      f = true;
      cout << -1 << endl;
      return 0;
    }

    if (!f) {
      ans *= a[i];
    }

    if (ans > ikichi) {
      f = true;
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;

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

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

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool over = 0, is0 = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      is0 = 1;
      ans = 0;
      continue;
    }
    if (ans > 1000000000000000000 / a) {
      over = 1;
    }
    ans *= a;
  }
  if (over && !is0) {
    ans = -1;
  }

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


Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool over = 0, is0 = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      is0 = 1;
      break;
    }
    if (a > 1000000000000000000 / ans) {
      over = 1;
    }
    ans *= a;
  }
  if (over && !is0) {
    ans = -1;
  }

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

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

long long teisuu = 1000000000000000000;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long kotae = 1;
  for (long long i = 0; i < n; i++) {
    if (teisuu / kotae < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    kotae *= a[i];
  }
  cout << kotae << endl;
  return 0;
}


Error: 0

Fixed submission:

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

long long teisuu = 1000000000000000000;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long kotae = a[0];
  for (long long i = 1; i < n; i++) {
    if (teisuu / kotae > a[i]) {
      cout << -1 << endl;
      return 0;
    }
    kotae *= a[i];
  }
  cout << kotae << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

typedef unsigned long long ull;

const ull LIMIT = 1000000000000000000llu;

int main() {
  int N;
  scanf("%d", &N);

  ull ans = 1ull;
  bool overflowed = false;
  for (int i = 0; i < N; i++) {
    ull temp;
    scanf("%llu", &temp);
    if (temp == 0) {
      puts("0");
      return 0;
    }

    if (ans != 0 && (LIMIT / ans) < temp)
      overflowed = true;

    ans = ans * temp;
  }

  if (overflowed) {
    puts("-1");
    return 0;
  } else
    printf("%llu\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>

typedef unsigned long long ull;

const ull LIMIT = 1000000000000000000llu;

int main() {
  int N;
  scanf("%d", &N);

  ull ans = 1ull;
  bool overflowed = false;
  for (int i = 0; i < N; i++) {
    ull temp;
    scanf("%llu", &temp);
    if (temp == 0) {
      puts("0");
      return 0;
    }

    if ((LIMIT / ans) < temp)
      overflowed = true;

    ans = ans * temp;
  }

  if (overflowed) {
    puts("-1");
    return 0;
  } else
    printf("%llu\\n", ans);

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


/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

#define ll long long
#define scf(n) scanf("%d", &n)
#define lscf(n) scanf("%lld", &n)
#define lpri(n) printf("%lld ", n)
#define pri(n) printf("%d ", (int)n)
#define prin(n) printf("%d\\n", (int)n)
#define lprin(n) printf("%lld\\n", n)
#define rep(i, ini, n) for (int i = ini; i < (int)n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)

const ll mod = 1e9 + 7;
const int N = 1e6 + 7;
using namespace std;

int main() {

  int n, f = 1;
  scf(n);

  ll x = 1;

  vector<ll> v;

  int ctr = 0;

  for (int i = 1; i <= n; i++) {
    ll a;
    lscf(a);

    if (a > 1e9)
      ctr++;

    v.pb(a);
  }

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

  if (v[0] == 0) {
    f = 0;
    prin(0);
  }

  else if (ctr >= 2)
    prin(-1), f = 0;

  else {

    cpp_int x = 1;

    for (auto it : v)
      x *= it;

    if (x <= 1000000000000000000 && x >= 0 && f)
      cout << x << endl;

    else
      prin(-1);
  }
}

Error: TLE

Fixed submission:


/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

#define ll long long
#define scf(n) scanf("%d", &n)
#define lscf(n) scanf("%lld", &n)
#define lpri(n) printf("%lld ", n)
#define pri(n) printf("%d ", (int)n)
#define prin(n) printf("%d\\n", (int)n)
#define lprin(n) printf("%lld\\n", n)
#define rep(i, ini, n) for (int i = ini; i < (int)n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)

const ll mod = 1e9 + 7;
const int N = 1e6 + 7;
using namespace std;

int main() {

  int n, f = 1;
  scf(n);

  ll x = 1;

  vector<ll> v;

  for (int i = 1; i <= n; i++) {
    ll a;
    lscf(a);

    v.pb(a);
  }

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

  if (v[0] == 0) {
    f = 0;
    prin(0);
  }

  else {

    cpp_int x = 1;

    for (auto it : v)
      x *= it;

    if (x <= 1000000000000000000 && x >= 0 && f)
      cout << x << endl;

    else
      prin(-1);
  }
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll MX = 1000000000000000000;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 1;
  rep(i, n) {
    if ((MX + 1) / ans < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  if (ans > MX)
    ans = -1;
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const unsigned long long INF = 1000000000000000000;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  bool zero = false;
  map<ll, ll> mp;
  rep(i, n) {
    cin >> a[i];
    map<ll, ll> pf = prime_factor(a[i]);
    for (auto p : pf) {
      mp[p.first] += p.second;
    }
    if (a[i] == 0LL)
      zero = true;
  }
  if (zero) {
    cout << 0 << endl;
    return 0;
  }
  unsigned long long ans = 1;
  for (auto p : mp) {
    rep(i, p.second) {
      if (ans * p.first > INF) {
        cout << -1 << endl;
        return 0;
      }
      ans *= p.first;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  long long lim = 1e18;
  int n;
  cin >> n;
  long long a[n], ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      ans = 0;
    else if (ans > lim / a[i])
      ans = -1;
    else if (ans != -1)
      ans *= a[i];
  }
  cout << ans << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  long long lim = 1e18;
  int n;
  cin >> n;
  long long a[n], ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      ans = 0;
    else if (a[i] > lim / ans)
      ans = -1;
    else if (ans != -1)
      ans *= a[i];
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#import <iostream>
#import <math.h>
using namespace std;

int main() {

  long a;
  cin >> a;

  unsigned long long int b;
  long long int realtotal = 1;
  long long temp = 1;
  bool error = false;
  int i;
  for (i = 0; i < a; i++) {
    cin >> b;
    temp = temp * b;
    if (b != 0 && realtotal != temp / b) {
      error = true;
      realtotal = -1;
      break;
    }
    realtotal = realtotal * b;
    if (realtotal == 0) {
      cout << 0;
      return 0;
    }
  }
  if (error) {
    for (; i < a; i++) {
      cin >> b;
      if (b == 0) {
        realtotal = 0;
        break;
      }
    }
  }

  if (0 <= realtotal && realtotal <= 1000000000000000000) {
    cout << realtotal;
  } else {
    cout << -1;
  }
}

Error: WA

Fixed submission:

#import <iostream>
#import <math.h>
using namespace std;

int main() {

  long a;
  cin >> a;

  unsigned long long int b;
  long long int realtotal = 1;
  long long temp = 1;
  bool error = false;
  int i;
  for (i = 0; i < a; i++) {
    cin >> b;
    temp = temp * b;
    if (realtotal != temp / b) {
      error = true;
      realtotal = -1;
      i++;
      break;
    }
    realtotal = realtotal * b;
    if (realtotal == 0) {
      cout << 0;
      return 0;
    }
  }
  if (error) {
    for (; i < a; i++) {
      cin >> b;
      if (b == 0) {
        realtotal = 0;
        break;
      }
    }
  }

  if (0 <= realtotal && realtotal <= 1000000000000000000) {
    cout << realtotal;
  } else {
    cout << -1;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
ll a[N], inf = 1e18;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  ll sum = 1;
  for (int i = 0; i < n; i++) {
    ll x = a[i];
    if (x == 0) {
      sum = 0;
      break;
    }
    if (sum > inf / x) {
      sum = -1;
      break;
    } else {
      sum *= x;
    }
  }
  cout << sum << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
ll a[N], inf = 1e18;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  ll sum = 1;
  for (int i = 0; i < n; i++) {
    ll x = a[i];
    if (sum > inf / x) {
      sum = -1;
      break;
    } else {
      sum *= x;
    }
  }
  cout << sum << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
using namespace boost::multiprecision;
using namespace std;

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

  cpp_int m = 1;
  cpp_int limit = 1000000000000000000;

  for (int i = 1; i <= n; i++) {
    cpp_int x;
    cin >> x;
    if (!x)
      m = 0;
    else if (m <= limit)
      m *= x;
  }
  if (m <= limit)
    cout << m;
  else
    cout << "-1";

  return 0;
}

Error: TLE

Fixed submission:

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
using namespace boost::multiprecision;
using namespace std;

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

  cpp_int m = 1;
  cpp_int limit = 1000000000000000000;

  for (int i = 1; i <= n; i++) {
    cpp_int x;
    cin >> x;
    m *= x;
  }
  if (m <= limit)
    cout << m;
  else
    cout << "-1";

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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

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

  unsigned long long out = 1;

  vector<unsigned long long> a(n);

  for (int x = 0; x < n; x++) {
    cin >> a[x];
  }

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

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

  for (int x = 0; x < n; x++) {

    if (out > 1000000000000000000 / a[x]) {
      cout << -1;
      return 0;
    }
    out = out * a[x];
  }

  if (out > 1000000000000000000) {
    cout << -1;
  } else {
    cout << out;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

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

  unsigned long long out = 1;

  vector<unsigned long long> a(n);

  for (int x = 0; x < n; x++) {
    cin >> a[x];
  }

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

  if (a[0] == 0) {
    cout << 0;
    cin >> n;
  }

  for (int x = 0; x < n; x++) {

    if (out > 1000000000000000000 / a[x]) {
      cout << -1;
      return 0;
    }
    out = out * a[x];
  }

  if (out > 1000000000000000000) {
    cout << -1;
  } else {
    cout << out;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  long long n;
  cin >> n;
  long long a[n], prod = 1, i, zero = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      zero++;
  }
  if (zero > 0)
    cout << "0\\n";
  else {
    bool flag = 0;
    for (i = 0; i < n; i++) {
      if (a[i] <= 1000000000000000000 / prod) {
        prod *= a[i];
      } else {
        cout << "-1" << endl;
        return 0;
      }
    }

    printf("%lld\\n", prod);
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  long long n;
  cin >> n;
  long long a[n], prod = 1, i, zero = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      zero++;
  }
  if (zero > 0)
    cout << "0\\n";
  else {
    bool flag = 0;
    for (i = 0; i < n; i++) {
      prod *= a[i];
      if (a[i] > (1000000000000000000 / prod)) {
        flag = 1;
        // break;
      }
    }
    if (flag == 1)
      cout << "-1\\n";
    else
      cout << prod << "\\n";
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {

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

    if (arr[i] == 0) {
      printf("0\\n");
      return 0;
    }
  }
  for (i = 0; i < brpkali; i++) {
    if (arr[i] <= (Data / hasil)) {
      hasil *= arr[i];

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

  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <stdio.h>

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

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

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

#include <stdio.h>

int main() {
  int aa;
  scanf("%d", &aa);
  long long int ab[aa], maa = 1e18, prd = 1, fg = 0, zer = 0;

  for (int i = 0; i < aa; i++) {
    scanf("%lld", &ab[i]);
    fg = (ab[i] > maa) ? 1 : fg;
    prd *= ab[i];
    (ab[i]) ? maa /= ab[i] : zer = 1;
  }

  (zer) ? puts("0") : ((fg) ? puts("-1") : printf("%lld\\n", prd));
  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 <= 1000000000000000000 / ans ? ans *= a : flag = 1;
  }
  cout << (flag ? -1 : ans) * (1 - zero) << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int n;
long long ans = 1;
bool zero = false, minuss = false;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0)
      zero = true;
    else if (ans <= 1000000000000000000 / a)
      ans *= a;
    else
      minuss = true;
  }
  if (zero)
    cout << 0 << "\\n";
  else if (minuss)
    cout << -1 << "\\n";
  else
    cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define speed                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define fr first
#define sc second
using namespace std;
ll ar[26];
int main() {
  /// freopen("input.txt" , "r" , stdin );
  /// freopen("output.txt", "w" , stdout );
  /// Murtazoev_2007
  speed;
  /// Autor of the greatest code :: Ahmadjon Murtazoev
  ll a, q, sum = 1;
  cin >> a;
  for (ll i = 0; i < a; i++) {
    cin >> ar[i];
    sum *= ar[i];
  }
  if (sum > 1000000000000000000) {
    cout << -1 << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

  scanf("%d", &N);

  unsigned 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;
}


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]);
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      printf("0");
      return 0;
    }
  }
  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 int N;
  scanf("%d", &N);
  long long int A[N];
  long long int B = 1;
  long long int x = 1000000000000000000;

  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    if (A[i] == 0) {
      printf("0\\n");
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (x < A[i]) {
      printf("-1\\n");
      return 0;
    } else {
      x = x / A[i];
      B = B * A[i];
    }
  }
  printf("%lld\\n", B);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int N;
  scanf("%d", &N);
  long long int A[100];
  long long int B = 1;
  long long int x = 1000000000000000000;

  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    if (A[i] == 0) {
      printf("0\\n");
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i != 0]) {
      x = x / A[i];

      if (x < 1) {
        printf("-1\\n");
        return 0;
      } else {
        B = B * A[i];
      }
    }
  }
  printf("%lld\\n", B);
  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: 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];
    }
  } else {
    return 0;
  }
  if (M < 0 || M > 10e18) {
    printf("%d", -1);
  } else {
    printf("%.0lf", M);
  }
  return 0;
}