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

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;

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

  int n;
  cin >> n;
  ll t;
  ld ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> t;
    if (ans != -1)
      ans *= t;
    if (ans > 1000000000000000000 || ans < 0)
      ans = -1;
    if (t == 0)
      ans = 0;
  }
  cout << (ll)ans;
  return 0;
}

Error: WA

Fixed submission:

//   Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e18;
long double PI = 3.1415926;

ll power(ll a, ll b) {
  if (b == 0) {
    return 1;
  }
  ll temp = power(a, b / 2) % mod;
  if (b % 2 == 0) {
    return (temp * temp) % mod;
  } else {
    return ((a * temp) % mod * temp) % mod;
  }
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

vector<ll> v;
vector<ll>::iterator it;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t;
  // cin>>t;
  t = 1;
  // ll c=1;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    for (ll x = 0; x < n; x++) {
      cin >> a[x];
    }
    sort(a, a + n);
    ll ans = 1;
    for (ll x = 0; x < n; x++) {
      if (ans != -1) {
        ans = ans = ans * a[x];
      }
      if (ans > mod / a[x]) {
        ans = -1;
        break;
      }
      if (a[x] == 0) {
        ans = 0;
      }
    }
    cout << ans << "\\n";
    v.clear();
    // cout<<"Case #"<<c<<": "<<ans<<"\\n";
    // c++;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long N;
  unsigned long long ans = 1;
  cin >> N;

  bool zero = false;
  bool ng = false;
  for (long long i = 0; i < N; i++) {
    unsigned long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      zero = true;
    }
    if (!zero && 1000000000000000000 / ans < tmp) {
      ng = true;
    }
    if (!zero && !ng) {
      ans *= tmp;
    }
  }

  if (zero) {
    cout << 0 << endl;
  } else if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  long long N;
  unsigned long long ans = 1;
  cin >> N;

  bool zero = false;
  bool ng = false;
  for (long long i = 0; i < N; i++) {
    unsigned long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      zero = true;
    }
    if (!zero && 1000000000000000000 / ans < tmp) {
      ng = true;
    }
    ans *= tmp;
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
long long a[100010];

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

  int n;
  cin >> n;

  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0\\n";
      return 0;
    }
  }

  long long prod = 1;
  rep(i, n) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      prod = -1;
      break;
    }
  }

  cout << prod;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
long long a[10001];

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

  int n;
  cin >> n;

  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0\\n";
      return 0;
    }
  }

  long long prod = 1;
  rep(i, n) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      prod = -1;
      break;
    }
  }

  cout << prod;

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

#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

