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

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

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) {
    printf("0\n");
    return 0;
  }

  ll prod = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      printf("-1\n");
      return 0;
    }
  }

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll 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) {
    printf("0\n");
    return 0;
  }

  ll prod = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      printf("-1\n");
      return 0;
    }
  }

  printf("%lld\n", prod);
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  ll ans = 1;
  SORT(a);
  if (a[0] = 0) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, N) {
    if (a[i] > (ll)1e18 / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  ll ans = 1;
  SORT(a);
  if (a[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, N) {
    if (a[i] > (ll)1e18 / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define forn(i, n) for (int i = 0; i < n; i++)
#define rforn(i, n) for (int i = n - 1; i >= 0; i--)
#define forne(i, n) for (int i = 1; i <= n; i++)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define rforse(i, s, e) for (int i = e - 1; i >= s; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a, x) memset(a, x, sizeof a);
#define trav(a, x) for (auto &a : x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif

void solve() {
  int n;
  cin >> n;
  ll ans = 1, x;
  bool ok = true, zero = false;
  vl arr(n);
  forn(i, n) cin >> arr[i];
  forn(i, n) {
    x = arr[i];
    if (x == 0) {
      zero = true;
    }
    if (x > INF / ans) {
      ok = false;
    } else {
      ans *= x;
    }
  }
  if (zero) {
    cout << '0';
  } else {
    if (ok) {
      cout << ans;
    } else {
      cout << "-1";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifdef SHUBHAM107
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("err.txt", "w", stderr);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}


Fixed submission:
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define forn(i, n) for (int i = 0; i < n; i++)
#define rforn(i, n) for (int i = n - 1; i >= 0; i--)
#define forne(i, n) for (int i = 1; i <= n; i++)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define rforse(i, s, e) for (int i = e - 1; i >= s; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a, x) memset(a, x, sizeof a);
#define trav(a, x) for (auto &a : x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif

void solve() {
  int n;
  cin >> n;
  ll ans = 1, x;
  bool ok = true, zero = false;
  vl arr(n);
  forn(i, n) cin >> arr[i];
  forn(i, n) {
    x = arr[i];
    if (x == 0) {
      zero = true;
      break;
    }
    if (x > INF / ans) {
      ok = false;
    } else {
      ans *= x;
    }
  }
  if (zero) {
    cout << '0';
  } else {
    if (ok) {
      cout << ans;
    } else {
      cout << "-1";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifdef SHUBHAM107
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("err.txt", "w", stderr);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool oror = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (mx / ans < a || mx < a * ans) {
      oror = true;
    }
    ans *= a;
  }
  if (oror)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool oror = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (oror || mx / ans < a || mx < a * ans) {
      oror = true;
    }
    ans *= a;
  }
  if (oror)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2)                                                   \
  freopen((string(s) + "." + end1).c_str(), "r", stdin),                       \
      freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i : x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int MAX = 4e18 + 5, MAX2 = 1e18;
int mul(int a, int b) {
  if (a > MAX / b)
    return MAX;
  return a * b;
}
signed main() {
#ifdef BLU
  in("blu.inp");
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 1;
  cin >> n;
  fw(i, 0, n) {
    int x;
    cin >> x;
    ans = mul(ans, x);
  }
  if (ans > MAX2)
    cout << "-1";
  else
    cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2)                                                   \
  freopen((string(s) + "." + end1).c_str(), "r", stdin),                       \
      freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i : x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int MAX = 4e18 + 5, MAX2 = 1e18;
int mul(int a, int b) {
  if (a == 0 || b == 0)
    return 0;
  if (a > MAX / b)
    return MAX;
  return a * b;
}
signed main() {
#ifdef BLU
  in("blu.inp");
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 1;
  cin >> n;
  fw(i, 0, n) {
    int x;
    cin >> x;
    ans = mul(ans, x);
  }
  if (ans > MAX2)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
Problem p02658 (C++)

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

using namespace std;

int main() {
  int n;
  unsigned long long a, ans = 1;
  bool overflow = false;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (!a || a <= LIMIT / ans) {
      ans *= a;
    } else {
      overflow = true;
    }
  }

  if (!overflow || ans == 0) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>
#define LIMIT 1000000000000000000

using namespace std;

int main() {
  int n;
  unsigned long long a, ans = 1;
  bool overflow = false;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (!a || !ans || a <= LIMIT / ans) {
      ans *= a;
    } else {
      overflow = true;
    }
  }

  if (!overflow || ans == 0) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}
Problem p02658 (C++)

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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double

const LL INF = 1e18;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  LL a;
  LL w = 1;
  bool czy = 1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      cout << 0;
      return 0;
    }
    LL x = INF / w;
    if (x < a) {
      czy = 0;
    }
    w *= a;
  }
  if (czy)
    cout << w;
  else
    cout << -1;
}


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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double

const LL INF = 1e18;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  LL a;
  LL w = 1;
  bool czy = 1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      cout << 0;
      return 0;
    }
    LL x = INF / w;
    if (x < a) {
      czy = 0;
    }
    if (czy)
      w *= a;
  }
  if (czy)
    cout << w;
  else
    cout << -1;
}
Problem p02658 (C++)

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

using namespace std;
#define sz(x) (int)((x).size())
#define forn(i, n) for (int i = 0; i < n; i++)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

double PI = 3.141592653589793;

void solve() {
  int n;
  cin >> n;
  ll mul = 1;
  ll INF = 1e18;
  bool tem = 1, tem2 = 1;
  forn(i, n) {
    ll k;
    cin >> k;
    if (k <= INF / mul) {
      mul *= k;
    } else
      tem = 0;
    if (k == 0)
      tem2 = 0;
  }
  if (!tem2) {
    cout << 0;
    return;
  }
  cout << (tem ? mul : -1);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  //	cin >> T;
  forse(c, 1, T + 1) {
    //	cout << "Case #" << cid << ": ";
    solve();
  }
}


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

using namespace std;
#define sz(x) (int)((x).size())
#define forn(i, n) for (int i = 0; i < n; i++)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

double PI = 3.141592653589793;

void solve() {
  int n;
  cin >> n;
  ll mul = 1;
  ll INF = 1e18;
  bool tem = 1, tem2 = 1;
  forn(i, n) {
    ll k;
    cin >> k;
    if (mul > 0 && k <= INF / mul) {
      mul *= k;
    } else
      tem = 0;
    if (k == 0)
      tem2 = 0;
  }
  if (!tem2) {
    cout << 0;
    return;
  }
  cout << (tem ? mul : -1);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  //	cin >> T;
  forse(c, 1, T + 1) {
    //	cout << "Case #" << cid << ": ";
    solve();
  }
}
Problem p02658 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> v(N);
  rep(i, N) {
    cin >> v.at(i);
    if (v.at(i) == 0) {
      std::cout << "0" << '\n';
      return 0;
    }
  }
  int64_t a = 1, b = 0, c = 0, x, y, z;
  x = 1000000000000000000;
  rep(i, N) {
    if (a >= x / b) {
      std::cout << "-1" << '\n';
      return 0;
    }
    a *= v.at(i);
  }
  std::cout << a << '\n';
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> v(N);
  rep(i, N) {
    cin >> v.at(i);
    if (v.at(i) == 0) {
      std::cout << "0" << '\n';
      return 0;
    }
  }
  int64_t a = 1, b = 0, c = 0, x, y, z;
  x = 1000000000000000000;
  rep(i, N) {
    if (a > x / v.at(i)) {
      std::cout << "-1" << '\n';
      return 0;
    }
    a *= v.at(i);
  }
  std::cout << a << '\n';
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ

 */
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T, typename cmp=less<T>> using oset =tree<T, null_type,
// cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define inf 100000000000000000
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(), _x.end()
#define f first
#define s second
#define pb push_back
void mahakal() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}
const ll N = 1e6 + 1;
void solve() {
  ll n;
  cin >> n;
  vector<ll> arr(n);
  for (ll i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr.begin(), arr.end());
  ll ans = 1, boundary = 1e18;
  for (ll i = 0; i < n; i++) {
    if ((arr[i] != 0 && arr[i] > boundary / ans) || ans < 0) {
      cout << -1 << endl;
      return;
    }
    ans = ans * arr[i];
  }
  cout << ans << endl;
}
int main() {
  // mahakal(),fast;
  ll t = 1;
  // cin>> t;
  while (t--)
    solve();

  return 0;
}

