alexjercan/bugnet huggingface dataset:
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;
typedef long long ll;
const ll INF = 1e18;

int main() {
  ll n, ans = 1, a;
  bool over = false, zero = false;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (a == 0) {
      zero = true;
      break;
    }
    if (a <= INF / ans)
      ans *= a;
    else
      over = true;
  }

  if (zero)
    puts("0");
  else
    cout << (over ? -1 : ans) << endl;
  return 0;
}


Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
// using boost::multiprecision::cpp_int;

int main() {
  ll n, ans = 1, a, bans;
  bool over = false, zero = false;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (a == 0)
      zero = true;
    if (a <= INF / ans)
      ans *= a;
    else
      over = true;
  }

  if (zero)
    puts("0");
  else
    cout << (over ? -1 : ans) << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
typedef long long ll;

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

ll c = 1e18;

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

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

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


Error: 0

Fixed submission:

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

using namespace std;
typedef long long ll;

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

ll c = 1e18;

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

  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (ll i = 0; i < n; i++) {
    sum *= a[i];
    if (i < n - 1 && a[i + 1] > c / sum && sum != 0) {
      cout << -1;
      return 0;
    }
  }
  cout << sum << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  long int tmp;
  long int ans = 1;
  long int limit = pow(10, 18);
  cin >> n;
  vector<long int> a(n);

  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }
    a[i] = tmp;
  }
  for (int i = 0; i < n; i++) {
    if (LONG_MAX / ans < a[i]) {
      cout << -1;
      return 0;
    }
    ans *= a[i];
  }
  if (ans > limit) {
    cout << -1;
  } else {
    cout << ans;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  long int tmp;
  long int ans = 1;
  long int limit = pow(10, 18);
  vector<long int> a(n);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }
    a[i] = tmp;
  }
  for (int i = 0; i < n; i++) {
    if (LONG_MAX / ans < a[i]) {
      cout << -1;
      return 0;
    }
    ans *= a[i];
  }
  if (ans > limit) {
    cout << -1;
  } else {
    cout << ans;
  }

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

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

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

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

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

  rep(i, N) {

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

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

Error: WA

Fixed submission:

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

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

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

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

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

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

#include <cmath>
#include <iostream>

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

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

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

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

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

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

  std::cout << ans;

  return 0;
}


Error: WA

Fixed submission:

#include <cmath>
#include <iostream>

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

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

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

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

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

  std::cout << ans;

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

#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  long long ans = 1;
  long long a[100011];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] > 1000000000000000000 / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  long long ans = 1;
  long long a[10010];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    ans *= a[i];
    if (a[i] > 1000000000000000000 / ans) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  const ll lim = 1e18;
  int N;
  cin >> N;
  vector<ll> A(N);
  ll mul = 1;
  bool flag = false;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] > lim / mul)
      flag = true;
    else
      mul *= A[i];
  }
  if (flag)
    mul = -1;

  cout << mul << endl;
}

Error: 0

Fixed submission:

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

int main() {
  const ll lim = 1e18;
  int N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 1;
  bool flag = false;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] > lim / sum)
      flag = true;
    sum *= A[i];
  }
  if (flag)
    sum = -1;

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

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

int main() {
  int ans = 0;
  long long int d = 1;
  long long int a[100000];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      ans += 1;
    }
    d *= a[i];
  }
  if (ans == 0) {
    if (d > 1000000000000000000 or d <= 0) {
      cout << -1;
    } else {
      cout << d;
    }
  } else {
    cout << 0;
  }
  return 0;
}

Error: WA

Fixed submission:

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

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

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) { // for debug
  ll n = vec.size();
  cout << "------------------------------------\\n";
  rep(i, n) cout << i << " " << vec.at(i) << "\\n";
  cout << "------------------------------------\\n";
}

