prithivMLmods/Coder-Stat huggingface dataset:
Problem p02658 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
arr = list(map(int, input().split()))

while len(arr) > 1:
    m = len(arr)
    if m & 1:
        arr.append(1)
        m += 1

    left, right = arr[: n // 2], arr[n // 2 :]
    arr = [x * y for x, y in zip(left, right)]

x = arr[0]
if x > 10**18:
    print(-1)
else:
    print(x)


Fixed submission:
n = int(input())
arr = list(map(int, input().split()))

while len(arr) > 1:
    m = len(arr)
    if m & 1:
        arr.append(1)
        m += 1

    left, right = arr[: m // 2], arr[m // 2 :]
    arr = [x * y for x, y in zip(left, right)]

x = arr[0]
if x > 10**18:
    print(-1)
else:
    print(x)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    m = 0
else:
    for i in a:
        m *= i
        if m > 10**18:
            m = -1
print(m)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    m = 0
else:
    for i in a:
        m *= i
        if m > 10**18:
            m = -1
            break
print(m)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
answer = 1
for i in range(len(a)):
    answer = answer * a[i]

if answer > 10**18:
    print(-1)
else:
    print(answer)


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
answer = 1
for i in range(len(a)):
    answer = answer * a[i]
    if answer > 10**18:
        if 0 in a:
            print(0)
        else:
            print(-1)
        break
else:
    print(answer)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
answer = 1
lens = int(input())
arrs = [int(x) for x in input().split()]
for x in arrs:
    answer *= x
if answer > int(10**18):
    answer = -1
print(answer)


Fixed submission:
answer = 1
lens = int(input())
arrs = [int(x) for x in input().split()]
if 0 in arrs:
    answer = 0
else:
    for x in arrs:
        answer *= x
        if answer > int(10**18):
            answer = -1
            break
print(answer)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
res = 1
for a_i in a:
    if 0 == a_i:
        print(0)
        exit(0)
    elif res > 10**18:
        res = -1
    else:
        res *= a_i

print(-1 if res > 10**18 else res)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
res = 1
for a_i in a:
    if 0 == a_i:
        print(0)
        exit(0)
    elif res > 10**18:
        continue
    else:
        res *= a_i

print(-1 if res > 10**18 else res)
Problem p02658 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
m = 10**18

ans = 1

for i in range(0, n):
    if a[i] == 0:
        print(0)
        exit()

for i in range(0, n):
    ans *= a[i]
    if ans > m:
        print(-1)
        exit(-1)


if ans > m:
    print(-1)
else:
    print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = 10**18

ans = 1

for i in range(0, n):
    if a[i] == 0:
        print(0)
        exit()

for i in range(0, n):
    ans *= a[i]
    if ans > m:
        print(-1)
        exit()


if ans > m:
    print(-1)
else:
    print(ans)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
from sys import stdin

input = stdin.readline

n = int(input().rstrip())
a = list(map(int, input().rstrip().split()))

cum = 1
over = False
for x in a:
    if x == 0:
        cum = 0
        break

    cum *= x
    if cum > 1e18:
        over = True

print(-1) if (over and cum != 0) else print(cum)


Fixed submission:
from sys import stdin

input = stdin.readline

n = int(input().rstrip())
a = list(map(int, input().rstrip().split()))

cum = 1
over = False
for x in a:
    if x == 0:
        cum = 0
        break

if cum == 0:
    print(0)
else:
    for x in a:
        cum *= x
        if cum > 1e18:
            over = True
            break
    print(-1) if over else print(cum)
Problem p02658 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)
else:
    ans = 1
    for i in range(A):
        ans += A[i]
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)
else:
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range(N):
    ans *= A[i]
if ans > 10**18:
    ans = -1
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 1
A.sort()
if A[0] == 0:
    print(0)
else:
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            exit(0)
    print(ans)
Problem p02658 (Python)

Buggy submission (status: Runtime Error):
N, A = map(int, open(0).read().split())
if 0 in A:
    print(0)
    exit()
ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)


Fixed submission:
N, *A = map(int, open(0).read().split())
if 0 in A:
    print(0)
    exit()
ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())

a = list(map(int, input().split()))

