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

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

#define INCANT                                                                 \
  cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define out(a) cout << a << endl
#define PRINT(V)                                                               \
  for (auto v : (V))                                                           \
  cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
  ll X, Y, A, B, C;
  ll ans = 0;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> p(A), q(B), r(C);
  rep(i, A) cin >> p.at(i);
  rep(i, B) cin >> q.at(i);
  rep(i, C) cin >> r.at(i);
  sort(all(p), greater<ll>());
  sort(all(q), greater<ll>());
  rep(i, A - X) p.pop_back();
  rep(i, B - Y) q.pop_back();
  r.insert(r.end(), all(p));
  r.insert(r.end(), all(q));
  sort(all(r), greater<ll>());
  rep(i, A + B + C - X - Y) r.pop_back();
  out(accumulate(all(r), 0));
}
int main() {
  INCANT;
  solve();
  return 0;
}


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

#define INCANT                                                                 \
  cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define out(a) cout << a << endl
#define PRINT(V)                                                               \
  for (auto v : (V))                                                           \
  cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
  ll X, Y, A, B, C;
  ll ans = 0;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> p(A), q(B), r(C);
  rep(i, A) cin >> p.at(i);
  rep(i, B) cin >> q.at(i);
  rep(i, C) cin >> r.at(i);
  sort(all(p), greater<ll>());
  sort(all(q), greater<ll>());
  rep(i, A - X) p.pop_back();
  rep(i, B - Y) q.pop_back();
  r.insert(r.end(), all(p));
  r.insert(r.end(), all(q));
  sort(all(r), greater<ll>());
  rep(i, C) r.pop_back();
  out(accumulate(all(r), ans));
}
int main() {
  INCANT;
  solve();
  return 0;
}
Problem p02727 (C++)

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

using namespace std;
typedef long long ll;

ll X, Y, A, B, C;
ll p[100005];
ll q[100005];
ll r[100005];
vector<ll> pq;

