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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <regex>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for (int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream &operator<<(ostream &out, vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    out << v[i] << ' ';
  }
  return out;
}

const long long INF = 1e18;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  // string s("hello william and me");
  // s.replace(s.find("william"), sizeof("william") - 1, "Somename");
  // cout << s << endl;

  ll N;
  cin >> N;
  bool a = false;
  ll ans = 1;
  while (N--) {
    ll b;
    cin >> b;
    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (INF / b < ans)
      a = true;
    ans *= b;
  }
  if (a)
    ans = -1;
  if (ans > INF)
    ans = -1;
  cout << ans << endl;
  return 0;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <regex>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for (int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream &operator<<(ostream &out, vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    out << v[i] << ' ';
  }
  return out;
}

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

  // string s("hello william and me");
  // s.replace(s.find("william"), sizeof("william") - 1, "Somename");
  // cout << s << endl;

  int n;
  ll a[10010] = {0};
  cin >> n;
  ll lim = 1e18;
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0" << endl;
      return 0;
    }
    if (a[i] > lim) {
      cout << "-1" << endl;
    }
  }
  ll ans = 1;
  rep(i, n) {
    ans *= a[i];
    if (ans > lim) {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << ans << endl;

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

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

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

#ifdef EBUG
#define debug(x) cout << "\\033[31m" << #x << ": " << x << "\\033[0m\\n";
#else
#define debug(x)
#endif

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

ll n, a[100000], ans = 1;
bool toobig = false;

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

Error: 0

Fixed submission:

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

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

#ifdef EBUG
#define debug(x) cout << "\\033[31m" << #x << ": " << x << "\\033[0m\\n";
#else
#define debug(x)
#endif

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

ll n, a[100000], ans = 1;
bool toobig = false;

int main() {
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (a[i] > 1000000000000000000 / ans) {
      toobig = true;
    }
    ans *= a[i];
  }
  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;
#define pri(str) cout << str << endl
using ll = long long;
using P = pair<int, int>;

const ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool ok = true;
  rep(i, n) {
    ll a;
    cin >> a;

    if (a == 0) {
      pri(0);
      return 0;
    }
    if ((mx + 1) / ans < a || ans * a > mx) {
      ans = -1;
      ok = false;
    }
    if (ok)
      ans *= a;
  }

  pri(ans);
  return 0;
}


Error: WA

Fixed submission:

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

const ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool ok = true;
  rep(i, n) {
    ll a;
    cin >> a;
    if (ok)
      ans *= a;
    else if (a == 0)
      ans = 0;

    if ((mx + 1) / ans < a || ans * a > mx) {
      ans = -1;
      ok = false;
    }
  }

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

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

int main() {
  int n;
  cin >> n;
  unsigned long long ans = 1;
  vector<unsigned long long> data(n);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());

  for (int i = 0; i < n; i++) {
    if (data.at(i) > 1000000000000000000 / ans) {
      cout << -1;
      return 0;
    }
    ans *= data.at(i);
    if (ans == 0) {
      cout << 0;
      return 0;
    }
  }
  cout << ans;
}


Error: WA

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  unsigned long long ans = 1;
  vector<unsigned long long> data(n);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());

  for (int i = 0; i < n; i++) {
    if (data.at(i) > 1000000000000000000 / ans) {
      cout << -1;
      return 0;
    }
    ans *= data.at(i);
  }
  cout << ans;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  int N;
  cin >> N;
  ll ans = 1, a;
  ll inf = 1e18;
  bool f = false;
  rep(i, N) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ans > inf / a) {
      f = true;
    }

    ans *= a;
  }
  if (f) {
    cout << -1 << endl;
    return 0;
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  int N;
  cin >> N;
  ll ans = 1, a;
  ll inf = 1e18;
  bool f = false;
  rep(i, N) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a > inf / ans) {
      f = true;
    }

    ans *= a;
  }
  if (f) {
    cout << -1 << endl;
    return 0;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define inf 1000000000
typedef long long ll;
typedef unsigned long long ull;
int n;
ull a;
ull ans = 1;

int main() {
  bool ok = true;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a > 1000000000000000000 / ans) {
      ok = false;
    }
    if (ok) {
      ans *= a;
    }
  }
  if (ok) {
    cout << ans << endl;
  }

  else {
    cout << -1 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define inf 1000000000
typedef long long ll;
typedef unsigned long long ull;
int n;
ull a;
ull ans = 1;

int main() {
  bool ok = true;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a > 1000000000000000000 / ans) {
      ok = false;
    }
    ans *= a;
  }
  if (ok) {
    cout << ans << endl;
  }

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