ans = 1
a_in = [s for s in a if 0 in a]
if a_in:
    print("0")
    exit()
else:
    for i in a:
        ans = ans * i

        if ans > 10**18:
            print("-1")
            exit()

print(ans)


Fixed submission:
n = int(input())

a = list(map(int, input().split()))

ans = 1
if min(a) == 0:
    print("0")
    exit()
else:
    for i in a:
        ans = ans * i

        if ans > 10**18:
            print("-1")
            exit()

print(ans)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
n = 1
for i in a:
    n *= i
if n > 10**18:
    n = -1
print(n)


Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    ans = 1
    for i in A:
        ans *= i
        if ans > 1000000000000000000:
            print(-1)
            return
    print(ans)


main()
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
n = int(input())

arg = list(map(int, input().split()))
ans = 1

if 0 in arg:
    ans = 0
else:
    for m in arg:
        ans *= m

        if ans > 1000000000000000000:
            ans = -1

print(ans)


Fixed submission:
#!/usr/bin/env python3
n = int(input())

arg = list(map(int, input().split()))
ans = 1

if 0 in arg:
    ans = 0
else:
    for m in arg:
        ans *= m

        if ans > 1000000000000000000:
            ans = -1
            break

print(ans)
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

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

  ll lim = 1;
  for (int i = 0; i < 18; i++) {
    lim *= 10;
  }

  ll ans = 1;
  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (a[i] > (lim / ans)) {
      ans = -1;
      ok = false;
    }

    ans *= a[i];
  }

  if (ans == 0) {
    cout << ans << ln;
  } else {
    cout << (ok ? ans : -1) << ln;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

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

  ll lim = 1;
  for (int i = 0; i < 18; i++) {
    lim *= 10;
  }

  ll ans = 1;
  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (ans == 0) {
      break;
    }

    if (a[i] > (lim / ans)) {
      ans = -1;
      ok = false;
    }

    ans *= a[i];
  }

  if (ans == 0) {
    cout << ans << ln;
  } else {
    cout << (ok ? ans : -1) << ln;
  }

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  bool flag = true, zero = false;
  ll a[n], ans = 1, maxi = 1e18;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (!zero && a[i] > maxi / ans) {
      flag = false;
    }
    if (a[i] == 0) {
      zero = true;
    }
    ans = ans * a[i];
  }
  if (flag && !zero) {
    cout << ans << "\n";
  } else if (zero) {
    cout << "0\n";
  } else {
    cout << "-1\n";
  }
}