void pr2d(vector<vector<ll>> vec) { // for debug
  ll h = vec.size();
  ll w = vec.at(0).size();
  cout << "------------------------------------\\n";
  rep(i, h) {
    rep(j, w) { cout << vec.at(i).at(j) << " "; }
    cout << "\\n";
  }
  cout << "------------------------------------\\n";
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a.at(i);
    if (a.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll cur = 1;
  rep(i, n) {
    ll x = a.at(i);
    if (1000000000000000000 / cur < x) {
      cout << -1 << endl;
      return 0;
    } else {
      cur *= x;
    }
  }
  cout << cur << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) { // for debug
  ll n = vec.size();
  cout << "------------------------------------\\n";
  rep(i, n) cout << i << " " << vec.at(i) << "\\n";
  cout << "------------------------------------\\n";
}

void pr2d(vector<vector<ll>> vec) { // for debug
  ll h = vec.size();
  ll w = vec.at(0).size();
  cout << "------------------------------------\\n";
  rep(i, h) {
    rep(j, w) { cout << vec.at(i).at(j) << " "; }
    cout << "\\n";
  }
  cout << "------------------------------------\\n";
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a.at(i);
    if (a.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll cur = a.at(0);
  rep(i, n - 1) {
    ll x = a.at(i + 1);
    if (1000000000000000000 / cur > x) {
      cout << -1 << endl;
      return 0;
    } else {
      cur *= x;
    }
  }
  if (cur > 1000000000000000000) {
    cout << -1 << endl;
    return 0;
  }
  cout << cur << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;
void solve1();
void solve() {
  int t;
  cin >> t;
  while (t--) {
    solve1();
  }
}
int main() {
  solve1();
  return 0;
}
void solve1() {
  ll n;
  cin >> n;
  ll ans;
  cin >> ans;
  for (ll i = 1; i < n; i++) {
    ll x;
    cin >> x;
    if (x == 0) {
      ans = 0;
      break;
    } else if (x > 1000000000000000000 / ans) {
      // cout<<"me"<<x<<ans<<endl<<1000000000000000000/ans;
      ans = -1;
    } else if (ans == -1) {
      ans = -1;
    } else {
      ans *= x;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
void solve1();
void solve() {
  int t;
  cin >> t;
  while (t--) {
    solve1();
  }
}
int main() {
  solve1();
  return 0;
}
void solve1() {
  ll n;
  cin >> n;
  ll ans;
  cin >> ans;
  for (ll i = 1; i < n; i++) {
    ll x;
    cin >> x;
    ll y;
    if (x != 0) {
      y = 1000000000000000000 / ans;
    } else {
      y = 1;
    }
    if (x <= y && ans != -1)
      ans *= x;
    else if (x == 0) {
      ans = 0;
    } else if (ans != 0) {
      ans = -1;
    }
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

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

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

Error: 0

Fixed submission:

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

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

  if (a == 0) {
    cout << a << endl;
  } else if (flg) {
    cout << -1 << endl;
  } else if (a < 0) {
    cout << -1 << endl;
  } else {
    cout << a << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <tuple>
#include <vector>

using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
#define eps 1.0e-14;

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


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <tuple>
#include <vector>

using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
#define eps 1.0e-14;

int main() {
  ll n, A[100006];
  cin >> n;
  rep(i, n) cin >> A[i];
  ll ans = 1;
  sort(A, A + n);
  rep(i, n) {
    ans *= A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (1 == 1000000000000000000 / 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;
/// Welcome to Nasif's Code
#define bug printf("bug\\n");
#define bug2(var) cout << #var << " " << var << endl;
#define co(q) cout << q << endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead                                                               \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int main() {
  FastRead
      // freopen("output.txt", "w", stdout);

      int n;
  cin >> n;
  ll arr[n + 5];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  ll m = 1e18;
  if (arr[0] == 0)
    cout << "0" << endl;
  else {
    ll ans = 1;
    for (int i = 0; i < n; i++) {
      if (arr[i] <= m / ans)
        ans *= arr[i];
      else {
        cout << "-1" << endl;
        return 0;
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
/// Welcome to Nasif's Code
#define bug printf("bug\\n");
#define bug2(var) cout << #var << " " << var << endl;
#define co(q) cout << q << endl;
typedef long long int ll;
typedef unsigned long long int ull;
const ll MOD = (ll)1e18 + 1;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead                                                               \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll two[70];
int msb(ll a) {
  for (int i = 63; i >= 0; i--) {
    if ((a / two[i]) % 2)
      return i;
  }
}
int main() {
  FastRead
      // freopen("output.txt", "w", stdout);
      two[0] = 1;
  for (int i = 1; i <= 64; i++)
    two[i] = two[i - 1] * 2ll;
  int n, z = 0, o = 0;
  ll m = 1e18;
  ll last = 1;
  cin >> n;
  cin >> last;
  n--;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (msb(last) + msb(a) > 58)
      o = 1;
    else if (msb(last) + msb(a) == 58) {
      if (last * a != m || i != n - 1)
        o = 1;
    }
    if (!a)
      z = 1;
    last = (a * last) % MOD;
  }
  if (z)
    cout << "0" << endl;
  else if (o)
    cout << "-1" << endl;
  else
    cout << last << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MX = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;

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

  vector<ll> as(N);
  bool has_zero = false;
  for (int i = 0; i < N; i++) {
    cin >> as[i];
    if (as[i] == 0) {
      has_zero = true;
    }
  }

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

  bool ok = true;
  ll acc = 1;
  for (int i = 0; i < N; i++) {
    ll x = acc * as[i];
    if (acc > MX / as[i]) {
      ok = false;
      break;
    }
    acc *= as[i];
  }

  if (ok) {
    cout << acc << 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;
using ll = long long;
using P = pair<int, int>;

const ll MX = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 510000;
const int MOD = 1000000007;

signed main() {
  cout << std::fixed << std::setprecision(15);
  int n, a[3], ans[3] = {};
  ans[0] = 1;
  int t[3] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    // cerr<<t[2]<<' '<<t[1]<<' '<<t[0]<<endl;
    cin >> a[0];
    a[1] = a[0] / (MOD - 7);
    a[0] %= MOD - 7;
    t[0] = ans[0] * a[0];
    t[1] = (ans[1] * a[0] + ans[0] * a[1] + t[0] / (MOD - 7));
    t[0] %= MOD - 7;
    t[2] = ans[2] * a[0] + ans[1] * a[1];
    t[2] += t[1] / (MOD - 7);
    t[1] %= MOD - 7;
    if (t[2] > 1 || (t[2] == 1 && (t[1] != 0 || t[0] != 0))) {
      for (int j = i + 1; j < n; j++) {
        int u;
        cin >> u;
        if (u == 0) {
          cout << 0 << endl;
          return 0;
        }
      }
      cout << -1 << endl;
      return 0;
    }
    for (int i = 0; i < 3; i++)
      ans[i] = t[i];
  }

  cout << ans[0] + (MOD - 7) * (ans[1] + ans[2] * (MOD - 7)) << endl;
}


Error: TLE

Fixed submission:

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

const int MAX = 510000;
const int MOD = 1000000007;
#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<512>>;

signed main() {
  cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;

  Bint a[n], ans = 1, t = 1000000000000000000;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    ans *= a[i];

  if (ans > t)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long n;
signed main() {
  cin >> n;
  vector<long double> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long double s = 1e18;
  long double ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= a[i];
    if (ans > s) {
      cout << "-1\\n";
      return 0;
    }
  }
  cout << (long long)ans << "\\n";
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
signed main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (a[0] == 0) {
    cout << 0 << "\\n";
    return (0);
  }
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= a[i];
    if (a[i] <= 1000000000000000000 / ans) {
      cout << -1 << "\\n";
      return 0;
    }
  }
  cout << ans << "\\n";
  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;
  vector<ll> A;
  for (int i = 0; i < N; ++i) {
    ll temp;
    cin >> temp;
    A.push_back(temp);
  }
  for (int i = 0; i < N; ++i) {
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll 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;
}


Error: WA

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;
  vector<ll> A(N, 0);
  for (int i = 0; i < N; ++i) {
    cin >> A[N];
  }
  for (int i = 0; i < N; ++i) {
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] <= 1000000000000000000 / ans) {
      ans *= A[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}