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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> pl;
  vector<ll> mn;
  int ze = 0;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    if (a == 0)
      ze++;
    if (a > 0)
      pl.push_back(a);
    if (a < 0)
      mn.push_back(-a);
  }
  if ((N - ze) < K) {
    cout << 0 << endl;
    return 0;
  }
  int f_pl, f_mn, s_pl, s_mn;
  s_pl = (int)pl.size();
  s_mn = (int)mn.size();
  sort(pl.begin(), pl.end());
  reverse(pl.begin(), pl.end());
  sort(mn.begin(), mn.end());
  reverse(mn.begin(), mn.end());
  f_mn = min(((K / 2) * 2) - 1, ((s_mn / 2) * 2) - 1);
  f_pl = K - f_mn - 2;
  // cout << f_pl << ' ' << f_mn << endl;
  ll ans = 1;
  ll m = 1e9 + 7;
  if (f_pl >= s_pl) {
    if (ze > 0) {
      cout << 0 << endl;
      return 0;
    } else {
      f_mn++;
      f_pl--;
      for (int i = 0; i <= f_pl; i++) {
        ans *= pl[i];
        ans %= m;
      }
      for (int i = 0; i <= f_mn; i++) {
        ans *= mn[s_mn - i - 1];
        ans %= m;
      }
      ans = m - ans;
      ans %= m;
      cout << ans << endl;
      return 0;
    }
  }
  // cout << f_pl << ' ' << f_mn << endl;
  // cout << ans << endl;
  while (f_pl + 2 < s_pl && f_mn - 1 >= 0 &&
         ((pl[f_pl + 1] * pl[f_pl + 2]) > (mn[f_mn] * mn[f_mn - 1]))) {
    f_pl += 2;
    f_mn -= 2;
  }
  // cout << endl;
  for (int i = 0; i <= f_pl; i++) {
    ans *= pl[i];
    ans %= m;
    // cout << pl[i] << endl;
  }
  // cout << f_pl << endl;
  for (int i = 0; i <= f_mn; i++) {
    ans *= mn[i];
    ans %= m;
    // cout << ans << endl;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> pl;
  vector<ll> mn;
  int ze = 0;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    if (a == 0)
      ze++;
    if (a > 0)
      pl.push_back(a);
    if (a < 0)
      mn.push_back(-a);
  }
  if ((N - ze) < K) {
    cout << 0 << endl;
    return 0;
  }
  int f_pl, f_mn, s_pl, s_mn;
  s_pl = (int)pl.size();
  s_mn = (int)mn.size();
  sort(pl.begin(), pl.end());
  reverse(pl.begin(), pl.end());
  sort(mn.begin(), mn.end());
  reverse(mn.begin(), mn.end());
  f_mn = (s_mn / 2 * 2) - 1;
  f_pl = K - f_mn - 2;
  // cout << f_pl << ' ' << f_mn << endl;
  ll ans = 1;
  ll m = 1e9 + 7;
  if (f_pl >= s_pl) {
    if (ze > 0) {
      cout << 0 << endl;
      return 0;
    } else {
      ans = m - mn[s_mn - 1];
      f_pl--;
    }
  }
  // cout << ans << endl;
  while (f_pl + 2 < s_pl && f_mn - 1 >= 0 &&
         ((pl[f_pl + 1] * pl[f_pl + 2]) > (mn[f_mn] * mn[f_mn - 1]))) {
    f_pl += 2;
    f_mn -= 2;
  }
  // cout << endl;
  for (int i = 0; i <= f_pl; i++) {
    ans *= pl[i];
    ans %= m;
    // cout << pl[i] << endl;
  }
  // cout << f_pl << endl;
  for (int i = 0; i <= f_mn; i++) {
    ans *= mn[i];
    ans %= m;
    // cout << ans << endl;
  }
  cout << ans << endl;
}
Problem p02616 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
using ll = long long int;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define MOD 1000000007LL

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<ll> pos, neg;

  rep(i, N) {
    ll tmp;
    cin >> tmp;
    if (tmp > 0) {
      pos.push_back(tmp);
    } else {
      neg.push_back(-tmp);
    }
  }

  if (K == N) {
    ll prod = 1;
    for (ll x : pos)
      prod = prod * x % MOD;
    for (ll x : neg)
      prod = prod * (MOD - x) % MOD;
    cout << prod << endl;
    return 0;
  }

  if (static_cast<ll>(neg.size()) == N && K % 2 == 1) {
    sort(neg.begin(), neg.end());
    ll prod = 1;
    rep(i, K) prod = prod * (MOD - neg[i]) % MOD;

    cout << prod << endl;
    return 0;
  }

  sort(pos.begin(), pos.end(), greater<ll>());
  sort(neg.begin(), neg.end(), greater<ll>());

  ll prod = 1;
  if (K % 2 == 1 && static_cast<ll>(pos.size()) > 0) {
    auto it = pos.begin();
    prod = prod * *it % MOD;
    pos.erase(it);
    K--;
  }

  vector<ll> sqs;
  for (ll i = 0; i + 1 < static_cast<ll>(pos.size()); i += 2) {
    sqs.push_back(pos[i] * pos[i + 1]);
  }
  for (ll i = 0; i + 1 < static_cast<ll>(neg.size()); i += 2) {
    sqs.push_back(neg[i] * neg[i + 1]);
  }

  sort(sqs.begin(), sqs.end(), greater<ll>());
  rep(i, K / 2) { prod = prod * (sqs[i] % MOD) % MOD; }

  cout << prod << endl;
}


