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

#include <bits/stdc++.h>
using namespace std;
long long 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) {
    cout << "0\\n" << endl;
    return 0;
  }
  long long prod = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      cout << "-1\\n" << endl;
      return 0;
    }
  }
  cout << prod << endl;
}


Error: 0

Fixed submission:

/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll long long int
#define pb push_back
#define ull unsigned long long int
#define endl "\\n"
#define sz(c) (c).size()
#define sall(c) sort((c).begin(), (c).end())
#define rsall(c) sort((c).rbegin(), (c).rend())
#define rev(c) reverse((c).begin(), (c).end())
#define FOR(i, n) for (ll i = 0; i < n; i++)
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
#define input(a, i, n)                                                         \\
  for (ll i = 0; i < n; i++) {                                                 \\
    cin >> a[i];                                                               \\
  }
#define output(a, i, n)                                                        \\
  for (ll i = 0; i < n; i++) {                                                 \\
    cout << a[i] << " ";                                                       \\
  }

using namespace std;
int64_t R = 1;
const int max_v = 100010;
int a[max_v];
int main() {
  int64_t n, res = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0" << endl;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / res) {
      res *= a[i];
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << res << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: 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 (a[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  if (t == 1)
    cout << -1;
  else
    cout << s;
  return 0;
}

Error: WA

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 (t == 1)
    cout << -1;
  else
    cout << s;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout << ((f) ? "Yes" : "No") << endl;
#define YORN(f) cout << ((f) ? "YES" : "NO") << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (a[i] == 0) {
      println(0);
      return 0;
    }
  }
  ll prod = 1;
  rep(i, n) {
    if (a[i] > (ll)1000000000000000000 / prod) {
      println(-1);
      return 0;
    }
    prod *= a[i];
  }
  println(prod);

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout << ((f) ? "Yes" : "No") << endl;
#define YORN(f) cout << ((f) ? "YES" : "NO") << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ld log = 0;
  rep(i, n) { log += log10(a[i]); }
  if (log > 18 + 1e-2) {
    println(-1) return -1;
  }

  ll x = 1;
  rep(i, n) { x *= a[i]; }
  if (x > 1000000000000000000) {
    println(-1)
  } else {
    println((ll)x);
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool hantei = true;
  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  if (a[0] == 0)
    cout << "0" << endl;
  else {
    rep(i, n) {
      if (a[n - i - 1] > 1000000000000000000 / ans) {
        cout << "-1" << endl;
        return 0;
      } else {
        ans *= a[n - i - 1];
      }
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool hantei = true;
  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  if (a[0] == 0)
    cout << "0" << endl;
  else {
    rep(i, n) {
      if (a[n - i - 1] > 1000000000000000000 / ans)
        hantei = false;
      ans *= a[n - i - 1];
    }
    if (hantei == false)
      cout << "-1" << endl;
    else
      cout << ans << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip> // std::setprecision()
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) { cin >> a[i]; }
  sort(a.begin(), a.end());

  if (a[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll sum = 1;
  rep(i, 0, n) {
    if (sum > (long long)pow(10, 18) / a[i]) {
      cout << -1 << endl;
      return 0;
    }
    sum *= a[i];
  }
  cout << sum << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iomanip> // std::setprecision()
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  ll x = 1;
  rep(i, 0, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  rep(i, 0, n) {
    if (i == 0) {
      sum = a[i];
    } else {
      sum *= a[i];
    }
    if (sum > (long long)pow(10, 18) / a[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main() {
  int N;
  cin >> N;
  vector<Bint> A(N);
  rep(i, N) cin >> A[i];
  Bint ans = 1;
  sort(A.begin(), A.end());
  rep(i, N) {
    ans *= A[i];
    if (ans > 1000000000000000000) {
      cout << -1;
      return 0;
    }
  }

  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main() {
  int N;
  cin >> N;
  vector<Bint> A(N);
  rep(i, N) cin >> A[i];
  Bint ans = 1;
  rep(i, N) { ans *= A[i]; }
  if (ans > 1000000000000000000) {
    cout << -1;
    return 0;
  } else
    cout << ans;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize(3)
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
// #include<ext/rope>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
const double PI = acos(-1.0);
const double eps = 1e-6;
ll a[100005];
int main() {
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);
  // cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  ll s = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      s = 0;
      break;
    } else if (s > INFL / a[i] || a[i] > INFL / s) {
      cout << -1 << endl;
      return 0;
    } else
      s = s * a[i];
  }
  if (s < 0 || s > 1000000000000000000)
    s = -1;
  cout << s << endl;
  return 0;
}


Error: 0

Fixed submission:

#pragma GCC optimize(3)
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
// #include<ext/rope>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
const double PI = acos(-1.0);
const double eps = 1e-6;
ll a[100005];
int main() {
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);
  // cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  ll s = 1;
  for (int i = 1; i <= n; i++) {
    if (s > INFL / a[i]) {
      cout << -1 << endl;
      return 0;
    } else
      s = s * a[i];
  }
  if (s < 0 || s > 1000000000100000000)
    s = -1;
  cout << s << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: 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];
    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;
  }
}

Error: 0

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

#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);

int main() {
  long long int max = pow(10, 18);

  long long int N;
  cin >> N;

  long long int A[N];
  long long int res;

  for (long long int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  res = 1l;

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

  printf("%lld\\n", res);

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);

int main() {
  long long int max = pow(10, 18);

  long long int N;
  cin >> N;

  long long int A[N];
  long long int res;

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

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

  printf("%lld\\n", res);

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

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

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

  long long *a;
  a = new long long[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      delete[] a;
      return 0;
    }
  }

  long long ans = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] > 1000000000000000000 / ans) {
      ans = -1;
      break;
    }
    ans *= a[i];
  }

  cout << ans << endl;
  delete[] a;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

  long long a, ans = 1;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a > 1000000000000000000 / ans) {
      flag = 1;
    }
    ans *= a;
  }
  if ((flag == 1) && (ans != 0))
    ans = -1;
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

// GNU C Compiler
// template<class T> inline string toString(T x) { ostringstream sout; sout <<
// x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
// using pair<T1, T2> = p12;

// container
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define ALL(v) v.begin(), v.end()

// repetition
#define REP(n) for (int i = 0; i < (n); i++)
#define REPj(n) for (int j = 0; j < (n); j++)
#define REPinit(i, a, n) for (int i = (a); i < (n); i++)
#define REPinitj(j, a, n) for (int j = (a); j < (n); j++)

// algorithm
// #define SORT(c) sort((c).begin(),(c).end())

// constant

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// Optimizer
//  #pragma GCC optimize("Ofast")
//  #pragma GCC
//  target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
        add utility Algorithm
*/

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;

  vector<ull> a(N, 0);
  REPinit(i, 0, N) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << (0) << endl;
      return 0;
    }
  }

  ull ans = 1;
  const ull boundary = 1000000000000000000;
  REPinit(i, 0, N) {
    if (a[i] <= boundary / ans) {
      ans *= a[i];
    } else {
      cout << (-1) << endl;
      return 0;
    }
  }

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


