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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long t = 1e18;
int main() {
  int n;
  bool flg = false;
  cin >> n;
  long long s = 1;
  for (int i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << "\n";
      return 0;
    }
    if ((t + 1) / s < tmp || s * tmp > t) {
      flg = true;
    }
    s *= tmp;
  }
  if (flg) {
    cout << -1 << "\n";
    return 0;
  }
  cout << s << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long t = 1e18;
int main() {
  int n;
  bool flg = false;
  cin >> n;
  long long s = 1;
  for (int i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << "\n";
      return 0;
    }
    if (flg || (t + 1) / s < tmp || s * tmp > t) {
      flg = true;
    }
    s *= tmp;
  }
  if (flg) {
    cout << -1 << "\n";
    return 0;
  }
  cout << s << "\n";
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  uint32_t N = 0;
  std::cin >> N;
  int64_t prod = 1;
  for (uint32_t i = 0; i < N; i++) {
    int64_t A = 0;
    std::cin >> A;

    if (prod == -1) {
      if (A == 0)
        prod = 0;
    } else {
      if ((1'000'000'000'000'000'000 + prod - 1) / prod < A) {
        prod = -1;
      } else {
        prod *= A;
        if (prod > 1'000'000'000'000'000'000)
          prod = -1;
      }
    }
  }

  std::cout << prod << std::endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  uint32_t N = 0;
  std::cin >> N;
  int64_t prod = 1;
  for (uint32_t i = 0; i < N; i++) {
    int64_t A = 0;
    std::cin >> A;

    if (prod == -1) {
      if (A == 0)
        prod = 0;
    } else if (prod != 0) {
      if ((1'000'000'000'000'000'000 + prod - 1) / prod < A) {
        prod = -1;
      } else {
        prod *= A;
        if (prod > 1'000'000'000'000'000'000)
          prod = -1;
      }
    }
  }

  std::cout << prod << std::endl;

  return 0;
}
Problem p02658 (C++)

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

