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

#include "bits/stdc++.h"
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()

using namespace std;
typedef unsigned long long ll;

template <typename T> T gcd(T a, T b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

struct Deep {
  ll all;
  ll notreef;
  ll reef;
};

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

/*
ans*a[i]>max
a[i]>max/ans
*/


Error: 0

Fixed submission:

#include "bits/stdc++.h"
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()

using namespace std;
typedef unsigned long long ll;

template <typename T> T gcd(T a, T b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

struct Deep {
  ll all;
  ll notreef;
  ll reef;
};

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

/*
ans*a[i]>max
a[i]>max/ans
*/
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  long long int ans = 1;
  for (int i = 0; i < n; i++) {
    if (a.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a.at(i) <= (1000000000000000000 / ans)) {
      ans *= a.at(i);
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Error: -8

Fixed submission:

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

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

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(i, a, n) for (int i = a; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

// int in() { int x; scanf("%d", &x); return x; }
// ll lin() { ll x; scanf("%lld", &x); return x; }
// void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const ll MAX = 1e18;

int main(void) {
  std::ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  ll ans = 1;
  bool ng = false;
  FOR(i, n) {
    ll tmp;
    cin >> tmp;

    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (ng || (MAX + 1) / ans < tmp || ans * tmp > MAX) {
      ng = true;
    }

    ans *= tmp;
  }

  if (ng)
    cout << -1 << endl;
  else
    cout << ans;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(i, a, n) for (int i = a; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

// int in() { int x; scanf("%d", &x); return x; }
// ll lin() { ll x; scanf("%lld", &x); return x; }
// void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const ll MAX = 1e18;

int main(void) {
  std::ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  ll ans = 1;
  bool ng = false;
  FOR(i, n) {
    ll tmp;
    cin >> tmp;

    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }

    if ((MAX + 1) / ans < tmp || ans * tmp > MAX) {
      ng = true;
    }

    ans *= tmp;
  }

  if (ng)
    cout << -1 << endl;
  else
    cout << ans;

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

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(i, a, n) for (int i = a; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

// int in() { int x; scanf("%d", &x); return x; }
// ll lin() { ll x; scanf("%lld", &x); return x; }
// void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const ll MAX = 1e18;

int main(void) {
  std::ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  ll ans = 1;
  bool ng = false;
  FOR(i, n) {
    ll tmp;
    cin >> tmp;

    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (ng || MAX / ans < tmp) {
      ng = true;
    }

    ans *= tmp;
  }

  if (ng)
    cout << -1 << endl;
  else
    cout << ans;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(i, a, n) for (int i = a; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

// int in() { int x; scanf("%d", &x); return x; }
// ll lin() { ll x; scanf("%lld", &x); return x; }
// void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const ll MAX = 1e18;

int main(void) {
  std::ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  ll ans = 1;
  bool ng = false;
  FOR(i, n) {
    ll tmp;
    cin >> tmp;

    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (MAX / ans < tmp || ans * tmp > MAX) {
      ng = true;
    }

    ans *= tmp;
  }

  if (ng)
    cout << -1 << endl;
  else
    cout << ans;

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

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

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

Error: 0

Fixed submission:

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

  for (int i = 0; i < n; i++) {
    if (((long)(1e9) * (long)(1e9) + ans - 1) / ans >= a[i]) {
      ans *= a[i];
    } else {
      if (ans != 0) {
        ans = -1;
        break;
      }
    }
  }
  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;

  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    if (A.at(i) > 1000000000000000000 / ans) {
      cout << -1 << endl;
      return 0;
    } else {
      ans *= A.at(i);
    }
  }

  cout << ans << endl;
}


Error: WA

Fixed submission:

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

int main() {
  unsigned long N;
  cin >> N;

  vector<unsigned long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());

  unsigned long ans = 1;
  for (int i = 0; i < N; i++) {
    ans *= A.at(i);
    if (A.at(i) <= 1000000000000000000 / ans) {
      cout << -1 << endl;
      return 0;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  long long res = 1;
  bool flag = true;
  bool zeroflag = false;

  long long aaa = pow(10, 18);

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

    if (a > aaa / res) {
      flag = false;
    }

    if (a == 0)
      zeroflag = true;

    if (flag) {
      res *= a;
      if (res > aaa || res < 0) {
        flag = false;
        res = 1;
      }
    }
  }
  if (zeroflag)
    cout << 0 << endl;
  else if (flag)
    cout << res << endl;
  else
    cout << "-1" << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  long long res = 1;
  bool flag = true;
  bool zeroflag = false;

  long long aaa = pow(10, 18);

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

    if (a > aaa / res) {
      flag = false;
    }

    res *= a;

    if (a == 0)
      zeroflag = true;
    else if (res > aaa || res < 0) {
      flag = false;
      res = 1;
    }
  }
  if (zeroflag)
    cout << 0 << endl;
  else if (flag)
    cout << res << endl;
  else
    cout << "-1" << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#define MAX 100100
typedef unsigned long long LL;
const LL Max = LL(1e18);
using namespace std;
LL a[MAX], ans = 1;
int main() {
  int n;
  cin >> n;
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      flag = 0;
  }
  if (!flag) {
    cout << "0" << endl;
  } else {
    ans = 1;
    for (int i = 1; i <= n; i++) {
      if (ans * a[i] > Max || Max / ans < a[i]) {
        flag = 0;
        break;
      }
      ans *= a[i];
    }
    if (flag)
      cout << ans << endl;
    else
      cout << "-1" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#define MAX 100100
typedef long long LL;
const LL Max = LL(1e18);
using namespace std;
LL a[MAX], ans = 1;
int main() {
  int n;
  cin >> n;
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      flag = 0;
  }
  if (!flag) {
    cout << "0" << endl;
  } else {
    ans = 1;
    for (int i = 1; i <= n; i++) {
      if (ans * a[i] > Max || Max / ans < a[i]) {
        flag = 0;
      }
      ans *= a[i];
    }
    if (flag)
      cout << ans << endl;
    else
      cout << "-1" << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  long long int limit = pow(10.0, 18.0);

  vector<long long int> inputs(N);
  rep(i, N) {
    cin >> inputs.at(i);
    if (inputs.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long int prod = 1;
  rep(i, N) {
    if (inputs.at(i) <= limit / prod) {
      prod *= inputs.at(i);
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << prod << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  long long int ans = 1;
  long long int limit = pow(10.0, 18.0);
  bool over = false;
  rep(i, N) {
    long long int input;
    cin >> input;
    if (input == '0') {
      ans = 0;
      break;
    }
    if ((limit / ans) < input)
      over = true;
    ans *= input;
    if (ans > limit)
      over = true;
  }
  if (ans != 0 && over)
    ans = -1;
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int a[100010];

inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch))
    X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}

inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

inline void writeln(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
  puts("");
}

signed main() {
  int n = read();

  for (int i = 1; i <= n; i++)
    a[i] = read();

  sort(a + 1, a + n + 1);

  int ans = 1LL;

  for (int i = 1; i <= n; i++) {
    if (ans != 0 && 1000000000000000000LL / ans < a[i]) {
      cout << "-1\\n";
      return 0;
    }
    ans *= a[i];
  }

  cout << ans << "\\n";

  return 0;
}

Error: 0

Fixed submission:

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

int a[100010];

int over(int a, int b) { return LLONG_MAX / a < b; }

inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch))
    X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}

inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

inline void writeln(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
  puts("");
}

signed main() {
  int n = read();

  for (int i = 1; i <= n; i++)
    a[i] = read();

  sort(a + 1, a + n + 1);

  int ans = 1LL;

  for (int i = 1; i <= n; i++) {
    if (over(a[i], ans)) {
      cout << "-1\\n";
      return 0;
    }
    ans *= a[i];
  }

  if (ans > 1e18)
    cout << "-1\\n";
  else
    cout << ans << "\\n";

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int(i) = (n - 1); (i) >= (0); (i)--)
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
  int N;
  cin >> N;
  vl A(N);
  ll ans = 1;
  rep(i, N) { cin >> A[i]; }
  rep(i, N) {
    if (A[i] == 0)
      ans = 0;
  }
  if (ans == 1) {
    rep(i, N) { ans *= A[i]; }
    if (ans > InfLL) {
      ans = -1;
    } else {
      ll ans1 = ans;
      rep(i, N) { ans1 /= A[i]; }
      if (ans1 != 1)
        ans = -1;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int(i) = (n - 1); (i) >= (0); (i)--)
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
  int N;
  cin >> N;
  vl A(N);
  ll ans = 1;
  rep(i, N) {
    cin >> A[i];
    ans *= A[i];
  }
  if (ans > InfLL) {
    ans = -1;
  }
  ll ans1 = ans;
  rep(i, N) { ans1 /= A[i]; }
  if (ans1 != 1)
    ans = -1;
  rep(i, N) {
    if (A[i] == 0) {
      ans = 0;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

// problem_B
int main() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum1 = 1;
  // ll sum2 = 1;
  ll ans1 = 0;
  ll ans2 = 0;
  ll a0 = pow(10, 18);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      ans2 += 1;
    }
  }
  if (ans2 == 0) {
    for (ll i = 0; i < n; i++) {
      if (a0 / sum1 < a[i]) {
        ans1 += 1;
        break;
      }
      sum1 *= a[i];
    }
  }

  // cout << sum1 << endl;
  // cout << ans1 << endl;
  // cout << ans2 << endl;
  if (ans2 != 0) {
    cout << 0 << endl;
  } else if (ans1 != 0) {
    cout << -1 << endl;
  } else {
    printf("%lld\\n", sum1);
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

// problem_B
int main() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum1 = 1;
  // ll sum2 = 1;
  ll ans1 = 0;
  ll ans2 = 0;
  ll a0 = pow(10, 18);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      ans2 += 1;
    }
  }
  if (ans2 == 0) {
    for (ll i = 0; i < n; i++) {
      if (a0 / sum1 < a[i]) {
        ans1 += 1;
      }
      sum1 *= a[i];
    }
  }

  // cout << sum1 << endl;
  // cout << ans1 << endl;
  // cout << ans2 << endl;
  if (ans2 != 0) {
    cout << 0 << endl;
  } else if (ans1 != 0) {
    cout << -1 << endl;
  } else {
    printf("%lld\\n", sum1);
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> V(n);
  for (int i = 0; i < n; i++)
    cin >> V[i];
  long long product = 1;
  long long val = 1e18;
  sort(V.begin(), V.end());
  for (int i = 0; i < n; i++) {
    if (V[i] == 0) {
      cout << 0;
      return 0;
    }
    if (product <= (val / V[i]))
      product *= V[i];
    else {
      cout << -1;
      return 0;
    }
  }
  cout << product;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> V(n);
  for (int i = 0; i < n; i++)
    cin >> V[i];
  long long product = 1;
  long long val = 1e18;
  sort(V.begin(), V.end());
  for (int i = 0; i < n; i++) {
    if (product == 0) {
      cout << 0;
      return 0;
    }
    if (product <= (val / V[i]))
      product *= V[i];
    else {
      cout << -1;
      return 0;
    }
  }
  cout << product;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define INF 1234567890
#define ll long long

int T, N, M, K;
int A, B, C, D;

int main() {
  scanf("%d", &N);
  ll res = 1;
  int die = 0;
  for (int i = 1; i <= N; i++) {
    ll t;
    scanf("%lld", &t);
    if (t == 0)
      return !printf("0");

    if (res > (ll)1e18 / t)
      die = 1;
    if (!die)
      res *= t;
  }
  if (die)
    return !printf("-1");
  printf("%lld", res);
  return 0;
}

Error: WA

Fixed submission:

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

#define INF 1234567890
#define ll long long

int T, N, M, K;
int A, B, C, D;

int main() {
  scanf("%d", &N);
  ll res = 1;
  int die = 0;
  for (int i = 1; i <= N; i++) {
    ll t;
    scanf("%lld", &t);
    if (res > (ll)1e18 / t)
      die = 1;
    if (!die)
      res *= t;

    if (t == 0)
      return !printf("0");
  }
  if (die)
    return !printf("-1");
  printf("%lld", res);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int64_t INF = 1e18;
int main() {

  ll n;
  cin >> n;
  vector<ll> a(n);
  ll res = 1;

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

  for (ll i = 0; i < n; i++) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    } else if (a[i] != 0) {
      if (a[i] <= 1000000000000000000 / res)
        res *= a[i];
      else
        res = -1;
    }
  }
  cout << res << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int64_t INF = 1e18;
int main() {

  ll n;
  cin >> n;
  vector<ll> a(n);
  ll res = 1;

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

  for (ll i = 0; i < n; i++) {
    if (a[i] == 0) {
      res = 0;
    } else if (a[i] != 0) {
      if (a[i] <= 1000000000000000000 / res)
        res *= a[i];
      else
        res = -1;
    }
  }
  cout << res << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main() {
  int64_t max = 1e+18;

  int N;
  cin >> N;

  vector<int64_t> nums(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> nums[i];
    if (nums[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  int64_t ans = 1;
  for (int i = 1; i <= N; i++) {
    if (max / nums[i] < ans) {
      ans = -1;
      break;
    } else {
      ans *= nums[i];
    }
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main() {
  int64_t ans = 1;
  int64_t max = 1e+18;

  int N;
  cin >> N;

  vector<int64_t> nums(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> nums[i];
    if (nums[i] == 0) {
      cout << 0 << endl;
      return 1;
    }
  }

  for (int i = 1; i <= N; i++) {
    if (max / nums[i] > ans) {
      ans = -1;
      break;
    } else {
      ans *= nums[i];
    }
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
    bans = ans;
    ans *= a;
    if (ans > INF || bans > ans)
      over = true;
    if (a == 0)
      zero = true;
  }

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


Error: TLE

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() {
  cpp_int n, ans = 1, a;
  bool over = false, zero = false;
  cin >> n;
  rep(i, n) {
    cin >> a;
    ans *= a;
    if (ans > INF)
      over = true;
    if (a == 0)
      zero = true;
  }

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