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

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

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(i, a, n) for (int i = a; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

// int in() { int x; scanf("%d", &x); return x; }
// ll lin() { ll x; scanf("%lld", &x); return x; }
// void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const ll MAX = 1e18;

int main(void) {
  std::ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  ll ans = 1;
  bool ng = false;
  FOR(i, n) {
    ll tmp;
    cin >> tmp;

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

    if (MAX / ans < tmp || ans * tmp > MAX) {
      ng = true;
    }

    ans *= tmp;
  }

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

  return 0;
}

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

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(i, a, n) for (int i = a; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

// int in() { int x; scanf("%d", &x); return x; }
// ll lin() { ll x; scanf("%lld", &x); return x; }
// void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const ll MAX = 1e18;

int main(void) {
  std::ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  ll ans = 1;
  bool ng = false;
  FOR(i, n) {
    ll tmp;
    cin >> tmp;

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

    if (ng || MAX / ans < tmp) {
      ng = true;
    }

    ans *= tmp;
  }

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

  return 0;
}
Problem p02658 (C++)

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

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

  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }

  ll ans = 1;
  int ansm = 0;
  sort(ALL(a));
  for (int i = 0; i < n; i++) {
    if (ans > 1000000000000000000 / a[i]) {
      ansm = -1;
      break;
    } else {
      ans *= a[i];
    }
  }

  if (ansm == -1) {
    cout << ansm << "\n";
  } else {
    cout << ans << "\n";
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

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

  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }

  ll ans = 1;
  int ansm = 0;
  sort(ALL(a));
  for (int i = 0; i < n; i++) {

    if (a[i] == 0) {
      ans = 0;
      break;
    }
    if (ans > 1000000000000000000 / a[i]) {
      ansm = -1;
      break;
    } else {
      ans *= a[i];
    }
  }

  if (ansm == -1) {
    cout << ansm << "\n";
  } else {
    cout << ans << "\n";
  }
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  long long lim = 1e18;
  int n;
  cin >> n;
  long long a[n], ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      ans = 0;
    else if (a[i] > lim / ans)
      ans = -1;
    else if (ans != -1)
      ans *= a[i];
  }
  cout << ans << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  long long lim = 1e18;
  int n;
  cin >> n;
  long long a[n], ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      ans = 0;
    else if (ans > lim / a[i])
      ans = -1;
    else if (ans != -1)
      ans *= a[i];
  }
  cout << ans << "\n";
  return 0;
}
Problem p02658 (C++)

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 1;
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (ans > INF / a[i]) {
      ans = -1;
      break;
    } else {
      ans *= a[i];
    }
  }
  cout << ans << '\n';
  return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 1;
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (a[i] && ans > INF / a[i]) {
      ans = -1;
      break;
    } else {
      ans *= a[i];
    }
  }
  cout << ans << '\n';
  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++)
#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;
}

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 (ng || (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 (status: 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 (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;
}


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 (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;
}
Problem p02658 (C++)

Buggy submission (status: 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 < 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;
  }
}


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 != 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;
  }
}
Problem p02658 (C++)

Buggy submission (status: 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;
}

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 (status: 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;
  // 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;
}


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(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;
}
Problem p02658 (C++)

Buggy submission (status: 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));
  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();
}


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));
  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();
}
Problem p02658 (C++)

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

int N;

int main() {
  cin >> N;
  long long a[10101], ans = 1;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (a[i] > 1000000000000000000 / ans) {
      cout << -1 << endl;
      return 0;
    } else {
      ans *= a[i];
    }
  }
  cout << ans << endl;
  return 0;
}

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

int N;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long long double
#define pb push_back

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

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long long double
#define pb push_back

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

  int n;
  cin >> n;
  unsigned long long prod = 1;
  vector<unsigned long long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  if (arr[0] == 0) {
    cout << 0;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    if (arr[i] > 1000000000000000000 / prod) {
      cout << -1;
      return 0;
    }
    prod = prod * arr[i];
  }
  // if(prod<0) {cout <<-1;return 0;}
  cout << prod;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long long double
#define pb push_back

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

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long long double
#define pb push_back

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

  int n;
  cin >> n;
  unsigned long long prod = 1;
  vector<unsigned long long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  if (arr[0] == 0) {
    cout << 0;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    if (arr[i] > 1000000000000000000 / prod) {
      cout << -1;
      return 0;
    }
    prod = prod * arr[i];
  }
  // if(prod<0) {cout <<-1;return 0;}
  cout << prod;
}
Problem p02658 (C++)

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

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

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

