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

#include <bits/stdc++.h>
#define rep(a, b, c) for (int a = b; a <= c; a++)
#define per(a, b, c) for (int a = b; a >= c; a--)
#define ios                                                                    \\
  ;                                                                            \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x << 1)
#define rs(x) (ls(x) | 1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int M = 1e3 + 5;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll ksm(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int n, m, k;
ll a[N];

ll solve() {
  rep(i, 1, n) if (a[i] == 0) return 0;
  ll sum = a[1], tmp = 1e18;
  rep(i, 2, n) {
    if (tmp / sum < a[i])
      return -1;
    sum *= a[i];
  }
  return sum;
}

int main() {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(a, b, c) for (int a = b; a <= c; a++)
#define per(a, b, c) for (int a = b; a >= c; a--)
#define ios                                                                    \\
  ;                                                                            \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x << 1)
#define rs(x) (ls(x) | 1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int M = 1e3 + 5;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll ksm(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int n, m, k;
ll a[N];

int main() {
  cin >> n;
  ll sum = 1, ans = 0, tmp = 1e18;
  rep(i, 1, n) {
    cin >> a[i];
    sum *= a[i];
    if (tmp / sum < a[i])
      ans = -1;
  }
  if (ans == 0)
    ans = sum;
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define BeatMeScanf                                                            \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define tc(x)                                                                  \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define inf 1 << 28
#define mem(x, y) memset(x, y, sizeof(x))
#define ps(x, y) fixed << setprecision(y) << x
#define show(val) cout << #val << " -> " << val << endl
#define Case cout << "Case " << ++cs << ": "
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define MOD 1000000007
#define MAX 100005

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

  ll prod = 1, zero = 0, flag = 0;
  for (ll i = 0; i < n; ++i) {
    ll x;
    cin >> x;
    if (x == 0) {
      cout << 0 << '\\n';
      return 0;
    }
    if (x <= 1000000000000000000 / prod)
      prod *= x;
    else
      flag++;
  }

  if (flag > 0)
    cout << -1 << '\\n';
  else
    cout << prod << '\\n';

  return 0;
}


Error: 0

Fixed submission:

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

#define BeatMeScanf                                                            \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define tc(x)                                                                  \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define inf 1 << 28
#define mem(x, y) memset(x, y, sizeof(x))
#define ps(x, y) fixed << setprecision(y) << x
#define show(val) cout << #val << " -> " << val << endl
#define Case cout << "Case " << ++cs << ": "
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define MOD 1000000007
#define MAX 100005

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

  ll prod = 1, zero = 0, flag = 0;
  for (ll i = 0; i < n; ++i) {
    ll x;
    cin >> x;
    if (x == 0)
      zero++;
    if (x <= 1000000000000000000 / prod)
      prod *= x;
    else
      flag++;
  }

  if (zero > 0)
    cout << 0 << '\\n';
  else if (flag > 0 && zero == 0)
    cout << -1 << '\\n';
  else
    cout << prod << '\\n';

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

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double

const LL INF = 1e18;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  LL a;
  LL w = 1;
  bool czy = 1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      cout << 0;
      return 0;
    }
    LL x = INF / w;
    if (x < a) {
      czy = 0;
    }
    if (czy)
      w *= a;
  }
  if (czy)
    cout << w;
  else
    cout << -1;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double

const LL INF = 1e18;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  LL a;
  LL w = 1;
  bool czy = 1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      cout << 0;
      return 0;
    }
    LL x = INF / w;
    if (x < a) {
      czy = 0;
    }
    w *= a;
  }
  if (czy)
    cout << w;
  else
    cout << -1;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long n;
  long long MX = 1e18;
  cin >> n;
  vector<long long> a(n);
  long long ans = 1;
  bool ng = false;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || MX / ans < a) {
      ng = true;
    }
    ans *= a;
  }
  if (ng)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Error: WA

Fixed submission:

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

int main() {
  long long n;
  long long MX = 1e18;
  cin >> n;
  vector<long long> a(n);
  int ans = 1;
  bool ng = false;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    ans *= a;
    if (ng || MX / ans < a) {
      ng = true;
    }
  }
  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;
using ll = long long;

const ll MAX = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  if (find(a.begin(), a.end(), 0) != a.end()) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, n) {
    if (MAX / ans < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
  return 0;
}


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;

const ll MAX = 1e18;

int main() {
  int n;
  ll ans = 1;
  cin >> n;
  vector<ll> a(n);
  bool ng = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a > MAX / ans) {
      ng = true;
    }
    ans *= a;
  }
  cout << (ng ? -1 : ans) << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int N;
  cin >> N;
  long long Total = 1;
  bool ok = true;
  for (int i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      ok = true;
      Total = 0;
      break;
    }
    if (tmp > static_cast<long long>(1000000000000000000) / Total) {
      ok = false;
      tmp = 1000000000000000001;
    } else
      Total *= tmp;
  }

  if (!ok)
    cout << -1 << endl;
  else
    cout << Total << endl;
}