int main() {
  cin >> X >> Y >> A >> B >> C;
  for (ll i = 0; i < A; i++)
    cin >> p[i];
  for (ll i = 0; i < B; i++)
    cin >> q[i];
  for (ll i = 0; i < C; i++)
    cin >> r[i];
  sort(p, p + A, std::greater<ll>());
  sort(q, q + B, std::greater<ll>());
  sort(r, r + C, std::greater<ll>());

  ll tans = 0;
  for (ll i = 0; i < X; i++) {
    tans += p[i];
    pq.push_back(p[i]);
  }
  for (ll i = 0; i < Y; i++) {
    tans += q[i];
    pq.push_back(q[i]);
  }
  sort(pq.begin(), pq.end());
  int pqi = 0;
  for (int i = 0; i < C && pqi < X + Y; i++) {
    if (pq[pqi] < r[i]) {
      tans -= pq[pqi];
      pqi--;
      tans += r[i];
    } else {
      break;
    }
  }

  cout << tans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

ll X, Y, A, B, C;
ll p[100005];
ll q[100005];
ll r[100005];
vector<ll> pq;

int main() {
  cin >> X >> Y >> A >> B >> C;
  for (ll i = 0; i < A; i++)
    cin >> p[i];
  for (ll i = 0; i < B; i++)
    cin >> q[i];
  for (ll i = 0; i < C; i++)
    cin >> r[i];
  sort(p, p + A, std::greater<ll>());
  sort(q, q + B, std::greater<ll>());
  sort(r, r + C, std::greater<ll>());

  ll tans = 0;
  for (ll i = 0; i < X; i++) {
    tans += p[i];
    pq.push_back(p[i]);
  }
  for (ll i = 0; i < Y; i++) {
    tans += q[i];
    pq.push_back(q[i]);
  }
  sort(pq.begin(), pq.end());
  int pqi = 0;
  for (int i = 0; i < C && pqi < X + Y; i++) {
    if (pq[pqi] < r[i]) {
      tans -= pq[pqi];
      pqi++;
      tans += r[i];
    } else {
      break;
    }
  }

  cout << tans << endl;
  return 0;
}
Problem p02727 (C++)

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

int main() {
  int red, green, numa, numb, numc;
  cin >> red >> green >> numa >> numb >> numc;
  vector<int> v_red;
  vector<int> v_green;
  vector<int> v_white;
  int current;
  for (int i = 0; i < numa; i++) {
    cin >> current;
    v_red.push_back(current);
  }
  for (int i = 0; i < numb; i++) {
    cin >> current;
    v_green.push_back(current);
  }
  for (int i = 0; i < numc; i++) {
    cin >> current;
    v_white.push_back(current);
  }
  sort(v_red.begin(), v_red.end(), greater<int>());
  sort(v_green.begin(), v_green.end(), greater<int>());
  sort(v_white.begin(), v_white.end(), greater<int>());
  long long ans = 0;
  vector<int> eat;
  for (int i = 0; i < red; i++) {
    ans += v_red[i];
    eat.push_back(v_red[i]);
  }
  for (int i = 0; i < green; i++) {
    ans += v_green[i];
    eat.push_back(v_green[i]);
  }
  sort(eat.begin(), eat.end());
  int index_eat = 0;
  int index_white = 0;
  while (eat[index_eat] <= v_white[index_white]) {
    ans -= eat[index_eat];
    ans += v_white[index_white];
    index_eat++;
    index_white++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int red, green, numa, numb, numc;
  cin >> red >> green >> numa >> numb >> numc;
  vector<int> v_red;
  vector<int> v_green;
  vector<int> v_white;
  int current;
  for (int i = 0; i < numa; i++) {
    cin >> current;
    v_red.push_back(current);
  }
  for (int i = 0; i < numb; i++) {
    cin >> current;
    v_green.push_back(current);
  }
  for (int i = 0; i < numc; i++) {
    cin >> current;
    v_white.push_back(current);
  }
  sort(v_red.begin(), v_red.end(), greater<int>());
  sort(v_green.begin(), v_green.end(), greater<int>());
  sort(v_white.begin(), v_white.end(), greater<int>());
  long long ans = 0;
  vector<int> eat;
  for (int i = 0; i < red; i++) {
    ans += v_red[i];
    eat.push_back(v_red[i]);
  }
  for (int i = 0; i < green; i++) {
    ans += v_green[i];
    eat.push_back(v_green[i]);
  }
  sort(eat.begin(), eat.end());
  int index_eat = 0;
  int index_white = 0;
  while (eat[index_eat] <= v_white[index_white]) {
    ans -= eat[index_eat];
    ans += v_white[index_white];
    index_eat++;
    index_white++;
    if (index_eat >= eat.size()) {
      break;
    }
    if (index_white >= v_white.size()) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02727 (C++)

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

int main(void) {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  long long p[100010] = {0};
  long long q[100010] = {0};
  long long r[100010] = {0};
  for (int i = 0; i < A; i++)
    cin >> p[i];
  for (int i = 0; i < B; i++)
    cin >> q[i];
  for (int i = 0; i < C; i++)
    cin >> r[i];

  sort(p, p + A, greater<>());
  sort(q, q + B, greater<>());
  sort(r, r + C, greater<>());

  long long z[300030] = {0};
  for (int i = 0; i < X; i++) {
    z[i] = p[i];
  }
  for (int i = 0; i < Y; i++) {
    z[i + X] = q[i];
  }
  for (long long i = 0; i < (X + Y); i++) {
    z[i + X + Y] = r[i];
  }
  sort(z, z + 300030, greater<>());
  long long sum = 0;
  for (long long i = 0; i < (X + Y); i++) {
    sum += z[i];
  }
  cout << sum << endl;

  return 0;
}

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

int main(void) {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  long long p[100010] = {0};
  long long q[100010] = {0};
  long long r[100010] = {0};
  for (int i = 0; i < A; i++)
    cin >> p[i];
  for (int i = 0; i < B; i++)
    cin >> q[i];
  for (int i = 0; i < C; i++)
    cin >> r[i];

  sort(p, p + A, greater<>());
  sort(q, q + B, greater<>());
  sort(r, r + C, greater<>());

  long long z[300030] = {0};
  for (int i = 0; i < X; i++) {
    z[i] = p[i];
  }
  for (int i = 0; i < Y; i++) {
    z[i + X] = q[i];
  }
  for (long long i = 0; i < C; i++) {
    z[i + X + Y] = r[i];
  }
  sort(z, z + 300030, greater<>());
  long long sum = 0;
  for (long long i = 0; i < (X + Y); i++) {
    sum += z[i];
  }
  cout << sum << endl;

  return 0;
}
Problem p02727 (C++)

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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vector<long long> p(a), q(b), r(c);
  for (int i = 0; i < a; i++)
    cin >> p.at(i);
  for (int i = 0; i < b; i++)
    cin >> q.at(i);
  for (int i = 0; i < c; i++)
    cin >> r.at(i);
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());

  vector<long long> A(x), B(y);
  for (int i = 0; i < x; i++)
    A.at(i) = p.at(a - x + i);
  for (int i = 0; i < y; i++)
    B.at(i) = q.at(b - y + i);

  if (c != 0)
    reverse(r.begin(), r.end());

  // for(int i=0;i<x;i++)
  // cout<<A.at(i);
  // cout<<endl;
  // for(int i=0;i<y;i++)
  // cout<<B.at(i);
  // cout<<endl;

  int count_a = 0, count_b = 0;

  for (int i = 0; i < c; i++) { // 1
    int x;
    if (A.at(count_a) > B.at(count_b)) { // 2
      x = B.at(count_b);
      if (r.at(i) > B.at(count_b)) { // 3
        B.at(count_b) = r.at(i);
        if (count_b < y)
          count_b++;
        // break;
      } // 3

    }      // 2
    else { // 4
      x = A.at(count_a);
      if (r.at(i) > A.at(count_a)) { // 5
        A.at(count_a) = r.at(i);
        if (count_a < x - 1)
          count_a++;
        // break;
      } // 5

    } // 4
  }
  long long sum = 0;
  for (int i = 0; i < x; i++) {
    sum += A.at(i);
    // cout<<A.at(i)<<" ";
  }
  // cout<<endl;

  for (int i = 0; i < y; i++) {
    sum += B.at(i);
    // cout<<B.at(i)<<" ";
  }
  // cout<<endl;
  cout << sum << endl;
}

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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vector<long long> p(a), q(b), r(c);
  for (int i = 0; i < a; i++)
    cin >> p.at(i);
  for (int i = 0; i < b; i++)
    cin >> q.at(i);
  for (int i = 0; i < c; i++)
    cin >> r.at(i);
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());

  vector<long long> A(x), B(y);
  for (int i = 0; i < x; i++)
    A.at(i) = p.at(a - x + i);
  for (int i = 0; i < y; i++)
    B.at(i) = q.at(b - y + i);

  if (c != 0)
    reverse(r.begin(), r.end());

  // for(int i=0;i<x;i++)
  // cout<<A.at(i);
  // cout<<endl;
  // for(int i=0;i<y;i++)
  // cout<<B.at(i);
  // cout<<endl;

  int count_a = 0, count_b = 0;

  for (int i = 0; i < c; i++) { // 1
    int x;
    if (A.at(count_a) > B.at(count_b)) { // 2
      x = B.at(count_b);
      if (r.at(i) > B.at(count_b)) { // 3
        B.at(count_b) = r.at(i);
        if (count_b < y - 1)
          count_b++;
        // break;
      } // 3

    }      // 2
    else { // 4
      x = A.at(count_a);
      if (r.at(i) > A.at(count_a)) { // 5
        A.at(count_a) = r.at(i);
        if (count_a < x - 1)
          count_a++;
        // break;
      } // 5

    } // 4
  }
  long long sum = 0;
  for (int i = 0; i < x; i++) {
    sum += A.at(i);
    // cout<<A.at(i)<<" ";
  }
  // cout<<endl;

  for (int i = 0; i < y; i++) {
    sum += B.at(i);
    // cout<<B.at(i)<<" ";
  }
  // cout<<endl;
  cout << sum << endl;
}
Problem p02727 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define VI vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF = (ll)1e19;
// const int INF=(1<<30);

