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

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 1;
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (a[i] && ans > INF / a[i]) {
      ans = -1;
      break;
    } else {
      ans *= a[i];
    }
  }
  cout << ans << '\\n';
  return 0;
}

Error: 0

Fixed submission:

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 1;
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (ans > INF / a[i]) {
      ans = -1;
      break;
    } else {
      ans *= a[i];
    }
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;
  std::vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
    if (a[i] == 0) {
      std::cout << 0 << std::endl;
      return 0;
    }
  }
  long long ms = 1e18;
  long long m = 1;

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

    if (ms / m < a[i]) {
      std::cout << -1 << std::endl;
      return 0;
    }
    m *= a[i];
  }

  std::cout << m << std::endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

int main() {
  int n;
  std::cin >> n;
  long long ms = 1e18;
  long long m = 1;
  bool ok = true;

  while (n--) {
    long long a;
    std::cin >> a;

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

    if ((ms / m) < a)
      ok = false;
    m *= a;
  }

  if (ok)
    std::cout << m << std::endl;
  else
    std::cout << -1 << std::endl;

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

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long long double
#define pb push_back

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  unsigned long long prod = 1;
  vector<unsigned long long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  if (arr[0] == 0) {
    cout << 0;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    if (arr[i] > 1000000000000000000 / prod) {
      cout << -1;
      return 0;
    }
    prod = prod * arr[i];
  }
  // if(prod<0) {cout <<-1;return 0;}
  cout << prod;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long long double
#define pb push_back

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  unsigned long long prod = 1;
  vector<unsigned long long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  for (int i = 0; i < n; i++) {
    if (arr[i] > 1000000000000000000 / prod) {
      cout << -1;
      return 0;
    }
    prod = prod * arr[i];
  }
  // if(prod<0) {cout <<-1;return 0;}
  cout << prod;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long long double
#define pb push_back

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  unsigned long long prod = 1;
  vector<unsigned long long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  if (arr[0] == 0) {
    cout << 0;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    if (arr[i] > 1000000000000000000 / prod) {
      cout << -1;
      return 0;
    }
    prod = prod * arr[i];
  }
  // if(prod<0) {cout <<-1;return 0;}
  cout << prod;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long long double
#define pb push_back

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  unsigned long long prod = 1;
  vector<unsigned long long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  // if(arr[0]==0){cout<<0;return 0;}
  for (long long i = 0; i < n; i++) {
    if (arr[i] > 1000000000000000000 / prod) {
      cout << -1;
      return 0;
    }
    prod = prod * arr[i];
  }
  // if(prod<0) {cout <<-1;return 0;}
  cout << prod;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);

  ll ans = 1;
  rep(i, N) {
    if (A.at(i) == 0)
      ans = 0;
  }

  if (ans != 0) {
    rep(i, N) {
      if (A.at(i) > (ll)pow(10, 18) / ans) {
        ans = -1;
      } else {
        ans *= A.at(i);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);

  ll ans = 1;
  rep(i, N) {
    if (A.at(i) != 0 && A.at(i) > (ll)pow(10, 18) / ans) {
      ans = (ll)pow(10, 18) + 1;
    } else {
      ans *= A.at(i);
    }
  }

  if (ans > (ll)pow(10, 18)) {
    ans = -1;
  }

  cout << ans << endl;

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

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define rep(i, x, y) for (__typeof(x) i = x; i < y; i++)
#define repr(i, x, y) for (__typeof(x) i = x; i > y; i--)
#define endl "\\n"
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort(all((x)))
#define rSort(x) sort((x).rbegin(), (x).rend())
#define X first
#define Y second
#define sep ' '
#define SZ(x) ll(x.size())
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define first X
#define second Y

const ll N = 1e18;
const ll M = 1e17 + 7;

int32_t main() {
  IOS;
  ll n, v, m = 1, c, flg = 1;
  cin >> n;
  vll A;
  rep(i, 0, n) {
    cin >> v;
    A.pb(v);
    if (v == 0) {
      cout << "0";
      flg = 2;
    }
  }
  Sort(A);
  if (flg != 2) {
    rep(i, 0, n) {
      v = A[i];
      c = N / v;
      if (m > c) {
        cout << "-1";
        flg = 0;
        break;
      }
      m *= v;
    }
    if (flg)
      cout << m;
  }
}


Error: WA

Fixed submission:

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define rep(i, x, y) for (__typeof(x) i = x; i < y; i++)
#define repr(i, x, y) for (__typeof(x) i = x; i > y; i--)
#define endl "\\n"
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort(all((x)))
#define rSort(x) sort((x).rbegin(), (x).rend())
#define X first
#define Y second
#define sep ' '
#define SZ(x) ll(x.size())
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define first X
#define second Y

const ll N = 1e18;
const ll M = 1e17 + 7;

int32_t main() {
  IOS;
  ll n, v, m = 1, c, flg = 1;
  cin >> n;
  vll A;
  rep(i, 0, n) {
    cin >> v;
    A.pb(v);
  }
  Sort(A);
  rep(i, 0, n) {
    v = A[i];
    c = N / v;
    if (m > c) {
      cout << "-1";
      flg = 0;
      break;
    }
    m *= v;
  }
  if (flg)
    cout << m;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#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: WA

Fixed submission:

//
// Created by admin on 2020/6/6.
//
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[10005];
int main() {
  long long p = 1;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  for (int i = 1; i <= n; i++) {
    if (a[i] < 1000000000000000000 / p)
      p *= a[i];
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << p << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#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:

//
// Created by admin on 2020/6/6.
//
#include <cstdio>
int n;
long long a[10005];
int main() {
  long long p = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++)
    if (a[i] == 0) {
      printf("0\\n");
      return 0;
    }
  for (int i = 1; i <= n; i++) {
    if (a[i] <= 1000000000000000000 / p)
      p *= a[i];
    else {
      printf("-1\\n");
      return 0;
    }
  }
  printf("%lld\\n", p);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pp pop_back
#define maximo 1e18
using namespace std;
static const long long INF = 1e18;

int main() {
  int n;
  cin >> n;
  ll nums[n];
  bool zero = false;
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
    if (nums[i] == 0)
      zero = true;
  }
  ll ans = 1;
  if (zero)
    cout << 0 << "\\n";
  else {
    for (int i = 0; i < n; i++) {
      if (nums[i] <= INF / ans) {
        ans = nums[i] * ans;
      } else {
        cout << -1 << "\\n";
        return 0;
      }
    }
    cout << ans << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pp pop_back
using namespace std;
ll nums[100005];
int main() {
  int n;
  scanf("%lld", &n);
  bool zero = false;
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
    if (nums[i] == 0)
      zero = true;
  }
  ll f = 1LL;
  if (zero)
    cout << 0 << "\\n";
  else {
    for (int i = 0; i < n; i++) {
      if (nums[i] > 1e18) {
        cout << -1 << "\\n";
        return 0;
      }
      if (f > 1e18 / nums[i]) {
        cout << -1 << "\\n";
        return 0;
      }
      f = 1LL * nums[i] * f;
    }
    cout << f << "\\n";
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
using namespace std;
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: WA

Fixed submission:

#include <bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define m 1000000007
using namespace std;
string s;
int main() {
  int n;
  cin >> n;
  ll a[n];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cnt++;
    }
  }
  if (cnt > 0) {
    std::cout << 0 << std::endl;
  }
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / ans) {
      ans *= a[i];
    } else {
      std::cout << -1 << std::endl;
    }
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1, maximum = pow(10, 18);
  REP(i, 0, N) {
    if (A[i] <= maximum / ans) {
      ans *= A[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

  const ll maxi = pow(10, 18);
  ll ans = 1;
  bool valid = true;
  bool zero = false;
  REP(i, 0, N) {
    ll a;
    cin >> a;
    if (a == 0) {
      zero = true;
    }
    if (ans > maxi / a) {
      valid = false;
    }

    ans *= a;
  }

  if (zero) {
    cout << 0 << endl;
  } else if (!valid) {
    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;

int main() {
  int n;
  int i;
  long long p;
  long long a;
  double x;

  cin >> n;
  cin >> a;

  if (a == 0) {
    cout << 0 << endl;
    return 0;
  }
  p = a;
  x = p;

  for (i = 1; i < n; i++) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (p > 0) {
      x = p;
      x = x * a;
      if (x > 4000000000000000000) {
        p = -1;
      } else {
        p = p * a;
        if (p > 1000000000000000000) {
          p = -1;
        }
      }
    }
  }
  cout << p << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  int i;
  long long p;
  long long a;

  cin >> n;
  cin >> a;

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

  for (i = 1; i++; i < n) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (p > 0) {
      p = p * a;
      if (p > 1000000000000000000) {
        p = -1;
      }
    }
  }
  cout << p << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using Bint = boost::multiprecision::cpp_int;
using namespace std;
typedef long long ll;
typedef pair<int, ll> Pil;

int N;
const int MAX_N = 1.0e5 + 10;
Bint A[MAX_N];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  bool is_over = false;
  Bint mul_A = 1;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      is_over = false;
      mul_A = 0;
      break;
    }
  }

  if (mul_A != 0) {
    for (int i = 0; i < N; i++) {
      mul_A *= A[i];
      if (mul_A > (Bint)1.0e18) {
        is_over = true;
        break;
      }
    }
  }

  cout << (is_over ? -1 : mul_A) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using Bint = boost::multiprecision::cpp_int;
using namespace std;
typedef long long ll;
typedef pair<int, ll> Pil;

int N;
const int MAX_N = 1.0e5 + 10;
Bint A[MAX_N];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  bool is_over = false;
  Bint mul_A = 1;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      is_over = false;
      mul_A = 0;
      break;
    } else {
      mul_A *= A[i];
      if (mul_A > (Bint)1.0e18) {
        is_over = true;
      }
    }
  }

  cout << (is_over ? -1 : mul_A) << endl;

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

#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll N = pow(10, 18);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  ll prod = 1;
  bool flag = true;
  ll arr[n];
  bool z = false;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    arr[i] = a;
    if (a == 0) {
      z = true;
    }
  }
  if (z == true) {
    prod = 0;
  } else {
    for (int i = 0; i < n; i++) {
      if (prod > N / arr[i]) {
        flag = false;
      } else {
        if (flag == true) {
          prod *= arr[i];
        }
      }
    }
  }
  if (flag == false) {
    prod = -1;
  }
  cout << prod << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll N = pow(10, 18);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  ll prod = 1;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (prod > N / a) {
      flag = false;
    } else {
      prod *= a;
    }
  }
  if (flag == false) {
    prod = -1;
  }
  cout << prod << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll lim = 1000000000000000000LL;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll res = 1;
  rep(i, n) {
    if (res > lim / a[i]) {
      cout << -1 << endl;
      return 0;
    }
    res *= a[i];
  }
  if (res > lim) {
    cout << -1 << endl;
    return 0;
  }
  cout << res << endl;
}


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;
using namespace boost::multiprecision;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
// # define M_PIl        3.141592653589793238462643383279502884
using namespace std;

typedef long long ll;
typedef long double ld;
#define faster                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

int main() {
  // faster;
  ll n;
  cin >> n;
  ll ans = 1;
  bool ex = false;
  bool zero = false;
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0;
      return 0;
    }
    if ((1000000000000000000 / a) < ans) {
      ex = true;
    }
    ans *= a;
  }
  if (ex) {
    cout << -1;
    return 0;
  } else {
    cout << ans;
    return 0;
  }
}

// 9223372036854775807

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
// # define M_PIl        3.141592653589793238462643383279502884
using namespace std;

typedef long long ll;
typedef long double ld;
#define faster                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

int main() {
  // faster;
  ll n;
  cin >> n;
  ll ans = 1;
  bool ex = false;
  bool zero = false;
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      zero = true;
    }
    if (((1000000000000000000 / a) < ans) || ex) {
      ex = true;
    }
    ans *= a;
  }
  if (zero) {
    cout << 0;
    return 0;
  } else {
    if (ex) {
      cout << -1;
      return 0;
    } else {
      cout << ans;
      return 0;
    }
  }
}

// 9223372036854775807
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  vector<int64_t> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int64_t flag = 1000000000000000000;
  int64_t answer = 1;

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

  for (int i = 0; i < N; i++) {
    if ((double)(flag / answer) < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    answer = answer * a[i];
  }

  cout << answer << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  vector<int64_t> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int64_t flag = 1000000000000000000;
  int64_t answer = 1;

  for (int i = 0; i < N; i++) {
    if ((flag / answer) < a[i]) {
      cout << -1 << endl;
    }
    answer = answer * a[i];
  }

  cout << answer << endl;

  return 0;
}