Error: 0

Fixed submission:

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

using namespace std;
using ll = long long int;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define MOD 1000000007LL

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<ll> pos, neg;

  rep(i, N) {
    ll tmp;
    cin >> tmp;
    if (tmp > 0) {
      pos.push_back(tmp);
    } else {
      neg.push_back(-tmp);
    }
  }

  if (K == N) {
    ll prod = 1;
    for (ll x : pos)
      prod = prod * x % MOD;
    for (ll x : neg)
      prod = prod * (MOD - x) % MOD;
    cout << prod << endl;
    return 0;
  }

  if (static_cast<ll>(neg.size()) == N && K % 2 == 1) {
    sort(neg.begin(), neg.end());
    ll prod = 1;
    rep(i, K) prod = prod * (MOD - neg[i]) % MOD;

    cout << prod << endl;
    return 0;
  }

  sort(pos.begin(), pos.end(), greater<ll>());
  sort(neg.begin(), neg.end(), greater<ll>());

  assert(pos.size() > 0);

  ll prod = 1;
  if (K % 2 == 1) {
    auto it = pos.begin();
    prod = prod * *it % MOD;
    pos.erase(it);
    K--;
  }

  vector<ll> sqs;
  for (ll i = 0; i + 1 < static_cast<ll>(pos.size()); i += 2) {
    sqs.push_back(pos[i] * pos[i + 1]);
  }
  for (ll i = 0; i + 1 < static_cast<ll>(neg.size()); i += 2) {
    sqs.push_back(neg[i] * neg[i + 1]);
  }

  sort(sqs.begin(), sqs.end(), greater<ll>());
  rep(i, K / 2) { prod = prod * (sqs[i] % MOD) % MOD; }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include<unordered_map>
using namespace std;
#define ll long long
#define dd cout << endl
const long long int inf = 1e18 + 7;
const int mod = 1e9 + 7;

using namespace std;

inline ll int max(ll int a, ll int b) { return a > b ? a : b; }
inline ll int min(ll int a, ll int b) { return a < b ? a : b; }

const int N = 2e5 + 10;

int n, k;
ll a[N];
ll mp[N];

inline bool cmp(ll x, ll y) { return abs(x) < abs(y); }

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

  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] >= 0)
      mp[1]++;
    else
      mp[2]++;
  }

  int l = 1, r = n;

  ll ans = 1;

  if (mp[1] == 0 && k % 2 == 1) {
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= k; ++i) {
      ans = a[i] * ans % mod;
    }
  } else {
    sort(a + 1, a + 1 + n, greater<int>());
    while (k > 0) {
      if (k % 2 == 1)
        ans = ans * a[l++] % mod, k--;
      else if (k >= 2) {
        if (a[l] * a[l + 1] >= a[r] * a[r - 1]) {
          ans = ans * a[l] % mod * a[l + 1] % mod;
          l += 2;
          k -= 2;
        } else {
          ans = ans * a[r - 1] % mod * a[r] % mod;
          r -= 2;
          k -= 2;
        }
      }
    }
  }

  cout << (ans % mod + mod) % mod << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include<unordered_map>
