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

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

const int MAXN = 2e5 + 2;
unsigned long long nums[MAXN];

const long long MAXL = 1e18;

// 判断a*b是否超过1e18
bool overflow(unsigned long long a, unsigned long long b) {
  // 判断是否越界
  if (ULLONG_MAX / a < b) {
    return true;
  }
  // 判断是否超过1e18
  unsigned long long ans = a * b;
  if (ans > MAXL) {
    return true;
  }
  return false;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%llu", &nums[i]);
    if (0 == nums[i]) {
      printf("0\\n");
      return 0;
    }
  }

  long long ans = 1;
  for (int i = 0; i < n; i++) {
    if (true == overflow(ans, nums[i])) {
      printf("-1\\n");
      return 0;
    }
    ans *= nums[i];
  }

  printf("%llu", ans);

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  bool flag = 0;
  long long a[10001], s = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      flag = 1;
  }
  if (flag == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    s *= a[i];
    if (s > 1000000000000000000) {
      cout << "-1";
      return 0;
    }
  }
  cout << s;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: 0

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  ll ans = 1;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      ans = 0;
    }
  }

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

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define x first
#define y second
#define sz(v) (int)v.size()
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979
#define N 200005

int solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (!a[i]) {
      cout << 0;
      return 0;
    }
  }
  int m = 1e18, ans = 1;
  for (int i = 0; i < n; ++i) {
    if (m / ans < a[i]) {
      cout << -1;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans;
  return 0;
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define x first
#define y second
#define sz(v) (int)v.size()
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979
#define N 200005

int solve() {
  int n, ans = 1;
  cin >> n;
  bool f = 0;
  int maxans = 1e18;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    if (t == 0) {
      cout << 0;
      return 0;
    }
    if (maxans / ans < t)
      f = 1;
    ans *= t;
  }
  if (f)
    cout << -1;
  else
    cout << ans;
  return 0;
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;
using P = pair<int, int>;

const long long MAX = 1e18;

int main() {
  long long n;
  cin >> n;
  long long ans = 1;
  bool ng = false;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      ans = 0;
      cout << ans << endl;
      return 0;
    }
    if (a[i] <= MAX / ans) {
      ans *= a[i];
    } else {
      ans = -1;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int INF = 10 ^ 18;

int main() {
  int N;
  cin >> N;
  vector<int> a(N); // 可変長配列
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int ans = 1;
  int tmp = 0;
  for (int i = N - 1; i >= 0; i = i - 2) {
    if (i - 1 < 0)
      a[i - 1] = 1;
    tmp = a[i] * a[i - 1];
    ans = ans * tmp;
  }
  if (ans > INF)
    ans = -1;
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define max 1000000000000000000
typedef uint64_t ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0";
      return 0;
    }
  }
  ll ans = 1;
  for (ll i = 0; i < n; i++) {
    if (a[i] <= max / ans) {
      ans *= a[i];
    } else {
      cout << "-1";
      return 0;
    }
  }
  cout << ans;

  return 0;
}


Error: WA

Fixed submission:

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

#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define max (ull)1e18
typedef uint64_t ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0";
      return 0;
    }
  }
  int ans = 1;
  for (ll i = 0; i < n; i++) {
    if (a[i] <= max / ans) {
      ans *= a[i];
    } else {
      cout << "-1";
      return 0;
    }
  }
  cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3], n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int, int> P;

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3], n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int, int> P;

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

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

int main() {
  int64_t N, ans = 1;
  cin >> N;
  vector<int64_t> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (a.at(i) == 0)
      ans = 0;
  }
  for (int i = 0; i < N; i++) {
    if (ans != 0 && (a.at(i) > (int64_t(pow(10, 18)) / ans))) {
      // cout << int64_t(pow(10,18))/ans << endl;
      ans = -1;
      break;
    }
    ans = ans * a.at(i);
    if (ans > int64_t(pow(10, 18))) {
      ans = -1;
      // cout << 2 << endl;
      break;
    }
  }

  cout << ans << endl;
}


Error: WA

Fixed submission:

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

