alexjercan/bugnet huggingface dataset:
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, j, n) for (int i = j; i < n; i++)
#define rrep(i, j, n) for (int i = j - 1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v)                                                         \\
  rep(__k, v.size()) {                                                         \\
    cout << v[__k];                                                            \\
    if (__k != v.size() - 1)                                                   \\
      cout << " ";                                                             \\
    else                                                                       \\
      cout << endl;                                                            \\
  }
#define YesorNo(a) printf(a ? "Yes\\n" : "No\\n")
#define fi first
#define se second
#define endl "\\n"
using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9 + 7;

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

  int n;
  cin >> n;
  vector<Bint> arr(n);
  rep(i, n) cin >> arr[i];
  sort(arr.begin(), arr.end());

  Bint res = 1;
  rep(i, n) {
    res *= arr[i];
    if (res > 1000000000000000000) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;
using Bint = boost::multiprecision::cpp_int;

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

  vector<Bint> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());

  Bint res = 1;
  for (int i = 0; i < n; i++)
    res *= a[i];

  cout << (res > 1000000000000000000 ? -1 : res) << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: 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 (result != 0) {
      if (1000000000000000000 / result < A[a]) {
        result = -1;
        break;
      }
    }
    result *= A[a];
  }
  cout << result << endl;
}


Error: 0

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 (1000000000000000000 / result < A[a]) {
      result = -1;
      break;
    }
    result *= A[a];
  }
  cout << result << endl;
}
Problem p02658 (C++) — buggy submission, verdict: 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] == 0) {
      cout << "0" << endl;
      return 0;
    } else if (a[i] > 1000000000000000000 / sum) {
      cout << "-1" << endl;
      return 0;
    } else
      sum *= a[i];
  }
  cout << sum << endl;
}

Error: 0

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] > 1000000000000000000 / sum) {
      cout << "-1" << endl;
      return 0;
    } else
      sum *= a[i];
  }
  cout << sum << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\\n"
#define fa(i, n) for (i = 0; i < n; i++)
#define fb(j, n) for (j = 1; j <= n; j++)
using namespace std;
int main() {
  long long int n, a[100006], j, i, z = 0, k = 1, l = 1e18, p = 1;
  cin >> n;
  fa(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      z++;
    }
  }

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\\n"
#define fa(i, n) for (i = 0; i < n; i++)
#define fb(j, n) for (j = 1; j <= n; j++)
using namespace std;
int main() {
  long long int n, a[100006], j, i, z = 0, k = 1, l = 1e18, p = 1;
  cin >> n;
  fa(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      z++;
    }
  }

  for (i = 0; i < n; i++) {
    if (z > 1) {
      cout << "0";
      break;
    }
    { p = p * a[i]; }
    if (l / p < 1 || a[i] < 0) {
      p = -1;
    }
  }
  cout << p;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

namespace adaptor = boost::adaptors;
namespace mp = boost::multiprecision;

void solve() {
  int64_t N;
  std::cin >> N;
  std::vector<mp::cpp_int> A(N);
  bool zero = false;
  for (int64_t i = 0; i < N; i++) {
    std::cin >> A[i];
    if (A[i] == 0) {
      std::cout << "0" << std::endl;
      zero = true;
    }
  }
  if (zero)
    return;

  mp::cpp_int ans = 1;
  for (int64_t i = 0; i < N; i++) {
    ans *= A[i];
    if (ans > (mp::cpp_int)pow(10, 18)) {
      ans = -1;
      break;
    }
  }

  std::cout << ans << std::endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  solve();
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

namespace adaptor = boost::adaptors;
namespace mp = boost::multiprecision;

void solve() {
  int64_t N;
  std::cin >> N;

  mp::cpp_int ans = 1;
  for (int64_t i = 0; i < N; i++) {
    mp::cpp_int tmp;
    std::cin >> tmp;
    if (tmp == 0) {
      ans = 0;
      break;
    }
    ans *= tmp;
  }
  if (ans > (mp::cpp_int)pow(10, 18)) {
    ans = -1;
  }

  std::cout << ans << std::endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  solve();
}
Problem p02658 (C++) — buggy submission, verdict: 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];
    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;
}


Error: 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];
    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, verdict: 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;
    } 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;
}

Error: -8

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

  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, verdict: 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 (ng || MX / ans < a) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Error: 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 (MX / ans < a) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int n;
  cin >> n;
  // vector<long> a;
  long long ans = 1;
  int flag = 0;
  int flag0 = 0;
  long long a;
  long long bans = ans;
  for (int i = 0; i < n; i++) {
    bans = ans;
    // cout << "bans = " << bans << endl;
    cin >> a;
    ans *= a;
    // if(abs(ans) <= 1000000000000000000){
    //     continue;
    // }
    if ((abs(ans) > 1000000000000000000) ||
        (abs(a) > pow(100000000000000000, 1 / n))) {
      flag = 1;
    }
    if (a == 0) {
      flag0 = 1;
    }
  }
  // cout << "bans = " << bans << " ans / a = " << ans / a << endl;
  // long long tmp = ans / a;
  // cout << "lbans = " << bans << endl;
  if (((flag == 1) && (flag0 == 0)) ||
      ((bans != ((int)(ans / a))) && (flag0 == 0))) {
    cout << -1 << endl;
  } else if (flag0 == 1) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }

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

#include <iostream>
#include <vector>