Fixed submission:
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  bool flag = true, zero = false;
  ll a[n], ans = 1, maxi = 1e18;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (ans != 0 && a[i] > maxi / ans) {
      flag = false;
    }
    if (a[i] == 0) {
      zero = true;
    }
    ans = ans * a[i];
  }
  if (flag && !zero) {
    cout << ans << "\n";
  } else if (zero) {
    cout << "0\n";
  } else {
    cout << "-1\n";
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> //min,max,swap,sort,reverse,lower_bound,upper_bound
#include <bitset>    //bitset
#include <cctype>    //isupper,islower,isdigit,toupper,tolower
#include <cstdint>   //int64_t,int*_t
#include <cstdio>    //printf
#include <cstdio>
#include <cstring>
#include <deque> //deque
#include <iomanip>
#include <iostream> //cout,endl,cin
#include <map>      //map
#include <math.h>
#include <queue>         //queue,priority_queue
#include <set>           //set
#include <stack>         //stack
#include <string>        //string,to_string,stoi
#include <tuple>         //tuple,make_tuple
#include <unordered_map> //unordered_map
#include <unordered_set> //unordered_set
#include <utility>       //pair,make_pair
#include <vector>        //vector

using namespace std;
typedef long long ll;

/*
int main() {
    ll a;
    double b;
    cin >> a >> b;
    cout << fixed << (ll)(floor(a * b)) << endl;
}
*/

int main() {
  ll n;
  ll result = 1;
  int a = 0;
  // vector<int> vc;
  cin >> n;
  while (n--) {
    ll x;
    cin >> x;
    // result = result * x;
    if (x == 0) {
      a = 0;
    } else if (x > 1000000000000000000 / result) {
      a = 1;
      result = 1;
    }
    result = result * x;
    // cout << result << endl;
    // vc.push_back(x);
  }
  if (result > 1000000000000000000 || a == 1) {
    cout << -1 << endl;
  } else {
    cout << result << endl;
  }
}


Fixed submission:
#include <algorithm> //min,max,swap,sort,reverse,lower_bound,upper_bound
#include <bitset>    //bitset
#include <cctype>    //isupper,islower,isdigit,toupper,tolower
#include <cstdint>   //int64_t,int*_t
#include <cstdio>    //printf
#include <cstdio>
#include <cstring>
#include <deque> //deque
#include <iomanip>
#include <iostream> //cout,endl,cin
#include <map>      //map
#include <math.h>
#include <queue>         //queue,priority_queue
#include <set>           //set
#include <stack>         //stack
#include <string>        //string,to_string,stoi
#include <tuple>         //tuple,make_tuple
#include <unordered_map> //unordered_map
#include <unordered_set> //unordered_set
#include <utility>       //pair,make_pair
#include <vector>        //vector

using namespace std;
typedef long long ll;

/*
int main() {
    ll a;
    double b;
    cin >> a >> b;
    cout << fixed << (ll)(floor(a * b)) << endl;
}
*/

int main() {
  ll n;
  ll result = 1;
  int a = 0;
  // vector<int> vc;
  cin >> n;
  while (n--) {
    ll x;
    cin >> x;
    // result = result * x;
    if (x == 0 || result == 0) {
      a = 0;
    } else if (x > 1000000000000000000 / result) {
      a = 1;
      result = 1;
    }
    result = result * x;
    // cout << result << endl;
    // vc.push_back(x);
  }
  if (result > 1000000000000000000 || a == 1) {
    cout << -1 << endl;
  } else {
    cout << result << endl;
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;

int main() {
  int N;
  cin >> N;
  LL out = 1;
  const LL MX = 1e18;
  bool ng = false;

  for (int i = 0; i < N; i++) {
    LL b;
    cin >> b;

    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (MX / out < b) {
      ng = true;
    }

    out *= b;
  }
  if (ng)
    cout << -1 << endl;
  else
    cout << out << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;

int main() {
  int N;
  cin >> N;
  LL out = 1;
  const LL MX = 1e18;
  bool ng = false;

  for (int i = 0; i < N; i++) {
    LL b;
    cin >> b;

    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || MX / out < b) {
      ng = true;
    }

    out *= b;
  }
  if (ng)
    cout << -1 << endl;
  else
    cout << out << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;
int main() {
  long long t, c = 1, p = 0, q = 0;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    if (x <= (1000000000000000000) / c) {
      c = c * x;
    } else {
      p = 1;
    }
    if (x == 0) {
      q = 1;
    }
  }
  if (p == 1 && q == 0)
    c = -1;
  cout << c << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;
int main() {
  long long t, c = 1, p = 0, q = 0;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    if (c != 0 && x <= (1000000000000000000) / c) {
      c = c * x;
    } else {
      p = 1;
    }
    if (x == 0) {
      q = 1;
    }
  }
  if (p == 1 && q == 0)
    c = -1;
  cout << c << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define nl "\n"
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define bs binary_search
#define pll pair<ll, ll>
#define ppll pair<ll, pll>
#define sll stack<ll>
#define qll queue<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define vc vector<char>
#define vvll vector<vector<ll>>
#define all(x) x.begin(), x.end()
#define loop(i, s, n) for (ll i = s; i < n; i++)
#define test                                                                   \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
ll mod = 1000000007;
double pi = 3.1415926535;

void solve() {
  ll n;
  cin >> n;
  ll ans = 1, d, flg = 0, p = 0;
  while (n--) {
    cin >> d;
    if (floor(1000000000000000000 / ans) < d)
      flg = 1;
    ans *= d;
    // cout<<ans<<nl;
    if (!d)
      p = 1;
    if (ans > 1000000000000000000 || ans < 0) {
      flg = 1;
    }
  }
  // ll k=1000000000000000000*;
  // cout<<k<<nl;
  if (p)
    cout << "0";
  else if (flg)
    cout << "-1";
  else
    cout << ans;
}

int main() {
  fast_io;

  solve();
  return 0;
}


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

typedef long long ll;
#define nl "\n"
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define bs binary_search
#define pll pair<ll, ll>
#define ppll pair<ll, pll>
#define sll stack<ll>
#define qll queue<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define vc vector<char>
#define vvll vector<vector<ll>>
#define all(x) x.begin(), x.end()
#define loop(i, s, n) for (ll i = s; i < n; i++)
#define test                                                                   \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
ll mod = 1000000007;
double pi = 3.1415926535;

void solve() {
  ll n;
  cin >> n;
  ll ans = 1, d, flg = 0, p = 0;
  while (n--) {
    cin >> d;
    if (((double)1000000000000000000 / ans) < d)
      flg = 1;
    ans *= d;
    // cout<<ans<<nl;
    if (!d)
      p = 1;
    if (ans > 1000000000000000000 || ans < 0) {
      flg = 1;
    }
  }
  // ll k=1000000000000000000*;
  // cout<<k<<nl;
  if (p)
    cout << "0";
  else if (flg)
    cout << "-1";
  else
    cout << ans;
}

int main() {
  fast_io;

  solve();
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 1, m = 1e18;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  sort(ALL(A));
  for (ll i : A) {
    if (ans > m / i) {
      ans = -1;
      break;
    }
    ans *= i;
  }
  print(ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 1, m = 1e18;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  sort(ALL(A));
  for (ll i : A) {
    if (i != 0 && ans > m / i) {
      ans = -1;
      break;
    }
    ans *= i;
  }
  print(ans);
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>

using namespace std;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

const long double Pi = acos(-1), e = 2.718;
const ll N = 1e18, mod = 1e9 + 7;

int main() {
  FASTIO;
  ll n;
  cin >> n;
  ll sum = 1;
  vll a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(all(a));
  for (auto x : a) {
    if (x > N / sum)
      return cout << -1 << endl, 0;
    sum *= x;
  }
  cout << sum << endl;
  return 0;
}
/**


*/


Fixed submission:
#include <bits/stdc++.h>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>

using namespace std;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

const long double Pi = acos(-1), e = 2.718;
const ll N = 1e18, mod = 1e9 + 7;

int main() {
  FASTIO;
  ll n;
  cin >> n;
  ll sum = 1;
  vll a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(all(a));
  if (a[0] == 0)
    return cout << 0 << endl, 0;
  for (auto x : a) {
    if (x > N / sum)
      return cout << -1 << endl, 0;
    sum *= x;
  }
  cout << sum << endl;
  return 0;
}
/**


*/
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  ll st = 1;
  ll lim = 1000000000000000000ll;
  ll A[N];
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  rep(i, N) {
    ll a;
    a = A[i];
    if (st > lim / a) {
      cout << -1 << endl;
      return 0;
    }
    st *= a;
  }
  cout << st << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  ll st = 1;
  ll lim = 1000000000000000000ll;
  ll A[N];
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  rep(i, N) {
    ll a;
    a = A[i];
    if (a == 0) {
      st = 0;
      continue;
    }
    if (st > lim / a) {
      cout << -1 << endl;
      return 0;
    }
    st *= a;
  }
  cout << st << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define go ios::sync_with_stdio(0)
ll inf = 1e18;
bool zero, over;
int main() {
  go;
  int n;
  cin >> n;
  ll x;
  cin >> x;
  if (!x)
    zero = 1;
  for (int i = 0; i < n - 1; i++) {
    ll y;
    cin >> y;
    if (!y)
      zero = 1;
    if (inf / x < y) {
      over = 1;
      continue;
    }
    x *= y;
  }
  if (zero)
    cout << 0;
  else if (over)
    cout << -1;
  else
    cout << x;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define go ios::sync_with_stdio(0)
ll inf = 1e18;
bool zero, over;
int main() {
  go;
  int n;
  cin >> n;
  ll x;
  cin >> x;
  if (!x)
    zero = 1;
  for (int i = 0; i < n - 1; i++) {
    ll y;
    cin >> y;
    if (!y)
      zero = 1;
    if (inf / x < y) {
      over = 1;
      continue;
    }
    if (over)
      continue;
    if (zero)
      continue;
    x *= y;
  }
  if (zero)
    cout << 0;
  else if (over)
    cout << -1;
  else
    cout << x;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

long long MAX = 1e18;

int main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int N;

  cin >> N;
  long long A[N];
  long long sum = 1;
  bool overflow = false;
  bool hasZero = false;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0)
      hasZero = true;
    if (A[i] > MAX / sum) {
      overflow = true;
    } else {
      sum *= A[i];
    }
    // if(overflow) break;
  }

  if (hasZero) {
    cout << "0\n";
  } else if (overflow) {
    cout << "-1\n";
  } else {
    cout << sum << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

long long MAX = 1e18;

int main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int N;

  cin >> N;
  long long A[N];
  long long sum = 1;
  bool overflow = false;
  bool hasZero = false;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0)
      hasZero = true;
    if (!overflow && A[i] > MAX / sum) {
      overflow = true;
    } else {
      sum *= A[i];
    }
    // if(overflow) break;
  }

  if (hasZero) {
    cout << "0\n";
  } else if (overflow) {
    cout << "-1\n";
  } else {
    cout << sum << endl;
  }

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, 0, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << "\n";
      return 0;
    }
  }
  ll ans = 1;
  rep(i, 0, n) {
    if (a[i] > 1000000000000000000 / ans) {
      cout << -1 << "\n";
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << "\n";
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
// sppsfver - 05.08.2020
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

ll n, a, ans = 1;
bool flag, zero;

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

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0)
      return cout << 0 << endl, 0;
    flag |= (a <= (ll)(1e18) / ans);
    ans *= a;
  }
  cout << (flag ? -1 : ans) << endl;
  return 0;
}


Fixed submission:
// sppsfver - 05.08.2020
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

ll n, a, ans = 1;
bool flag, zero;

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

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0)
      return cout << 0 << endl, 0;
    a <= (ll)(1e18) / ans ? ans *= a : flag = 1;
  }
  cout << (flag ? -1 : ans) << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// T+N
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <class T, class T2> inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2> inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const ll mod = 1000000000000000000ll;
template <class T> inline void fix(T &x) {
  if (x >= mod || x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
  // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll n, ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      ans = 0;
    } else if (a > (2 * mod) / ans) {
      ans = 2 * mod;
    } else {
      ans *= a;
    }
  }
  if (ans > mod) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// T+N
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <class T, class T2> inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2> inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const ll mod = 1000000000000000000ll;
template <class T> inline void fix(T &x) {
  if (x >= mod || x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
  // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll n, ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    } else if (a > (2 * mod) / ans) {
      ans = 2 * mod;
    } else {
      ans *= a;
    }
  }
  if (ans > mod) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define faster                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define f(i, a, b) for (ll i = a; i < b; i++)