Fixed submission:
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ

 */
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T, typename cmp=less<T>> using oset =tree<T, null_type,
// cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define inf 100000000000000000
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(), _x.end()
#define f first
#define s second
#define pb push_back
void mahakal() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}
const ll N = 1e6 + 1;
void solve() {
  ll n;
  cin >> n;
  vector<ll> arr(n);
  for (ll i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr.begin(), arr.end());
  ll ans = 1, boundary = 1e18;
  for (ll i = 0; i < n; i++) {
    if (arr[i] == 0 || ans == 0) {
      cout << 0 << endl;
      return;
    }
    if (arr[i] > boundary / ans || ans < 0) {
      cout << -1 << endl;
      return;
    }
    ans = ans * arr[i];
  }
  cout << ans << endl;
}
int main() {
  // mahakal(),fast;
  ll t = 1;
  // cin>> t;
  while (t--)
    solve();

  return 0;
}
Problem p02658 (C++)

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

#define PI 3.14159265358979323846264338327950L

long long res;

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

  int N;
  bool flag = true;
  long long *array = new long long[N];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> array[i];
    if (array[i] == 0) {
      flag = false;
    }
  }

  res = 1;
  if (flag == false) {
    res = 0;
  } else {
    for (int i = 0; i < N; i++) {

      if (array[i] <= 1000000000000000000 / res)

      {
        res *= array[i];
      } else {
        res = -1;
        break;
      }
    }
  }

  cout << res << endl;
  return 0;
}