int main() {
  int n;
  long long ans = 1, f = 0;
  cin >> n;
  for (int i = 0; n > i; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    cout << ans << endl;
    if (a > 1000000000000000000LL / ans) {
      f = 1;
    }
    ans = ans * a;
  }
  if (f)
    ans = -1;
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  long long ans = 1, f = 0;
  cin >> n;
  for (int i = 0; n > i; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    // cout << ans << endl;
    if (ans > 1000000000000000000LL / a) {
      f = 1;
    }
    ans = ans * a;
  }
  if (f)
    ans = -1;
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

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

int main() {
  int n;
  const long long k = 1000000000000000000;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  long long ans = 1;
  for (long long i = 0; i < n; i++) {
    if (k / ans < a.at(i)) {
      ans = -1;
      break;
    }
    ans *= a.at(i);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  const long long k = 1000000000000000000;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  long long ans = 1;
  for (long long i = 0; i < n; i++) {
    if (ans == 0)
      break;
    else if (k / ans < a.at(i)) {
      ans = -1;
      break;
    }
    ans *= a.at(i);
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

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

int main() {
  int N;
  cin >> N;
  int64_t Z = 1, A = 0;
  int64_t K = 1000000000000000000;
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    if (1 + (K - 1) / Z < a && a != 0) {
      A++;
    } else {
      Z *= a;
    }
  }
  if ((A == 0 && Z <= K) || Z == 0) {
    cout << Z << endl;
  } else {
    cout << "-1" << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  int64_t Z = 1, A = 0;
  int64_t K = 1000000000000000000;
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    if (1 + (K - 1) / Z < a && a != 0) {
      A++;
    } else {
      Z *= a;
    }
    if (Z == 0) {
      break;
    }
  }
  if ((A == 0 && Z <= K) || Z == 0) {
    cout << Z << endl;
  } else {
    cout << "-1" << endl;
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
lint inf = 1E18L + 1;
int main() {
  int n;
  lint out = 1, a;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (inf / out + 1 < a)
      out = inf;
    else
      out *= a;
  }
  if (out >= inf)
    cout << -1 << endl;
  else
    cout << out << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
lint inf = 1E18L + 1;
int main() {
  int n;
  lint out = 1, a;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (out < 1L)
      continue;
    if (inf / out + 1 < a)
      out = inf;
    else
      out *= a;
  }
  if (out >= inf)
    cout << -1 << endl;
  else
    cout << out << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define MOD 1000000007
#define INF 1e18
#define M 1000000009
#define pi 3.14159265358979323846264338327950
typedef pair<int, int> pr;
#define N 1000002
signed main() {
  SPEED;
  int n;
  cin >> n;
  int a[n], ans = 1;
  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])) {
      cout << -1;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define MOD 1000000007
#define INF 1e18
#define M 1000000009
#define pi 3.14159265358979323846264338327950
typedef pair<int, int> pr;
#define N 1000002
signed main() {
  SPEED;
  int n;
  cin >> n;
  int a[n], ans = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (a[0] == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (ans > (1000000000000000000 / a[i])) {
      cout << -1;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

const ll MX = 1e18;

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

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool flag = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (flag || MX / ans < a)
      flag = true;
    ans *= a;
  }
  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() {
  int n;
  cin >> n;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      ans = 0;
    } else if (a <= 1000000000000000000 / ans) {
      ans = ans * a;
    } else {
      ans = -1;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      ans = 0;
      cout << ans << endl;
      return 0;
    } else if (a <= 1000000000000000000 / ans) {
      ans = ans * a;
    } else {
      ans = -1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

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

using namespace std;

#pragma GCC optimize("-O3")
#pragma GCC target("avx2")

#define int long long

const int INF = 1e18;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int m = INF;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    m /= a[i];
  }
  if (m == 0) {
    cout << -1 << endl;
  } else {
    int ans = 1;
    for (auto el : a) {
      ans *= el;
    }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

#pragma GCC optimize("-O3")
#pragma GCC target("avx2")

#define int long long

const int INF = 1e18;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int m = INF;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    m /= a[i];
  }
  if (m == 0) {
    cout << -1 << endl;
  } else {
    int ans = 1;
    for (auto el : a) {
      ans *= el;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
  int n;
  scanf("%d", &n);
  LL ans = 1, x, inf = 1e18, fl = 1, fl1 = 1;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &x);
    if (!x)
      fl1 = 0;
    if (x > inf / ans || (ans * x > inf))
      fl = 0;
    ans *= x;
  }
  if (!fl1 || fl)
    printf("%lld", ans);
  else
    puts("-1");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
  int n;
  scanf("%d", &n);
  LL ans = 1, x, inf = 1e18, fl = 1, fl1 = 1;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &x);
    if (!x)
      fl1 = 0;
    if (fl && (x > inf / ans || ans * x > inf))
      fl = 0;
    ans *= x;
  }
  if (!fl1 || fl)
    printf("%lld", ans);
  else
    puts("-1");
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: 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 (sum > inf / x) {
      sum = -1;
      break;
    } else {
      sum *= x;
    }
  }
  cout << sum << endl;
}


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 (x == 0) {
      sum = 0;
      break;
    }
    if (sum > inf / x) {
      sum = -1;
      break;
    } else {
      sum *= x;
    }
  }
  cout << sum << endl;
}
Problem p02658 (C++)

Buggy submission (status: 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 ((LIMIT / ans) < temp)
      overflowed = true;

    ans = ans * temp;
  }

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

  return 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 (ans != 0 && (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 (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define int long long
template <typename T> using vv = vector<vector<T>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using ll = long long;
constexpr ll INF = 1LL << 60;

signed main() {

  int n;
  cin >> n;

  int ans = 1;
  bool flag = false;
  bool zero = false;
  rep(i, n) {
    int a;
    cin >> a;
    if (a > (ll)(1e18) / ans) {
      flag = true;
    }
    if (a == 0) {
      zero = true;
    }
    ans *= a;
  }

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

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define int long long
template <typename T> using vv = vector<vector<T>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using ll = long long;
constexpr ll INF = 1LL << 60;

signed main() {

  int n;
  cin >> n;

  int ans = 1;
  bool flag = false;
  bool zero = false;
  rep(i, n) {
    int a;
    cin >> a;
    if (ans != 0 && a > (ll)(1e18) / ans) {
      flag = true;
    }
    if (a == 0) {
      zero = true;
    }
    ans *= a;
  }

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

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ll n = 0;
  cin >> n;
  vector<ll> a(n);
  ll res = 0;
  res = 1;
  bool ok = true;
  bool zero = false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    string copy, now;
    copy = to_string(res);
    now = to_string(a[i]);
    // cout << (ll)pow(10,18) / a[i] << " " << res << endl;
    if (res > ((ll)pow(10, 18) / a[i]) + (ll)1) {
      // cout << "!" << endl;
      ok = false;
    }
    if (ok)
      res *= a[i];
    if (res > (ll)pow(10, 18))
      ok = false;
    // cout << res << endl;
    // cout << pow(10,18) << endl;
    if (a[i] == 0)
      zero = true;
  }
  if (ok)
    cout << res << endl;
  else {
    if (zero)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ll n = 0;
  cin >> n;
  vector<ll> a(n);
  ll res = 0;
  res = 1;
  bool ok = true;
  bool zero = false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    string copy, now;
    copy = to_string(res);
    now = to_string(a[i]);
    // cout << (ll)pow(10,18) / a[i] << " " << res << endl;
    if (a[i] == 0) {
      res = 0;
      zero = true;
      break;
    }
    if (res > ((ll)pow(10, 18) / a[i]) + (ll)1) {
      // cout << "!" << endl;
      ok = false;
    }
    if (ok)
      res *= a[i];
    if (res > (ll)pow(10, 18))
      ok = false;
    // cout << res << endl;
    // cout << pow(10,18) << endl;
    if (a[i] == 0)
      zero = true;
  }
  if (ok)
    cout << res << endl;
  else {
    if (zero)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  }
}
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++)
#define REP(i, l, r) for (int i = (l); i < (r); i++)

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

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

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

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

  if (an == 1) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
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 ll = long long;

const ll MX = 1e18;

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

  bool flg = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (MX / ans < a) {
      flg = true;
    }
    ans *= a;
  }
  if (flg)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}


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

