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

#include <bits/stdc++.h>
#define ll long long int
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end));                                         \\
       i += 1 - 2 * ((begin) >                                                 \\
                     (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) -->
                             // {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main() {
  ll n;
  cin >> n;
  ll x = 1000000000000000000;
  ll res = 1LL;
  bool y = false;
  bool z = false;
  while (n--) {
    ll a;
    cin >> a;
    if (a == 0)
      y = true;
    if (res == 0) {
      y = true;
      break;
    }
    if (x / res >= a)
      res = res * a;
    else
      z = true;
  }
  if (y == true)
    cout << 0;
  else if (z == true)
    cout << -1;
  else
    cout << res;
  return 0;
}
// Instead of com

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end));                                         \\
       i += 1 - 2 * ((begin) >                                                 \\
                     (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) -->
                             // {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main() {
  ll n;
  cin >> n;
  ll x = 1000000000000000000;
  ll res = 1LL;
  bool y = false;
  bool z = false;
  while (n--) {
    ll a;
    cin >> a;
    if (a == 0)
      y = true;
    if (x / res >= a)
      res = res * a;
    else
      z = true;
  }
  if (y == true)
    cout << 0;
  else if (z == true)
    cout << -1;
  else
    cout << res;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long maxn = 1000000000000000000;
  long long ans = 1;
  for (int i = 0; i < N; i++) {
    if (A[i] > maxn / ans) {
      cout << -1 << endl;
      return 0;
    } else {
      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;

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

#include <bits/stdc++.h>
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>>;

int main() {
  int N;
  cin >> N;
  Bint A[N];
  cin >> A[0];
  Bint ans;
  ans = A[0];

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

  int flag = 1;
  for (int i = 1; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 1; i < N; i++) {
    ans *= A[i];
    if (ans > 1000000000000000000) {
      flag = 0;
      break;
    }
  }
  if (flag == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
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>>;

int main() {
  int N;
  cin >> N;
  Bint A[N];
  cin >> A[0];
  Bint ans;
  ans = A[0];
  Bint temp;
  int flag = 1;

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

#include <stdio.h>

int main() {
  long long int n;
  scanf("%lld", &n);
  long long int num[n] = {};
  long long int res = 1;
  long long int temp;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &num[i]);
  }
  for (int i = 0; i < n; i++) {

    if (num[i] == 0) {
      printf("0\\n");
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (num[i] <= 1000000000000000000 / res) {
      res *= num[i];
    } else {
      printf("-1\\n");
      return 0;
    }
  }
  printf("%lld", res);
  return 0;
}


Error: WA

Fixed submission:

#include <stdio.h>
int main() {
  // soal F
  long long int N;             // test case
  long long int g = 1;         // buat hasil perkalian
  long long int h[10000] = {}; // array buat menampung angka
  scanf("%lld", &N);
  getchar();
  for (long long int i = 0; i < N; i++) {
    scanf("%lld", &h[i]);
    // printf("number = %lld\\n", h[i]);
    if (h[i] == 0) {
      printf("0");
      return 0;
    } else if (h[i] > 1000000000000000000) {
      printf("-1");
      return 0;
    } else {
      g *= h[i];
      //	printf("numbers multiplied = %lld\\n", g);
      if (g > 1000000000000000000) {
        printf("-1");
        return 0;
      }
    }
  }
  printf("%lld", g);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long
#define endl "\\n"

const ll int MOD = 1e9 + 7;

void solve() {
  ll n, ans = 1, i, x;
  cin >> n;
  vector<ll> arr(n);
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 0)
      ans = 0;
  }
  x = (ll)1e18;
  for (i = 0; i < n and ans != 0; i++) {
    if (ans > x / arr[i]) {
      ans = -1;
      break;
    }
    ans = ans * arr[i];
  }
  cout << ans << endl;
}

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

  solve();
  return 0;
}

Error: WA

Fixed submission:

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

#define ll long long
#define endl "\\n"

const ll int MOD = 1e9 + 7;

void solve() {
  ll n, ans = 1, i;
  cin >> n;
  vector<ll> arr(n);

  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 0)
      ans = 0;
  }

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

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

  solve();
  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++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MX = 1e18;
int main() {
  int N;
  cin >> N;
  ll sum = 1;
  bool ng = false;
  REP(i, N) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (ng || (MX / sum) < a || sum * a > MX) {
      ng = true;
    }
    sum *= a;
  }
  if (ng) {
    cout << -1 << endl;
  } else {
    cout << sum << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MX = 1e18;
int main() {
  int N;
  cin >> N;
  ll sum = 1;
  bool ng = false;
  REP(i, N) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }

    if ((MX / sum) < a || sum * a > MX) {
      ng = true;
    }
    sum *= a;
  }
  if (ng) {
    cout << -1 << endl;
  } else {
    cout << sum << endl;
  }

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

#include <algorithm>
#include <cmath> //sqrt
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll unsigned long long
int main() {
  auto mul = [](ll x, ll y) {
    ll inf = pow(10, 18);
    if (x != 0 && inf / x < y)
      return inf + 1;
    else
      return x * y;
  };
  int N;
  ll MA = 1;
  rep(i, 18) MA *= 10;

  cin >> N;
  ll tot = 1;
  rep(i, N) {
    ll a;
    cin >> a;
    tot = mul(tot, a);
  }
  if (MA < tot)
    cout << "-1" << endl;
  else
    cout << tot << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath> //sqrt
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll unsigned long long
int main() {
  auto mul = [](ll x, ll y) {
    ll inf = pow(10, 18);
    if (inf / x < y)
      return inf + 1;
    else
      return x * y;
  };
  int N;
  ll MA = 1;
  rep(i, 18) MA *= 10;

  cin >> N;
  ll tot = 1;
  rep(i, N) {
    ll a;
    cin >> a;
    tot = mul(tot, a);
  }
  if (MA < tot)
    cout << "-1" << endl;
  else
    cout << tot << endl;

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

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

int main() {
  int N;
  long long int answer;
  bool ans;
  ans = false;
  answer = 1;
  cin >> N;
  vector<long long int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      answer = 0;
    }
  }

  for (int i = 0; i < N; i++) {
    if (answer != 0 && A[i] <= 1000000000000000000 / answer) {
      answer *= A[i];
    } else {
      ans = true;
    }
  }

  if (answer == 0) {
    cout << 0 << endl;
  } else if (ans) {
    cout << -1 << endl;
  } else {
    cout << answer << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  int N;
  long long int answer;
  bool ans;
  ans = false;
  answer = 1;
  cin >> N;
  vector<long long int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      answer = 0;
    }
  }

  for (int i = 0; i < N; i++) {
    if (answer < 1000000000000000000 / A[i]) {
      answer *= A[i];
    } else {
      ans = true;
    }
  }

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

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

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

  int n;
  cin >> n;
  unsigned ll ans = 1;
  unsigned ll lim = 1000000000000000000LL;
  bool bl = true;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (ans == 0)
      continue;
    if (lim / ans < a) {

      bl = false;
    }
    if (bl != false)
      ans *= a;
    if (a == 0) {
      bl = true;
      ans = 0;
    }
  }
  if (bl) {
    cout << ans << "\\n";
  } else {
    cout << -1 << "\\n";
  }
  /*ll a;

  long double b;
  cin>>a>>b;
  b*=100.00;

  ll B = b;
  ll ans = a*B;
  ans/=100;
  cout<<(ans)<<"\\n";*/
}