Fixed submission:
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

#define PI 3.14159265358979323846264338327950L

long long res;

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

  int N;
  bool flag = true;
  // long long *array = new long long [N];
  long long array[100010];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> array[i];
    if (array[i] == 0) {
      flag = false;
    }
  }

  res = 1;
  if (flag == false) {
    res = 0;
  } else {
    for (int i = 0; i < N; i++) {

      if (array[i] <= 1000000000000000000 / res)

      {
        res *= array[i];
      } else {
        res = -1;
        break;
      }
    }
  }

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

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


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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll unsigned long long int
/* run this program using the console pauser or add your own getch,
 * system("pause") or input loop */
using namespace std;

const ll lim = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1;
  bool fail{false}, abs = false;
  while (n--) {
    ll term;
    cin >> term;
    if (term == 0) {
      abs = true;
    }
    if (ans > lim / term) {
      fail = true;
    }
    ans *= term;
  }
  if (abs) {
    cout << 0;
  } else if (fail) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll unsigned long long int
/* run this program using the console pauser or add your own getch,
 * system("pause") or input loop */
using namespace std;

const ll lim = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1;
  bool fail{false}, abs = false;
  while (n--) {
    ll term;
    cin >> term;
    if (term == 0) {
      abs = true;
    }
    if (term != 0 && ans > lim / term) {
      fail = true;
    }
    ans *= term;
  }
  if (abs) {
    cout << 0;
  } else if (fail) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; i < n; i++)

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

  ll a;
  ll ans = 1;
  ll MAX = 1e18;
  bool flag = 0;
  bool zero = 0;

  rep(i, n) {
    cin >> a;
    if (a == 0)
      zero = 1;
    if (ans > MAX / a)
      flag = 1;
    ans *= a;
    // cout << ans << endl;
  }

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