const ll MX = 1e18;

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

  bool flg = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (flg || MX / ans < a) {
      flg = true;
    }
    ans *= a;
  }
  if (flg)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
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++)
#define all(v) begin(v), end(v)
using ll = long long;

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


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

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

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

using namespace std;

int main() {
  int n;
  long long a[10010];

  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++;
      break;
    }
  }

  if (zero > 0) {
    printf("0\n");
    return 0;
  }

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

  printf("%lld\n", p);
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n;
  long long a[100010];

  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++;
      break;
    }
  }

  if (zero > 0) {
    printf("0\n");
    return 0;
  }

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

  printf("%lld\n", p);
  return 0;
}
Problem p02658 (C++)

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back

const ll MAX = 1e18;

int main() {
  int n;
  cin >> n;
  vll a(10010);
  ll ans = 1;
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (ans <= MAX / a[i]) {
      ans *= a[i];
    } else {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back

const ll MAX = 1e18;

int main() {
  int n;
  cin >> n;
  vll a(100010);
  ll ans = 1;
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (ans <= MAX / a[i]) {
      ans *= a[i];
    } else {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <math.h>
#include <set>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));

int main() {
  long long int MX = 1e18;
  int n;
  cin >> n;
  long long int a;
  long long int ans = 1;
  bool ng = false;
  rep(i, n) {
    cin >> a;
    if (a == 0) {
      cout << '0';
      return 0;
    }

    if ((MX + 1) / ans < a || ans * a > MX) {
      ng = true;
    }
    ans *= a;
  }
  if (ng)
    cout << "-1";
  else
    cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <math.h>
#include <set>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));

int main() {
  long long int MX = 1e18;
  int n;
  cin >> n;
  long long int a;
  long long int ans = 1;
  bool ng = false;
  rep(i, n) {
    cin >> a;
    if (a == 0) {
      cout << '0';
      return 0;
    }

    if (ng || (MX + 1) / ans < a || ans * a > MX) {
      ng = true;
    }
    ans *= a;
  }
  if (ng)
    cout << "-1";
  else
    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 ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;

  ll ans = 1;
  ll T = 1000000000000000000LL;
  bool over = false;
  rep(i, N) {
    ll A;
    std::cin >> A;
    if (A == 0) {
      std::cout << 0 << '\n';
      return 0;
    }

    if (A > T / ans) {
      over = true;
    }
    ans *= A;
  }

  std::cout << (over ? -1LL : ans) << '\n';
}


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

#define rep(i, n) for (int(i) = 0; i < (n); ++(i))

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;

  ll ans = 1;
  ll T = 1000000000000000000LL;
  bool over = false;
  rep(i, N) {
    ll A;
    std::cin >> A;
    if (A == 0) {
      std::cout << 0 << '\n';
      return 0;
    }

    if (ans <= 0 || A > T / ans) {
      over = true;
    }
    ans *= A;
  }

  std::cout << (over ? -1LL : ans) << '\n';
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int64_t INF = 1e18;
int main() {

  ll n;
  cin >> n;
  vector<ll> a(n);
  ll res = 1;

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

  for (ll i = 0; i < n; i++) {
    if (a[i] == 0) {
      res = 0;
    } else if (a[i] != 0) {
      if (a[i] <= 1000000000000000000 / res)
        res *= a[i];
      else
        res = -1;
    }
  }
  cout << res << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int64_t INF = 1e18;
int main() {

  ll n;
  cin >> n;
  vector<ll> a(n);
  ll res = 1;

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

  for (ll i = 0; i < n; i++) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    } else if (a[i] != 0) {
      if (a[i] <= 1000000000000000000 / res)
        res *= a[i];
      else
        res = -1;
    }
  }
  cout << res << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, mn, flag, sum = 1, cnt;

ll c = 1e18;

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

  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (ll i = 0; i < n; i++) {
    sum *= a[i];
    if (i < n - 1 && a[i + 1] > c / sum && sum != 0) {
      cout << -1;
      return 0;
    }
  }
  cout << sum << endl;
}


Fixed submission:
#include <algorithm>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, mn, flag, sum = 1, cnt;

ll c = 1e18;

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

  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (ll i = 0; i < n; i++) {
    sum *= a[i];
    if (sum == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (i < n - 1 && a[i + 1] > c / sum) {
      cout << -1;
      return 0;
    }
  }
  cout << sum << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  ll N, flag = 0, ans = 1;

  cin >> N;
  vector<ll> a(N);

  rep(i, N) cin >> a[i];

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

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

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  ll N, flag = 0, ans = 1;

  cin >> N;
  vector<ll> a(N);

  rep(i, N) cin >> a[i];

  rep(i, N) {

    if (a[i] <= (ll)1000000000000000000 / ans) {
      ans *= a[i];
    } else {
      flag = 1;
    }
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

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

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>

long long MAX = std::pow(10, 18);

int main(int argc, const char *argv[]) {
  long long N = 0;
  scanf("%lld", &N);

  long long ans = 0;
  scanf("%lld", &ans);

  for (int i = 1; i < N; i++) {
    long long num = 0;
    scanf("%lld", &num);

    if (ans == -1 && num == 0) {
      ans = 0;
    } else if (ans == -1 && num > 0) {
      ans = -1;
    } else if (MAX / ans < num) {
      ans = -1;
    } else {
      ans *= num;
    }
  }

  std::cout << ans;

  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>

long long MAX = std::pow(10, 18);

int main(int argc, const char *argv[]) {
  long long N = 0;
  scanf("%lld", &N);

  long long ans = 0;
  scanf("%lld", &ans);

  for (int i = 1; i < N; i++) {
    long long num = 0;
    scanf("%lld", &num);

    if (ans == -1 && num == 0) {
      ans = 0;
    } else if (ans == -1 && num > 0) {
      ans = -1;
    } else if (MAX / ans < num) {
      ans = -1;
    } else {
      ans *= num;
    }

    if (ans == 0) {
      break;
    }
  }

  std::cout << ans;

  return 0;
}
Problem p02658 (C++)

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

using namespace std;

int main() {
  unsigned int n;
  unsigned long int a[100001];
  unsigned long long int s = 1;
  int t = 0;
  cin >> n;
  for (unsigned int i = 0; i < n; i++) {
    cin >> a[i];

    if (a[i] > 1000000000000000000 / s)
      t = 1;
    else
      s *= a[i];
  }
  if (t == 1)
    cout << -1;
  else
    cout << s;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  unsigned int n;
  unsigned long int a[100001];
  unsigned long long int s = 1;
  int t = 0;
  cin >> n;
  for (unsigned int i = 0; i < n; i++) {
    cin >> a[i];

    if (a[i] > 1000000000000000000 / s)
      t = 1;
    else
      s *= a[i];
    if (a[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  if (t == 1)
    cout << -1;
  else
    cout << s;
  return 0;
}
Problem p02658 (C++)

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

int main() {
  int64_t n, a;
  cin >> n;
  a = 1;
  bool flg = false;
  int64_t upper = 1000000000000000000;
  for (int i = 0; i < n; i++) {
    int64_t tmp;
    cin >> tmp;
    if (tmp == 0) {
      a = 0;
      break;
    }
    if (tmp > (upper / a)) {
      flg = true;
    }
    a *= tmp;
    if (a > upper) {
      flg = true;
    }
  }

  if (a == 0) {
    cout << a << endl;
  } else if (flg) {
    cout << -1 << endl;
  } else if (a < 0) {
    cout << -1 << endl;
  } else {
    cout << a << endl;
  }
}

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

int main() {
  int64_t n, a;
  cin >> n;
  a = 1;
  bool flg = false;
  int64_t upper = 1000000000000000000;
  for (int i = 0; i < n; i++) {
    int64_t tmp;
    cin >> tmp;
    if (tmp == 0) {
      a = 0;
      break;
    } else if (a > (upper / tmp)) {
      flg = true;
    }
    a *= tmp;
    if (a > upper) {
      flg = true;
    }
  }

  if (a == 0) {
    cout << a << endl;
  } else if (flg) {
    cout << -1 << endl;
  } else if (a < 0) {
    cout << -1 << endl;
  } else {
    cout << a << endl;
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a, ll n, ll m);
ll power(ll a, ll n, ll m) {
  if (n == 0)
    return 1;
  ll x = power(a, n / 2, m);
  if (n % 2 != 0)
    return (((a * x) % m) * (x) % m) % m;
  else
    return (x * x) % m;
}
map<ll, ll>::iterator itr;
ll ans;
double PI = 3.14159265357;
int32_t main() {
  ll n, i, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a, o, temp;
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  ll arr[n];
  for (i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  cnt = 1;
  for (i = 0; i < n; i++) {
    if (arr[i] > (inf / cnt)) {
      cout << "-1\n";
      return 0;
    }
    cnt = (cnt * arr[i]);
  }
  cout << cnt;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a, ll n, ll m);
ll power(ll a, ll n, ll m) {
  if (n == 0)
    return 1;
  ll x = power(a, n / 2, m);
  if (n % 2 != 0)
    return (((a * x) % m) * (x) % m) % m;
  else
    return (x * x) % m;
}
map<ll, ll>::iterator itr;
ll ans;
double PI = 3.14159265357;
int32_t main() {
  ll n, i, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a, o, temp;
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  ll arr[n];
  for (i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  cnt = 1;
  for (i = 0; i < n; i++) {
    if (arr[i] == 0) {
      cout << "0\n";
      return 0;
    }

    if (arr[i] > (inf / cnt)) {
      cout << "-1\n";
      return 0;
    }
    cnt = (cnt * arr[i]);
  }
  cout << cnt;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)

int main() {
  ios::sync_with_stdio(false);
  int n, t = 0;
  ll w = 1, k, a = 1000000000000000000;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    if (k == 0) {
      cout << "0";
      return 0;
    }
    if (a / w < k)
      t = 1;
    w = w * k;
  }
  if (t)
    cout << "-1";
  else
    cout << w;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)

int main() {
  ios::sync_with_stdio(false);
  int n, t = 0;
  ll w = 1, k, a = 1000000000000000000;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    if (k == 0) {
      cout << "0";
      return 0;
    }
    if (a / w < k)
      t = 1;
    if (!t)
      w = w * k;
  }
  if (t)
    cout << "-1";
  else
    cout << w;
  return 0;
}
Problem p02658 (C++)

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

int main() {
  int n;
  cin >> n;
  unsigned long long x;
  unsigned long long z = 1;
  bool flag = false;
  bool zeroflag = false;
  for (int i = 0; i < n; i++) {
    cin >> x;

    if (x == 0) {
      zeroflag = true;
    }
    if (x <= 1000000000000000000 / z) {
      z = z * x;
    } else {
      flag = true;
    }
  }
  if (!zeroflag) {
    if (!flag) {
      cout << z << endl;
    } else {
      cout << -1 << endl;
    }
  } else {
    cout << 0 << endl;
  }

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  unsigned long long x;
  unsigned long long z = 1;
  bool flag = false;
  bool zeroflag = false;
  for (int i = 0; i < n; i++) {
    cin >> x;

    if (x == 0) {
      zeroflag = true;
      break;
    }
    if (x <= 1000000000000000000 / z) {
      z = z * x;
    } else {
      flag = true;
    }
  }
  if (!zeroflag) {
    if (!flag) {
      cout << z << endl;
    } else {
      cout << -1 << endl;
    }
  } else {
    cout << 0 << endl;
  }

  return 0;
}
Problem p02658 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<long long int> a(n);
  int zer = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      zer = 1;
  }
  long long int ans = 1;
  for (int i = 0; i < n; i++) {
    long long int op = 1000000000000000000LL / ans;
    long long int p = (1000000000000000001LL) / ans;
    if (p != op)
      p = op;
    if (a[i] > p) {
      if (zer == 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
    ans = ans * a[i];
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<long long int> a(n);
  int zer = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      zer = 1;
  }
  long long int ans = 1;
  for (int i = 0; i < n; i++) {
    if (ans == 0) {
      cout << "0" << endl;
      return 0;
    }
    long long int op = 1000000000000000000LL / ans;
    long long int p = (1000000000000000001LL) / ans;
    if (p != op)
      p = op;
    if (a[i] > p) {
      if (zer == 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
    ans = ans * a[i];
  }
  cout << ans << endl;
}
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;

const long long mx = 1e18;

int main() {
  int n;
  long long ans = 1;
  bool ng = false;
  cin >> n;
  rep(i, n) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (a > (mx / ans)) {
      ng = true;
    }
    ans *= a;
  }

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


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

using namespace std;

const long long mx = 1e18;

int main() {
  int n;
  long long ans = 1;
  bool ng = false;
  cin >> n;
  rep(i, n) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (ans > (mx / a)) {
      ng = true;
    }
    ans *= a;
  }

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

Buggy submission (status: Runtime Error):
#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;
}


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

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

using ll = long long;
#define max_sum 1000000000000000000

int main() {

  ll n;
  cin >> n;
  ll a;
  long long sum = 1;
  bool flag = 0;

  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      flag = 0;
      sum = 0;
    }
    if (flag || max_sum / sum < a) {
      flag = 1;
      sum = 0;
    } else {
      sum *= a;
    }
  }

  if (flag == 1) {
    cout << -1 << endl;
  } else {
    cout << sum << endl;
  }
}

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

using ll = long long;
#define max_sum 1000000000000000000

int main() {

  ll n;
  cin >> n;
  ll a;
  long long sum = 1;
  bool flag = 0;

  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (flag || max_sum / sum < a) {
      flag = 1;
      sum = 0;
    } else {
      sum *= a;
    }
  }

  if (flag == 1) {
    cout << -1 << endl;
  } else {
    cout << sum << endl;
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k, x, l(1);
  cin >> n;
  k = pow(10, 18);
  for (int i = 0; i < n; i++) {
    cin >> x;
    k = k / x;
    l *= x;
  }
  if (k == 0) {
    cout << "-1";
  } else
    cout << l;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k, x, l(1);
  cin >> n;
  k = pow(10, 18);
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 0) {
      l = 0;
      k = 1;
      break;
    }
    k = k / x;
    l *= x;
  }
  if (k == 0) {
    cout << "-1";
  } else
    cout << l;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;
int n;
ll A[MAXN];

void solve() {
  ll ans = 1;
  sort(A, A + n);
  for (int i = 0; i < n; i++) {
    if (1000000000000000000 / ans < A[i]) {
      cout << -1 << endl;
      return;
    }
    ans *= A[i];
    if (ans > 1000000000000000000) {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  solve();
}


Fixed submission:
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;
int n;
ll A[MAXN];

void solve() {
  ll ans = 1;
  sort(A, A + n);
  for (int i = 0; i < n; i++) {
    if (ans == 0) {
      cout << 0 << endl;
      return;
    }
    if (1000000000000000000 / ans < A[i]) {
      cout << -1 << endl;
      return;
    }
    ans *= A[i];
    if (ans > 1000000000000000000) {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  solve();
}
Problem p02658 (C++)

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

using namespace std;
using ll = long long;

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < (int)s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

istream &operator>>(istream &is, __int128_t &a) {
  string s;
  is >> s;
  a = parse(s);
  return (is);
}
using Int = __int128_t;

int main() {
  int n;
  cin >> n;
  vector<Int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (count(a.begin(), a.end(), Int(0))) {
    cout << 0 << endl;
    return 0;
  }
  Int t = 1;
  for (int i = 0; i < n; i++) {
    if (t * a[i] > Int(1000000000000000000)) {
      cout << -1 << endl;
      return -1;
    }
    t *= a[i];
  }
  cout << t << endl;
}

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

using namespace std;
using ll = long long;

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < (int)s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

istream &operator>>(istream &is, __int128_t &a) {
  string s;
  is >> s;
  a = parse(s);
  return (is);
}
using Int = __int128_t;

int main() {
  int n;
  cin >> n;
  vector<Int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (count(a.begin(), a.end(), Int(0))) {
    cout << 0 << endl;
    return 0;
  }
  Int t = 1;
  for (int i = 0; i < n; i++) {
    if (t * a[i] > Int(1000000000000000000)) {
      cout << -1 << endl;
      return 0;
    }
    t *= a[i];
  }
  cout << t << endl;
}