long long teisuu = 1000000000000000000;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long kotae = 1;
  for (long long i = 0; i < n; i++) {
    if (teisuu / kotae < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    kotae *= a[i];
  }
  cout << kotae << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main() {
  long long int n;
  long long tmp;
  cin >> n;
  long long int res = 1;
  vector<int> a(n);
  int flag_zero = 0;
  int flag_18 = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp == 0) {
      flag_zero = 1;
    }
    if (tmp <= 1000000000000000000 / res) {
      res = res * tmp;
    } else {
      flag_18 = 1;
    }
  }

  // flag++;
  // cout << flag << endl;
  // cout << res << endl;

  if (flag_zero == 1) {
    cout << 0 << endl;
  } else if (flag_18 == 1) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
}
// 1000000000000000000
// 9223372036854775807
// 1000000000000000001

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main() {
  long long int n;
  long long tmp;
  cin >> n;
  long long int res = 1;
  vector<int> a(n);
  int flag_zero = 0;
  int flag_18 = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp == 0) {
      flag_zero = 1;
      break;
    }
    if (tmp <= 1000000000000000000 / res) {
      res = res * tmp;
    } else {
      flag_18 = 1;
    }
  }

  // flag++;
  // cout << flag << endl;
  // cout << res << endl;

  if (flag_zero == 1) {
    cout << 0 << endl;
  } else if (flag_18 == 1) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
}
// 1000000000000000000
// 9223372036854775807
// 1000000000000000001
Problem p02658 (C++)

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