Fixed submission:
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; i < n; i++)

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

  ll a;
  ll ans = 1;
  ll MAX = 1e18;
  bool flag = 0;
  bool zero = 0;

  rep(i, n) {
    cin >> a;
    if (a == 0)
      zero = 1;
    // else if (ans > MAX/a) flag = 1;
    if (ans != 0)
      if (a > MAX / ans)
        flag = 1;
    ans *= a;
    // cout << ans << endl;
  }

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

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

int main() {
  long long N;

  cin >> N;

  vector<long long> A(N);

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

  long long X = 1;
  long long Y = 1;

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

  if (A.at(0) == 0) {
    X = 0;
  }

  for (int i = 0; i < 18; i++) {
    Y = Y * 10;
  }

  for (int i = 0; i < N; i++) {
    long long emer = Y / X + 1;
    X *= A.at(i);
    if (X > Y || A.at(i) > emer) {
      cout << -1 << endl;
      exit(0);
    }
  }

  cout << X << endl;
}


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

int main() {
  long long N;

  cin >> N;

  vector<long long> A(N);

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

  long long X = 1;
  long long Y = 1;

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

  if (A.at(0) == 0) {
    cout << 0 << endl;
    exit(0);
  }

  for (int i = 0; i < 18; i++) {
    Y = Y * 10;
  }

  for (int i = 0; i < N; i++) {
    long long emer = Y / X + 1;
    X *= A.at(i);
    if (X > Y || A.at(i) > emer) {
      cout << -1 << endl;
      exit(0);
    }
  }

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

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
long long arr[100010];
int main() {
  long long sum = 1;
  long long n;
  cin >> n;
  long long max = pow(10, 18);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] <= max / sum) {
      sum *= arr[i];
    } else {
      cout << -1 << endl;
      return 1;
    }
  }
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
long long arr[100010];
int main() {
  long long sum = 1;
  long long n;
  cin >> n;
  long long max = pow(10, 18);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] <= max / sum) {
      sum *= arr[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unsigned long long int arr[n];
  unsigned long long int pro = 1, temp;
  int flag = 0, flag1 = 0;
  for (int a = 0; a < n; a++) {
    cin >> arr[a];
    if (arr[a] == 0) {
      flag = 1;
      cout << "0";
      break;
    }
  }
  if (flag == 0) {
    for (int a = 0; a < n; a++) {
      temp = pro;
      pro *= arr[a];
      if (pro > 1000000000000000000 || (pro / a) != temp) {
        cout << "-1";
        flag1 = 1;
        break;
      }
    }
    if (flag1 == 0)
      cout << pro;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unsigned long long int arr[n];
  unsigned long long int pro = 1, temp;
  int flag = 0, flag1 = 0;
  for (int a = 0; a < n; a++) {
    cin >> arr[a];
    if (arr[a] == 0) {
      flag = 1;
      cout << "0";
      break;
    }
  }
  if (flag == 0) {
    for (int a = 0; a < n; a++) {
      temp = pro;
      pro *= arr[a];
      if (pro > 1000000000000000000 || (pro / arr[a]) != temp) {
        cout << "-1";
        flag1 = 1;
        break;
      }
    }
    if (flag1 == 0)
      cout << pro;
  }
}
Problem p02658 (C++)

Buggy submission (status: 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 (ans > 1000000000000000000 / a) {
      ans = -1;
      over = true;
    } else {
      ans *= a;
    }

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

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

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

Buggy submission (status: 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 (ans <= 1000000000000000000 / A[i]) {
      ans *= A[i];
    } else {
      ok = false;
      break;
    }
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 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 (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;
}
Problem p02658 (C++)

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

int main() {
  int n;
  cin >> n;
  ll pro = 1;
  bool boo = false;
  for (int i = 0; i < n; i++) {
    ll proo = pro;
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
    }
    if (pro > 1000000000000000000 / a) {
      boo = true;
    }
    pro *= a;
  }
  if (boo) {
    cout << -1 << endl;
    return 0;
  }
  if (pro > 1000000000000000000) {
    cout << -1 << endl;
    return 0;
  }
  cout << pro << endl;
}

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

int main() {
  int n;
  cin >> n;
  ll pro = 1;
  bool boo = false;
  for (int i = 0; i < n; i++) {
    ll proo = pro;
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (pro > 1000000000000000000 / a) {
      boo = true;
    }
    pro *= a;
  }
  if (boo) {
    cout << -1 << endl;
    return 0;
  }
  if (pro > 1000000000000000000) {
    cout << -1 << endl;
    return 0;
  }
  cout << pro << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define xx first
#define yy second
#define D if (0)
#define cerr D cerr

using namespace std;
typedef long long ll;

template <typename T> vector<T> read_n(ll n) {
  vector<T> ret(n);
  for (ll i = 0; i < n; i++)
    cin >> ret[i];
  return ret;
}

template <typename iter> void dump(iter begin, iter end) {
  for (iter it = begin; it != end; it++) {
    if (it != begin)
      cout << " ";
    cout << *it;
  }
  cout << endl;
}

const ll top = 1e18;

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

  ll ret = 1;
  ll n;
  cin >> n;

  int fail = 0;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;

    if (top / ret < x) {
      fail = 1;
    }

    if (x == 0) {
      fail = 0;
    }

    ret *= x;
  }

  if (fail) {
    cout << "-1\n";
  } else {
    cout << ret << "\n";
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define xx first
#define yy second
#define D if (0)
#define cerr D cerr

using namespace std;
typedef long long ll;

template <typename T> vector<T> read_n(ll n) {
  vector<T> ret(n);
  for (ll i = 0; i < n; i++)
    cin >> ret[i];
  return ret;
}

template <typename iter> void dump(iter begin, iter end) {
  for (iter it = begin; it != end; it++) {
    if (it != begin)
      cout << " ";
    cout << *it;
  }
  cout << endl;
}

const ll top = 1e18;

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

  ll ret = 1;
  ll n;
  cin >> n;

  int fail = 0;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;

    if (ret != 0 && top / ret < x) {
      fail = 1;
    }

    if (x == 0) {
      fail = 0;
    }

    ret *= x;
  }

  if (fail) {
    cout << "-1\n";
  } else {
    cout << ret << "\n";
  }

  return 0;
}
Problem p02658 (C++)

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

using namespace std;
using ll = long long;

template <typename Tu>
static inline constexpr bool is_multiplication_safe(Tu a, Tu b) {
  return !a || b <= numeric_limits<Tu>::max() / a;
}

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

  ll ans = 1, a = 0;
  int n;
  bool over = false, zero = false;

  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a == 0) {
      zero = true;
      break;
    }
    if (ans * a > 1000000000000000000ll || !is_multiplication_safe(ans, a))
      over = true;
    ans *= a;
  }

  if (zero)
    printf("0\n");
  else if (over)
    printf("-1\n");
  else
    printf("%lld\n", ans);

  return 0;
}

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