using namespace std;
#define ll long long
#define dd cout << endl
const long long int inf = 1e18 + 7;
const int mod = 1e9 + 7;

using namespace std;

inline ll int max(ll int a, ll int b) { return a > b ? a : b; }
inline ll int min(ll int a, ll int b) { return a < b ? a : b; }

const int N = 2e5 + 10;

int n, k;
ll a[N];
ll mp[N];

inline bool cmp(ll x, ll y) { return abs(x) < abs(y); }

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

  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] >= 0)
      mp[1]++;
    else
      mp[2]++;
  }

  int l = 1, r = n;

  ll ans = 1;

  if (mp[1] == 0 && k % 2 == 1) {
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= k; ++i) {
      ans = a[i] * ans % mod;
    }
  } else {
    sort(a + 1, a + 1 + n, greater<int>());
    while (k > 0) {
      if (k % 2 == 1)
        ans = ans * a[l++] % mod;
      else if (k >= 2) {
        if (a[l] * a[l + 1] >= a[r] * a[r - 1]) {
          ans = ans * a[l] % mod * a[l + 1] % mod;
          l += 2;
          k -= 2;
        } else {
          ans = ans * a[r - 1] % mod * a[r] % mod;
          r -= 2;
          k -= 2;
        }
      }
    }
  }

  cout << (ans % mod + mod) % mod << endl;

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

#include <iostream>
#define ll long long
#define rep(i, l, r) for (ll i = (l); i < (r); i++)
int upll(const void *a, const void *b) {
  return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0;
}
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
#define MOD 1000000007
ll m[200010], p[200010];
int mm_c, p_c;
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  rep(i, 0, n) {
    int t;
    scanf("%d", &t);
    if (t >= 0)
      p[p_c++] = t;
    else
      m[mm_c++] = -t;
  }
  sortup(m, mm_c);
  sortup(p, p_c);
  if (q == n) {
    ll ans = 1;
    rep(i, 0, mm_c) ans = ans * (MOD - m[i]) % MOD;
    rep(i, 0, p_c) ans = ans * p[i] % MOD;
    printf("%lld", ans);
    return 0;
  }
  if (q % 2 == 1 && mm_c == n) {
    ll ans = 1;
    rep(i, 0, q) ans = ans * (MOD - m[i]) % MOD;
    printf("%lld", ans);
    return 0;
  }
  ll ans = 1;
  while (q) {
    if (q >= 2 && mm_c >= 2 &&
        (p_c <= 1 ||
         (p_c >= 2 && m[mm_c - 1] * m[mm_c - 2] >= p[p_c - 1] * p[p_c - 2]))) {
      ans = ans * m[--mm_c] % MOD;
      ans = ans * m[--mm_c] % MOD;
      q -= 2;
    } else {
      ans = ans * p[--p_c] % MOD;
      q--;
    }
  }
  printf("%lld", ans);
}


Error: -11

Fixed submission:

#include <iostream>
typedef long long ll;
ll m[200010], p[200010];
#define MOD 1000000007
#define rep(i, l, r) for (ll i = (l); i < (r); i++)
int upll(const void *a, const void *b) {
  return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0;
}
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
int main() {
  int n, q;
  int m_c, p_c;
  scanf("%d%d", &n, &q);
  rep(i, 0, n) {
    int t;
    scanf("%d", &t);
    if (t >= 0) {
      p[p_c++] = t;
    } else {
      m[m_c++] = -t;
    }
  }
  sortup(m, m_c);
  sortup(p, p_c);
  if (q == n) {
    ll ans = 1;
    rep(i, 0, m_c) ans = ans * (MOD - m[i]) % MOD;
    rep(i, 0, p_c) ans = ans * p[i] % MOD;
    printf("%lld", ans);
    return 0;
  }
  if (q % 2 == 1 && m_c == n) {
    ll ans = 1;
    rep(i, 0, q) ans = ans * (MOD - m[i]) % MOD;
    printf("%lld", ans);
    return 0;
  }
  ll ans = 1;
  while (q) {
    if (q >= 2 && m_c >= 2 &&
        (p_c <= 1 ||
         (p_c >= 2 && m[m_c - 1] * m[m_c - 2] >= p[p_c - 1] * p[p_c - 2]))) {
      ans = ans * m[--m_c] % MOD;
      ans = ans * m[--m_c] % MOD;
      q -= 2;
    } else {
      ans = ans * p[--p_c] % MOD;
      q--;
    }
  }
  printf("%lld", ans);
}
Problem p02616 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define maxn 200005
#define ll long long
#define mod 1000000007
using namespace std;
ll a[maxn], n, k, fhw, l, r, ans = 1;
bool cmp(ll x, ll y) { return x > y; }
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    scanf("%lld", &a[i]);
  sort(a, a + n);
  l = 0;
  r = n - 1;
  if (k & 1)
    k--, ans *= a[r--];
  if (ans < 0)
    fhw = -1;
  else
    fhw = 1;
  while (k) {
    if (a[l] * a[l + 1] * fhw < a[r] * a[r - 1] * fhw)
      (ans *= a[r] * a[r - 1] % mod) %= mod, r -= 2;
    else
      (ans *= a[l] * a[l + 1] % mod) %= mod, l += 2;
    k -= 2;
  }
  cout << (ans % mod + mod) % mod;

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;

ll n, k, a[maxn], ans = 0;
bool cmp(const ll &a, const ll &b) { return abs(a) > abs(b); }
void slove() {
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n, cmp);
  vector<ll> a1, a2;
  for (int i = 0; i < n; i++) {
    if (a[i] > 0)
      a1.push_back(a[i]);
    else if (a[i] < 0)
      a2.push_back(a[i]);
  }
  if (a1.size() + a2.size() < k) {
    ans = 0;
    return;
  }
  int flag0 = 0;
  if (a1.size() + a2.size() < n)
    flag0 = 1;
  if (a1.size() + a2.size() == k && k < n && (a2.size() % 2 == 1)) {
    ans = 0;
    return;
  }
  if (a1.size() == 0) {
    if (k % 2 == 1) {
      if (flag0 == 1) {
        ans = 0;
        return;
      }
      ans = 1;
      for (int i = a2.size() - 1; i >= a2.size() - k; i--) {
        ans = ans * a2[i];
        ans %= mod;
      }
      return;
    }
    ans = 1;
    for (int i = 0; i < k; i++) {
      ans = ans * a2[i];
      ans %= mod;
    }
    return;
  }
  int c1 = 0, c2 = 0;
  for (int i = 0; c1 + c2 < k; i++) {
    if (a[i] > 0)
      c1++;
    if (a[i] < 0)
      c2++;
  }
  if (c2 % 2 == 0) {
  } else {
    ll t1, t2;
    t1 = a1[c1 - 1] * a1[c1], t2 = a2[c2 - 1] * a2[c2];
    if (t1 > t2) {
      c1++, c2--;
    } else {
      c1--, c2++;
    }
  }
  ans = 1;
  for (int i = 0; i < c1; i++) {
    ans = ans * a1[i];
    ans %= mod;
  }
  for (int i = 0; i < c2; i++) {
    ans = ans * (-a2[i]);
    ans %= mod;
  }
}
int main() {
  slove();
  if (ans < 0)
    ans += mod;
  printf("%lld", ans);
  return 0;
}
Problem p02616 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod = 1e9 + 7;
const int N = 2e5 + 100;
ll a[N];
int f[5];
bool cmp(int x, int y) { return abs(x) < abs(y); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] >= 0)
      f[1]++;
    else
      f[2]++;
  }
  int l = 1, r = n;
  ll ans = 1;
  if (!f[1] && m % 2 == 1) {
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= m; i++) {
      ans = a[i] * ans % mod;
    }
  } else {
    sort(a + 1, a + 1 + n, greater<int>());
    while (m > 0) {
      if (m % 2)
        ans = ans * a[l] % mod, l++, m--;
      else if (m >= 2) {
        if (a[l] * a[l + 1] >= a[r] * a[r - 1]) {
          ans = ans * a[l] % mod * a[l + 1] % mod;
          l += 2;
          m -= 2;
        } else {
          ans = ans * a[r - 1] % mod * a[r] % mod;
          r -= 2;
          m -= 2;
        }
      }
    }
  }
  cout << (ans % mod + mod) % mod << endl;
  return 0;
}