Error: 0

Fixed submission:

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

int main() {

  int N;
  cin >> N;
  long long Total = 1;
  bool ok = true;
  for (int i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    if (tmp > static_cast<long long>(1000000000000000000) / Total) {
      ok = false;
      tmp = 1;
    } else
      Total *= tmp;
    if (tmp == 0)
      ok = true;
  }

  if (!ok)
    cout << -1 << endl;
  else
    cout << Total << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  long long n = 0;
  cin >> n;
  long long a[n];

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

  long long ans = 1;
  for (long long i = 0; i < n; i++) {

    if (a[i] <= 1000000000000000000 / ans) {
      ans *= a[i];
    } else {
      cout << "-1";
      return 0;
    }
  }
  cout << ans;
}


Error: -11

Fixed submission:

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

int main() {

  long long n;

  long long a[n];

  cin >> n;

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

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

    if (ans <= 1000000000000000000 / ans) {
      ans *= a[i];
    } else {
      cout << "-1";
      return 0;
    }
  }
  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;
using P = pair<int, int>;

int main() {
  int n;
  ll a = 1;
  bool can = true;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) { cin >> vec.at(i); }
  rep(i, n) {
    if (vec.at(i) == 0) {
      cout << 0 << endl;
      can = false;
      break;
    }
  }

  if (can) {
    rep(i, n) {

      if (vec.at(i) > 1000000000000000000 / a) {
        cout << -1 << endl;
        can = false;
        break;
      }
      a *= vec.at(i);
    }
  }

  if (can) {
    cout << a << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)


Fixed submission:

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

int main() {
  int n;
  ll a = 1;
  bool can = true;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) { cin >> vec.at(n); }
  rep(i, n) {
    if (vec.at(i) == 0) {
      cout << 0 << endl;
      can = false;
      break;
    }
  }

  if (can) {
    rep(i, n) {
      a *= vec.at(i);
      if (vec.at(i) > 1000000000000000000 / a) {
        cout << -1 << endl;
        can = false;
        break;
      }
    }
  }

  if (can) {
    cout << a << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define int boost::multiprecision::cpp_int
using namespace std;

typedef unsigned long long ll;
typedef unsigned long long ull;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
struct Edge {
  long long to;
  long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
const long long INF = 1LL << 60;
int a[100000];

signed main() {
  int n;

  cin >> n;

  int total = 1;
  long tmp = 0;
  for (ll i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp == (int)0) {

      cout << 0 << endl;
      return 0;
    }
    a[i] = tmp;
  }

  for (ll i = 0; i < n; i++) {
    total *= a[i];

    if (total > (int)1000000000000000000) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << total << endl;
}
// cout << std::fixed << std::setprecision(15)


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define int boost::multiprecision::cpp_int
using namespace std;

typedef unsigned long long ll;
typedef unsigned long long ull;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
struct Edge {
  long long to;
  long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
const long long INF = 1LL << 60;

signed main() {
  int n;

  cin >> n;

  int total = 1;
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    total *= tmp;
  }

  if (total > 1000000000000000000) {
    cout << -1 << endl;
    return 0;
  }

  cout << total << endl;
}
// cout << std::fixed << std::setprecision(15)
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

class BMultiplication2 {
public:
  void solve(std::istream &cin, std::ostream &cout) {
    using namespace std;
    int n;
    cin >> n;
    ll ans = 1;
    bool flag = false;
    while (n--) {
      ll tp;
      cin >> tp;
      if (ans == 0 || tp == 0) {
        ans = 0;
        flag = false;
        continue;
      }
      if (tp > 1000000000000000000 / ans) {
        flag = true;
      }
      if (flag)
        continue;
      ans *= tp;
    }
    if (flag)
      cout << "-1\\n";
    else
      cout << ans << '\\n';
  }
};

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  BMultiplication2 solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Error: 0

Fixed submission:

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

class BMultiplication2 {
public:
  void solve(std::istream &cin, std::ostream &cout) {
    using namespace std;
    int n;
    cin >> n;
    ll ans = 1;
    bool flag = false;
    while (n--) {
      ll tp;
      cin >> tp;
      if (tp > (ll)(1e18) / ans) {
        flag = true;
      }
      ans *= tp;
      if (ans == 0)
        flag = false;
    }
    if (flag)
      cout << "-1\\n";
    else
      cout << ans << '\\n';
  }
};

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  BMultiplication2 solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define LIMIT_M 1000000000000000000 // 10^18
using namespace std;
static const long long LIMIT = 1000000000000000000; // 10^18

int main() {
  long long res = 1, A[100005];
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (res > LIMIT / A[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      res *= A[i];
    }
  }
  cout << res << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
static const long long LIMIT = 1000000000000000000; // 10^18

int main() {
  long long res = 1, A;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A;
    if (A > LIMIT / res) {
      cout << -1 << endl;
    } else {
      res *= A;
    }
  }
  cout << res << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool oror = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (oror || mx / ans < a || mx < a * ans) {
      oror = true;
    }
    ans *= a;
  }
  if (oror)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool oror = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (mx / ans < a || mx < a * ans) {
      oror = true;
    }
    ans *= a;
  }
  if (oror)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
  ll max = 1e18;
  ll sum = 1;
  int n;
  cin >> n;
  bool fl = false;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (max / sum < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    sum *= a[i];
  }
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
  ll max = 1e18;
  ll sum = 1;
  int n;
  cin >> n;
  bool fl = false;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (sum * a[i] > max || max / sum < a[i]) {
      fl = true;
    }
    sum *= a[i];
  }
  if (fl) {
    sum = -1;
  }
  cout << sum << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