int main() {
  int64_t N, ans = 1;
  cin >> N;
  vector<int64_t> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (a.at(i) == 0)
      ans = 0;
  }
  for (int i = 0; i < N; i++) {
    ans = ans * a.at(i);
    if (a.at(i) > (int64_t(pow(10, 18)) / ans)) {
      ans = -1;
      break;
    }
    if (ans > int64_t(pow(10, 18))) {
      ans = -1;
      break;
    }
  }

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

// 169

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll n, ans = 1, buf;
  cin >> n;
  bool c = false;
  for (ll i = 0; i < n; i++) {
    cin >> buf;
    if (buf == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (c || ans * buf > 1000000000000000000 ||
        1000000000000000001 / ans < buf) {
      c = true;
    }
    ans *= buf;
  }

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


Error: 0

Fixed submission:

// 69

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll n, ans = 1, buf;
  cin >> n;
  bool c = false;
  for (ll i = 0; i < n; i++) {
    cin >> buf;
    if (buf == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ans * buf > 1000000000000000000 || 1000000000000000001 / ans < buf) {
      c = true;
    }
    ans *= buf;
  }

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

#include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX / 3
#define PI 3.14159265359
using namespace std;
int mypow(int fa, int fb, int fc) {
  if (fb == 0)
    return 1;
  if (fb % 2)
    return mypow(fa, fb - 1, fc) * fa % fc;
  int z = mypow(fa, fb / 2, fc);
  return z * z % fc;
}
int k(int fa) {
  int x = 0;
  while (fa) {
    x++;
    fa /= 10;
  }
  return x;
}
int gcd(int fa, int fb) {
  if (fb == 0)
    return fa;
  return gcd(fb, fa % fb);
}
signed main() {
  int n, z = 1;
  cin >> n;
  bool b = false;
  f(i, n) {
    int a;
    cin >> a;
    if (a == 0) {
      puts("0");
      return 0;
    }
    if (mypow(10, 18, LLONG_MAX) / z < a) {
      b = true;
    }
    if (!b)
      z *= a;
  }
  if (b)
    puts("-1");
  else
    cout << z << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX / 3
#define PI 3.14159265359
using namespace std;
int mypow(int fa, int fb, int fc) {
  if (fb == 0)
    return 1;
  if (fb % 2)
    return mypow(fa, fb - 1, fc) * fa % fc;
  int z = mypow(fa, fb / 2, fc);
  return z * z % fc;
}
int k(int fa) {
  int x = 0;
  while (fa) {
    x++;
    fa /= 10;
  }
  return x;
}
int gcd(int fa, int fb) {
  if (fb == 0)
    return fa;
  return gcd(fb, fa % fb);
}
signed main() {
  int n, z = 1;
  cin >> n;
  bool b = false;
  f(i, n) {
    int a;
    cin >> a;
    if (mypow(10, 18, LLONG_MAX) / z < a) {
      b = true;
    }
    z *= a;
    if (a == 0) {
      puts("0");
      return 0;
    }
  }
  if (b)
    puts("-1");
  else
    cout << z << endl;
}
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++)
const long long MX = 1e18;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  rep(i, N) {
    if (A.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long out = 1;
  for (long long i : A) {
    if ((MX / out) < i) {
      cout << -1 << endl;
      return 0;
    }
    out *= i;
  }
  cout << out << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int64_t MX = 1e18;
int main() {
  int N;
  cin >> N;
  int64_t ans = 1;
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    if ((MX + 1) / ans <= a) {
      cout << -1 << endl;
    }
    ans *= a;
    if (ans == 0) {
      cout << 0 << endl;
    }
  }
  cout << ans << endl;
  return 0;
}
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 P = pair<int, int>;
using ll = long long;

const ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool over = false;

  rep(i, n) {
    ll a;
    cin >> a;

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

    if (over || (mx + 1) / ans < a || a * ans > mx) {
      over = true;
    }

    ans *= a;
  }

  if (over)
    ans = -1;
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

const ll mx = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool over = false;

  rep(i, n) {
    ll a;
    cin >> a;

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

    if ((mx + 1) / ans < a || a * ans > mx || over) {
      over = true;
    }

    ans *= a;
  }

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

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

int main() {
  int n;
  cin >> n;
  long long ans = 1;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      ans = 0;
      break;
    }

    if (ans > (1000000000000000000 / a[i])) {
      ans = -1;
      break;
    }
    ans = ans * a[i];
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

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

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll limit = 1000000000000000000;

int main() {
  // 入力
  ll N;
  cin >> N;
  vector<ll> vec(N);
  for (ll i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

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

  ll ans = 1;
  for (ll i = 0; i < N; i++) {
    if (vec.at(i) <= limit / ans) {
      ans *= vec.at(i);
    } else {
      ans = -1;
      break;
    }
    if (ans == 0) {
      break;
    }
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll limit = 1000000000000000000;

int main() {
  // 入力
  ll N;
  cin >> N;
  vector<ll> vec(N);
  for (ll i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

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

  ll ans = 1;
  for (ll i = 0; i < N; i++) {
    if (vec.at(i) <= limit / ans) {
      ans *= vec.at(i);
    } else {
      ans = -1;
      break;
    }
  }

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

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

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


Error: 0

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  long long count = 1;
  for (int i = 0; i < n; i++) {
    if (count > 0) {
      if (count <= 1000000000000000000 / a[i])
        count *= a[i];
      else
        count = -1;
    }
  }
  cout << count << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
  ll n, i;
  vector<ll> a(100010);
  cin >> n;
  ll ans = 1;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0" << endl;
      return 0;
    }
  }
  for (i = 0; i < n; i++) {
    if (1000000000000000000 / a[i] < ans) {
      cout << "-1" << endl;
      return 0;
    }
    ans = ans * a[i];
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
typedef long long ll;
typedef pair<int, int> P;
ll tmp(ll a) {
  ll ans = 0;
  while (a > 0) {
    a = a / 10;
    ans++;
  }
  return ans;
}
int main() {
  int n, i;
  cin >> n;
  Bint ans = 1, a;
  for (i = 0; i < n; i++) {
    cin >> a;
    ans *= a;
  }
  if (ans > 1000000000000000000) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a[100005], ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  if (a[0] == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / ans)
      ans *= a[i];
    else {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main() {
  int n;
  cin >> n;
  long ans = 1;
  vec<long> a(n);
  for (auto &&e : a) {
    cin >> e;
  }
  sort(a.begin(), a.end());
  bool flag = true;
  for (auto &&e : a) {
    if (e == 0) {
      ans *= e;
      break;
    }

    if (e > 1000000000000000000 / ans) {
      flag = false;
      break;
    }
    ans *= e;
  }
  if (flag) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main() {
  int n;
  cin >> n;
  long ans = 1;
  vec<long> a(n);
  for (auto &&e : a) {
    cin >> e;
  }
  sort(a.begin(), a.end());
  bool flag = true;
  for (auto &&e : a) {
    if (e > 1000000000000000000) {
      flag = false;
      break;
    }
    if (e > 1000000000000000000 / ans) {
      flag = false;
      break;
    }
    ans *= e;
  }
  if (flag) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  unsigned long long n, x = 0, proa = 1, prob = 1;
  cin >> n;
  vector<unsigned long long> a(n + 1);
  a[0] = 1;
  for (unsigned long long i = 0; i < n; i++) {
    cin >> a[i + 1];
    if (a[i + 1] == 0) {
      proa = 0;
    }
  }
  for (unsigned long long i = 0; i < n; i++) {
    if (proa == 0) {
      break;
    }
    proa *= a[i + 1];
    prob *= a[i];
    if (proa > 1000000000000000000 || proa / a[i + 1] != prob) {
      x += 1;
      break;
    }
  }
  if (x == 0) {
    cout << proa << endl;
  } else {
    cout << -1 << endl;
  }
  // cout << x << endl;
  // cout << x << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  long long n, x = 0, pro = 1;
  cin >> n;
  vector<long long> a(n);
  a[0] = 1;
  for (long long i = 0; i < n; i++) {
    cin >> a[i + 1];
    if (a[i + 1] == 0) {
      pro = 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    pro *= a[i + 1];
    // cout << pro;
    if (pro > 1000000000000000000 || pro / a[i + 1] != a[i]) {
      x += 1;
      break;
    }
  }
  // cout << pro / a[1] << endl;
  // cout << pro;
  if (x == 0) {
    cout << pro << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}