#define r(i, a, b) for (ll i = a; i > b; i--)
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1000000000000000000;

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

  bool tr = false;
  ll ans = 1;

  f(i, 0, n) {

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

    if ((INF / ans < a) || tr) {
      tr = true;
    }

    ans *= a;
  }

  if (tr) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define faster                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define f(i, a, b) for (ll i = a; i < b; i++)
#define r(i, a, b) for (ll i = a; i > b; i--)
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1000000000000000000;

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

  bool tr = false;
  ll ans = 1;

  f(i, 0, n) {

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

    if (tr || (INF / ans < a)) {
      tr = true;
    }

    ans *= a;
  }

  if (tr) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
  int a, over = 0;
  long long int total = 1;
  cin >> a;
  for (int k = 0; k < a; k++) {
    long long int b;
    cin >> b;
    if (total > 1000000000000000000ll / b) {
      over++;
    } else if (b == 0) {
      cout << 0;
      return 0;
    } else {
      total *= b;
    }
  }
  if (over > 0) {
    cout << -1;
  } else {
    cout << total;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
  int a, over = 0;
  long long int total = 1;
  cin >> a;
  for (int k = 0; k < a; k++) {
    long long int b;
    cin >> b;
    if (b != 0 && total > 1000000000000000000ll / b) {
      over++;
    } else if (b == 0) {
      cout << 0;
      return 0;
    } else {
      total *= b;
    }
  }
  if (over > 0) {
    cout << -1;
  } else {
    cout << total;
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 1, m = 1e18;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  sort(ALL(A));
  for (ll a : A) {
    if (ans > m / a) {
      ans = -1;
      break;
    }
    ans *= a;
  }
  print(ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 1, m = 1e18;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  sort(ALL(A));
  for (ll a : A) {
    if (a > 0 && ans > m / a) {
      ans = -1;
      break;
    }
    ans *= a;
  }
  print(ans);
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;
double pi = 3.14159265358979;

ll r(ll x, ll y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return r(x, y / 2) * r(x, y / 2) % mod;
  else
    return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod;
}

int main() {
  ll n;
  cin >> n;
  ll sum = 1;
  bool f = 1;
  ll p = 1000000000000000000;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      sum = 0;
    } else if (p / sum < a) {
      f = 0;
    } else
      sum = sum * a;
  }
  if (f || sum == 0)
    printf("%lld\n", sum);
  else
    cout << -1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;
double pi = 3.14159265358979;

ll r(ll x, ll y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return r(x, y / 2) * r(x, y / 2) % mod;
  else
    return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod;
}

int main() {
  ll n;
  cin >> n;
  ll sum = 1;
  bool f = 1;
  ll p = 1000000000000000000;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      sum = 0;
    } else if (p / a < sum) {
      f = 0;
    } else
      sum = sum * a;
  }
  if (f || sum == 0)
    printf("%lld\n", sum);
  else
    cout << -1 << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n;
  ll tmp, res = 1, max = 1000000000000000000;
  cin >> n;
  bool ng = false;

  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << "\n";
      return 0;
    }
    if (tmp > max / res) {
      ng = true;
    }
    res *= tmp;
  }

  cout << (ng ? -1 : res) << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n;
  ll tmp, res = 1, max = 1000000000000000000;
  cin >> n;
  bool ng = false;

  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << "\n";
      return 0;
    }
    if (ng || tmp > max / res || res * tmp > max) {
      ng = true;
    }
    res *= tmp;
  }

  cout << (ng ? -1 : res) << "\n";
  return 0;
}
Problem p02658 (C++)

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