int main() {
  int x, y, a, b, c;

  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  vector<ll> sp(x + 1, 0), sq(y + 1, 0), sr(c + 1, 0);

  REP(i, a) cin >> p[i];
  REP(i, b) cin >> q[i];
  REP(i, c) cin >> r[i];

  sort(ALL(p));
  reverse(ALL(p));
  sort(ALL(q));
  reverse(ALL(q));
  sort(ALL(r));
  reverse(ALL(r));

  REP(i, x) { sp[i + 1] = sp[i] + p[i]; }
  REP(i, y) { sq[i + 1] = sq[i] + q[i]; }
  REP(i, c) { sr[i + 1] = sr[i] + r[i]; }

  ll ans = -1;
  REP(i, x + 1) {
    REP(j, y + 1) {
      if (x - i + y - j > c)
        continue;
      ans = max(ans, sp[i] + sq[j] + sr[x - i + y - j]);
    }
  }

  cout << ans << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define VI vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF = (ll)1e19;
// const int INF=(1<<30);

int main() {
  int x, y, a, b, c;

  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  vector<ll> sp(x + 1, 0), sq(y + 1, 0), sr(c + 1, 0);

  REP(i, a) cin >> p[i];
  REP(i, b) cin >> q[i];
  REP(i, c) cin >> r[i];

  sort(ALL(p));
  reverse(ALL(p));
  sort(ALL(q));
  reverse(ALL(q));
  sort(ALL(r));
  reverse(ALL(r));

  REP(i, x) { sp[i + 1] = sp[i] + p[i]; }
  REP(i, y) { sq[i + 1] = sq[i] + q[i]; }
  REP(i, c) { sr[i + 1] = sr[i] + r[i]; }

  vector<ll> nn;
  REP(i, x) nn.push_back(p[i]);
  REP(i, y) nn.push_back(q[i]);
  REP(i, c) nn.push_back(r[i]);

  sort(ALL(nn));
  reverse(ALL(nn));

  ll ans = 0;
  REP(i, x + y) ans += nn[i];

  cout << ans << endl;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define f first
#define s second
#define double long double
const int MAX = 2e3 + 5;
const int MAX2 = 2e5 + 4;
const int MAAX = 1e10;
const int MOD = 1e9 + 7;

int x, y, a, b, c;
int r[MAX], g[MAX], nc[MAX];
in main() {
  cin >> x >> y >> a >> b >> c;
  for (int i = 0; i < a; i++) {
    scanf("%lld", &r[i]);
    r[i] *= -1;
  }
  for (int i = 0; i < b; i++) {
    scanf("%lld", &g[i]);
    g[i] *= -1;
  }
  for (int i = 0; i < c; i++) {
    scanf("%lld", &nc[i]);
    nc[i] *= -1;
  }
  sort(r, r + a);
  sort(g, g + b);
  sort(nc, nc + c);
  vector<int> ans;
  for (int i = 0; i < x; i++) {
    ans.pb(-r[i]);
  }
  for (int i = 0; i < y; i++) {
    ans.pb(-g[i]);
  }
  sort(ans.begin(), ans.end());
  int idx = 0;
  for (int i = 0; i < c; i++) {
    if (idx < ans.size() && ans[idx] < -nc[i]) {
      ans[idx++] = -nc[i];
    }
  }
  int anss = 0;
  for (int i = 0; i < ans.size(); i++)
    anss += ans[i];
  cout << anss << endl;
  return 0;
}


Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define f first
#define s second
#define double long double
const int MAX = 2e5 + 5;
const int MAX2 = 2e5 + 4;
const int MAAX = 1e10;
const int MOD = 1e9 + 7;

int x, y, a, b, c;
int r[MAX], g[MAX], nc[MAX];
in main() {
  cin >> x >> y >> a >> b >> c;
  for (int i = 0; i < a; i++) {
    scanf("%lld", &r[i]);
    r[i] *= -1;
  }
  for (int i = 0; i < b; i++) {
    scanf("%lld", &g[i]);
    g[i] *= -1;
  }
  for (int i = 0; i < c; i++) {
    scanf("%lld", &nc[i]);
    nc[i] *= -1;
  }
  sort(r, r + a);
  sort(g, g + b);
  sort(nc, nc + c);
  vector<int> ans;
  for (int i = 0; i < x; i++) {
    ans.pb(-r[i]);
  }
  for (int i = 0; i < y; i++) {
    ans.pb(-g[i]);
  }
  sort(ans.begin(), ans.end());
  int idx = 0;
  for (int i = 0; i < c; i++) {
    if (idx < ans.size() && ans[idx] < -nc[i]) {
      ans[idx++] = -nc[i];
    }
  }
  int anss = 0;
  for (int i = 0; i < ans.size(); i++)
    anss += ans[i];
  cout << anss << endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int, int> P;

int main() {
  ll x, y, a, b, c, ans;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c), qp, dp(c + 10);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  sort(p.begin(), p.end(), greater<ll>());
  sort(q.begin(), q.end(), greater<ll>());
  sort(r.begin(), r.end(), greater<ll>());
  rep(i, x) {
    qp.push_back(p[i]);
    ans += p[i];
  }
  rep(i, y) {
    qp.push_back(q[i]);
    ans += q[i];
  }
  sort(qp.begin(), qp.end());
  dp[0] = ans;
  // for(int i=1; i<=c; ++i){
  //     dp[i] = max(dp[i-1], dp[i-1]-qp[i-1]+r[i-1]);
  // }
  rep(i, c) {
    if (qp[i] < r[i])
      ans += r[i] - qp[i];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int, int> P;

int main() {
  ll x, y, a, b, c, ans;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c), qp, dp(c + 10);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  sort(p.begin(), p.end(), greater<ll>());
  sort(q.begin(), q.end(), greater<ll>());
  sort(r.begin(), r.end(), greater<ll>());
  rep(i, x) { qp.push_back(p[i]); }
  rep(i, y) { qp.push_back(q[i]); }
  rep(i, c) qp.push_back(r[i]);
  sort(qp.begin(), qp.end(), greater<ll>());
  rep(i, x + y) { ans += qp[i]; }
  cout << ans << endl;
  return 0;
}
Problem p02727 (C++)

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

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repl(i, s, e) for (int i = s; i < e; i++)
#define reple(i, s, e) for (int i = s; i <= e; i++)
#define revrep(i, n) for (int i = n - 1; i >= 0; i--)

#define vll vector<ll>
#define vvll vector<vector<ll>>
#define all(x) (x).begin(), (x).end()

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<ll> p(A);
  rep(i, A) cin >> p[i];

  vector<ll> q(A);
  rep(i, B) cin >> q[i];

  priority_queue<ll> r;
  rep(i, C) {
    ll tmp;
    cin >> tmp;
    r.push(tmp);
  }

  // pの大きい方からX個、qの大きい方からY個とって降順に並べる
  sort(all(p), greater<ll>());
  sort(all(q), greater<ll>());

  priority_queue<ll, vector<ll>, greater<ll>> pq;

  rep(i, X) pq.push(p[i]);
  rep(i, Y) pq.push(q[i]);

  // 貪欲法で小さい方から処理（大きいりんごを残した方が有利）
  ll ans = 0;

  while (!pq.empty()) {
    auto x = pq.top();
    pq.pop();

    if (!r.empty() && x < r.top()) {
      x = r.top();
      r.pop();
    }

    ans += x;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repl(i, s, e) for (int i = s; i < e; i++)
#define reple(i, s, e) for (int i = s; i <= e; i++)
#define revrep(i, n) for (int i = n - 1; i >= 0; i--)

#define vll vector<ll>
#define vvll vector<vector<ll>>
#define all(x) (x).begin(), (x).end()

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<ll> p(A);
  rep(i, A) cin >> p[i];

  vector<ll> q(B);
  rep(i, B) cin >> q[i];

  priority_queue<ll> r;
  rep(i, C) {
    ll tmp;
    cin >> tmp;
    r.push(tmp);
  }

  // pの大きい方からX個、qの大きい方からY個とって降順に並べる
  sort(all(p), greater<ll>());
  sort(all(q), greater<ll>());

  priority_queue<ll, vector<ll>, greater<ll>> pq;

  rep(i, X) pq.push(p[i]);
  rep(i, Y) pq.push(q[i]);

  // 貪欲法で小さい方から処理（大きいりんごを残した方が有利）
  ll ans = 0;

  while (!pq.empty()) {
    auto x = pq.top();
    pq.pop();

    if (!r.empty() && x < r.top()) {
      x = r.top();
      r.pop();
    }

    ans += x;
  }

  cout << ans << endl;

  return 0;
}
Problem p02728 (C++)

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

#define MAXN 100010
#define ll long long

using namespace std;

const int mod = 1e9 + 7;

int n, tot;

ll product = 1;

int head[MAXN], siz[MAXN];

ll f[MAXN];

struct edge {
  int to, next;
} e[MAXN * 2];

void add_edge(int x, int y) {
  e[++tot].to = y;
  e[tot].next = head[x];
  head[x] = tot;
  return;
}

ll qp(ll a, ll b) {
  ll res = 1, base = a;
  while (b) {
    if (b & 1)
      res = (res * base) % mod;
    base = (base * base) % mod;
    b >>= 1;
  }

  return res;
}

void dfs1(int x, int fa) {
  siz[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa)
      continue;
    dfs1(v, x);
    siz[x] += siz[v];
  }

  f[1] = (1ll * f[1] * siz[x]) % mod;
  return;
}

void dfs2(int x, int fa) {
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa)
      continue;
    f[v] =
        (1ll * f[x] * (1ll * (n - siz[v]) * qp(siz[v], mod - 2) % mod)) % mod;
    dfs2(v, x);
  }

  return;
}