Error: 0

Fixed submission:

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

// GNU C Compiler
// template<class T> inline string toString(T x) { ostringstream sout; sout <<
// x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
// using pair<T1, T2> = p12;

// container
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define ALL(v) v.begin(), v.end()

// repetition
#define REP(n) for (int i = 0; i < (n); i++)
#define REPj(n) for (int j = 0; j < (n); j++)
#define REPinit(i, a, n) for (int i = (a); i < (n); i++)
#define REPinitj(j, a, n) for (int j = (a); j < (n); j++)

// algorithm
// #define SORT(c) sort((c).begin(),(c).end())

// constant

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// Optimizer
//  #pragma GCC optimize("Ofast")
//  #pragma GCC
//  target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
        add utility Algorithm
*/

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;

  vector<ull> a(N, 0);
  REPinit(i, 0, N) cin >> a[i];

  sort(ALL(a));

  ull ans = 1;
  const ull boundary = 1e18;
  REPinit(i, 0, N) {
    if (a[i] <= boundary / ans) {
      ans *= a[i];
    } else {
      cout << (-1) << endl;
      return 0;
    }
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
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;
}


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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#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;
}


Error: 0

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

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

Error: 0

Fixed submission:

#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;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
long long 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;
  }
  long long 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);
}

Error: WA

Fixed submission:

// b
#include <bits/stdc++.h>
#define int long long
#define inf 10000000000000
using namespace std;

int a[30000], t = 0, n;
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0)
      return cout << 0 << endl, 0;
  }
  for (int i = 1; i <= n; i++) {
    if (t > inf / a[i])
      return cout << -1 << endl, 0;
    t *= a[i];
  }
  cout << t - 1 << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using bint = boost::multiprecision::cpp_int;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  bool ok = true;
  bint ans = 1;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(a.begin(), a.end());
  rep(i, n) {
    ans *= a[i];
    if (ans > 1000000000000000000) {
      ok = false;
      break;
    }
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using bint = boost::multiprecision::cpp_int;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  bint ans = 1;
  bool ok = true;
  rep(i, n) {
    bint a;
    cin >> a;
    ans *= a;
  }
  if (ans > 1000000000000000000)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}