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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define translow transform(s.begin(), s.end(), s.begin(), ::tolower);
#define transup transform(s.begin(), s.end(), s.begin(), ::toupper);
#define endl "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll mod = 1e9 + 7;

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

      ll n,
      m;
  cin >> n >> m;
  ll x = (n * (n - 1)) / 2;
  ll y = (m * (m - 1)) / 2;
  cout << x + y;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define translow transform(s.begin(), s.end(), s.begin(), ::tolower);
#define transup transform(s.begin(), s.end(), s.begin(), ::toupper);
#define endl "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll mod = 1e9 + 7;

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

  ll n, m;
  cin >> n >> m;
  ll x = (n * (n - 1)) / 2;
  ll y = (m * (m - 1)) / 2;
  cout << x + y;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
long long fact(int x) {
  if (x == 0)
    return 1;
  else
    return x * fact(x - 1);
}
long long permu(int x, int r) { return (fact(x) / ((fact(x - r)) * fact(r))); }
int main() {
  fast;
  int n, m;
  long long p, q;
  cin >> n >> m;
  cout << ((n - 1) * n) / 2 + (m * (m - 1)) / 2;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
long long fact(int x) {
  if (x == 0)
    return 1;
  else
    return x * fact(x - 1);
}
long long permu(int x, int r) { return (fact(x) / ((fact(x - r)) * fact(r))); }
int main() {
  fast;
  int n, m;
  long long p, q;
  cin >> n >> m;
  if (n >= 2)
    p = permu(n, 2);
  else
    p = n / 2;
  if (m >= 2)
    q = permu(m, 2);
  else
    q = m / 2;
  cout << p + q;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int a, b, i, j, ans, xans, yans;
  cin >> a >> b;
  xans = 1;
  yans = 1;
  for (i = a; i >= a - 1; i--) {
    xans = xans * i;
  }

  xans = xans / 2;

  for (j = b; j >= b - 1; j--) {
    yans = yans * j;
  }

  yans = yans / 2;

  ans = xans + yans;

  cout << ans << endl;

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int a, b, i, j, ans, xans, yans;
  cin >> a >> b;
  for (i = 1; i <= a; i++) {
    xans = xans * i;
  }

  xans = xans / a;

  for (j = 1; j <= b; j++) {
    yans = yans * j;
  }

  yans = yans / b;

  ans = xans + yans;

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d", &x);
int main() {
  int n, m;
  sc(n) sc(m) ll ans = 0;
  if (n > 1)
    ans += n * (n - 1) / 2;
  if (m > 1)
    ans += m * (m - 1) / 2;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d", &x);

ll fac(ll n) {
  if (n == 1 || n == 0)
    return 1;
  return n * fac(n - 1);
}
int main() {
  int n, m;
  sc(n) sc(m) ll ans = 0;
  if (n > 1)
    ans += fac(n) / (fac(2) * fac(n - 2));
  if (m > 1)
    ans += fac(m) / (fac(2) * fac(m - 2));
  cout << ans << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

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

  int a = 0;
  int b = 0;

  if (n >= 2) {

    a = (n * (n - 1)) / 2;
  }

  if (m >= 2) {
    b = (m * (m - 1)) / 2;
  }

  int total = a + b;
  cout << total << endl;
}


Error: 0

Fixed submission:

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

int main() {

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

  long long an, bn, aan, bbn;
  an = 1;
  bn = 1;
  aan = 1;
  bbn = 1;
  int x = 0;
  int y = 0;

  for (int i = n; i > 0; i--) {
    an = an * i;
    x = 1;
  }
  for (int i = n - 2; i > 0; i--) {
    aan = aan * i;
  }

  an = an / aan;
  an = an / 2;

  for (int i = m; i > 0; i--) {
    bn = bn * i;
    y = 1;
  }
  for (int i = m - 2; i > 0; i--) {
    bbn = bbn * i;
  }

  bn = bn / bbn;
  bn = bn / 2;

  if (x == 0) {
    an = 0;
  }

  if (y == 0) {
    bn = 0;
  }

  int total = an + bn;

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

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X)                                                                  \\
  ({                                                                           \\
    if (1)                                                                     \\
      cerr << "TR: " << (#X) << " = " << (X) << endl;                          \\
  })

vl choose;

int main() {

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

  choose = vl(101, 1);
  choose[0] = 0;
  choose[1] = 0;
  choose[2] = 1;
  FOR(i, 3, 101) { choose[i] = (choose[i - 1] * i) / (i - 2); }

  ll N, M;

  cin >> N >> M;

  cout << choose[N] + choose[M] << endl;
}


Error: 0

Fixed submission:

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X)                                                                  \\
  ({                                                                           \\
    if (1)                                                                     \\
      cerr << "TR: " << (#X) << " = " << (X) << endl;                          \\
  })

vl facs;

ll choose(ll n, ll k) {
  if (k > n)
    return 0;
  return facs[n] / (facs[k] * facs[n - k]);
}

int main() {

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

  facs = vl(150, 1);
  FOR(i, 1, 150) { facs[i] = facs[i - 1] * i; }

  ll N, M;

  cin >> N >> M;

  cout << choose(N, 2) + choose(M, 2) << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

// const ll INF = 1e18L + 5;
// const int INF = 1e9 + 5;

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

  int n, m;
  cin >> n >> m;
  int np = n;
  int mp = m;
  ll cnt = 0;
  rep(i, n) {
    np--;
    rep(j, np) { cnt++; }
  }
  rep(i, m) {
    mp--;
    rep(j, mp) { cnt++; }
  }
  cout << cnt << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

// const ll INF = 1e18L + 5;
// const int INF = 1e9 + 5;

ll factorial(int n) {
  if (n <= 0)
    return 1;
  return n * factorial(n - 1);
}

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

  int n, m;
  cin >> n >> m;
  ll ans_n = factorial(n) / (factorial(2) * factorial(n - 2));
  ll ans_m = factorial(m) / (factorial(2) * factorial(m - 2));
  cout << ans_n + ans_m << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

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

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans++;
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

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

long long fact(long long n) {
  if (n == 0)
    return 1;
  return n * fact(n - 1);
}

int main() {
  long long n, m, ans;
  cin >> n >> m;

  if (n > 1) {
    ans += fact(n) / (fact(n - 2) * 2);
  }
  if (m > 1) {
    ans += fact(m) / (fact(m - 2) * 2);
  }

  cout << ans << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p, a, b) for (int p = a; p < b; p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define INF 0x3f3f3f3f

int C(int n, int r) {
  int ans = 1;
  if (r > n - r)
    r = n - r;

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

  return ans;
}

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

  ll n, k, i, t, ans = 0;
  cin >> n >> k;

  if (n)
    ans = n * (n - 1) / 2;
  if (k)
    ans += k * (k - 1) / 2;
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p, a, b) for (int p = a; p < b; p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define INF 0x3f3f3f3f

int C(int n, int r) {
  int ans = 1;
  if (r > n - r)
    r = n - r;

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

  return ans;
}

int main() {

#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("o2.txt", "w", stdout);
#endif

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

  ll n, k, i, t, ans = 0;
  cin >> n >> k;

  if (n)
    ans = n * (n - 1) / 2;
  if (k)
    ans += k * (k - 1) / 2;
  cout << ans;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int factorial(int n, int lim) {
  int res = 1;
  while (lim--) {
    res *= n;
    n--;
  }
  return res;
}
int main() {
  int N, M;
  int a = 0, b = 0;
  scanf("%d %d", &N, &M);
  if (N > 1)
    a = factorial(N, 2) >> 1;
  if (M > 1)
    b = factorial(M, 2) >> 1;
  printf("%d\\n", a + b);
  return 0;
}

Error: 1

Fixed submission:

#include <iostream>
using namespace std;
long factorial(int n, int lim) {
  long res = 1;
  while (lim--) {
    res *= n;
    n--;
  }
  return res;
}
int main() {
  int N, M;
  long a = 0, b = 0;
  scanf("%d %d", &N, &M);
  if (N > 1)
    a = factorial(N, 2) >> 1;
  if (M > 1)
    b = factorial(M, 2) >> 1;
  printf("%d\\n", a + b);
  return 1;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M, ans;
  cin >> N >> M;
  ans = N * (N - 1) / 2 + M * (M - 1) / 2;
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, a, ans;
  cin >> n >> m;
  if (n == 1 && m == 1)
    cout << "0" << endl;
  else if ((n + m) % 2 != 0) {
    a = n / m + 1;
    ans = pow(m, a);
    cout << ans << endl;
  } else {
    a = n / m;
    ans = pow(m, a);
    cout << ans << endl;
  }
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n, m) for (int i = n; i >= m; i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define mp make_pair
using namespace std;

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int binomialCoeff(int n, int k) {
  // Base Cases
  if (k == 0 || k == n)
    return 1;

  // Recur
  return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}
void solve() {
  int n, m, total = 0;
  cin >> n >> m;
  if (n > 1)
    total += binomialCoeff(n, 2);
  if (m > 1)
    total += binomialCoeff(m, 2);
  cout << total;
}
signed main() {

  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n, m) for (int i = n; i >= m; i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define mp make_pair
using namespace std;

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int binomialCoeff(int n, int k) {
  // Base Cases
  if (k == 0 || k == n)
    return 1;

  // Recur
  return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}
void solve() {
  int n, m, total = 0;
  cin >> n >> m;
  if (n > 1)
    total += binomialCoeff(n, 2);
  if (m > 1)
    total += binomialCoeff(m, 2);
  cout << total;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;

int p(int i) {
  int sum = 0;
  for (int q = i - 1; q > 0; q--)
    sum += q;
  return sum;
}

int main(void) {
  int n, m, sum = 0;
  scanf("%d%d", &n, &m);
  if (n >= 2)
    sum += p(n);
  if (m >= 2)
    sum += p(m);
  printf("%d\\n", sum);
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int p(int i) {
  int sum = 1;
  for (int q = 1; q <= i; q++)
    sum *= q;
  return sum;
}

int main(void) {
  int n, m, sum = 0;
  scanf("%d%d", &n, &m);
  if (n >= 2)
    sum = (p(n) / (p(n - 2) * p(2)));
  if (m >= 2)
    sum += (p(m) / (p(m - 2) * p(2)));
  printf("%d\\n", sum);
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#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;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  long long int n, m, a, sum;
  cin >> n >> m;
  if (n == m)
    cout << "0" << endl;

  else if ((n + m) % 2 != 0) {
    a = n / m + 1;
    sum = pow(m, a);
    cout << sum << endl;
  } else {
    a = n / m;
    sum = pow(m, a);
    cout << sum << endl;
  }
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  cout << (n + m) * (n + m - 1) / 2 - n * m;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int fac(int n) {
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
  }
  return ans;
}

int main() {
  int n, m, ans;
  cin >> n >> m;
  ans = (fac(n) / (fac(n - 2) * 2)) + (fac(m) / (fac(m - 2) * 2));
  cout << ans;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int N, M;
  int Ball[201];

  scanf("%d %d", &N, &M);

  int BallCnt = 0;
  for (int n = 1; n <= N; n++) // even
    Ball[BallCnt++] = 2 * n;

  for (int m = 0; m < M; m++) // odd
    Ball[BallCnt++] = 2 * m + 1;

  int ResultCnt = 0;
  for (int b = 0; b < BallCnt; b++)
    for (int t = 0; t < BallCnt; t++)
      if (b != t)
        if ((Ball[b] + Ball[t]) % 2 == 0)
          ResultCnt++;

  printf("%d", ResultCnt / 2);
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  int N, M;
  int Ball[201];

  freopen("input.txt", "r", stdin);

  scanf("%d %d", &N, &M);

  int BallCnt = 0;
  for (int n = 1; n <= N; n++) // even
    Ball[BallCnt++] = 2 * n;

  for (int m = 0; m < M; m++) // odd
    Ball[BallCnt++] = 2 * m + 1;

  int ResultCnt = 0;
  for (int b = 0; b < BallCnt; b++)
    for (int t = 0; t < BallCnt; t++)
      if (b != t)
        if ((Ball[b] + Ball[t]) % 2 == 0)
          ResultCnt++;

  printf("%d", ResultCnt / 2);
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;

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

  printf("%d\\n", (n * (n - 1)) / 2 + (m * (m - 1)) / 2);

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

long long fact(int x) {
  long long prod = 1;
  for (int i = 2; i <= x; i++) {
    prod *= i;
  }

  return prod;
}

int main() {
  int n, m;

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

  long long ans = fact(n) / (fact(n - 2) * 2) + fact(m) / (fact(m - 2) * 2);

  cout << ans;

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

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

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

Error: 0

Fixed submission:

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

long long factorial(int n) {
  if (n == 0)
    return 1;
  else
    return n * factorial(n - 1);
}

long long combination(int n, int k) {
  if (n < k)
    return 0;
  else if (n == k)
    return 1;
  else if (k < n - k)
    return factorial(n) / factorial(k) / factorial(n - k);
  else
    return combination(n, n - k);
}

int main() {
  int n, m;
  cin >> n >> m;
  cout << combination(n, 2) + combination(m, 2) << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  cout << N * (N - 1) / 2 + M * (M - 1) / 2;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  a %= b;
  return gcd(b, a);
}

int NcR(int n, int r) {
  long long p = 1, k = 1;

  // C(n, r) == C(n, n-r),
  if (n - r < r)
    r = n - r;

  if (r != 0) {
    while (r) {
      p *= n;
      k *= r;

      long long m = gcd(p, k);

      p /= m;
      k /= m;

      n--;
      r--;
    }
  }

  else
    p = 1;

  return p;
}

int main() {
  int N, M;
  cin >> N >> M;

  cout << (M == 1 ? 0 : NcR(M, 2)) + (N == 1 ? 0 : NcR(N, 2)) << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#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;

  return 0;
}


Error: 0

Fixed submission:

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

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

int permutation_calc(int a, int b) {
  return factorial_calc(a) / factorial_calc(a - b);
}

int combination_calc(int a, int b) {
  return permutation_calc(a, b) / factorial_calc(b);
}

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

  if ((n >= 2) && (m >= 2))
    cout << combination_calc(n, 2) + combination_calc(m, 2) << endl;
  else if ((n >= 1) && (m >= 2))
    cout << 1 << endl;
  else if ((n >= 2) && (m >= 1))
    cout << 1 << endl;
  else
    cout << 0 << endl;

  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\\n'
int facctorialMethod(int k) {
  int sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
uintmax_t combination(unsigned int n, unsigned int r) {
  if (r * 2 > n)
    r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor = 1;
  for (unsigned int i = 1; i <= r; ++i) {
    dividend *= (n - i + 1);
    divisor *= i;
  }
  return dividend / divisor;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> nv(n, 2);
  int ans = 0;
  vector<int> mv(m, 1);
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans++;
    }
  }
  for (int i = 0; i < m - 1; i++) {
    for (int j = i + 1; j < m; j++) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\\n'
int facctorialMethod(int k) {
  int sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
uintmax_t combination(unsigned int n, unsigned int r) {
  if (r * 2 > n)
    r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor = 1;
  for (unsigned int i = 1; i <= r; ++i) {
    dividend *= (n - i + 1);
    divisor *= i;
  }
  return dividend / divisor;
}
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  if (n != 0) {
    ans += combination(n, 2);
  }
  if (m != 0) {
    ans += combination(m, 2);
  }
  cout << ans << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

long long fact(long long n, long long m) {
  if (n == 0 || n == 1 || n == m) {
    return 1;
  } else {
    return n * fact(n - 1, m);
  }
}

long long comb(long long n, long long m) { return fact(n, n - m) / fact(m, 1); }

int main() {
  long long ret = 0, a, b;
  cin >> a;
  if (a >= 2) {
    ret += comb(a, 2);
  }
  cin >> b;
  if (b >= 2) {
    ret += comb(b, 2);
  }
  cout << ret << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

long long fact(long long n) {
  if (n == 0 || n == 1) {
    return 1;
  } else {
    return n * fact(n - 1);
  }
}

long long comb(long long n, long long m) {
  return fact(n) / (fact(m) * fact(n - m));
}

int main() {
  long long ret = 0, a, b;
  cin >> a;
  if (a >= 2) {
    ret += comb(a, 2);
  }
  cin >> b;
  if (b >= 2) {
    ret += comb(b, 2);
  }
  cout << ret << endl;
  return 0;
}