int main(void) {
  int N;
  cin >> N;
  long A[N];
  long long result = 1;
  long long thre = 1000000000000000000;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  if (A[0] == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = N - 1; i >= 0; i--) {
      result *= A[i];
      if (thre / result > 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << result << endl;

  return 0;
}


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

int main(void) {
  int N;
  cin >> N;
  long A[N];
  long long result = 1;
  long long thre = 1000000000000000000;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  if (A[0] == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = N - 1; i >= 0; i--) {
      if (A[i] <= thre / result) {
        result *= A[i];
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << result << endl;

  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
typedef unsigned long long ll;
const ll inf = 1e18;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1, temp, t;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (inf / temp < ans)
      flag = 1;
    else
      ans *= temp;
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
typedef unsigned long long ll;
const ll inf = 1e18;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 1, temp, t;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (temp == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (inf / temp < ans)
      flag = 1;
    else
      ans *= temp;
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}
Problem p02658 (C++)

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

typedef long long ll;

int main() {
  int N;
  std::cin >> N;
  ll a[N];
  for (ll e : a) {
    std::cin >> e;
    if (e == 0) {
      std::cout << 0 << std::endl;
      return 0;
    }
  }

  ll max = 1e18;
  ll multi = 1;

  for (ll e : a) {
    if (multi > max / e) {
      std::cout << -1 << std::endl;
      return 0;
    };
    multi *= e;
  }
  if (multi <= max) {
    std::cout << multi << std::endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>

typedef long long ll;

int main() {
  int N;
  std::cin >> N;
  ll a[N];
  for (ll i; i < N; ++i) {
    std::cin >> a[i];
    if (a[i] == 0) {
      std::cout << 0 << std::endl;
      return 0;
    }
  }

  ll max = 1e18;
  ll multi = 1;

  for (ll e : a) {
    if (multi > max / e) {
      std::cout << -1 << std::endl;
      return 0;
    };
    multi *= e;
  }
  if (multi <= max) {
    std::cout << multi << std::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;
using ll = long long;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  rep(i, n) {
    ll a;
    cin >> a;
    if (ans == -1) {
      if (a == 0)
        ans = 0;
    } else {
      if (a > 1'000'000'000'000'000'000 / ans) {
        ans = -1;
        continue;
      } else {
        ans *= a;
      }
    }
  }
  if (ans == -1)
    cout << to_string(ans) << endl;
  else
    cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  rep(i, n) {
    ll a;
    cin >> a;
    if (ans == -1) {
      if (a == 0)
        ans = 0;
    } else {
      if (a == 0 || ans == 0) {
        ans *= a;
        continue;
      }
      if (a > 1'000'000'000'000'000'000 / ans) {
        ans = -1;
        continue;
      } else {
        ans *= a;
      }
    }
  }
  if (ans == -1)
    cout << to_string(ans) << endl;
  else
    cout << ans << endl;
  return 0;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <ciso646>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
ll M = 1e18;

using namespace std;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (a[0] == 0) {
    cout << "0";
    return 0;
  }
  for (int i = 0; i < n + 1; i++) {
    if (M / ans < 1) {
      cout << "-1";
      return 0;
    }
    if (i != n)
      ans *= a[i];
  }
  cout << ans;
}


Fixed submission:
#include <algorithm>
#include <ciso646>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
ll M = 1e18;

using namespace std;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (a[0] == 0) {
    cout << "0";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (M / ans < 1 or M / ans < a[i]) {
      cout << "-1";
      return 0;
    }
    if (i != n)
      ans *= a[i];
  }
  cout << ans;
}
Problem p02658 (C++)

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

const int64_t mx = 1e18;

int main() {
  int N;
  cin >> N;
  bool ng = false;
  int64_t ans = 1;

  for (int i = 0; i < N; i++) {
    int64_t A;
    cin >> A;

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

    if (mx / ans < A) {
      ng = true;
    }

    ans *= A;
  }

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

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

const int64_t mx = 1e18;

int main() {
  int N;
  cin >> N;
  bool ng = false;
  int64_t ans = 1;

  for (int i = 0; i < N; i++) {
    int64_t 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;
}
Problem p02658 (C++)

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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll ans = 1;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      ans = 0;
    }
  }
  ll judge = pow(10, 18);
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  for (ll i = 0; i < N; i++) {
    if (ans <= judge / A[i]) {
      ans *= A[i];
    } else {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}

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

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

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

  ll judge = pow(10, 18);
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  for (ll i = 0; i < N; i++) {
    if (ans <= judge / A[i]) {
      ans *= A[i];
    } else {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()

using namespace std;
typedef unsigned long long ll;

template <typename T> T gcd(T a, T b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

struct Deep {
  ll all;
  ll notreef;
  ll reef;
};

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

/*
ans*a[i]>max
a[i]>max/ans
*/


Fixed submission:
#include "bits/stdc++.h"
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()

using namespace std;
typedef unsigned long long ll;

template <typename T> T gcd(T a, T b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

struct Deep {
  ll all;
  ll notreef;
  ll reef;
};

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

/*
ans*a[i]>max
a[i]>max/ans
*/
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

// problem_B
int main() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum1 = 1;
  // ll sum2 = 1;
  ll ans1 = 0;
  ll ans2 = 0;
  ll a0 = pow(10, 18);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      ans2 += 1;
    }
  }
  if (ans2 == 0) {
    for (ll i = 0; i < n; i++) {
      if (a0 / sum1 < a[i]) {
        ans1 += 1;
      }
      sum1 *= a[i];
    }
  }

  // cout << sum1 << endl;
  // cout << ans1 << endl;
  // cout << ans2 << endl;
  if (ans2 != 0) {
    cout << 0 << endl;
  } else if (ans1 != 0) {
    cout << -1 << endl;
  } else {
    printf("%lld\n", sum1);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

// problem_B
int main() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum1 = 1;
  // ll sum2 = 1;
  ll ans1 = 0;
  ll ans2 = 0;
  ll a0 = pow(10, 18);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      ans2 += 1;
    }
  }
  if (ans2 == 0) {
    for (ll i = 0; i < n; i++) {
      if (a0 / sum1 < a[i]) {
        ans1 += 1;
        break;
      }
      sum1 *= a[i];
    }
  }

  // cout << sum1 << endl;
  // cout << ans1 << endl;
  // cout << ans2 << endl;
  if (ans2 != 0) {
    cout << 0 << endl;
  } else if (ans1 != 0) {
    cout << -1 << endl;
  } else {
    printf("%lld\n", sum1);
  }
}
Problem p02658 (C++)

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

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

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

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

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

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

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

int main() {
  long long int n, k = 1, a[100001];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      k = 0;
      break;
    }
    if (k > 1000000000000000000 / a[i] || k == -1) {
      k = -1;
    } else {
      k *= a[i];
    }
  }
  cout << k;
  return 0;
}
Problem p02658 (C++)

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

int main() {
  long long n;
  cin >> n;
  long long ar[n + 5];
  long long res = 1;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] == 0) {
      res = 0;
      continue;
    }
    if (ar[i] <= 1000000000000000000 / res)
      res *= ar[i];
    else {
      res = -1;
      continue;
    }
  }
  cout << res;
  return 0;
}

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

int main() {
  long long n;
  cin >> n;
  long long ar[n + 5];
  long long res = 1;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] == 0) {
      cout << "0";
      return 0;
    }
    if (ar[i] <= 1000000000000000000 / res)
      res *= ar[i];
    else {
      res = -1;
      continue;
    }
  }
  cout << res;
  return 0;
}
Problem p02658 (C++)

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