using namespace std;
using ll = long long;

template <typename Tu>
static inline constexpr bool is_multiplication_safe(Tu a, Tu b) {
  return !a || b <= numeric_limits<Tu>::max() / a;
}

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

  ll ans = 1, a = 0;
  int n;
  bool over = false, zero = false;

  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a == 0) {
      zero = true;
      break;
    }
    if (!over) {
      if (ans * a > 1000000000000000000ll || !is_multiplication_safe(ans, a))
        over = true;
      ans *= a;
    }
  }

  if (zero)
    printf("0\n");
  else if (over)
    printf("-1\n");
  else
    printf("%lld\n", ans);

  return 0;
}
Problem p02658 (C++)

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

using namespace std;

inline int ctoi(char c) {
  if (c < '0' || '9' < c)
    throw invalid_argument("ctoi error");
  return c - '0';
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T> inline T gcd(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("gcd error: x <= 0 or y <= 0");

  if (x < y)
    swap(x, y);
  T r = x % y;

  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}
template <typename T> inline T lcm(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("lcm error: x <= 0 or y <= 0");

  return x * y / gcd(x, y);
}

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

  vector<unsigned long long int> input;

  rep(i, n) {
    unsigned long long int a;
    cin >> a;

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

  unsigned long long ans = input[0];

  REP(i, 1, input.size()) {
    if (18 <= log10(ans) + log10(input[i])) {
      if (1000000000000000000 / ans == input[i]) {
        ans = 1000000000000000000;
      } else {
        cout << -1;
        return 0;
      }
    } else {
      ans *= input[i];
    }
  }

  cout << ans;

  return 0;
}

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

using namespace std;

inline int ctoi(char c) {
  if (c < '0' || '9' < c)
    throw invalid_argument("ctoi error");
  return c - '0';
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T> inline T gcd(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("gcd error: x <= 0 or y <= 0");

  if (x < y)
    swap(x, y);
  T r = x % y;

  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}
template <typename T> inline T lcm(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("lcm error: x <= 0 or y <= 0");

  return x * y / gcd(x, y);
}

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

  vector<unsigned long long int> input;

  rep(i, n) {
    unsigned long long int a;
    cin >> a;

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

    input.push_back(a);
  }

  unsigned long long ans = input[0];

  REP(i, 1, input.size()) {
    if (18 <= log10(ans) + log10(input[i])) {
      if (1000000000000000000 / ans == input[i]) {
        ans = 1000000000000000000;
      } else {
        cout << -1;
        return 0;
      }
    } else {
      ans *= input[i];
    }
  }

  cout << ans;

  return 0;
}
Problem p02658 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  unsigned long long s = 1;
  for (int i = 0; i < n; i++) {
    if (a.at(i) == 0) {
      cout << 0 << endl;
    }

    if (1000000000000000000 / s < a.at(i)) {
      cout << -1 << endl;
      return 0;
    }

    s *= a.at(i);
  }
  cout << s << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  unsigned long long s = 1;
  for (int i = 0; i < n; i++) {
    if (a.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (1000000000000000000 / s < a.at(i)) {
      cout << -1 << endl;
      return 0;
    }

    s *= a.at(i);
  }
  cout << s << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int flag = 0;
  long long result = 1;
  cin >> N;
  vector<long long> A(N);
  for (int a = 0; a < N; a++)
    cin >> A[a];
  sort(A.begin(), A.end());
  for (int a = 0; a < N; a++) {
    if (1000000000000000000 / result < A[a]) {
      result = -1;
      break;
    }
    result *= A[a];
  }
  cout << result << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int flag = 0;
  long long result = 1;
  cin >> N;
  vector<long long> A(N);
  for (int a = 0; a < N; a++)
    cin >> A[a];
  sort(A.begin(), A.end());
  for (int a = 0; a < N; a++) {
    if (result != 0) {
      if (1000000000000000000 / result < A[a]) {
        result = -1;
        break;
      }
    }
    result *= A[a];
  }
  cout << result << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int inf = (1 << 30);
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, a, n) for (int i = (a - 1); i >= n; i--)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int inf = (1 << 30);
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, a, n) for (int i = (a - 1); i >= n; i--)