int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }

  f[1] = 1;
  dfs1(1, 0);
  dfs2(1, 0);

  for (int i = 1; i <= n; i++) {
    product = (1ll * product * i) % mod;
  }
  for (int i = 1; i <= n; i++) {
    printf("%lld\n", (ll)(1ll * product * qp(f[i], mod - 2)) % mod);
  }
  return 0;
}

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

#define MAXN 200010
#define ll long long

using namespace std;

const int mod = 1e9 + 7;

int n, tot;

ll product = 1;

int head[MAXN], siz[MAXN];

ll f[MAXN];

struct edge {
  int to, next;
} e[MAXN * 2];

void add_edge(int x, int y) {
  e[++tot].to = y;
  e[tot].next = head[x];
  head[x] = tot;
  return;
}

ll qp(ll a, ll b) {
  ll res = 1, base = a;
  while (b) {
    if (b & 1)
      res = (res * base) % mod;
    base = (base * base) % mod;
    b >>= 1;
  }

  return res;
}

void dfs1(int x, int fa) {
  siz[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa)
      continue;
    dfs1(v, x);
    siz[x] += siz[v];
  }

  f[1] = (1ll * f[1] * siz[x]) % mod;
  return;
}

void dfs2(int x, int fa) {
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa)
      continue;
    f[v] =
        (1ll * f[x] * (1ll * (n - siz[v]) * qp(siz[v], mod - 2) % mod)) % mod;
    dfs2(v, x);
  }

  return;
}