int main() {
  long long ans = 1;
  int n;
  bool flag = false;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long b;
    cin >> b;
    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }

    if ((K + 1) / ans < b || ans * b > K) {
      flag = true;
    }
    ans *= b;
  }

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


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

int main() {
  long long ans = 1;
  int n;
  bool flag = false;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long b;
    cin >> b;
    if (b == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (flag || K / ans < b || ans * b > K) {
      flag = true;
    }
    ans *= b;
  }

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

Buggy submission (status: Time Limit Exceeded):
n = int(input())
n_list = [int(i) for i in input().split()]
ans = 1
n_list.sort()
for i in n_list:
    ans *= i
    if ans > 10**18:
        ans = -1
print(ans)


Fixed submission:
n = int(input())
n_list = [int(i) for i in input().split()]
ans = 1
n_list.sort()
n_list = list(reversed(n_list))
if 0 in n_list:
    print(0)
else:
    for i in n_list:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
    print(ans)
Problem p02658 (Python)

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

n = int(input())
list_input = list(map(int, sys.stdin.readline().strip().split()))

if 0 in list_input:
    print(0)
    exit()

a = 1
for i in list_input:
    a *= i


if a > pow(10, 18):
    print(-1)
else:
    print(a)


Fixed submission:
import sys

n = int(input())
list_input = list(map(int, sys.stdin.readline().strip().split()))

if 0 in list_input:
    print(0)
    exit()

a = 1
for i in list_input:
    a *= i
    if a > pow(10, 18):
        break


if a > pow(10, 18):
    print(-1)
else:
    print(a)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
from operator import mul
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
ans = reduce(mul, a)
if ans > 10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
from operator import mul
from functools import reduce

n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

cnt = 1
if 0 in a:
    print(0)
    exit()

for i in range(len(a)):
    cnt *= a[i]
    if cnt > 10**18:
        print(-1)
        exit()
print(cnt)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)

else:
    total = 1
    for i in range(N):
        total *= A[i]

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


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

if 0 in A:
    print(0)

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

Buggy submission (status: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)
else:
    out = 1
    for a in A:
        out *= a
    out = -1 if (out > 10**18) else out
    print(out)


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

if 0 in A:
    print(0)
else:
    out = 1
    for a in A:
        out *= a
        if out > 10**18:
            out = -1
            break
    print(out)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
# B - Multiplication 2

n = int(input())
a = list(map(int, input().split()))
limit = 10**18
for i in range(1, n):
    a[i] *= a[i - 1]
    if a[i] > limit:
        a[i] = -1
print(a[-1])


Fixed submission:
# B - Multiplication 2

n = int(input())
a = list(map(int, input().split()))
limit = 10**18
for i in range(1, n):
    a[i] = min(a[i] * a[i - 1], limit + 1)

print(a[-1] if a[-1] <= limit else -1)
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
res = 1
a = map(int, input().split())
for x in a:
    res *= x
if res > 1e18:
    res = -1
print(res)


Fixed submission:
def solve():
    _ = int(input())
    a = list(map(int, input().split()))
    res = 1
    for x in a:
        if x == 0:
            print(0)
            return
    for x in a:
        res *= x
        if res > int(1e18):
            print(-1)
            return
    print(res)


solve()
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import Counter

N = input()
A_str = input().split()

if "0" in A_str:
    print(0)
    exit()

c = Counter(sorted(A_str))
res = 1
for i, v in c.items():
    res *= int(i) ** v