Error: 0

Fixed submission:

// 及时当勉励，岁月不待人！
// 当前状态 : attempted
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
struct node {
  ll val;
  ll op;
  bool operator<(const node &b) const { return this->val > b.val; }
};
const int maxn = 2e5 + 120;
int tmp, n, k;
ll ans = 1;
node aaa[200050];
int maxN = -1 * inf;
bool cmp(node a, node b) { return a.val > b.val; }
// 函数
int main() {
  // std::ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> tmp;
    maxN = max(maxN, tmp);
    if (tmp > 0) {
      aaa[i] = node{tmp, 1};
    } else {
      aaa[i] = node{-1 * tmp, 0};
    }
  }
  // aaa[0]=node{-1*inf,0};
  if (k == 1) {
    cout << (maxN % mod + mod) % mod << endl;
    return 0;
  }
  sort(aaa + 1, aaa + n + 1, cmp);
  int now = 1;
  ll mut = 1;
  int isH = 0;
  while (k) {
    node t = aaa[now++];
    if (t.op == 1) {
      ans = (ans * t.val) % mod;
      --k;
    } else {
      if (isH == 1) {
        mut = (mut * t.val % mod) % mod;
        ans = (ans * mut) % mod;
        mut = 1;
        isH = 0;
        k -= 2;
      } else {
        mut = (mut * t.val) % mod;
        isH = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02616 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define lowbit(i) ((i) & (-i))
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MAXN = 2 * 1e5 + 15;
const ll M = 1e9 + 7;
vector<ll> v;
int main() {
#ifdef CitricAcid
  freopen("input.txt", "rt", stdin);
#endif

  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    ll x;
    scanf("%lld", &x);
    v.push_back(x);
  }
  sort(v.begin(), v.end());

  ll ans = 1;
  int l = 0, r = n - 1, op = 1;
  if (k & 1) {
    ans = v[r--];
    k--;
    if (ans < 0)
      op = -1;
  }

  while (k > 0) {
    ll x = v[l] * v[l + 1];
    ll y = v[r] * v[r - 1];

    if (x * op > y * op) {
      ans = x % M * ans % M;
      l += 2;
    } else {
      ans = y % M * ans % M;
      r -= 2;
    }

    k -= 2;
  }
  printf("%lld\\n", (ans + M) % M);

#ifdef CitricAcid
  cerr << "\\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
#endif
  return 0;
}
/*
# author : CitricAcid
# date : 2020/07/25
*/

Error: 0

Fixed submission:

// 及时当勉励，岁月不待人！
// 当前状态 : attempted
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
struct node {
  ll val;
  ll op;
  bool operator<(const node &b) const { return this->val > b.val; }
};
const int maxn = 2e5 + 120;
int tmp, n, k;
ll ans = 1;
node aaa[200050];
int maxN = -1 * inf;
bool cmp(node &a, node &b) { return a.val > b.val; }
// 函数
int main() {
  // std::ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> tmp;
    maxN = max(maxN, tmp);
    if (tmp > 0) {
      aaa[i] = node{tmp, 1};
    } else {
      aaa[i] = node{-1 * tmp, 0};
    }
  }
  // aaa[0]=node{-1*inf,0};
  if (k == 1) {
    cout << (maxN % mod + mod) % mod << endl;
    return 0;
  }
  sort(aaa + 1, aaa + n + 1, cmp);
  int now = 1;
  ll mut = 1;
  int isH = 0;
  while (k) {
    node t = aaa[now++];
    if (t.op == 1) {
      ans = (ans * t.val) % mod;
      --k;
    } else {
      if (isH == 1) {
        mut = (mut * t.val % mod) % mod;
        ans = (ans * mut) % mod;
        mut = 1;
        isH = 0;
        k -= 2;
      } else {
        mut = (mut * t.val) % mod;
        isH = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02616 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define faster                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define endl "\\n"

#define mod ll(1e9 + 7)

int main() {
  faster;

  ll n, k;
  cin >> n >> k;

  vector<ll> a(n);

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

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

  ll res = 1, sign = 1, left = 0, right = n - 1;

  if (k % 2) {
    res = (a[right--] % mod);
    res %= mod;
    if (res < 0) {
      sign = -1;
    }
    k--;
  }
  while (k) {
    ll x = a[left] * a[left + 1], y = a[right] * a[right - 1];
    if (x * sign > y * sign) {
      res *= (x % mod);
      res %= mod;
      left += 2;
    } else {
      res *= (y % mod);
      res %= mod;
      right -= 2;
    }
    k -= 2;
  }
  cout << ((mod + res) % mod) << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define faster                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define endl "\\n"

#define mod ll(1e9 + 7)

int main() {
  faster;

  ll n, k;
  cin >> n >> k;

  vector<ll> a(n);

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

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

  ll mxN = 1;

  for (ll i = 0; i < k; i++) {
    mxN *= (a[i] % mod);
    mxN %= mod;
  }

  ll start = 0;

  ll curr = mxN % mod;

  for (ll i = k; i < n; i++) {
    curr /= (a[start] % mod);
    curr %= mod;
    start++;
    curr *= (a[i] % mod);
    curr %= mod;
    mxN = max(mxN, curr);
  }

  cout << (mxN % mod) << endl;

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
// #define mod 998244353

int N, K;
int A[200005];
signed main() {
  scanf("%lld %lld", &N, &K);
  rep(i, N) scanf("%lld", &A[i]);
  sort(A, A + N);
  if (K == 1) {
    printf("%lld\\n", A[N - 1]);
    return 0;
  }
  if (A[N - 1] < 0 && K % 2 == 1) {
    int prod = 1;
    rep(i, K) {
      prod *= A[N - i - 1];
      prod %= mod;
    }
    printf("%lld\\n", (prod % mod + mod) % mod);
    return 0;
  }
  int cnt = 0;
  int left = -1;
  int right = N;
  int prod = 1;
  while (cnt < K) {
    if (K - cnt == 1) {
      prod *= A[right - 1];
      prod %= mod;
      break;
    }
    if (A[left + 2] >= 0) {
      prod *= A[right - 1];
      prod %= mod;
      right -= 1;
      cnt += 1;
      continue;
    }
    if (A[right - 2] < 0) {
      prod *= (A[left + 1] * A[left + 2]) % mod;
      prod %= mod;
      left += 2;
      cnt += 2;
      continue;
    }
    int p1 = A[left + 1] * A[left + 2];
    int p2 = A[right - 1] * A[right - 2];
    if (p1 > p2) {
      prod *= (A[left + 1] * A[left + 2]) % mod;
      left += 2;
      cnt += 2;
    } else {

      prod *= A[right - 1];
      right -= 1;
      cnt += 1;
    }
    prod %= mod;
  }
  printf("%lld\\n", (prod % mod + mod) % mod);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  ll a[n];
  for (auto &i : a) {
    cin >> i;
  }
  sort(a, a + n);
  if (k < n) {
    ll ans = -(1e9 + 7);
    ll temp = 1;
    for (int i = 0; i < k; i++) {
      temp = (temp * a[i]) % mod;
    }
    // cout<<"temp->"<<temp<<endl;
    ans = max(ans, temp);
    int id = k - 1;
    for (int i = n - 1; i >= n - k; i--) {
      temp /= a[id];
      // cout<<"1->temp->"<<temp<<endl;
      temp = (temp * a[i]) % mod;
      // cout<<"2->temp->"<<temp<<endl;
      ans = max(ans, temp);
      id--;
    }
    // cout<<ans<<endl;
    ans = (ans + mod) % mod;
    cout << ans << endl;
  } else {
    ll temp = 1;
    for (int i = 0; i < k; i++) {
      temp = (temp * a[i]) % mod;
    }
    temp = (temp + mod) % mod;
    cout << temp << endl;
  }
  return 0;
}