int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }

  f[1] = 1;
  dfs1(1, 0);
  dfs2(1, 0);

  for (int i = 1; i <= n; i++) {
    product = (1ll * product * i) % mod;
  }
  for (int i = 1; i <= n; i++) {
    printf("%lld\n", (ll)(1ll * product * qp(f[i], mod - 2)) % mod);
  }
  return 0;
}
Problem p02728 (C++)

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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 1e5 + 5;
ll mod = 1e9 + 7;
vector<ll> node[N];
ll sz[N], dp[N], fact[N], ans[N], n;
ll inv(ll u, ll p) {
  if (p == 0)
    return 1;
  if (p == 1)
    return u;
  ll t = inv(u, p / 2) % mod;
  if (p & 1)
    return t * t % mod * u % mod;
  return t * t % mod;
}
void dfs(ll u, ll p) {
  sz[u] = 1;
  for (auto j : node[u]) {
    if (j != p) {
      dfs(j, u);
      sz[u] += sz[j];
    }
  }
}
ll tot = 1;
void reroot(ll u, ll v) {
  tot = tot * inv(sz[u], mod - 2) % mod * inv(sz[v], mod - 2) % mod;
  sz[u] = n - sz[v];
  sz[v] = n;
  tot = tot * sz[u] % mod * sz[v] % mod;
}
void dfs1(ll u, ll p) {
  ans[u] = fact[n] * inv(tot, mod - 2) % mod;
  for (auto j : node[u]) {
    if (j != p) {
      reroot(u, j);
      dfs1(j, u);
      reroot(j, u);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen(".INP", "r")) {
    freopen(".INP", "r", stdin);
    freopen(".OUT", "w", stdout);
  }
  cin >> n;
  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % mod;
  for (int i = 1; i < n; i++) {
    ll u, v;
    cin >> u >> v;
    node[u].push_back(v);
    node[v].push_back(u);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    tot = (tot * sz[i]) % mod;
  }
  dfs1(1, 0);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
}


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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e5 + 5;
ll mod = 1e9 + 7;
vector<ll> node[N];
ll sz[N], dp[N], fact[N], ans[N], n;
ll inv(ll u, ll p) {
  if (p == 0)
    return 1;
  if (p == 1)
    return u;
  ll t = inv(u, p / 2) % mod;
  if (p & 1)
    return t * t % mod * u % mod;
  return t * t % mod;
}
void dfs(ll u, ll p) {
  sz[u] = 1;
  for (auto j : node[u]) {
    if (j != p) {
      dfs(j, u);
      sz[u] += sz[j];
    }
  }
}
ll tot = 1;
void reroot(ll u, ll v) {
  tot = tot * inv(sz[u], mod - 2) % mod * inv(sz[v], mod - 2) % mod;
  sz[u] = n - sz[v];
  sz[v] = n;
  tot = tot * sz[u] % mod * sz[v] % mod;
}
void dfs1(ll u, ll p) {
  ans[u] = fact[n] * inv(tot, mod - 2) % mod;
  for (auto j : node[u]) {
    if (j != p) {
      reroot(u, j);
      dfs1(j, u);
      reroot(j, u);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen(".INP", "r")) {
    freopen(".INP", "r", stdin);
    freopen(".OUT", "w", stdout);
  }
  cin >> n;
  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % mod;
  for (int i = 1; i < n; i++) {
    ll u, v;
    cin >> u >> v;
    node[u].push_back(v);
    node[v].push_back(u);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    tot = (tot * sz[i]) % mod;
  }
  dfs1(1, 0);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02728 (C++)

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

using namespace std;

const int mod = 1e9 + 7;

int pw(int x, int y) {
  int r = 1;
  while (y) {
    if (y & 1)
      r = 1ll * r * x % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return r;
}
int inv(int x) { return pw(x, mod - 2); }

int n;
vector<int> adj[200005];
int dad[200005];
int sz[120005];
int ans[200005];
int add = 1;

void dfs(int u) {
  sz[u] = 1;
  for (auto v : adj[u]) {
    if (v == dad[u])
      continue;
    dad[v] = u;
    dfs(v);
    sz[u] += sz[v];
  }
  add = 1ll * add * inv(sz[u]) % mod;
}
void dfs2(int u) {
  ans[u] = add;
  for (auto v : adj[u]) {
    if (v == dad[u])
      continue;
    int save = add;
    add = 1ll * add * sz[v] % mod;
    add = 1ll * add * inv(n - sz[v]) % mod;
    dfs2(v);
    add = save;
  }
}

int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i)
    add = 1ll * add * i % mod;
  dfs(1);
  dfs2(1);
  for (int i = 1; i <= n; i++)
    cout << ans[i] << "\n";
  return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

int pw(int x, int y) {
  int r = 1;
  while (y) {
    if (y & 1)
      r = 1ll * r * x % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return r;
}
int inv(int x) { return pw(x, mod - 2); }

int n;
vector<int> adj[200005];
int dad[200005];
int sz[200005];
int ans[200005];
int add = 1;

void dfs(int u) {
  sz[u] = 1;
  for (auto v : adj[u]) {
    if (v == dad[u])
      continue;
    dad[v] = u;
    dfs(v);
    sz[u] += sz[v];
  }
  add = 1ll * add * inv(sz[u]) % mod;
}
void dfs2(int u) {
  ans[u] = add;
  for (auto v : adj[u]) {
    if (v == dad[u])
      continue;
    int save = add;
    add = 1ll * add * sz[v] % mod;
    add = 1ll * add * inv(n - sz[v]) % mod;
    dfs2(v);
    add = save;
  }
}

int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i)
    add = 1ll * add * i % mod;
  dfs(1);
  dfs2(1);
  for (int i = 1; i <= n; i++)
    cout << ans[i] << "\n";
  return 0;
}
Problem p02729 (C++)

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

ll factorial(ll x) {
  if (x == 1 || x == 0) {
    return 1;
  } else {
    return x * factorial(x - 1);
  }
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

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

  int odd = 0, even = 0;

  if (n <= 1)
    even = 0;
  else
    even = combination(n, 2);

  if (m <= 1)
    odd = 0;
  else
    odd = combination(m, 2);

  int ans = even + odd;

  cout << ans << endl;
}

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

ll factorial(ll x) {
  if (x == 1 || x == 0) {
    return 1;
  } else {
    return x * factorial(x - 1);
  }
}

ll combination(ll n, ll r) {
  ll tmp = 1;
  REP(i, r) {
    tmp *= n--;
    tmp /= i + 1;
  }
  return tmp;
}

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

  int odd = 0, even = 0;

  if (n <= 1)
    even = 0;
  else
    even = combination(n, 2);

  if (m <= 1)
    odd = 0;
  else
    odd = combination(m, 2);

  int ans = even + odd;

  cout << ans << endl;
}
Problem p02729 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  int64_t x = 1;
  int64_t y = 1;

  for (int i = 1; i < N + 1; i++) {
    x *= i;
  }
  for (int i = 1; i < N - 1; i++) {
    y *= i;
  }
  int z = x / (2 * y);

  int64_t a = 1;
  int64_t b = 1;

  for (int i = 1; i < M + 1; i++) {
    a *= i;
  }
  for (int i = 1; i < M - 1; i++) {
    b *= i;
  }
  int c = a / (2 * b);

  cout << z + c << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 7;
ll fact(ll x) {
  ll sum = 1;
  for (int i = 2; i <= x; i++) {
    sum *= i;
  }
  return sum;
}
ll p(ll x) { return (fact(x) / (2 * fact(x - 2))); }

int main() {
  ll n, m;
  cin >> n >> m;
  cout << p(n) + p(m);
}
/*
100 100

*/


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 7;

ll p(ll x) { return (x * (x - 1) / 2); }

int main() {
  ll n, m;
  cin >> n >> m;
  cout << p(n) + p(m);
}
/*
100 100

*/
Problem p02729 (C++)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

float sumOfAP(float a, float d, float n) {
  float sum = (n / 2) * (2 * a + (n - 1) * d);
  return sum;
}

void solve() {
  int n, m;
  cin >> n >> m;

  int ans1 = sumOfAP(1, 1, n - 1);
  int ans2 = sumOfAP(1, 1, m - 1);
  cout << ans1 + ans2 << "\n";
}

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  // int t;
  // cin>>t;

  // while(t--)
  solve();

  return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

float sumOfAP(float a, float d, float n) {
  float sum = (n / 2) * (2 * a + (n - 1) * d);
  return sum;
}

void solve() {
  int n, m;
  cin >> n >> m;

  int ans1 = sumOfAP(1, 1, n - 1);
  int ans2 = sumOfAP(1, 1, m - 1);
  cout << ans1 + ans2 << "\n";
}

int main() {

  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt","r",stdin);
  //     freopen("output.txt","w",stdout);
  // #endif

  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  // int t;
  // cin>>t;

  // while(t--)
  solve();

  return 0;
}
Problem p02729 (C++)

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

int factorial(int n) { // 階乗
  long int ans = 0;
  long int ansa = 1;
  long int answ = 1;
  for (int i = 1; i <= n; i++) {
    ansa *= i;
  }
  for (int j = 1; j <= n - 2; j++) {
    answ *= j;
  }

  ans = ansa / (2 * answ);
  return ans;
}
int main() {
  int N = 0; // 偶数の数
  int M = 0; // 奇数の数
  int count1 = 0;
  int count2 = 0;
  cin >> N >> M;

  if (N != 0 && N != 1 && N != 2) {
    count1 = factorial(N);
  }

  else if (N == 2) {
    count1 = 1;
  }

  else {
    count1 = 0;
  }

  if (M != 0 && M != 1 && M != 2) {
    count2 = factorial(M);
  }

  else if (M == 2) {
    count2 = 1;
  }

  else {
    count2 = 0;
  }

  cout << count1 + count2 << endl;
}


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

int factorial(int n) { // 階乗
  double ans = 0;
  double ansa = 1;
  double answ = 1;
  for (int i = 1; i <= n; i++) {
    ansa *= i;
  }
  for (int j = 1; j <= n - 2; j++) {
    answ *= j;
  }

  ans = ansa / (2 * answ);
  return ans;
}
int main() {
  int N = 0; // 偶数の数
  int M = 0; // 奇数の数
  int count1 = 0;
  int count2 = 0;
  cin >> N >> M;

  if (N != 0 && N != 1 && N != 2) {
    count1 = factorial(N);
  }

  else if (N == 2) {
    count1 = 1;
  }

  else {
    count1 = 0;
  }

  if (M != 0 && M != 1 && M != 2) {
    count2 = factorial(M);
  }

  else if (M == 2) {
    count2 = 1;
  }

  else {
    count2 = 0;
  }

  cout << count1 + count2 << endl;
}
Problem p02729 (C++)

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

using namespace std;

int main() {
  int N, M;

  cin >> N >> M;
  int ans = 0;

  if (M == 0 || M == 1) {
    ans = 0;
  } else {
    ans = M;
  }

  if (N == 0 || N == 1) {
    ans += 0;
  } else {
    long f = 1;
    for (long i = 1; i <= N; i++)
      f *= i;
    long n = f;
    f = 1;

    for (long i = 1; i <= N - 2; i++)
      f *= i;
    long nr = f;
    ans += n / (2 * nr);
  }

  cout << ans << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int N, M;

  cin >> N >> M;
  int ans = 0;

  ans = N * (N - 1) / 2 + M * (M - 1) / 2;
  cout << ans << endl;
}
Problem p02729 (C++)

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

int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i;
  return res;
}