const ll MX = 1e18;

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

  ll ans = 1;
  bool flag = 0;

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

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

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

const ll MX = 1e18;

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

  ll ans = 1;
  bool flag = 0;

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

  if (flag) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

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

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


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

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

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

int32_t main() {
  fastio;

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

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

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

/*

*/

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

int32_t main() {
  fastio;

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

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

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

/*

*/
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int m = 1;
  bool q = false;
  for (int x = 1; x <= n; ++x) {
    long long int v;
    cin >> v;
    if (v <= 1000000000000000000 / m) {
      m *= v;
    } else {
      q = true;
    }
  }
  if (q && m != 0) {
    m = -1;
  }
  cout << m << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int m = 1;
  bool q = false;
  for (int x = 1; x <= n; ++x) {
    long long int v;
    cin >> v;
    if (v <= 1000000000000000000 / m) {
      m *= v;
    } else {
      q = true;
    }
    if (m == 0) {
      break;
    }
  }
  if (q && m != 0) {
    m = -1;
  }
  cout << m << endl;
  return 0;
}
Problem p02658 (C++)

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

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

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

  cout << ans << endl;

  return 0;
}


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

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

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

  cout << ans << endl;

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

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


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

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

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

const ld pi = 3.141592653589793;

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

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

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

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

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

using namespace std;

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

const ld pi = 3.141592653589793;

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

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

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

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

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

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

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

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

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

  else {
    cout << -1 << endl;
  }
  return 0;
}
Problem p02659 (Python)

Buggy submission (status: Runtime Error):
from decimal import Decimal

numbers = input().split()
a = float(numbers[0])
b = Decimal(numbers[1])

c = a * b

print(int(c))


Fixed submission:
from decimal import Decimal

numbers = input().split()
a = Decimal(numbers[0])
b = Decimal(numbers[1])

c = a * b

print(int(c))