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

#include <bits/stdc++.h>
#include <stdio.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) {
    // a[i] contains 0
    printf("0\\n");
    return 0;
  }

  long long prod = 1;

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

    if (a[i] <= 1000000000000000000 / prod) {
      // This condition is equivalent to prod*a[i] <=10ˆ18
      prod *= a[i];
    } else {
      printf("-1\\n");
      return 0;
    }
  }

  printf("%lld\\n", prod);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <stdio.h>
#define ll long long
ll a[10010];

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

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll 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;
  }

  ll 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: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[10010];

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

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

#include <bits/stdc++.h>
using namespace std;
/*
vector<string> v(n, string(m,"*"));
vector<vector<int>>
*/
int main() {
  long long s;
  int i, n;
  cin >> n;
  vector<long long> r(n);
  s = 1;
  for (i = 0; i < n; i++) {
    cin >> r[i];
    if (r[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (i = 0; i < n; i++) {
    if ((long long)pow((long long)10, 18) / s < r[i]) {
      cout << -1 << endl;
      return 0;
    }
    s *= r[i];
  }
  cout << s << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
/*
vector<string> v(n, string(m,"*"));
vector<vector<int>>
*/
int main() {
  long long n, i, s;
  cin >> n;
  long long r[10005];
  s = 1;
  for (i = 0; i < n; i++) {
    cin >> r[i];
    if (r[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (i = 0; i < n; i++) {
    if ((long long)pow((long long)10, (long long)18) / s < r[i]) {
      cout << -1 << endl;
      return 0;
    }
    s *= r[i];
  }
  cout << s << endl;

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

// 私は<= と <の区別がつかないカスです
#include <iostream>
using namespace std;
#define ll long long
// Google大好き！！！
int main(void) {
  int n;
  cin >> n;

  ll ans = 1;
  const ll m = 1e18;
  bool flag = false;

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

    // cout << a << "kasu" << ans << endl;
    if (a == 0) {
      cout << a << endl;
      return 0;
    }
    // ans >mとしていたカスです。あほバカ
    if (flag || (m + 1) / ans < a || ans * a > m) {
      flag = true;
    }
    ans *= a;
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
#define ll long long
// Google大好き！！！
int main(void) {
  int n;
  cin >> n;

  ll ans = 1;
  const ll m = 1e18;
  bool flag = false;

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

    // cout << a << "kasu" << ans << endl;
    if (a == 0) {
      cout << a << endl;
      return 0;
    }
    if ((m + 1) / ans < a || ans > m) {
      flag = true;
    }
    ans *= a;
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

// 私はずっとC問題の実行ファイルを動かし、動かねえと嘆いていました。
// とても... とても... 悔しいです。
// 編入終わったら、ちゃんとAtCoderをやります。
#include <algorithm>
#include <iostream>

using namespace std;
#define ll long long
// Google大好き！！！
int main(void) {
  int n;
  cin >> n;

  ll ans = 1;
  const ll m = 1e18;
  bool flag = false;
  ll a[100010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if ((m) / ans < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

// 私はずっとC問題の実行ファイルを動かし、動かねえと嘆いていました。
// とても... とても... 悔しいです。
// 編入終わったら、ちゃんとAtCoderをやります。
#include <algorithm>
#include <iostream>

using namespace std;
#define ll long long
// Google大好き！！！
int main(void) {
  int n;
  cin >> n;

  ll ans = 1;
  const ll m = 1e18;
  bool flag = false;
  int a[10010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);

  // cout << a << "kasu" << ans << endl;
  if (a[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if ((m + 1) / ans < a[i] || ans * a[i] > m) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

int main(void) {
  int n;
  long long dv = 1;
  long long max = 1;
  bool flag = 0;
  for (int i = 0; i < 18; i++) {
    max *= 10;
  }
  std::cin >> n;
  std::vector<long long> a(n);

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      std::cout << 0 << std::endl;
      flag = !flag;
      break;
    }
  }

  bool flag2 = 0;

  if (!flag) {
    for (int i = 0; i < n; i++) {
      if (dv <= max / a[i] + 1 && dv * a[i] <= max) {
        dv *= a[i];
      } else {
        std::cout << -1 << std::endl;
        flag2 = 1;
        break;
      }
    }
    if (!flag2)
      std::cout << dv << std::endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>

int main(void) {
  int n;
  long long dv = 1;
  long long max = 1;
  for (int i = 0; i < 18; i++) {
    max *= 10;
  }
  std::cin >> n;
  std::vector<long long> a(n);

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      std::cout << 0 << std::endl;
      return -1;
    }
  }

  for (int i = 0; i < n; i++) {
    if (dv * a[i] <= max) {
      dv *= a[i];
    } else {
      std::cout << -1 << std::endl;
      return -1;
    }
  }
  std::cout << dv << std::endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

int main(void) {
  int n;
  long long dv = 1;
  long long max = 1;
  for (int i = 0; i < 18; i++) {
    max *= 10;
  }
  std::cin >> n;
  std::vector<long long> a(n);

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      std::cout << 0 << std::endl;
      return 0;
    }
  }

  for (int i = 0; i < n; i++) {
    if (dv <= max / a[i] + 1 && dv * a[i] <= max) {
      dv *= a[i];
    } else {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  std::cout << dv << std::endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>

int main(void) {
  int n;
  long long dv = 1;
  long long max = 1;
  for (int i = 0; i < 18; i++) {
    max *= 10;
  }
  std::cin >> n;
  std::vector<long long> a(n);

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      std::cout << 0 << std::endl;
      return 1;
    }
  }

  for (int i = 0; i < n; i++) {
    if (dv <= max / a[i] + 1 && dv * a[i] <= max) {
      dv *= a[i];
    } else {
      std::cout << -1 << std::endl;
      return 2;
    }
  }
  std::cout << dv << std::endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

long long n, a, m = 1, e = 1e18, fl;
int main() {
  cin >> n;
  while (n--) {
    cin >> a;
    if (a <= e / m)
      m *= a;
    else
      fl = 1;
    if (m == 0)
      break;
  }
  if (m == 0)
    cout << 0;
  else if (fl)
    cout << -1;
  else
    cout << m;
  return 0;
}


Error: WA

Fixed submission:

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

long long n, a, m = 1, e = 1e18, fl;
int main() {
  cin >> n;
  while (n--) {
    cin >> a;
    if (a <= e / m)
      m *= a;
    else
      fl = 1;
  }
  if (m == 0)
    cout << 0;
  else if (fl)
    cout << -1;
  else
    cout << m;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
ll res = 1;
bool fl = 1;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    if (!x) {
      fl = 1;
      res = 0;
      break;
    }
    // cout <<x<<" "<<(ll)1e18/res<<" ##\\n";
    if (x > (ll)1e18 / res)
      fl = 0;
    else
      res *= x;
  }
  cout << (fl ? res : -1);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
ll res = 1;
bool fl = 1;
int main() {
  cin >> n;
  while (n--) {
    ll x;
    cin >> x;
    if (!x) {
      fl = 1;
      res = 0;
      break;
    }
    // cout <<x<<" "<<(ll)1e18/res<<" ##\\n";
    if (x > (ll)1e18 / res)
      fl = 0;
    res *= x;
  }
  cout << (fl ? res : -1);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long a[100010];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int zero = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0)
      zero++;
  }
  if (zero > 0) {
    cout << "0" << 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 << endl;
      return 0;
    }
  }
  cout << prod << endl;
}

Error: 0

Fixed submission:

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

int main() {
  long long int N, A, sum;
  cin >> N >> sum;
  for (int i = 0; i < N - 1; i++) {
    cin >> A;
    sum *= A;
    if (sum > 1000000000000000000) {
      cout << -1 << endl;
      return -1;
    }
  }
  cout << sum << endl;
}
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;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll ans = 1;
  bool zeroExist = false;
  for (ll i = 0; i < n; i++) {
    if (a[i] == 0) {
      zeroExist = true;
      break;
    }
    if (ans > 1000000000000000000LL / a[i]) {
      ans = -1;
      break;
    } else {
      ans *= a[i];
    }
  }
  if (zeroExist)
    cout << 0 << endl;
  else
    cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {

  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll ans = 1;
  ll zeroCnt = 0;
  for (ll i = 0; i < n; i++) {
    if (ans > 1000000000000000000LL / a[i]) {
      ans = -1;
      break;
    } else {
      ans *= a[i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long n;
  long long data[100000];
  long long limit = 1000000000000000000;
  cin >> n;

  bool zero = false;

  for (int i = 0; i < n; i++) {
    cin >> data[i];
    if (data[i] == 0) {
      zero = true;
    }
  }

  if (zero) {
    cout << 0;
  } else {
    long long result = 1;
    for (int i = 0; i < n && result != -1; i++) {
      if (((long double)result * data[i] / limit) > 1) {
        result = -1;
      } else {
        result *= data[i];
      }
    }
    cout << result;
  }
}


Error: 0

Fixed submission:

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

int main() {
  long n;
  long long limit = 1000000000000000000;
  long long data[10000];
  cin >> n;
  long long times = 1;
  for (long i = 0; i < n; i++) {
    cin >> data[i];
    if (data[i] == 0) {
      times = 0;
    }
  }
  if (times == 0) {
    printf("0\\n", times);
  } else {
    long i = 0;
    while (i < n && times != -1) {
      times *= data[i];
      if (times > limit) {
        times = -1;
      }
      i++;
    }
    printf("%lld\\n", times);
  }
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision; // for use cpp_int
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\\n"

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::ifstream in("input.txt");
  // std::cin.rdbuf(in.rdbuf());
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(all(a), greater<ll>());
  cpp_int ans = 1;
  rep(i, n) {
    ans *= a[i];
    if (ans > 1000000000000000000) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision; // for use cpp_int
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\\n"

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::ifstream in("input.txt");
  // std::cin.rdbuf(in.rdbuf());
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  cpp_int ans = 1;
  rep(i, n) { ans *= a[i]; }
  if (ans > 1000000000000000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<ll> a;
  ll ans = 1;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    ll b;
    cin >> b;
    a.push_back(b);
    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a[i] > 1000000000000000000 / ans) {
      flag = false;
      break;
    }
    ans *= a[i];
  }
  if (flag) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}

Error: 0

Fixed submission:

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

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

void solve() {
  int n;
  cin >> n;
  cpp_int a[n];
  cpp_int res = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {

    res = res * a[i];
    if (res > 1000000000000000000) {
      cout << -1 << endl;
      return;
    }
  }
  cout << res << endl;
}

int32_t main() {
  FIO

  {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

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

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

  ll ans = 1, lim = 1000000000000000000;
  bool flg = true;

  rep(i, n) {
    ll a;
    cin >> a;
    if (ans != 0 && lim / ans < a) {
      flg = false;
    }
    if (a == 0) {
      flg = true;
      ans = 0;
      break;
    }
    ans *= a;
  }
  if (!flg || ans > lim) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

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

  ll ans = 1, lim = 1000000000000000000;
  bool flg = true;
  rep(i, n) {
    ll a;
    cin >> a;
    if (lim / ans < a) {
      flg = false;
    }
    if (a == 0) {
      flg = true;
    }
    ans *= a;
  }
  if (!flg || ans > lim) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

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

#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()

int main() {
  int N;
  cin >> N;
  vector<ull> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ull over = pow(10, 18);
  ull ans = 1;
  for (int i = 0; i < N; i++)
    if (A[i] == 0) {
      puts("0");
      return 0;
    }
  for (int i = 0; i < N; i++) {
    over /= A[i];
    if (over == 0) {
      puts("-1");
      return 0;
    }
    ans *= A[i];
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()

int main() {
  int N;
  cin >> N;
  vector<ull> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ull over = pow(10, 18);
  ull ans = 1;
  for (int i = 0; i < N; i++) {
    over /= A[i];
    if (A[i] == 0) {
      puts("0");
      return 0;
    }
    ans *= A[i];
  }
  if (over == 0) {
    puts("-1");
    return 0;
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
// cout << fixed << setprecision(20) << *** << endl;
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
  ll t;
  if (a < b) {
    t = a;
    a = b;
    b = t;
  }
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
int main() {
  ll N, F = 0, ANS = 1;
  vector<ll> vec;
  cin >> N;
  rep(i, N) {
    ll t;
    cin >> t;
    vec.push_back(t);
  }
  sort(vec.begin(), vec.end());
  if (vec[0] == 0) {
    cout << "0" << endl;
  } else {
    rep(i, N) {
      if (ANS <= 1000000000000000000 / vec[i]) {
        ANS = ANS * vec[i];
      } else {
        F = 1;
        break;
      }
    }
    if (F == 0) {
      cout << ANS << endl;
    } else {
      cout << "-1" << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
// cout << fixed << setprecision(20) << *** << endl;
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
  ll t;
  if (a < b) {
    t = a;
    a = b;
    b = t;
  }
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
int main() {
  ll N, F = 0, ANS = 1;
  vector<ll> vec;
  cin >> N;
  rep(i, N) {
    ll t;
    cin >> t;
    vec.push_back(t);
  }
  sort(vec.begin(), vec.end());
  rep(i, N) {
    if (ANS <= 1000000000000000000 / vec[i]) {
      ANS = ANS * vec[i];
    } else {
      F = 1;
      break;
    }
  }
  if (F == 0) {
    cout << ANS << endl;
  } else {
    cout << "-1" << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  unsigned long long int *a;
  unsigned long long int n;
  unsigned long long int x = 1;
  unsigned long long int i, j, k;
  unsigned long long int a2, x2;
  cin >> n;
  a = (unsigned long long int *)malloc(n * sizeof(unsigned long long int));

  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (i = 0; i < n; i++) {
    j = 0;
    k = 0;
    a2 = a[i];
    x2 = x;
    while (a2 >= 10) {
      a2 /= 10;
      j++;
    }
    while (x2 >= 10) {
      x2 /= 10;
      k++;
    }
    if (j + k >= 18 && a2 * x2 > 1) {
      cout << -1 << endl;
      free(a);
      return 0;
    }
    x *= a[i];
  }
  if (x > 1000000000000000000) {
    cout << -1 << endl;
    free(a);
    return 0;
  }
  free(a);

  cout << x << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  unsigned long long int *a;
  int n;
  unsigned long long int x = 1;
  int i;
  cin >> n;
  a = (unsigned long long int *)malloc(n);

  for (i = 0; i < n; i++) {
    cin >> a[i];
    x *= a[i];
  }

  if (x > 1.0E18) {
    cout << -1 << endl;
    return 0;
  }
  cout << x << endl;
  free(a);
  return 0;
}