int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }

int main() {
  int n, m;
  cin >> n >> m;
  cout << nCr(n, 2) + nCr(m, 2);
}


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

int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i;
  return res;
}

int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2;
}
Problem p02729 (C++)

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

int main() {
  using namespace std;
  long N, M;

  cin >> N >> M;

  int result = N * (N - 1) / 2 + M * (M - 1) / 2;

  cout << result << endl;
  return 1;
}


Fixed submission:
#include <iostream>

int main() {
  using namespace std;
  long N, M;

  cin >> N >> M;

  int result = N * (N - 1) / 2 + M * (M - 1) / 2;

  cout << result << endl;
  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;
ll fast_pow(ll a, ll b, ll mod) {
  ll c = 1;
  while (b >= 2) {
    if (b % 2 == 0)
      a *= a, b /= 2;
    else
      c *= a, a *= a, b--, b /= 2;
    a %= mod, c %= mod;
  }
  return (a * c) % mod;
}
ll cal(ll n, ll m);
int main() {
  int n, m;
  while (cin >> n >> m) {
    ll ans = 0;
    if (n > 1)
      ans += cal(n, 2);
    if (m > 1)
      ans += cal(m, 2);
    cout << ans << endl;
  }
  return 0;
}

ll cal(ll n, ll m) {
  ll up = 1, a = 1, b = 1, c = n - m;
  for (ll i = 1; i <= n; i++)
    up *= i;
  for (ll i = 1; i <= m; i++)
    a *= i;
  for (ll i = 1; i <= c; i++)
    b *= i;
  return up / a / b;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;
ll fast_pow(ll a, ll b, ll mod) {
  ll c = 1;
  while (b >= 2) {
    if (b % 2 == 0)
      a *= a, b /= 2;
    else
      c *= a, a *= a, b--, b /= 2;
    a %= mod, c %= mod;
  }
  return (a * c) % mod;
}
ll cal(ll n, ll m);
int main() {
  int n, m;
  while (cin >> n >> m) {
    ll ans = 0;
    if (n > 1)
      ans += cal(n, 2);
    if (m > 1)
      ans += cal(m, 2);
    cout << ans << endl;
  }
  return 0;
}

ll cal(ll n, ll m) { return n * (n - 1) / 2; }
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int fact(int n) {
  if (n <= 1)
    return 1;
  else
    return n * fact(n - 1);
}
int result(int e, int o) {
  int odd = fact(o) / (2 * fact(o - 2));
  int even = fact(e) / (2 * fact(e - 2));

  return odd + even;
}

int main() {
  int even_no, odd_no;
  cin >> even_no >> odd_no;
  cout << result(even_no, odd_no);
}

Fixed submission:
#include <iostream>
using namespace std;
int fact(int n) {
  if (n <= 1)
    return 1;
  else
    return n * fact(n - 1);
}
int result(int e, int o) {
  int odd = o * (o - 1) / 2;
  int even = e * (e - 1) / 2;

  return odd + even;
}

int main() {
  int even_no, odd_no;
  cin >> even_no >> odd_no;
  cout << result(even_no, odd_no);
}
Problem p02729 (C++)

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

using namespace std;

const int MAX = 1e6;
const int INF = 2e9;
typedef long long ll;

int comb(int n, int r) {

  if (n < r) {
    return 0;
  }

  if (n == r || r == 0) {
    return 1;
  }

  int x = 1;
  int y = 1;
  for (int i = 0; i < n - r; ++i) {
    x = x * (n - i);
    y = y * (i + 1);
  }

  return x / y;
}

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

  int n, m;
  cin >> n >> m;

  cout << comb(n, 2) + comb(m, 2);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>

using namespace std;

const int MAX = 1e6;
const int INF = 2e9;
typedef long long ll;

int comb(int n, int r) {

  if (n < r) {
    return 0;
  }

  if (n == r || r == 0) {
    return 1;
  }

  int x = 1;
  int y = 1;
  for (int i = 0; i < r; ++i) {
    x = x * (n - i);
    y = y * (i + 1);
  }

  return x / y;
}

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

  int n, m;
  cin >> n >> m;

  cout << comb(n, 2) + comb(m, 2);

  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", n, m);
  printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2);
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2);
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
/* SANDEEP YADAv*/
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
lld gcd(lld a, lld b) {
  if (a < b) {
    a = a + b;
    b = a - b;
    a = a - b;
  }
  while (b != 0) {
    lld r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long power(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
void judge() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}

int main() {
  fastio;
  judge();

  lld n, m;
  cin >> n >> m;

  cout << n * (n - 1) / 2 + m * (m - 1) / 2;
  return 0;
}

Fixed submission:
/* SANDEEP YADAv*/
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
lld gcd(lld a, lld b) {
  if (a < b) {
    a = a + b;
    b = a - b;
    a = a - b;
  }
  while (b != 0) {
    lld r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long power(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
void judge() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}

int main() {
  fastio;
  // judge();

  lld n, m;
  cin >> n >> m;

  cout << n * (n - 1) / 2 + m * (m - 1) / 2;
  return 0;
}
Problem p02729 (C++)

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

// マクロ //
#define rep(i, N) for (int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
  int t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

double distance(pii a, pii b) {
  double dist;
  dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
  return dist;
}

lint perm(int a) {
  lint perm = 1;
  for (int i = a; i >= 1; i--) {
    perm *= i;
  }
  return perm;
}

lint comb(lint n, lint m) { return perm(n) / (perm(n - m) * perm(m)); }

// 定数 //
#define pi acos(-1)
// End of Template //

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  lint N, M;
  cin >> N >> M;

  cou(comb(N, 2) + comb(M, 2));
}


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

// マクロ //
#define rep(i, N) for (int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
  int t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

double distance(pii a, pii b) {
  double dist;
  dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
  return dist;
}

lint perm(int a) {
  lint perm = 1;
  for (int i = a; i >= 1; i--) {
    perm *= i;
  }
  return perm;
}

lint comb(lint n, lint m) { return perm(n) / (perm(n - m) * perm(m)); }

// 定数 //
#define pi acos(-1)
// End of Template //

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  lint N, M;
  cin >> N >> M;

  cou(N * (N - 1) / 2 + M * (M - 1) / 2);
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
// file creato da gio il 2020-03-25 09:50:14.759573

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

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;

int counter(int n) {
  int sum = 0;
  for (int i = 1; i < n; i++) {
    sum += (n - i);
  }
  return sum;
}

int main() {
  // freopen("output","w",stdout);
  // freopen("input","r",stdin);
#ifdef FAST
  ios::sync_with_stdio(0);
  cin.tie(0);
#endif

  int N, M;
  cin >> N >> M;
  cout << counter(N) + counter(M) << endl;
}

Fixed submission:
// file creato da gio il 2020-03-25 09:50:14.759573

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

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;

int counter(int n) { return n * (n - 1) / 2; }

int main() {
  // freopen("output","w",stdout);
  // freopen("input","r",stdin);
#ifdef FAST
  ios::sync_with_stdio(0);
  cin.tie(0);
#endif

  int N, M;
  cin >> N >> M;
  cout << counter(N) + counter(M) << endl;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long long int i = 1;
  long long int j = 1;
  long long int p1 = 1;
  long long int p2 = 1;
  long long int c1 = n - 2;
  long long int c2 = m - 2;

  if (n + m >= 2) {

    while (n > 0) {
      i = n * i;
      n--;
    }

    while (m > 0) {
      j = m * j;
      m--;
    }
    if (c1 >= 0 && c2 >= 0) {
      while (c1 > 0) {
        p1 = c1 * p1;
        c1--;
      }
      while (c2 > 0) {
        p2 = c2 * p2;
        c2--;
      }
    }
  }
  p2 = p2 * 2;
  p1 = p1 * 2;

  int o;
  o = i / p1;

  int o1;
  o1 = j / p2;

  cout << o1 + o;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2;
  return 0;
}
Problem p02729 (C++)

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

using namespace std;

int main() {
  int n, m;
  scanf("%d %d", n, m);
  printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2);

  return 0;
}

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

using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2);

  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int kaijou(int a) { return a * kaijou(a - 1); }

int main() {
  int N, M;
  cin >> N >> M;
  N = kaijou(N) / 2;
  M = kaijou(M) / 2;
  cout << N + M << endl;
}

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

int kaijou(int a) { return a * (a - 1); }

int main() {
  int N, M;
  cin >> N >> M;
  N = kaijou(N) / 2;
  M = kaijou(M) / 2;
  cout << N + M << endl;
}