ll maxVal = 1e18;

int main() {
  std::ios_base::sync_with_stdio(false);
  ll n;
  ll ret = 0ll;
  cin >> n;
  vector<ll> a(n);
  int count0 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    count0 += (a[i] == 0);
  }
  if (!count0) {
    ret = 1ll;
    for (int i = 0; i < n; i++) {
      if (a[i] <= maxVal / ret)
        ret *= a[i];
      else {
        ret = -1;
        break;
      }
    }
  }
  cout << ret << '\\n';
}


Error: WA

Fixed submission:

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

typedef long long ll;
ll maxVal = 1e18;

int main() {
  std::ios_base::sync_with_stdio(false);
  ll n;
  ll ret = 0ll;
  cin >> n;
  vector<int> a(n);
  int count0 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    count0 += !a[i];
  }
  if (count0) {
    ret = 1ll;
    for (int i = 0; i < n; i++) {
      if (a[i] <= maxVal / ret)
        ret *= a[i];
      else {
        ret = -1;
        break;
      }
    }
  }
  cout << ret << '\\n';
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

/*
 * author: calgagi
 *         Calvin Gagliano
 */
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define ar array
#define f first
#define s second
#define dd long double

void solve() {
  int n;
  cin >> n;
  vector<dd> a(n);
  for (dd &x : a) {
    cin >> x;
  }

  sort(a.begin(), a.end());

  dd ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= a[i];
    if (ans > 1e18) {
      break;
    }
  }

  cout << fixed << setprecision(0);
  if (ans > 1e18) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  srand(chrono::steady_clock::now().time_since_epoch().count());

  int t = 1;
  /* cin >> t; */
  while (t--) {
    solve();
  }

  return 0;
}


Error: 0

Fixed submission:

/*
 * author: calgagi
 *         Calvin Gagliano
 */
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define ar array
#define f first
#define s second
#define dd long double

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

  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    if (LLONG_MAX / x <= ans) {
      ans = LLONG_MAX;
    } else {
      ans *= x;
    }
  }

  if (ans > (ll)1e18) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  srand(chrono::steady_clock::now().time_since_epoch().count());

  int t = 1;
  /* cin >> t; */
  while (t--) {
    solve();
  }

  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 < n; i++)

int main() {
  int N;
  cin >> N;
  vector<int64_t> v(N);
  rep(i, N) {
    cin >> v.at(i);
    if (v.at(i) == 0) {
      std::cout << "0" << '\\n';
      return 0;
    }
  }
  int64_t a = 1, b = 0, c = 0, x, y, z;
  x = 1000000000000000000;
  rep(i, N) {
    if (a > x / v.at(i)) {
      std::cout << "-1" << '\\n';
      return 0;
    }
    a *= v.at(i);
  }
  std::cout << a << '\\n';
}


Error: -8

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> v(N);
  rep(i, N) {
    cin >> v.at(i);
    if (v.at(i) == 0) {
      std::cout << "0" << '\\n';
      return 0;
    }
  }
  int64_t a = 1, b = 0, c = 0, x, y, z;
  x = 1000000000000000000;
  rep(i, N) {
    if (a >= x / b) {
      std::cout << "-1" << '\\n';
      return 0;
    }
    a *= v.at(i);
  }
  std::cout << a << '\\n';
}