Error: 0

Fixed submission:

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

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

  int n;
  cin >> n;
  ll ans = 1;
  ll lim = 1e18;
  bool bl = true;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (lim / ans < a) {

      bl = false;
    }
    ans *= a;
    if (a == 0)
      bl = true;
  }
  if (bl) {
    cout << ans << "\\n";
  } else {
    cout << -1 << "\\n";
  }
}
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)
using ll = long long;
using P = pair<int, int>;
const ll limit = 1e18;
int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool flg = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    } else if (flg || a > (limit / ans)) {
      flg = true;
      continue;
    }
    ans *= a;
  }
  if (flg)
    cout << -1 << endl;
  else
    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 < (n); ++i)
using ll = long long;
using P = pair<int, int>;
const ll limit = 1e18;
int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool flg = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    } else if (a > (limit / ans)) {
      flg = true;
    }
    ans *= a;
  }
  if (flg)
    cout << -1 << endl;
  else
    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++)   // 普通のループ
#define REPR(i, n) for (int i = n; i >= 0; i--) // 逆ループ
#define FOR(i, m, n) for (int i = m; i < n; i++) // 最初の数値を指定したループ

// 型名省略
typedef long long ll;

// 配列要素数
static const int MAX = 200000;

// 値
static const ll MX = 1e18;

using namespace std;