int main() {
  int a, over;
  std::cin >> a;
  long double count;
  count = 1;
  over = 0;
  std::vector<long long int> b(a);
  for (int i = 0; i < a; i++) {
    std::cin >> b[i];
    if (b[i] == 0) {
      count = 0;
    }
    //        std::cout<<count<<std::endl;
  }
  //    std::cout<<count<<std::endl;
  if (count == 0) {
    std::cout << 0 << std::endl;
  } else {
    for (int i = 0; i < a; i++) {
      if (count / 1000000000 * b[i] / 1000000000 > 1) {
        over = -1;
        break;
      }
      count = count * b[i];
      //            std::cout<<count<<std::endl;
    }
    //        std::cout<<count<<std::endl;
    long long int c;
    c = count;
    if (over == -1) {
      std::cout << -1 << std::endl;
    } else {
      std::cout << c << std::endl;
    }
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>

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

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

int main() {
  long long N;
  cin >> N;
  long long X = 1;
  vector<long long> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) == 0) {
      X = 0;
      break;
    }
  }
  if (X != 0) {
    for (int i = 0; i < N; i++) {
      if (A.at(i) <= 1000000000000000000 / X) {
        X *= A.at(i);
      } else {
        X = -1;
        break;
      }
    }
  }
  cout << X;
}


Error: WA

Fixed submission:

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

int main() {
  long long N;
  cin >> N;
  long long X = 1;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) == 0) {
      X = 0;
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) <= 1000000000000000000 / X) {
      X *= A.at(i);
    } else {
      X = -1;
      break;
    }
  }

  cout << X;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG // TLEの原因になるので注意！！！！！！！！！！！
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool Ch = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    ll A = 1000000000000000000 / ans + 1;
    if (ans != 0 && A <= a) {
      Ch = 1;
      ans = 0;
    }
    ans *= a;
  }
  if (Ch == 1) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG // TLEの原因になるので注意！！！！！！！！！！！
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool Ch = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ans != 0 && 1000000000000000000 / ans + 1 <= a) {
      Ch = 1;
    }
    ans *= a;
  }
  if (Ch == 1) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  int N;
  bool is_overflow = false;
  bool is_zero = false;
  ll res = 1, max = 1e18;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    if (a == 0) {
      is_zero = true;
      break;
    }
    if ((double)a > (double)max / (double)res) {
      is_overflow = true;
    }
    res *= a;
    if (res > max) {
      is_overflow = true;
    }
  }

  if (is_zero) {
    cout << 0 << endl;
  } else if (is_overflow) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
typedef long long ll;

int get_digit(ll a) {
  int res = 0;
  while (a / 10 != 0) {
    a /= 10;
    res++;
  }
  return res;
}

int main() {
  int N;
  bool is_overflow = false;
  bool is_zero = false;
  ll res = 1, max = 1e18;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    if (a == 0) {
      is_zero = true;
      break;
    }
    if (a > max / res) {
      is_overflow = true;
    }
    res *= a;
    if (res > max) {
      is_overflow = true;
    }
  }

  if (is_zero) {
    cout << 0 << endl;
  } else if (is_overflow) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long int result;
  int n;
  long long int a[100000] = {};
  n = 0;

  result = 1;
  cin >> n;

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

    cin >> a[i];
    if (1000000000000000000 / result < a[i])
      result = -1;
    if (result != -1)
      result *= a[i];
    if (result > 1000000000000000000)
      result = -1;
    if (a[i] == 0) {
      result = 0;
      break;
    }
  }
  cout << result << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long int n, a[100000], result;
  result = 1;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (result == 0) {
      printf("0");
      return 1;
    } else if (result > 1000000000000000000)
      result = -1;
    else
      result *= a[i];
  }
  cout << result;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  bool zero = false;
  long long res = 1, input;
  vector<long long> numbers;
  for (int i = 0; i < n; ++i) {
    cin >> input;
    if (!input) {
      zero = true;
      break;
    }
    numbers.push_back(input);
  }
  if (zero)
    res = 0;
  else {
    for (int i = 0; i < n; ++i) {
      if (res > 1000000000000000000 / numbers[i]) {
        res = -1;
        break;
      }
      res *= numbers[i];
    }
  }
  cout << res;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<long long> numbers;
  long long res = 1, input;
  for (int i = 0; i < n; ++i) {
    cin >> input;
    numbers.push_back(input);
  }
  sort(numbers.begin(), numbers.end());
  for (int i = 0; i < n; ++i) {
    if (res > 1000000000000000000 / numbers[i]) {
      res = -1;
      break;
    }
    res *= numbers[i];
  }
  cout << res;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  rep(i, n) {
    cin >> a.at(i);
    if (a.at(i) == 0) {
      cout << 0;
      return 0;
    }
  }
  int64_t ans = 1;
  bool is = true;
  rep(i, n) {
    ans *= a.at(i);
    if (ans > 1000000000000000000) {
      is = false;
    }
  }
  int64_t t = ans;
  if (!is) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    t /= a.at(i);
  }
  if (t != a.at(0)) {
    cout << -1;
    return 0;
  }

  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  rep(i, n) { cin >> a.at(i); }
  int64_t ans = 1;
  bool is = true;
  rep(i, n) {
    ans *= a.at(i);
    if (ans > 1000000000000000000) {
      is = false;
    }
  }
  int64_t t = ans;
  for (int i = 1; i < n; i++) {
    t /= a.at(i);
  }
  if (!is && ans != 0) {
    cout << -1;
    return 0;
  }
  if (t != a.at(0)) {
    cout << -1;
    return 0;
  }

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int n;
  cin >> n;
  // ll a;
  vector<ll> a(n);
  int64_t ans = 1;
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (a[i] > (1000000000000000000 / abs(ans))) {
      cout << -1 << endl;
      return 0;
    } else {
      ans *= a[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int n;
  cin >> n;
  ll a;
  int64_t ans = 1;
  rep(i, n) {
    cin >> a;
    if (a > (1000000000000000000 / abs(ans))) {
      ans = -1;
    }
    ans *= a;
  }
  // cout << ans << endl;
  if (ans > 1000000000000000000 || ans < 0) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}