if res > 10**18:
    res = -1

print(res)


Fixed submission:
from collections import Counter

N = input()
A_str = input().split()

if "0" in A_str:
    print(0)
    exit()

c = Counter(sorted(A_str))
res = 1
for i, v in c.items():
    res *= int(i) ** v

    if res > 10**18:
        res = -1
        break

print(res)
Problem p02658 (Python)

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


Fixed submission:
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Problem p02658 (Python)

Buggy submission (status: Runtime Error):
def main():
    _ = input()
    lst = list(map(int, input().split()))
    ans = 1

    if 0 in lst:
        print(0)
        exit()
    for i in map(int, input().split()):
        ans *= i
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    _ = input()
    lst = list(map(int, input().split()))
    ans = 1

    if 0 in lst:
        print(0)
        exit()
    for i in lst:
        ans *= i
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)


if __name__ == "__main__":
    main()
Problem p02658 (Python)

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


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

Buggy submission (status: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
result = 1
flag = 0
for a in A:
    if a == 0:
        zero_flag = 1
        result = 0
        break
    else:
        result = result * a
        if result > pow(10, 18):
            flag = 1
            result = 0
if flag == 1 and zero_flag != 1:
    print(-1)
else:
    print(result)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
result = 1
flag = 0
zero_flag = 0
for a in A:
    if a == 0:
        zero_flag = 1
        result = 0
        break
    else:
        result = result * a
        if result > pow(10, 18):
            flag = 1
            result = 0
if flag == 1 and zero_flag != 1:
    print(-1)
else:
    print(result)
Problem p02658 (Python)

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

n = int(input())
a = [int(i) for i in input().split()]
tmp = 10**18
if 0 in a:
    print(0)
    sys.exit()
else:
    acc = 1
    for i in a:
        acc *= i
    if len(str(i)) + len(str(acc)) < 19:
        pass
    elif acc > tmp:
        print(-1)
        sys.exit()
print(acc)


Fixed submission:
import sys

n = int(input())
a = [int(i) for i in input().split()]
tmp = 10**18
if 0 in a:
    print(0)
    sys.exit()
else:
    acc = 1
    for i in a:
        acc *= i
        if acc > tmp:
            print(-1)
            sys.exit()
print(acc)
Problem p02658 (Python)

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


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

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
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
if 0 in a:
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
const llong N = 1e18;
int main() {
  int n;
  llong a = 1, b, c;
  scanf("%d", &n);
  while (n--) {
    scanf("%lld", &b);
    c = N / b;
    if (a > c) {
      a = -1;
    }
    a = a * b;
  }
  a = a < 0 ? -1 : a;
  cout << a;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
const llong N = 1e18;
int main() {
  int n;
  llong a = 1, b, c;
  scanf("%d", &n);
  while (n--) {
    scanf("%lld", &b);
    if (b == 0) {
      a = 0;
      break;
    }
    c = N / a;
    if (b > c) {
      a = -1;
    }
    a = a * b;
  }
  a = a < 0 ? -1 : a;
  cout << a;

  return 0;
}
Problem p02658 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a.sort()
judge = True
ans = 1
for i in a:
    ans *= i
    if ans > 1000000000000000000:
        judge = False

if judge:
    print(ans)
else:
    print(-1)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
judge = True
ans = 1
for i in a:
    ans *= i
    if ans > 1000000000000000000:
        judge = False
        break

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

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


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 1
if 0 in A:
    print(0)
else:
    for a in A:
        ans *= a
        if ans > 10**18:
            ans = -1
            break
    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 a:
    ans *= i
print(ans if not ans > 10**18 else -1)


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

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

input = sys.stdin.readline

"""

"""

tot = 1
n = int(input())
arr = map(int, input().split())

for v in arr:
    tot *= v

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


Fixed submission:
import sys

input = sys.stdin.readline

"""

"""

tot = 1
n = int(input())
arr = map(int, input().split())

for v in arr:
    if v == 0:
        tot = 0
        break
    if tot <= 10**18:
        tot *= v


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

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

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

ans = 1

if 0 in A:
    print(0)
    sys.exit()

for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        ans = -1

print(ans)


Fixed submission:
import sys

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

ans = 1

if 0 in A:
    print(0)
    sys.exit()

for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        ans = -1
        break

print(ans)