// #include "./lib/generic/sort.h"

std::tuple<int, int> swap(int num1, int num2) {
  return std::forward_as_tuple(num1, num2);
}

void traceArray(int A[], int N) {
  for (int i = 0; i < N; i++) {
    cout << A[i];
    if (i != N - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

int push(int A[], int pointer, int tmp) {
  A[pointer] = tmp;
  return pointer++;
}

int main() {
  /*int  N;
  cin >> N;
  int  A[N];
  REP(i, N) cin >> A[i];*/
  // sort::Sort test;
  // test.sortByIntention(A, N);
  // test.sortByBubble(A, N);
  // test.sortBySelection(A, N);
  // traceArray(A, N);

  /*int N=200, pointer=0;
  int A[N];
  char tmp;
  while(1){
      cin >> tmp;
      //pointer == push(A, pointer, tmp);
      if(cin.eof()){
         cout << "bbb" << endl;
          break;
      }
  }*/

  ll N;
  cin >> N;
  ll tmp, ans = 1;
  bool ng = false;

  REP(i, N) {
    cin >> tmp;
    if (tmp == 0) {
      cout << "0" << endl;
      return 0;
    }

    if (tmp <= MX / ans) {
      ans *= tmp;
    } else {
      ng = true;
    }
  }

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

Error: WA

Fixed submission:

#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

// ループ
#define REP(i, n) for (int i = 0; i < n; i++)   // 普通のループ
#define REPR(i, n) for (int i = n; i >= 0; i--) // 逆ループ
#define FOR(i, m, n) for (int i = m; i < n; i++) // 最初の数値を指定したループ

// 型名省略
typedef long long ll;

// 配列要素数
static const int MAX = 200000;

// 値
static const ll MX = 1e18;

using namespace std;

// #include "./lib/generic/sort.h"

std::tuple<int, int> swap(int num1, int num2) {
  return std::forward_as_tuple(num1, num2);
}

void traceArray(int A[], int N) {
  for (int i = 0; i < N; i++) {
    cout << A[i];
    if (i != N - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

int push(int A[], int pointer, int tmp) {
  A[pointer] = tmp;
  return pointer++;
}

int main() {
  /*int  N;
  cin >> N;
  int  A[N];
  REP(i, N) cin >> A[i];*/
  // sort::Sort test;
  // test.sortByIntention(A, N);
  // test.sortByBubble(A, N);
  // test.sortBySelection(A, N);
  // traceArray(A, N);

  /*int N=200, pointer=0;
  int A[N];
  char tmp;
  while(1){
      cin >> tmp;
      //pointer == push(A, pointer, tmp);
      if(cin.eof()){
         cout << "bbb" << endl;
          break;
      }
  }*/

  ll N;
  cin >> N;
  ll tmp, ans = 1;
  bool ng = false;

  REP(i, N) {
    cin >> tmp;
    if (tmp == 0) {
      cout << "0" << endl;
      return 0;
    }

    if (tmp >= MX / ans) {
      ans *= tmp;
    } else {
      ng = true;
    }
  }

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

#include <climits>
#include <iostream>

using namespace std;

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

  long long int sum = 1LL;
  int c = 0;
  long long int o = 1000000000000000000LL;

  for (int i = 1; i <= n; i++) {
    long long int t;
    cin >> t;
    if (t == 0) {
      c = 0;
      sum = 0;
      break;
    }
    if (sum > o / t)
      c++;
    sum *= t;
  }

  cout << (c ? -1 : sum) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  long long int sum = 1LL;
  int c = 0;
  long long int o = 1000000000000000000LL;

  for (int i = 1; i <= n; i++) {
    long long int t;
    cin >> t;
    if (t == 0) {
      c = 0;
      sum = 0;
      break;
    }
    if (t > o / sum)
      c++;
    sum *= t;
  }

  cout << (c ? -1 : sum) << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <climits>
#include <iostream>
using namespace std;
#define MAX 1e18

int main(void) {
  int n;
  cin >> n;
  long long int a[100005];
  long long int sum = 1;
  long long max = MAX;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      sum = 0;
  }
  for (int j = 1; j <= n; j++) {
    if (a[j] == 0)
      break;
    else if (sum > max / a[j]) {
      sum = -1;
      break;
    } else {
      sum *= a[j];
    }
  }

  cout << sum << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <climits>
#include <iostream>
using namespace std;
#define MAX 1000000000000000000

int main(void) {
  int n;
  cin >> n;
  long long int a[100005];
  long long int sum = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      sum = 0;
  }
  for (int j = 1; j <= n; j++) {
    if (sum <= MAX / a[j])
      sum *= a[j];
    else {
      sum = -1;
      break;
    }
  }
  cout << MAX << endl;
  cout << sum << 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 A[N + 1];
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }

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

  long long ans = 1;

  for (int i = 1; i <= N; i++) {
    if (A[i] <= 1000000000000000000 / ans) {
      ans *= A[i];
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  int N;
  cin >> N;

  long long A[N];
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }

  long long ans = 1;

  for (int i = 1; i <= N; i++) {
    ans = ans * A[i];
  }

  if (ans > 1000000000000000000) {
    cout << "-1" << endl;
  } else if (ans <= 1000000000000000000) {
    cout << ans << endl;
  }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#define MAX 1000000000000000000
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long int> v(n);
  // bool zeroes=false;
  unsigned long long int mul = 1, prev = 1, flag = 0;

  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    if (v[i] == 0) {
      flag = 1;
      break;
    }
  }
  if (flag) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    mul *= v[i];
    if (mul / v[i] != prev || mul > MAX) {
      cout << "-1" << endl;
      return 0;
    }
    prev = mul;
  }
  cout << mul << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#define MAX 1000000000000000000
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long int> v;
  // bool zeroes=false;
  unsigned long long int mul = 1, prev = 1, flag = 0;

  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    if (v[i] == 0) {
      flag = 1;
      break;
    }
  }
  if (flag) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    mul *= v[i];
    if (mul / v[i] != prev || mul > MAX) {
      cout << "-1" << endl;
      return 0;
    }
    prev = mul;
  }
  cout << mul << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

// J'aime
// Chemise Blanche

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

// #define int long long
#define int unsigned long long

#define ii pair<int, int>
#define fi first
#define sc second

#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

#define i1e18 1000000000000000000

void MAIN() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a)
    cin >> i;
  sort(all(a));
  if (a[0] == 0) {
    cout << 0 << '\\n';
    return;
  }
  int ans = 1;
  for (auto &t : a) {
    if (ans <= i1e18 / t) {
      ans *= t;
      if (ans > i1e18) {
        cout << -1 << '\\n';
        return;
      }
    } else {
      cout << -1 << '\\n';
      return;
    }
  }
  cout << ans << '\\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    MAIN();
}


Error: 0

Fixed submission:

// J'aime
// Chemise Blanche

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

// #define int long long
#define int unsigned long long

#define ii pair<int, int>
#define fi first
#define sc second

#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

#define i1e18 1000000000000000000

void MAIN() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a)
    cin >> i;
  sort(all(a));
  int ans = 1;
  for (auto &t : a) {
    if (ans <= i1e18 / t) {
      ans *= t;
      if (ans > i1e18) {
        cout << -1 << '\\n';
        return;
      }
    } else {
      cout << -1 << '\\n';
      return;
    }
  }
  cout << ans << '\\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    MAIN();
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mo = 1000000007;
int main() {
  ll t1 = 1;
  // cin>>t1;
  while (t1) {
    ll n;
    cin >> n;
    ll arr[n];
    for (ll i = 0; i < n; i++)
      cin >> arr[i];
    sort(arr, arr + n);
    if (arr[0] == 0)
      cout << "0" << endl;
    else {
      ll ans = 1;
      bool st = true;
      for (ll i = 0; i < n; i++) {
        // cout<<ans*arr[i]<<endl;
        if (arr[i] > 1000000000000000000 / ans) {
          cout << -1 << endl;
          st = false;
          break;
        }
        ans = ans * arr[i];
      }
      if (st == true)
        cout << ans << endl;
    }
    t1--;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mo = 1000000007;
int main() {
  ll t1 = 1;
  // cin>>t1;
  while (t1) {
    ll n;
    cin >> n;
    ll arr[n];
    for (ll i = 0; i < n; i++)
      cin >> arr[i];
    sort(arr, arr + n);
    ll ans = 1;
    bool st = true;
    for (ll i = 0; i < n; i++) {
      // cout<<ans*arr[i]<<endl;
      if (arr[i] > 1000000000000000000 / ans) {
        cout << -1 << endl;
        st = false;
        break;
      }
      ans = ans * arr[i];
    }
    if (st == true)
      cout << ans << endl;
    t1--;
  }
  return 0;
}