int main() {
  ll n;
  cin >> n;
  ll sum = 1;
  ll a[n];
  rep(i, 0, n) cin >> a[i];
  sort(a, a + n);
  rep(i, 0, n) {
    if (a[i] == 0) {
      cout << "0" << endl;
      return 0;
    } else if (a[i] > 1000000000000000000 / sum) {
      cout << "-1" << endl;
      return 0;
    } else
      sum *= a[i];
  }
  cout << sum << endl;
}
Problem p02658 (C++)

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

int main() {

  int berapaKali;
  long long a1[10001];
  long long a2 = 1;
  long long max = 1000000000000000000;

  scanf("%d", &berapaKali);

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

  for (int i = 0; i < berapaKali; i++) {
    if (a1[i] > max) {
      printf("-1");
      return 0;
    }
    a2 *= a1[i];
    max /= a1[i];
  }

  printf("%lld", a2);

  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {

  int berapaKali;
  long long a1[100001];
  long long a2 = 1;
  long long max = 1000000000000000000;

  scanf("%d", &berapaKali);

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

  for (int i = 0; i < berapaKali; i++) {
    if (a1[i] > max) {
      printf("-1");
      return 0;
    }
    a2 *= a1[i];
    max /= a1[i];
  }

  printf("%lld", a2);

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
const long double PI = 3.14159265358979;
const ll MAX = 0;

int main() {
  ll N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = 1;
  sort(A, A + N);
  for (int i = 0; i < N; i++) {
    if (ans > 1000000000000000000 / A[i]) {
      ans = -1;
      break;
    }
    ans *= A[i];
    if (ans > 1000000000000000000) {
      ans = -1;
      break;
    }
    if (ans < 0) {
      ans = -1;
      break;
    }
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
const long double PI = 3.14159265358979;
const ll MAX = 0;

int main() {
  ll N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = 1;
  sort(A, A + N);
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      ans = 0;
      break;
    }
    if (ans > 1000000000000000000 / A[i]) {
      ans = -1;
      break;
    }
    ans *= A[i];
    if (ans > 1000000000000000000) {
      ans = -1;
      break;
    }
    if (ans < 0) {
      ans = -1;
      break;
    }
  }
  cout << ans;
}
Problem p02658 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using lint = long long;

const lint MAX = 1e18;

int main(void) {
  int N;
  cin >> N;
  lint ans = 1;

  int over = 0;
  int zero = 0;
  for (int i = 0; i < N; i++) {
    long long x;
    cin >> x;
    if (x == 0) {
      zero = 1;
    } else if (MAX / ans < x) {
      over = -1;
    }
    ans *= x;
    // cout << ans << endl;
  }
  if (zero == 1)
    cout << 0 << endl;
  else if (over == 0)
    cout << ans << endl;
  else
    cout << over << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using lint = long long;

const lint MAX = 1e18;

int main(void) {
  int N;
  cin >> N;
  lint ans = 1;

  int over = 0;
  int zero = 0;
  for (int i = 0; i < N; i++) {
    long long x;
    cin >> x;
    if (x == 0) {
      zero = 1;
    } else if (ans != 0 && MAX / ans < x) {
      over = -1;
    }
    ans *= x;
    // cout << ans << endl;
  }
  if (zero == 1)
    cout << 0 << endl;
  else if (over == 0)
    cout << ans << endl;
  else
    cout << over << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, ans = 1;
  bool zeros = false, o = false;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0)
      zeros = true;
  }
  for (ll i = 0; i < n; i++) {
    if (ans > 1000000000000000000 / a[i]) {
      o = true;
    } else {
      ans *= a[i];
    }
  }
  if (zeros)
    cout << 0 << endl;
  else if (o)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, ans = 1;
  bool zeros = false, o = false;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0)
      zeros = true;
  }
  if (!zeros) {
    for (ll i = 0; i < n; i++) {
      if (ans > 1000000000000000000 / a[i]) {
        o = true;
      } else {
        ans *= a[i];
      }
    }
  }
  if (zeros)
    cout << 0 << endl;
  else if (o)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02658 (C++)

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

int main() {
  long long A[100100];
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << "0" << endl;
      return 0;
    }
  }

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

  cout << ans << endl;

  return 0;
}

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

int main() {
  long long A[100100];
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << "0" << endl;
      return 0;
    } else {
      A[i] = a;
    }
  }

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

  cout << ans << endl;

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
int main() {
  int n;
  cin >> n;
  long long ans = 1;
  long long MX = 1e18;
  bool ng = false;
  rep(i, 0, n) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (MX / ans < a) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
int main() {
  int n;
  cin >> n;
  long long ans = 1;
  long long MX = 1e18;
  bool ng = false;
  rep(i, 0, n) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || MX / ans < a) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}