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

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll maxN = 1'000'000'000'000'000'000;

template <typename T> vector<T> getValues(int num) {
  vector<T> values(num);
  for (int i = 0; i < num; i++) {
    cin >> values.at(i);
  }
  return values;
}

ll culSum(vector<ll> inputs) {
  ll ret = 1;
  rep(i, inputs.size()) {
    if (inputs.at(i) == 0) {
      return 0;
    }
  }
  rep(i, inputs.size()) {
    if (inputs.at(i) <= maxN / ret) {
      ret *= inputs.at(i);
    } else {
      return -1;
    }
  }
  return ret;
}

int main() {
  int N;
  cin >> N;
  auto inputs = getValues<ll>(N);
  printl(culSum(inputs));
}


Error: 0

Fixed submission:

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll maxN = 1'000'000'000'000'000'000;

template <typename T> vector<T> getValues(int num) {
  vector<T> values(num);
  for (int i = 0; i < num; i++) {
    cin >> values.at(i);
  }
  return values;
}

ll culSum(vector<int> inputs) {
  ll ret = 1;
  rep(i, inputs.size()) {
    if (inputs.at(i) <= maxN / ret) {
      ret *= inputs.at(i);
    } else {
      return -1;
    }
  }
  return ret;
}

int main() {
  int N;
  cin >> N;
  auto inputs = getValues<int>(N);
  printl(culSum(inputs));
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

/* ********************************* JAI SAI RAM
 * ************************************* */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lb;
#define endl "\\n"
ll P = 1000000007;
ll MAX = (P - 7) * (P - 7);
int main() {
  ll i, j, k, l, m, n, o, p, q, r, s, t;
  cin >> n;
  ll ans = 1;
  ll flag = 0;
  vector<ll> v;
  for (i = 1; i <= n; i++) {

    cin >> j;
    v.push_back(j);
  }
  sort(v.begin(), v.end());
  for (i = 0; i < n; i++) {
    j = v[i];
    if ((MAX / ans) >= j)
      ans *= j;
    else {
      flag = 1;
      break;
    }
    if (j == 0) {
      ans = 0;
      flag = 0;
      break;
    }
  }
  if (flag == 1)
    cout << "-1";
  else
    cout << ans;
  return 0;
}


Error: WA

Fixed submission:

/* ********************************* JAI SAI RAM
 * ************************************* */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lb;
#define endl "\\n"
ll P = 1000000007;
ll MAX = (P - 7) * (P - 7);
int main() {
  ll i, j, k, l, m, n, o, p, q, r, s, t;
  cin >> n;
  ll ans = 1;
  ll flag = 0;
  for (i = 1; i <= n; i++) {
    cin >> j;
    if ((MAX / ans) >= j)
      ans *= j;
    else {
      flag = 1;
    }
    if (j == 0) {
      flag = 0;
    }
  }
  if (flag == 1)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int main() {
  int n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  cpp_int pro = 1;
  sort(arr, arr + n);
  bool zer = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] == 0) {
      zer = 1;
      break;
    } else {
      pro *= arr[i];
      if (pro > 1000000000000000000) {
        ans = 1;
        break;
      }
    }
  }
  if (zer)
    cout << 0;
  else if (ans)
    cout << -1;
  else
    cout << pro;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int main() {
  int n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  cpp_int pro = 1;
  for (int i = 0; i < n; i++) {
    pro *= arr[i];
  }
  if (pro > 1000000000000000000)
    cout << -1;
  else
    cout << pro;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define debug_input freopen("stdin.in", "w", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n, a, num;
  const ll comp = 1e18;

  cin >> n;
  cin >> a;

  bool flag = 1;
  for (int i = 1; i < n; i++) {
    cin >> num;
    if (num == 0) {
      flag = 1;
      a *= num;
      break;
    } else if (a <= (comp / num)) {
      a *= num;
    } else {
      flag = 0;
    }
  }

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

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define debug_input freopen("stdin.in", "w", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n, a, num;
  const ll comp = 1e18;

  cin >> n;
  cin >> a;

  bool flag = 1;
  for (int i = 1; i < n; i++) {
    cin >> num;
    if (a <= (comp / num)) {
      a *= num;
    } else
      flag = 0;
  }

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

  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 int k = 1, a[n + 1];
  int e = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      e = 1;
    if (a[i] > 1000000000000000000)
      e = 2;
  }
  if (e == 1) {
    cout << 0;
    return 0;
  }
  if (e == 2) {
    cout << -1;
    return 0;
  }
  // sort(a,a+n)
  for (int i = 1; i <= n; i++) {
    string s = to_string(a[i]);
    string s1 = to_string(k);
    int d = s.length() - 1;
    int e1 = s1.length() - 1;
    int f = d + e1;
    int g = (s[0] - '0') * (s1[0] - '0');
    string s2 = to_string(g);
    f += s2.length() - 1;
    int d1 = s2[0] - '0';
    if (f > 18) {
      e = 1;
      break;
    }
    if (f == 18 && d1 > 1) {
      e = 1;
      break;
    }
    k = k * a[i];

    if (k > 1000000000000000000)
      break;
  }
  if (k > 1000000000000000000 || e == 1)
    cout << -1;
  else
    cout << k;
}

Error: -11

Fixed submission:

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

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

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

Error: -8

Fixed submission:

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

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

int main() {
  int N;
  cin >> N;
  vector<long long> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  long long num = 1;
  for (int i = 0; i < N; i++) {
    if (vec.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long comp = pow(10, 18);
  for (int i = 0; i < N; i++) {
    if (vec.at(i) > comp / num) {
      num = -1;
      break;
    }
    num = num * vec.at(i);
  }
  cout << num << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<long long> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  long long num = 1;
  for (int i = 0; i < N; i++) {
    if (vec.at(i) == 0) {
      num = 0;
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    if (vec.at(i) > 1000000000000000000 / num) {
      num = -1;
      break;
    }
    num = num * vec.at(i);
  }
  cout << num << 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;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  ll a[n], ans = 1, m = pow(10, 18);
  rep(i, n) cin >> a[i];

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

  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;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  ll a[n], ans = 1, m = pow(10, 18);
  rep(i, n) cin >> a[i];
  int flag = 0;
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;

    } else if (a[i] > m / ans) {
      flag = 1;
    }
    ans *= a[i];
  }

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

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

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


Error: 0

Fixed submission:

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

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

int main() {
  long long N;

  cin >> N;

  vector<long long> A(N);

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

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

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

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

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

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

  cout << X << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long long N;

  cin >> N;

  vector<long long> A(N);

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

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

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

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

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

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

  cout << X << endl;
}
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;
using P = pair<int, int>;

const ll MX = 1e18;

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


Error: WA

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 1;
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (100000000000000000 / ans > a[i]) {
      ans = -1;
      break;
    }
    ans = ans * a[i];
  }
  cout << ans << endl;

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

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

using namespace std;
typedef long long ll;

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

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

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

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

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

Error: 0

Fixed submission:

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

using namespace std;
typedef long long ll;

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

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

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

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

  if (zero)
    cout << 0 << endl;
  else if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using int_t = boost::multiprecision::cpp_int;

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

  bool over = false;
  boost::multiprecision::cpp_int A(1);
  for (std::size_t i = 0; i < N; ++i) {
    std::int64_t a;
    std::cin >> a;

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

    if (over) {
      continue;
    }

    if (boost::multiprecision::cpp_int(1'000'000'000'000'000'000) < A) {
      over = true;
    }
    A *= a;
  }
  if (over) {
    std::cout << "-1" << std::endl;
  } else if (boost::multiprecision::cpp_int(1'000'000'000'000'000'000) < A) {
    std::cout << "-1" << std::endl;
  } else {
    std::cout << A << std::endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using int_t = boost::multiprecision::cpp_int;

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

  boost::multiprecision::cpp_int A(1);
  for (std::size_t i = 0; i < N; ++i) {
    std::int64_t a;
    std::cin >> a;

    A *= a;
  }
  if (boost::multiprecision::cpp_int(1'000'000'000'000'000'000) < A) {
    std::cout << "-1" << std::endl;
  } else {
    std::cout << A << std::endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int main() {
  int n;
  cin >> n;
  ll aux, ans = 1;
  bool sw = 0, sw2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> aux;
    if (aux == 0)
      sw = 1;
    else if (ans > (1000000000000000000 / aux) || ans < 0)
      sw2 = 1;
    ans *= aux;
  }
  if (sw) {
    cout << "0\\n";
    return 0;
  } else if (sw2) {
    cout << "-1\\n";
    return 0;
  }
  cout << ans << "\\n";

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int main() {
  int n;
  cin >> n;
  ll aux, ans = 1;
  bool sw = 0, sw2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> aux;
    if (aux == 0)
      sw = 1;
    if (ans > (1000000000000000000 / aux) || ans < 0)
      sw2 = 1;
    ans *= aux;
  }
  if (sw) {
    cout << "0\\n";
    return 0;
  } else if (sw2) {
    cout << "-1\\n";
    return 0;
  }
  cout << ans << "\\n";

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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORa(i, a, b) for (int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a, n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define UP(s) transform(s.begin(), s.end(), s.begin(), ::toupper)

//-------------------------------------------------------//

int main() {
  unsigned ll m = 1;
  int n;
  bool flag1 = false, flag2 = false;
  cin >> n;

  vector<unsigned ll> v(n);
  FOR(i, n) cin >> v[i];

  FOR(i, n) {
    if (v[i] == 0)
      flag1 = true;
  }

  for (int i = 0; i < n && !flag1; i++) {
    if (v[i] <= 1000000000000000000 / m)
      m *= v[i];
    else {
      flag2 = true;
      break;
    }
  }

  if (flag1)
    cout << "0" << endl;
  else if (flag2)
    cout << "-1" << endl;
  else
    cout << m << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORa(i, a, b) for (int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a, n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define UP(s) transform(s.begin(), s.end(), s.begin(), ::toupper)

//-------------------------------------------------------//

int main() {
  unsigned ll m = 1;
  int n;
  bool flag = false;
  cin >> n;

  vector<unsigned ll> v(n);
  FOR(i, n) cin >> v[i];

  FOR(i, n) {
    if (v[i] == 0)
      flag = true;
  }

  FOR(i, n) {
    if (v[i] <= 1000000000000000000 / m)
      m *= v[i];
    else
      flag = true;
  }

  if (flag)
    cout << "-1" << endl;
  else
    cout << m << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

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

  int n;
  cin >> n;

  constexpr ll M = (ll)1e+18;
  ll r = 1;
  int b = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;

    if (a == 0) {
      cout << 0 << endl;
      exit(0);
    }
    if (!b && a > (M + r - 1) / r)
      b = 1;
    r *= a;
    if (r > M)
      b = 1;
  }

  if (b) {
    cout << -1 << endl;
  } else {
    cout << r << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

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

  int n;
  cin >> n;

  constexpr ll M = (ll)1e+18;
  ll r = 1;
  int b = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;

    if (a == 0) {
      cout << 0 << endl;
      exit(0);
    }
    if (a > (M + r - 1) / r)
      b = 1;
    r *= a;
    if (r > M)
      b = 1;
  }

  if (b) {
    cout << -1 << endl;
  } else {
    cout << r << 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;

int main() {
  int N;
  cin >> N;
  long A[100005];
  REP(i, N) cin >> A[i];
  long ans = 1l;
  long sai = 1000000000000000000;
  bool ok = true;
  sort(A, A + N);
  REP(i, N) {
    if (A[i] == 0l) {
      ans = 0l;
      break;
    }
    if (sai / ans < A[i]) {
      ok = false;
      break;
    }
    ans *= A[i];
    // cout << ans << endl;
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << 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;

int main() {
  int N;
  cin >> N;
  long A[100005];
  REP(i, N) cin >> A[i];
  long ans = 1l;
  long sai = 1000000000000000000;
  bool ok = true;
  sort(A, A + N);
  REP(i, N) {
    if (A[i] == 0l) {
      ans = 0l;
      break;
    }
    if (sai / ans < A[i]) {
      ok = false;
    }
    ans *= A[i];
    // cout << ans << endl;
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define int long long

using namespace std;

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

  int N;
  cin >> N;

  bool flag = false;

  bool fff = true;

  int mult = 1;

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

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

    if (mult > 1000000000000000000 / n) {
      fff = false;
      mult = 0;
    }

    mult *= n;
  }

  if (flag) {
    cout << 0 << '\\n';
  } else {
    if (fff) {
      cout << mult << '\\n';
    } else {
      cout << -1 << '\\n';
    }
  }

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define int long long

using namespace std;

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

  int N;
  cin >> N;

  bool flag = false;

  bool fff = true;

  int mult = 1;

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

    if (mult > 1000000000000000000 / n) {
      fff = false;
      break;
    }

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

  if (flag) {
    cout << 0 << '\\n';
  } else {
    if (fff) {
      cout << mult << '\\n';
    } else {
      cout << -1 << '\\n';
    }
  }

  return 0;
}