void Main() {
  // input
  int N;
  cin >> N;
  u_int64_t MAX = 1000000000000000000;

  u_int64_t ans = 1;
  bool flag = true;
  for (int i = 0; i < N; i++) {
    u_int64_t num;
    cin >> num;

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

    if (flag) {
      if (ans > MAX / num) {
        ans = 0;
        flag = false;
      }
      ans *= num;
    }
  }

  if (!flag) {
    cout << -1 << endl;
    return;
  }
  cout << ans << endl;

  // translate

  // output
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: -11

Fixed submission:

#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

void Main() {
  // input
  int N;
  cin >> N;
  u_int64_t MAX = 1000000000000000000;

  u_int64_t ans = 1;
  vector<u_int64_t> vec = vector<u_int64_t>();
  for (int i = 0; i < N; i++) {
    u_int64_t num;
    cin >> num;

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

  for (int i = 0; i < N; i++) {
    ans *= vec[i];
    if (ans > MAX) {
      cout << -1 << endl;
      return;
    }
  }

  cout << ans << endl;

  // translate

  // output
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <numeric>
#define ll long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll, ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i, a, b) for (ll i = a; i <= b; i++)
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ren(i, n) for (ll i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (ll i = a; i >= b; i--)
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld", &x)
#define clr(x, val) memset(x, val, sizeof(x))
#define pr(x) printf("%lld\\n", x)
#define gc getchar
#define pdd pair<dd, dd>
#define prec(x) cout << fixed << setprecision(x)
using namespace std;
ll a[100005];
map<ll, ll> help;
int main() {
  ll n, m;
  cin >> n;
  ll li = 1e18;
  ll ans = 1ll;
  ll f = 1;
  for (ll i = 1; i <= n; i++)
    cin >> a[i], help[a[i]]++;
  if (help[0])
    cout << 0;
  else {
    for (ll i = 1; i <= n; i++) {
      if (ans > li / a[i]) {
        f = 0;
        ans = -1;
        break;
      } else {
        ans *= a[i];
      }
    }

    cout << ans;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <numeric>
#define ll long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll, ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i, a, b) for (ll i = a; i <= b; i++)
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ren(i, n) for (ll i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (ll i = a; i >= b; i--)
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld", &x)
#define clr(x, val) memset(x, val, sizeof(x))
#define pr(x) printf("%lld\\n", x)
#define gc getchar
#define pdd pair<dd, dd>
#define prec(x) cout << fixed << setprecision(x)
using namespace std;

int main() {
  ll n, m;
  cin >> n;
  ll lim = 1e18;
  ll ans = 1ll;
  ll f = 1;
  for (ll i = 1; i <= n; i++) {
    ll j;
    cin >> j;
    // cout<<lim/j<<" "<<ans<<endl;

    if ((lim / j) < ans && (j > 0)) {
      ans = -1;
      f = 0;
    }
    if (j == 0)
      ans = 0;
    if (f)
      ans *= j;
  }
  cout << ans;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  ll FULL = 1'000'000'000'000'000'000;

  bool zeroflg = false;
  vector<ll> A;
  rep(i, N) {
    ll x;
    cin >> x;
    if (x == 0)
      zeroflg = true;
    A.push_back(x);
  }

  if (zeroflg) {
    // cout << "0" << endl;
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  bool ansflg = true;
  rep(i, N) {
    // ll ret = ans;
    ans *= A[i];
    if (ans > FULL || ans % A[i] != 0 || ans < A[i]) {
      ansflg = false;
      break;
    }
  }

  if (ansflg) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}


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;

int main() {
  int N;
  cin >> N;
  ll FULL = 1'000'000'000'000'000'000;

  bool zeroflg = false;
  vector<ll> A;
  rep(i, N) {
    ll x;
    cin >> x;
    if (x == 0)
      zeroflg = true;
    A.push_back(x);
  }

  if (zeroflg) {
    // cout << "0" << endl;
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  bool ansflg = true;
  rep(i, N) {
    ll ret = ans;
    ans *= A[i];
    if (ans > FULL || ans % ret != 0 || ans % A[i] != 0) {
      ansflg = false;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int num;
  cin >> num;
  unsigned long long int arr[num], ans = 1;
  bool zero = false, over = false;
  for (int i = 0; i < num; i++) {
    cin >> arr[i];
    if (arr[i] == 0) {
      zero = true;
      cout << '0' << '\\n';
      break;
    }
  }
  if (!zero) {
    for (int i = 0; i < num; i++) {
      if (arr[i] > 1000000000000000000 / ans) {
        cout << "-1" << '\\n';
        over = true;
        break;
      } else
        ans *= arr[i];
    }
    if (!over)
      cout << ans << '\\n';
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define MAXSIZE 30000

using namespace std;

class bignum {
public:
  bool operator>(const bignum &a);
  bignum operator*(const bignum &a);
  void findlength();
  int num[MAXSIZE] = {0};
  int len;
};

void bignum::findlength() {
  int length = MAXSIZE - 1;
  while (num[length] == 0 && length != 0)
    length--;
  len = length + 1;
}

bool bignum::operator>(const bignum &a) {
  if (len < a.len)
    return false;
  else if (len > a.len)
    return true;
  else {
    for (int i = len - 1; i >= 0; i--) {
      if (num[i] > a.num[i])
        return true;
      else if (num[i] < a.num[i])
        return false;
    }
  }
  return false;
}

bignum bignum::operator*(const bignum &a) {
  bignum newnum;
  for (int i = 0; i < len; i++)
    for (int j = 0; j < a.len; j++)
      newnum.num[i + j] += num[i] * a.num[j];
  for (int i = 0; i < MAXSIZE; i++) {
    newnum.num[i + 1] += (newnum.num[i] / 10);
    newnum.num[i] %= 10;
  }
  newnum.findlength();
  return newnum;
}

void output(const bignum a) {
  for (int i = a.len - 1; i >= 0; i--)
    cout << a.num[i];
  cout << '\\n';
}

void string_to_array(string num, int *n) {
  int length = num.length();
  for (int i = length - 1; i >= 0; i--)
    n[i] = (num[length - i - 1] - '0');
}

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

  int size;
  string num, limit_str = "1000000000000000000", ans_str = "1";
  bignum a, ans, limit;

  string_to_array(limit_str, limit.num);
  limit.len = limit_str.length();
  string_to_array(ans_str, ans.num);
  ans.len = ans_str.length();

  cin >> size;
  for (int i = 0; i < size; i++) {
    cin >> num;
    string_to_array(num, a.num);
    a.len = num.length();
    ans = ans * a;
  }

  if (ans > limit)
    cout << "-1" << '\\n';
  else
    output(ans);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long

signed main() {
  int n;
  ll t = 1, a;
  cin >> n;

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

    if (t == 0 || a == 0) {
      t = 0;
    } else if (t > 0 && t <= 1000000000000000000 / a) {
      t *= a;
    } else {
      t = -1;
    }
  }

  cout << t << endl;
}

Error: WA

Fixed submission:

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

#define ll long long

const ll MX = 1e18;

signed main() {
  int n;
  ll a, ans = 1;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if ((MX + 1) / a) {
      cout << -1 << endl;
    }
    ans *= a;
  }

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

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

#define ll long long

signed main() {
  int n;
  cin >> n;
  ll num = 1, a;

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

    if (a > 0 && 1000000000000000000 / num >= a) {
      num *= a;
    }

    else if (a == 0) {
      num = 0;
      break;
    }

    else {
      num = -1;
    }
  }

  cout << num;
}

Error: WA

Fixed submission:

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

#define ll long long

signed main() {
  int n;
  cin >> n;
  ll num = 1, a;

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

    if (a > 0 && 1000000000000000000 / num >= a) {
      num *= a;
    }

    else if (a == 0) {
      num = 0;
    }

    else {
      num = -1;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x : a) {
    cin >> x;
    if (x == 0) {
      cout << "0\\n";
      return 0;
    }
  }
  ll p = 1;
  for (auto &x : a) {
    if (x > (ll)1e18 / p) {
      cout << "-1\\n";
      return 0;
    }
    p *= x;
  }
  cout << p << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  ll prod = 1, x;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    ll y = prod;
    prod *= x;
    if (prod % x == 0 && prod / x == y && prod <= (ll)1e18) {
      continue;
    } else {
      cout << "-1\\n";
    }
  }
  cout << prod << "\\n";
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int N;
ll A[110000];

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


Error: 0

Fixed submission:

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

int N;
ll A[110000];

void check(ll ans) {
  if (ans > 1000000000000000000) {
    cout << "-1" << endl;
    exit(1);
  }
  return;
}

int main() {
  cin >> N;
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  ll ans = 1;
  rep(i, N) {
    ans *= A[i];
    check(ans);
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N;
  cin >> N;
  long long int A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sort(A, A + N);
  long long int ans = 1;
  long long int limit = 1e18;
  bool flag = true;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      ans = 0;
      break;
    } else if (A[i] > limit / ans) {
      flag = false;
      break;
    } else
      ans *= A[i];
  }
  if (flag)
    cout << ans << "\\n";
  else
    cout << "-1\\n";
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N;
  cin >> N;
  long long int A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sort(A, A + N);
  long long int ans = 1;
  long long int limit = 1e18;
  bool flag = true;
  for (int i = 0; i < N; i++) {
    if (A[i] > limit / ans) {
      flag = false;
      break;
    }
    ans *= A[i];
  }
  if (flag)
    cout << ans << "\\n";
  else
    cout << "-1\\n";
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

int main() {
  ios::sync_with_stdio(false);
  int n, t = 0;
  ll w = 1, k, a = 1000000000000000000;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    if (k == 0) {
      cout << "0";
      return 0;
    }
    if (a / w < k)
      t = 1;
    if (!t)
      w = w * k;
  }
  if (t)
    cout << "-1";
  else
    cout << w;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

int main() {
  ios::sync_with_stdio(false);
  int n, t = 0;
  ll w = 1, k, a = 1000000000000000000;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    if (k == 0) {
      cout << "0";
      return 0;
    }
    if (a / w < k)
      t = 1;
    w = w * k;
  }
  if (t)
    cout << "-1";
  else
    cout << w;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a, ll n, ll m);
ll power(ll a, ll n, ll m) {
  if (n == 0)
    return 1;
  ll x = power(a, n / 2, m);
  if (n % 2 != 0)
    return (((a * x) % m) * (x) % m) % m;
  else
    return (x * x) % m;
}
map<ll, ll>::iterator itr;
ll ans;
double PI = 3.14159265357;
int32_t main() {
  ll n, i, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a, o, temp;
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  ll arr[n];
  for (i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  cnt = 1;
  for (i = 0; i < n; i++) {
    if (arr[i] == 0) {
      cout << "0\\n";
      return 0;
    }

    if (arr[i] > (inf / cnt)) {
      cout << "-1\\n";
      return 0;
    }
    cnt = (cnt * arr[i]);
  }
  cout << cnt;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a, ll n, ll m);
ll power(ll a, ll n, ll m) {
  if (n == 0)
    return 1;
  ll x = power(a, n / 2, m);
  if (n % 2 != 0)
    return (((a * x) % m) * (x) % m) % m;
  else
    return (x * x) % m;
}
map<ll, ll>::iterator itr;
ll ans;
double PI = 3.14159265357;
int32_t main() {
  ll n, i, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a, o, temp;
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  ll arr[n];
  for (i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  cnt = 1;
  for (i = 0; i < n; i++) {
    if (arr[i] > (inf / cnt)) {
      cout << "-1\\n";
      return 0;
    }
    cnt = (cnt * arr[i]);
  }
  cout << cnt;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long int N;
  long unsigned int product = 1;
  cin >> N;
  long int arr[N];
  if (N <= 1000000000000000 && N >= 2) {
    for (int i = 0; i < N; i++) {
      cin >> arr[i];
      if (arr[i] == 0) {
        product = 0;
        i = N;
      } else if (arr[i] <= 1000000000000000000 / product && arr[i] != 0) {
        product = product * arr[i];
      } else {
        product = -1;
      }
    }
    if (product <= 1000000000000000000) {
      cout << product;
    }

    else {
      cout << -1;
    }
  }

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  long int N;
  long int product = 1;
  cin >> N;
  long int arr[N];
  if (N < 1000000000000000) {
    for (int i = 0; i < N; i++) {
      cin >> arr[i];
      if (arr[i] <= 1000000000000000000 / product) {
        product = product * arr[i];
      } else if (arr[i] == 0) {
        product = 0;
      } else {
        product = -1;
      }
    }
    if (product <= 1000000000000000000) {
      cout << product;
    } else {
      cout << -1;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < (int)s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

istream &operator>>(istream &is, __int128_t &a) {
  string s;
  is >> s;
  a = parse(s);
  return (is);
}
using Int = __int128_t;

int main() {
  int n;
  cin >> n;
  vector<Int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (count(a.begin(), a.end(), Int(0))) {
    cout << 0 << endl;
    return 0;
  }
  Int t = 1;
  for (int i = 0; i < n; i++) {
    if (t * a[i] > Int(1000000000000000000)) {
      cout << -1 << endl;
      return 0;
    }
    t *= a[i];
  }
  cout << t << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < (int)s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

istream &operator>>(istream &is, __int128_t &a) {
  string s;
  is >> s;
  a = parse(s);
  return (is);
}
using Int = __int128_t;

int main() {
  int n;
  cin >> n;
  vector<Int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (count(a.begin(), a.end(), Int(0))) {
    cout << 0 << endl;
    return 0;
  }
  Int t = 1;
  for (int i = 0; i < n; i++) {
    if (t * a[i] > Int(1000000000000000000)) {
      cout << -1 << endl;
      return -1;
    }
    t *= a[i];
  }
  cout << t << endl;
}