alexjercan/bugnet huggingface dataset:
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp> // 整数を使う時
using namespace boost::multiprecision;

int main() {
  int N;
  std::cin >> N;
  cpp_int ans = 1;
  int fin = 0;
  cpp_int X[N];
  for (int i = 0; i < N; i++) {
    std::cin >> X[i];
    if (X[i] == 0) {
      ans = 0;
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    ans = ans * X[i];
    if (ans == 0) {
      break;
    }
    if (ans > 1000000000000000000) {
      ans = -1;
      break;
    }
  }
  std::cout << ans << std::endl;
}

Error: TLE

Fixed submission:

#include <boost/multiprecision/cpp_int.hpp> // 整数を使う時
using namespace boost::multiprecision;

int main() {
  int N;
  std::cin >> N;
  cpp_int ans = 1;
  for (int i = 0; i < N; i++) {
    cpp_int x;
    std::cin >> x;
    ans = ans * x;
  }
  if (ans > 1000000000000000000) {
    ans = -1;
  }
  std::cout << ans << std::endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
const long long INF = 1e18;

int main() {
  int n;
  cin >> n;
  bool is_z = false;
  bool is_r = false;
  long long a = 1;
  for (int i = 0; i < n; ++i) {
    if (is_z)
      continue;
    long long num;
    cin >> num;
    if (num == 0)
      is_z = true;
    if (is_r)
      continue;
    if (num > (INF / a) || (a * num) > INF)
      is_r = true;
    a *= num;
  }
  if (is_z)
    cout << 0 << endl;
  else if (is_r)
    cout << -1 << endl;
  else
    cout << a << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define y_n(ans) cout << (ans ? "Yes" : "No") << endl;
const long long INF = 1e18;

int main() {
  int n;
  cin >> n;
  long long a = 1;
  bool isz = false;
  bool ans = true;
  for (int i = 0; i < n; ++i) {
    long long num;
    cin >> num;
    if (num == 0)
      isz = true;
    else if (a == 0)
      continue;
    else if (a * num > INF || num > INF / a) {
      ans = false;
    }
    if (isz)
      break;
    a *= num;
  }
  if (isz)
    cout << 0 << endl;
  else if (ans)
    cout << a << endl;
  else
    cout << -1 << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
const long long INF = 1e18;

int main() {
  int n;
  cin >> n;
  bool is_z = false;
  bool is_r = false;
  long long a = 1;
  for (int i = 0; i < n; ++i) {
    if (is_z)
      continue;
    long long num;
    cin >> num;
    if (num == 0)
      is_z = true;
    if (is_r)
      continue;
    if (num > INF / a)
      is_r = true;
    a *= num;
  }
  if (is_z)
    cout << 0 << endl;
  else if (is_r)
    cout << -1 << endl;
  else
    cout << a << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define y_n(ans) cout << (ans ? "Yes" : "No") << endl;
const long long INF = 1e18;

int main() {
  int n;
  cin >> n;
  long long a = 1;
  bool isz = false;
  bool ans = true;
  for (int i = 0; i < n; ++i) {
    long long num;
    cin >> num;
    if (num == 0)
      isz = true;
    else if (a == 0)
      continue;
    else if (a * num > INF || num > INF / a) {
      ans = false;
    }
    if (isz)
      break;
    a *= num;
  }
  if (isz)
    cout << 0 << endl;
  else if (ans)
    cout << a << endl;
  else
    cout << -1 << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const long long t = 1e18;
int main() {
  int n;
  bool flg = false;
  cin >> n;
  long long s = 1;
  for (int i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << "\\n";
      return 0;
    }
    if (flg || (t + 1) / s < tmp || s * tmp > t) {
      flg = true;
    }
    s *= tmp;
  }
  if (flg) {
    cout << -1 << "\\n";
    return 0;
  }
  cout << s << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long t = 1e18;
int main() {
  int n;
  bool flg = false;
  cin >> n;
  long long s = 1;
  for (int i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << "\\n";
      return 0;
    }
    if ((t + 1) / s < tmp || s * tmp > t) {
      flg = true;
    }
    s *= tmp;
  }
  if (flg) {
    cout << -1 << "\\n";
    return 0;
  }
  cout << s << "\\n";
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d", &a);
#define fli(a) scanf("%ld", &a);
#define fll(a) scanf("%lld", &a);
#define pi(a) printf("%d\\n", a);
#define ppi(i, a) printf("Case %d: %d\\n", i, a);
#define ll long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

int main() {
  fast unsigned long long n, x = 1000000000000000000, arr[100005], ans = 1,
                             zero = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 0)
      zero = 1;
  }
  if (zero)
    cout << 0 << endl;
  else {
    for (int i = 0; i < n; i++) {
      x /= arr[i];
      if (x == 0)
        break;
      ans *= arr[i];
    }
    if (x > 0)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d", &a);
#define fli(a) scanf("%ld", &a);
#define fll(a) scanf("%lld", &a);
#define pi(a) printf("%d\\n", a);
#define ppi(i, a) printf("Case %d: %d\\n", i, a);
#define ll long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  uint32_t N = 0;
  std::cin >> N;
  int64_t prod = 1;
  for (uint32_t i = 0; i < N; i++) {
    int64_t A = 0;
    std::cin >> A;

    if (prod == -1) {
      if (A == 0)
        prod = 0;
    } else if (prod != 0) {
      if ((1'000'000'000'000'000'000 + prod - 1) / prod < A) {
        prod = -1;
      } else {
        prod *= A;
        if (prod > 1'000'000'000'000'000'000)
          prod = -1;
      }
    }
  }

  std::cout << prod << std::endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  uint32_t N = 0;
  std::cin >> N;
  int64_t prod = 1;
  for (uint32_t i = 0; i < N; i++) {
    int64_t A = 0;
    std::cin >> A;

    if (prod == -1) {
      if (A == 0)
        prod = 0;
    } else {
      if ((1'000'000'000'000'000'000 + prod - 1) / prod < A) {
        prod = -1;
      } else {
        prod *= A;
        if (prod > 1'000'000'000'000'000'000)
          prod = -1;
      }
    }
  }

  std::cout << prod << std::endl;

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

#include <bits/stdc++.h>
#define int unsigned long long

using namespace std;

bool flag = true;

signed main() {
  //	freopen("input.txt", "r", stdin);
  cin.tie(0);
  int n;
  cin >> n;

  int ans = 1, ma = 1e18;
  while (n--) {
    int x;
    cin >> x;
    if (x == 0) {
      puts("0");
      return 0;
    }
    if (ma % ans == 0) {
      if (ma / ans < x) {
        //				printf("%lld %lld\\n",ma/ans,x);
        //				puts("-1");
        flag = false;
        //				return 0;
      }
    } else {
      if (ma / ans < x) {
        //				printf("%lld %lld %lld
        //%lld\\n",n,ans,ma/ans,x); 				puts("-1");
        flag = false;
        //				return 0;
      }
    }
    if (flag)
      ans *= x;
  }
  if (!flag)
    puts("-1");
  else
    printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long

using namespace std;

bool flag = true;

signed main() {
  //	freopen("input.txt", "r", stdin);
  cin.tie(0);
  int n;
  cin >> n;

  int ans = 1, ma = 1e18;
  while (n--) {
    int x;
    cin >> x;
    if (x == 0) {
      puts("0");
      return 0;
    }
    if (ma % ans == 0) {
      if (ma / ans < x) {
        //				printf("%lld %lld\\n",ma/ans,x);
        //				puts("-1");
        flag = false;
        //				return 0;
      }
    } else {
      if (ma / ans < x) {
        //				printf("%lld %lld %lld
        //%lld\\n",n,ans,ma/ans,x); 				puts("-1");
        flag = false;
        //				return 0;
      }
    }
    ans *= x;
  }
  if (!flag)
    puts("-1");
  else
    printf("%lld\\n", ans);
  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 lint = long long;

const lint MAX = 1e18;

int main(void) {
  int N;
  cin >> N;
  lint ans = 1;

  int over = 0;
  int zero = 0;
  for (int i = 0; i < N; i++) {
    long long x;
    cin >> x;
    if (x == 0) {
      zero = 1;
    } else if (ans != 0 && MAX / ans < x) {
      over = -1;
    }
    ans *= x;
    // cout << ans << endl;
  }
  if (zero == 1)
    cout << 0 << endl;
  else if (over == 0)
    cout << ans << endl;
  else
    cout << over << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using lint = long long;

const lint MAX = 1e18;

int main(void) {
  int N;
  cin >> N;
  lint ans = 1;

  int over = 0;
  int zero = 0;
  for (int i = 0; i < N; i++) {
    long long x;
    cin >> x;
    if (x == 0) {
      zero = 1;
    } else if (MAX / ans < x) {
      over = -1;
    }
    ans *= x;
    // cout << ans << endl;
  }
  if (zero == 1)
    cout << 0 << endl;
  else if (over == 0)
    cout << ans << endl;
  else
    cout << over << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error


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

signed main() {
  int n, tot = 1, a[200005];

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (tot > inf / a[i]) {
      cout << -1;
      return 0;
    } else {
      tot *= a[i];
    }
  }
  cout << tot << endl;

  return 0;
}


Error: WA

Fixed submission:



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

int main() {
  long long int i, N, sum;
  i = N = sum = 0;
  sum = 1;
  cin >> N;

  int a[N];

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

  if (sum >= 0 && sum <= (1000000000000000000)) {
    cout << sum;
  } else {
    cout << -1;
    //        sum = -1;
  }

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

#include <stdio.h>
int main() {
  long long int N; // test case
  long long int total = 1;

  scanf("%lld", &N);
  long long int A[N]; // input nilainya

  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  for (int j = 0; j < N; j++) {
    if (A[j] == 0) { // mirip seperti ?: (ternary operator)
      printf("0");   // angka berapapun kalo dikali 0, hasilnya tetap 0
      return 0;
    }
  }
  for (int k = 0; k < N; k++) {
    if (A[k] <= 1000000000000000000 / total) {
      total = total * A[k];
      // apakah angka yang dikalikan itu < 10^18
      // apakah input <= 10^18/total
    } else {
      printf("-1");
      return 0;
    }
  }
  printf("%lld", total);

  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <stdio.h>

int main() {
  long long int n;
  long long int arr[] = {};
  scanf("%lld", &n);
  long long int hasil = 1;

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

    if (arr[i] == 0) {
      printf("0\\n");
      return 0;
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (arr[i] <= 1000000000000000000 / hasil) {
      hasil *= arr[i];
    } else {
      printf("-1\\n");
      return 0;
    }
  }
  printf("%lld", hasil);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int N;
  scanf("%d", &N);
  long long int array[N], max = 1e18, p = 1, f = 0, z = 0;

  for (int i = 0; i < N; i++) {
    scanf("%lld", &array[i]);
    f = (array[i] > max) ? 1 : f;
    p *= array[i];
    (array[i]) ? max /= array[i] : z = 1;
  }

  (z) ? puts("0") : ((f) ? puts("-1") : printf("%lld\\n", p));
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int a;
  long long int result = 1;

  scanf("%d", &a);
  long long int angka[a];

  for (int i = 0; i < a; i++) {
    scanf("%lld", angka[i]);
  }

  for (int i = 0; i < a; i++) {
    if (angka[i] == 0) {
      printf("0");
      return 0;
    }
  }

  for (int i = 0; i < a; i++) {
    if (angka[i] <= 1e18 / result) {
      result = result * angka[i];

    } else {
      printf("-1");
      return 0;
    }
  }
  printf("%lld\\n", result);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int N;
  scanf("%d", &N);
  long long int arr[N], max = 1e18, prod = 1, flag = 0, zero = 0;

  for (int i = 0; i < N; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\\n", prod));
  return 0;
}

Error: WA

Fixed submission:


#include <stdio.h>
int main() {

  int n;
  scanf("%d ", &n);

  long long int data[100] = {0};
  long long int total = 1;

  for (int i = 0; i < n; i++) {
    scanf("%lld", &data[i]);
  }
  for (int i = 0; i < n; i++) {
    if (data[i] == 0) {
      printf("0");
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (data[i] > 1000000000000000000 / total) {
      printf("-1");
      return 0;
    } else {
      total *= data[i];
    }
  }
  printf("%lld", &total);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  long long int test, result = 1;
  scanf("%lld", &test);
  long long x[test];

  for (int i = 0; i < test; i++) {
    scanf("%lld", &x[i]);
  }
  for (int i = 0; i < test; i++) {
    if (x[i] == 0) {
      printf("0");
      return 0;
    }
  }
  for (int i = 0; i < test; i++) {
    if (x[i] <= (1000000000000000000 / result)) {
      result *= x[i];
    } else {
      result = -1;
      break;
    }
  }
  printf("%lld", result);

  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  long long int test, result = 1;
  scanf("%lld", &test);
  long long x[test];

  for (int i = 0; i < test; i++) {
    scanf("%lld", &x[i]);
  }
  for (int i = 0; i < test; i++) {
    if (x[i] <= (1000000000000000000 / result)) {
      result *= x[i];
    }
    if (result > 1000000000000000000) {
      result = -1;
      break;
    }
  }
  printf("%lld", result);

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

#include <stdio.h>
int main() {
  long int N;
  int tanda = 0;
  scanf("%d", &N);
  long int A[N];
  long long int risolt = 1;
  long long int limit = 1000000000000000000;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    if (A[i] == 0) {
      puts("0");
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] > limit) {
      puts("-1");
      return 0;
    }
    limit = limit / A[i];
    risolt = risolt * A[i];
  }
  printf("%lld\\n", risolt);
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {

  unsigned long long int a, T[1000], result = 1;
  scanf("%llu", &a);

  for (int i = 0; i < a; i++) {
    scanf("%llu", &T[i]);
  }
  for (int j = 0; j < a; j++) {
    result *= T[j];
  }
  if (result > 1000000000000000000) {
    printf("-1");
  } else {
    printf("%llu", result);
  }

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

#include <stdio.h>

int main() {

  int a;
  long long int ans = 1;
  scanf("%d", &a);
  long long arr[a + 10];
  long long int batas = 1e18;
  for (long long int i = 0; i < a; i++) {
    scanf("%lld", &arr[i]);
  }

  for (long long int i = 0; i < a; i++) {
    if (arr[i] == 0) {
      printf("0\\n");
      return 0;
    }
  }

  for (long long int i = 0; i < a; i++) {
    if (batas / ans < arr[i]) {
      printf("-1\\n");
      return 0;
    }
    ans *= arr[i];
  }
  printf("%lld\\n", ans);

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int t;
  long long u = 1;
  long long s = 1000000000000000000;
  long long a[100005];
  scanf("%d", &t);

  for (int i = 0; i < t; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0) {
      printf("%d\\n", 0);
      return 0;
    } else {
      u *= a[i];
      if ((s / u < 1)) {
        printf("%d\\n", -1);
        return 0;
      } else if (i == (t - 1)) {
        printf("%lld\\n", u);
      }
    }
  }

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

#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;

  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\\n", prod));
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  long long int N, A[N], M = 1;
  scanf("%lld", &N);
  if (N >= 2 && N <= 100000) {
    for (int i = 0; i < N; i++) {
      scanf("%lld", &A[i]);
      M *= A[i];
    }
  } else {
    return 0;
  }
  (M < 0 || M >= 1000000000000000000) ? printf("%d\\n", -1)
                                      : printf("%lld\\n", M);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fore(i, a, b) for (int i = a; i < b; i++)
#define fst first
#define snd second
#define ll long long
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

using namespace std;

const int N_MAX = 1e5 + 15;
const ll Z = 1000000000000000000LL;
ll A[N_MAX];

int main() {
  int N;
  cin >> N;
  bool zr = 0;
  fore(i, 0, N) {
    cin >> A[i];
    if (A[i] == 0LL)
      zr = 1;
  }
  ll M = 1LL;
  bool ans = 1;
  if (zr) {
    M = 0LL;
  } else {
    fore(i, 0, N) {
      ll q = Z / M;
      if (A[i] > q) {
        ans = 0;
        break;
      }
      M *= A[i];
    }
  }
  if (ans)
    cout << M << endl;
  else
    cout << "-1" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fore(i, a, b) for (int i = a; i < b; i++)
#define fst first
#define snd second
#define ll long long
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

using namespace std;

const int N_MAX = 1e5 + 15;
const ll Z = 1000000000000000000LL;
ll A[N_MAX];

int main() {
  int N;
  cin >> N;
  bool zr = 0;
  fore(i, 0, N) {
    cin >> A[i];
    if (A[i] == 0LL)
      zr = 1;
  }
  ll M = 1LL;
  bool ans = 1;
  fore(i, 0, N) {
    ll q = Z / M;
    if (A[i] > q) {
      ans = 0;
    }
    M *= A[i];
  }
  if (ans or zr)
    cout << M << endl;
  else
    cout << "-1" << 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;
#define INF 1e18
typedef long long ll;
typedef pair<int, int> P;

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool ng = false;
  rep(i, n) {
    ll 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;
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
long long GetDigit(long long num) {
  long long digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}

int main() {
  long long n, m[n];
  long long ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m[i];
    ans *= m[i];
  }
  unsigned x = GetDigit(ans);
  if (ans > 1000000000000000000) {
    cout << -1 << endl;
    return 0;
  } else {
    cout << ans << endl;
    return 0;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

// #include<bits/stdc++.h>

using namespace std;

int main() {

  int n;
  cin >> n;

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

  cout << p << endl;

  return 0;
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

// #include<bits/stdc++.h>

using namespace std;

int main() {

  int n;
  cin >> n;

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

  cout << p << endl;

  return 0;
}