#include <bits/stdc++.h>

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, n) for (int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const ll INF = 1e+18;
const ll MOD = 1e+9 + 7;

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A));
  if (A[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  REP(i, N) {
    if ((INF + ans - 1) / ans < A[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= A[i];
  }
  if (ans > INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define int ll

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, n) for (int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

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

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

int n, i, ans = 1ll;
int a[100010];

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

  return 0;
}

Error: 0

Fixed submission:

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

int n, x, ans = 1, now = 1;

signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x == 0)
      return cout << 0 << endl, 0;
    if (1000000000000000000 / ans < x)
      now = 0;
    ans *= x;
  }
  if (now == 0)
    cout << -1 << endl;
  else
    cout << ans << endl;

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

#include <cmath>
#include <iostream>
#define MAXN 10 * 10 * 10 * 10 * 10

using namespace std;

long long a[100500];

signed main() {
  long long n;
  scanf("%lld", &n);

  for (long long i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }

  long long res = a[0];
  if (res == 0) {
    cout << 0 << endl;
    return 0;
  }

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

  for (long long i = 1; i < n; i++) {
    if ((long long)pow(10, 18) / res < a[i]) {
      cout << -1 << endl;
      return 0;
    }

    res = a[i] * res;
  }

  printf("%lld", res);

  return 0;
}


Error: WA

Fixed submission:

#include <cmath>
#include <iostream>
#define MAXN 10 * 10 * 10 * 10 * 10

using namespace std;

long long a[100500];

signed main() {
  long long n;
  scanf("%lld", &n);

  for (long long i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }

  long long res = a[0];
  if (res == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (long long i = 1; i < n; i++) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    res = a[i] * res;
    if ((long long)pow(10, 18) / res < a[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  printf("%lld", res);

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a[100010];
  long long sum = 1, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (long long i = 0; i < n; i++) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (sum > 1000000000000000000 / a[i]) {
      ans = -1;
      break;
    }
    sum *= a[i];
  }
  if (ans != -1) {
    ans = sum;
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a[100010];
  long long sum = 1, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      sum = 0;
  }
  sort(a, a + n);
  for (long long i = 0; i < n; i++) {
    if (sum > 1000000000000000000 / a[i]) {
      ans = -1;
      break;
    }
    sum *= a[i];
  }
  if (ans != -1) {
    ans = sum;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n";
#define int long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
#define double long double
#define M_PI 3.14159265358979323846
const int mod = 1e9 + 7;

int32_t main() {
  fastio;

  int n;
  cin >> n;
  bool flag = true, zero = false;
  int ans = 1, maxi = 1e18;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (ans != 0 && x > maxi / ans) {
      flag = false;
    } else {
      ans *= x;
    }

    if (x == 0)
      zero = true;
  }

  if (zero)
    flag = true;
  cout << (flag ? ans : -1) << endl;
  return 0;
}

/*

*/

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n";
#define int long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
#define double long double
#define M_PI 3.14159265358979323846
const int mod = 1e9 + 7;

int32_t main() {
  fastio;

  int n;
  cin >> n;
  bool flag = true, zero = false;
  int ans = 1, maxi = 1e18;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x > maxi / ans) {
      flag = false;
    } else {
      ans *= x;
    }

    if (x == 0)
      zero = true;
  }

  if (zero)
    flag = true;
  cout << (flag ? ans : -1) << endl;
  return 0;
}

/*

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

#include <bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define ppll pair<pll, pll>
#define pii pair<int, int>
#define pb push_back
const ll inf = 2e18 + 7;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 7;
const ld pi = 3.14159265358979;

void solve() {
  ll n;
  cin >> n;
  vector<ll> arr(n);
  ll pro = 1;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  for (int i = 0; i < n; i++) {
    if (pro == 0) {
      cout << "0";
      return;
    }
    if (((ll)(1e18) / pro) < arr[i]) {
      cout << "-1";
      return;
    }
    pro = pro * arr[i];
  }
  cout << pro;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
    // cout<<"\\n";
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define ppll pair<pll, pll>
#define pii pair<int, int>
#define pb push_back
const ll inf = 2e18 + 7;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 7;
const ld pi = 3.14159265358979;

void solve() {
  ll n;
  cin >> n;
  vector<ll> arr(n);
  ll pro = 1;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  for (int i = 0; i < n; i++) {
    if (((ll)(1e18) / pro) < arr[i]) {
      cout << "-1";
      return;
    }
    pro = pro * arr[i];
  }
  cout << pro;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
    // cout<<"\\n";
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int i, n;
  long long a[100000];
  cin >> n;
  long long proud = 1;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      flag = true;
    }
  }

  if (flag) {
    cout << 0 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] > 1000000000000000000 / proud) {
        cout << -1 << endl;
        flag = true;
        break;
      }
      proud *= a[i];
    }
  }
  if (!flag)
    cout << proud << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;
int main() {
  // 整数の入力
  int n;
  cin >> n;
  unsigned long long int a = 1;
  unsigned long long int b[10000];
  bool flg = true;

  unsigned long long int limit = 1;

  for (int i = 0; i < 18; i++) {
    limit *= 10;
  }

  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

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

    if (a * b[i] > limit) {
      cout << -1 << endl;
      flg = false;
      break;
    }

    a *= b[i];
  }
  if (flg) {
    cout << a << 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++)
using ll = long long;

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);

  ll ans = 1;
  bool flag = 0;

  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a > MX / ans || MX < ans * a) {
      flag = 1;
      continue;
    }
    ans *= a;
  }

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

Error: 0

Fixed submission:

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

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);

  ll ans = 1;
  bool flag = 0;

  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a > MX / ans || MX < ans * a) {
      flag = 1;
    }
    ans *= a;
  }

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

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  long long int sum;
  long long int a;
  bool zero = false;
  bool over = false;
  cin >> a;
  sum = a;
  if (a == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a;
    // 1000000000000000000
    if (a == 0)
      zero = true;
    else if (sum > 1000000000000000000 / a) {
      over = true;
    }
    sum *= a;
  }
  if (zero) {
    cout << 0 << endl;
    return 0;
  }
  if (over) {
    cout << -1 << endl;
    return 0;
  }
  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  long long int sum;
  long long int a;
  bool zero = false;
  bool over = false;
  cin >> a;
  sum = a;
  if (a == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a;
    // 1000000000000000000
    if (a == 0)
      zero = true;
    if (sum > 1000000000000000000 / a && a != 0) {
      over = true;
    }
    sum *= a;
  }
  if (over) {
    cout << -1 << endl;
    return 0;
  }
  if (zero) {
    cout << 0 << endl;
    return 0;
  }
  cout << sum << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// Begin Header {{{
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define loop(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
using namespace std;
using Graph = vector<vector<ll>>;
using P = pair<int, int>;
// }}} End Header
struct edge {
  int to;
  int cost;
};
int main() {
  ll n, ans = 1;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (a[i] > (1000000000000000000 / ans)) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
// Begin Header {{{
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define loop(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
using namespace std;
using Graph = vector<vector<ll>>;
using P = pair<int, int>;
// }}} End Header
struct edge {
  int to;
  int cost;
};
int main() {
  ll n, 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) && ans != 0) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#pragma GCC optimize "O3"
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = (int)1e9 + 7;
const ll INF = MOD * MOD;
const ll powll = 1LL << 1;

int main() {
  ll n;
  cin >> n;
  ll a[n];
  rep(i, 0, n) cin >> a[i];
  sort(a, a + n);
  ll ans = 1;
  bool f = false;
  rep(i, 0, n) {
    if (a[i] > 0 && ans > (ll)1e18 / a[i])
      f = true;
    ans *= a[i];
  }
  if (f)
    cout << -1 << "\\n";
  else
    cout << ans << "\\n";
}

Error: 0

Fixed submission:

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

#pragma GCC optimize "O3"
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = (int)1e9 + 7;
const ll INF = MOD * MOD;
const ll powll = 1LL << 1;

int main() {
  ll n;
  cin >> n;
  ll a[n];
  rep(i, 0, n) cin >> a[i];

  ll ans = 1;
  bool f = false;
  rep(i, 0, n) {
    if (ans > (ll)1e18 / a[i])
      f = true;
    ans *= a[i];
  }
  if (f)
    cout << -1 << "\\n";
  else
    cout << ans << "\\n";
}