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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

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

  vector<ll> a(n);
  bool zero = false;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];

    if (a[i] == 0)
      zero = true;
  }

  if (zero) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1LL;
  ll x = ll(1e18);
  for (int i = 0; i < n; ++i) {
    if (a[i] <= x / ans) {
      ans *= a[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

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

  vector<ll> a(n);
  bool zero = false;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];

    if (a[i] == 0)
      zero = true;
  }

  if (zero) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1LL;
  ll x = 1e18;
  for (int i = 0; i < n; ++i) {
    ans *= a[i];

    if (a[i] < x / ans) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;

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

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

int main() {
  long long int n, k = 1, a[100001];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      k = 0;
      break;
    }
    if (k > 1000000000000000000 / a[i] || k == -1) {
      k = -1;
    } else {
      k *= a[i];
    }
  }
  cout << k;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  long long int n, k = 1, a[10001];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      k = 0;
      break;
    }
    if (k > 1000000000000000000 / a[i] || k == -1) {
      k = -1;
    } else {
      k *= a[i];
    }
  }
  cout << k;
  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;

constexpr ll INF = ll(1e+18) + 1;

int main() {
  int N;
  vector<ll> A;
  ll ans = 1, LIM = 1e+18, buf;

  cin >> N;
  rep(i, N) {
    cin >> buf;
    if (buf == 0) {
      cout << 0 << endl;
      return 0;
    }
    A.push_back(buf);
  }
  rep(i, N) {
    if (LIM / ans < A[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= A[i];
  }
  cout << ans << endl;
}


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;

constexpr ll INF = ll(1e+18) + 1;

int main() {
  int N;
  ll A, ans = 1, LIM = 1e+18;
  bool ng = false;

  cin >> N;
  rep(i, N) {
    cin >> A;
    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (LIM / ans < A) {
      ng = true;
    }
    ans *= A;
  }
  if (ng == true) {
    ans = -1;
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1) // sからnまでのループ
#define rep(i, n) rep2(i, 0, n)        // 0からnまでのループ

using namespace std;

int main() {
  int n;
  cin >> n;
  long long int x;
  bool done = false;
  bool zero = false;
  long long int MAX = pow(10, 18);
  long double tot = 1;

  rep(i, n) {
    cin >> x;
    tot *= x;
    if (x == 0) {
      zero = true;
    } else if (tot > MAX || tot < 0) {
      done = true;
    }
  }

  if (zero) {
    cout << 0 << endl;
  } else if (done) {
    cout << -1 << endl;
  } else {
    cout << (long long int)tot << endl;
  }
}

Error: WA

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  long long x[n];
  for (int i; i < n; i++)
    cin >> x[n];
  long long count1 = 1;
  long long count2 = 0;
  bool xx = true;

  for (int i; i < n; i++) {
    if (x[i] = 0) {
      count1 = 0;
      break;
    }
    count1 = count1 * x[i] % 1000000000000000000;
    count2 = count1 * x[i] / 1000000000000000000;
    if (count2) {
      xx = false;
      break;
    }
  }
  if (xx)
    cout << count1 << endl;
  else
    cout << -1 << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;

  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\\n", prod));
  return 0;
}


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


Fixed submission:

#include <stdio.h>

int main() {

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

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

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

#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
const llong N = 1e18;
int main() {
  int n;
  llong a = 1, b, c;
  scanf("%d", &n);
  while (n--) {
    scanf("%lld", &b);
    if (b == 0) {
      a = 0;
      break;
    }
    c = N / a;
    if (b > c) {
      a = -1;
    }
    a = a * b;
  }
  a = a < 0 ? -1 : a;
  cout << a;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
const llong N = 1e18;
int main() {
  int n;
  llong a = 1, b, c;
  scanf("%d", &n);
  while (n--) {
    scanf("%lld", &b);
    c = N / b;
    if (a > c) {
      a = -1;
    }
    a = a * b;
  }
  a = a < 0 ? -1 : a;
  cout << a;

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, x, y) for (int i = x; i < (y); ++i)
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
/* start */

signed main() {
  IOS;
  int n;
  cin >> n;
  int ans = 1, roof = (int)1e18;
  rep(i, 0, n) {
    int x;
    cin >> x;
    if (x == 0) {
      cout << "0\\n";
      return 0;
    } else if (x == 1)
      continue;
    else {
      int y = roof / ans;
      if (x <= y)
        ans *= x;
      else
        ans = roof + 1;
    }
  }
  if (ans > roof)
    cout << "-1\\n";
  else
    cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, x, y) for (int i = x; i < (y); ++i)
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
/* start */

signed main() {
  IOS;
  int n;
  cin >> n;
  int ans, roof = (int)1e18;
  cin >> ans;
  rep(i, 0, n - 1) {
    int x;
    cin >> x;
    if (x == 0)
      ans = 0;
    else if (x == 1)
      continue;
    else {
      int y = roof / ans;
      if (x <= y)
        ans *= x;
      else
        ans = roof + 1;
    }
  }
  if (ans > roof)
    cout << "-1\\n";
  else
    cout << ans << "\\n";
}

/*


   x*y > 1e18 ?
   x > 1e18/y

*/
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  boost::multiprecision::cpp_int sum = 1;
  for (auto &i : a) {
    cin >> i;
    if (i == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    sum *= a[i];
    if (sum > 1000000000000000000) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  boost::multiprecision::cpp_int z, sum = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> z;
    sum *= z;
  }
  if (sum > 1000000000000000000) {
    cout << -1 << endl;
  } else {
    cout << sum << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define K 1000000000000000000

int main() {
  long long ans = 1;
  int n;
  bool flag = false;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long b;
    cin >> b;
    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (flag || (K + 1) / ans < b || ans * b > K) {
      flag = true;
    }
    ans *= b;
  }

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


Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define K 1000000000000000001

int main() {
  long long ans = 1;
  int n;
  bool flag = false;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long b;
    cin >> b;
    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (K / ans <= b && ans * b != 1000000000000000000) {
      flag = true;
    }
    ans *= b;
  }

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

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define K 1000000000000000000

int main() {
  long long ans = 1;
  int n;
  bool flag = false;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long b;
    cin >> b;
    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (flag || K / ans < b || ans * b > K) {
      flag = true;
    }
    ans *= b;
  }

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


Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define K 1000000000000000000

int main() {
  long long ans = 1;
  int n;
  bool flag = false;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long b;
    cin >> b;
    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }

    if ((K + 1) / ans < b || ans * b > K) {
      flag = true;
    }
    ans *= b;
  }

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

#include <bits/stdc++.h>
using namespace std;
// T+N
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#define endl "\\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <class T, class T2> inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2> inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const ll mod = 1000000000000000000ll;
template <class T> inline void fix(T &x) {
  if (x >= mod || x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
  // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll n, ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    } else if (a > (2 * mod) / ans) {
      ans = 2 * mod;
    } else {
      ans *= a;
    }
  }
  if (ans > mod) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// T+N
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#define endl "\\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <class T, class T2> inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2> inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const ll mod = 1000000000000000000ll;
template <class T> inline void fix(T &x) {
  if (x >= mod || x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
  // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll n, ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      ans = 0;
    } else if (a > (2 * mod) / ans) {
      ans = 2 * mod;
    } else {
      ans *= a;
    }
  }
  if (ans > mod) {
    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 FAST_IO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
// #define MULTIPLE_TESTS 1

int n;
vector<ll> arr;
void readArray() {
  arr.resize(n);
  for (auto &a : arr) {
    cin >> a;
  }
}

void solve() {
  cin >> n;
  readArray();
  ll res = arr[0];
  for (int i = 0; i < n; ++i) {
    if (arr[i] == 0) {
      cout << 0 << endl;
      return;
    }
  }
  const ll MAX = 1e18;
  for (int i = 1; i < n; ++i) {
    if (arr[i] > int64_t(MAX / res)) {
      cout << "-1" << endl;
      return;
    }
    res *= arr[i];
  }
  cout << res << endl;
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
// #define MULTIPLE_TESTS 1

int n;
vector<ll> arr;
void readArray() {
  arr.resize(n);
  for (auto &a : arr) {
    cin >> a;
  }
}

void solve() {
  cin >> n;
  readArray();
  ll res = arr[0];
  vector<int> arr;
  for (int i = 0; i < n; ++i) {
    if (arr[i] == 0) {
      cout << 0 << endl;
      return;
    }
  }
  cout << "here" << endl;
  return;
  for (int i = 1; i < n; ++i) {
    if (res > ll((1e18) / arr[i])) {
      cout << "-1" << endl;
      return;
    }
    res *= arr[i];
  }
  cout << res << endl;
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mx = 1e18;
int n, a;
int ans = 1;
int calcws(int x) {
  int cnt = -1;
  while (x)
    x /= 10, cnt++;
  return cnt;
}
int g(int x) {
  while (x >= 10)
    x /= 10;
  return x;
}
signed main() {
  cin >> n;
  a = 1ll;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    int rr = (g(a) * g(x)) >= 10;
    if (calcws(a) + calcws(x) + rr >= 18)
      ans = -1;
    a = a * x;
    if (a == mx)
      ans = 1;
    if ((a && a < x) || a > mx)
      ans = -1;
    if (x == 0)
      ans = 0;
  }
  if (ans == -1 || ans == 0)
    cout << ans << endl;
  else
    cout << a << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mx = 1e18;
int n, a;
int ans = 1;
int calcws(int x) {
  int cnt = -1;
  while (x)
    x /= 10, cnt++;
  return cnt;
}
int g(int x) {
  while (x > 10)
    x /= 10;
}
signed main() {
  cin >> n;
  a = 1ull;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    int rr = (g(a) + g(x) > 10);
    if (calcws(a) + calcws(x) + rr >= 18)
      ans = -1;
    a = a * x;
    if ((a && a < x) || a > mx)
      ans = -1;
    if (x == 0)
      ans = 0;
  }
  if (ans == -1 || ans == 0)
    cout << ans << endl;
  else
    cout << a << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

const unsigned long long int maxv = pow(10, 18);
int main(void) {

  int N;
  unsigned long long int A;

  cin >> N;
  vector<unsigned long long int> vec{};

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

  sort(vec.begin(), vec.end());
  __int128 ans = vec[0];

  if (ans == 0) {
    cout << 0 << endl;
  } else {
    for (int i = 1; i < N; i++) {

      if (ans * vec[i] > maxv) {
        cout << -1 << endl;
        return 0;
      }

      ans *= vec[i];
    }
    unsigned long long t = ans;
    cout << t << endl;
  }
}

Error: -11

Fixed submission:

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

const unsigned long long int maxv = pow(10, 18);
int main(void) {

  unsigned long long int N, ans;
  vector<unsigned long long int> vec{};
  cin >> N;

  for (unsigned long long int i = 0; i < N; i++)
    cin >> vec[i];
  sort(vec.begin(), vec.end());
  ans = vec[0];
  if (ans == 0) {
    cout << 0 << endl;
  } else {
    for (unsigned long long int i = 1; i < N; i++) {
      ans *= vec[i];
      if (ans > maxv) {
        cout << -1 << endl;
        return 0;
      }
    }

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

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

int main() {
  long long n;
  cin >> n;
  long long ar[n + 5];
  long long res = 1;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] == 0) {
      cout << "0";
      return 0;
    }
    if (ar[i] <= 1000000000000000000 / res)
      res *= ar[i];
    else {
      res = -1;
      continue;
    }
  }
  cout << res;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  long long ar[n + 5];
  long long res = 1;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] == 0) {
      res = 0;
      continue;
    }
    if (ar[i] <= 1000000000000000000 / res)
      res *= ar[i];
    else {
      res = -1;
      continue;
    }
  }
  cout << res;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n + 1];
  int z = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (a[0] == 0)
    cout << "0" << endl;
  else {
    long long ans = 1;
    long long z = 1000000000000000000 / n;

    int flag = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] > z) {
        flag = 1;
        break;
      }
      ans *= a[i];
      z = 1000000000000000000 / ans;
    }
    if (flag == 1 || ans > 1000000000000000000)
      cout << "-1" << endl;
    else
      cout << ans << endl;
  }
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>
using namespace std;

typedef long long ll;
const ll maxn = 1e18;
int main() {
  long long sum = 1;
  int n;
  long long mid;
  cin >> n;
  int flag = 0;
  while (n--) {
    cin >> mid;
    if (mid == 0) {
      flag = -1;
    }
    if (maxn / sum >= mid)
      sum *= mid;
    else
      flag = 1;
  }

  if (flag == 1)
    cout << "-1";
  else if (flag == -1)
    cout << "0";
  else
    cout << sum;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const long long MAX = 1000000000000000000LL;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (auto &e : a)
    cin >> e;
  sort(a.begin(), a.end());
  long long ans = 1;
  for (int i = 0; i < n; ++i) {
    if (ans && a[i] > MAX / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
#include <iostream>

using namespace std;

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

int main() {
  int n;
  cin >> n;
  Bint ans = 1;
  for (int i = 0; i < n; ++i) {
    Bint a;
    cin >> a;
    ans *= a;
  }
  if (ans > (Bint)1000000000000000000LL)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  ll tmp, res = 1, max = 1000000000000000000;
  cin >> n;
  bool ng = false;

  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << "\\n";
      return 0;
    }
    if (ng || tmp > max / res || res * tmp > max) {
      ng = true;
    }
    res *= tmp;
  }

  cout << (ng ? -1 : res) << "\\n";
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  ll tmp, res = 1, max = 1000000000000000000;
  cin >> n;
  bool ng = false;

  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << "\\n";
      return 0;
    }
    if (tmp > max / res) {
      ng = true;
    }
    res *= tmp;
  }

  cout << (ng ? -1 : res) << "\\n";
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

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

  bool flag = true;
  ll prod = 1, a;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a > 1000000000000000000 / prod) {
      flag = false;
    } else {
      prod *= a;
    }

    if (a == 0) {
      flag = true;
      break;
    }
  }

  cout << ((flag) ? prod : -1) << endl;
}

Error: 0

Fixed submission:

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

typedef long long ll;

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

  bool flag = true;
  ll prod = 1, a;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a > 1000000000000000000 / prod) {
      flag = false;
    } else {
      prod *= a;
    }

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

  cout << ((flag) ? prod : -1) << endl;
}