alexjercan/bugnet huggingface dataset:
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int combination(int n, int r) {
  int tmp = r;
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  } else if (r > n) {
    return 0;
  } else {
    for (int i = r - 1; i >= 1; i--) {
      r *= i;
      n *= n - (tmp - i);
    }
    return n / r;
  }
}

int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  int a = combination(n, 2) + combination(m, 2);
  printf("%d", a);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int combination(int n, int r) {
  if (r == 0 || r == n)
    return (1);
  else if (r == 1)
    return (n);
  return (combination(n - 1, r - 1) + combination(n - 1, r));
}

int main(void) {
  int n, m;
  scanf("%d", &n, &m);
  int a = combination(n, 2) + combination(m, 2);
  printf("%d", a);
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int combination(int n, int r) {
  if (n == 0 || n == 1)
    return 0;
  if (r * 2 > n)
    r = n - r;
  long long dividend = 1;
  long long divisor = 1;
  for (int i = 1; i <= r; ++i) {
    dividend *= (n - i + 1);
    divisor *= i;
  }

  return dividend / divisor;
}

int main() {
  int n, m;
  cin >> n >> m;
  long long ans = 0;
  if (n == 1 && m == 1)
    cout << ans << endl;
  else {
    ans += combination(n, 2);
    ans += combination(m, 2);
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int combination(int n, int r) {
  if (n == 0)
    return 0;
  if (r * 2 > n)
    r = n - r;
  int dividend = 1;
  int 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 == 1 && m == 1)
    cout << ans << endl;
  else {
    ans += combination(n, 2);
    ans += combination(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 count = 0;
  cout << (n * (n - 1) + m * (m - 1)) / 2;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
long long fact(int x) {
  if (x == 1 || x == 0) {
    return 1;
  } else {
    return x * fact(x - 1);
  }
}
long long comb(int x) { return fact(x) / (fact(x - 2) * 2); }

int main() {
  int n, m;
  cin >> n >> m;
  if (n < 2 && m < 2) {
    cout << 0;
  } else if (m < 2) {
    cout << comb(n);
  } else if (n < 2) {
    cout << comb(m);
  } else {
    cout << comb(n) + comb(m);
  }
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
// typedef pair<int, int> P;
// priority_queue<int, vector<int>, greater<int> > q;
const int maxn = 110;
ll qpow(ll a, ll x) {
  ll ret = 1;
  while (x) {
    if (x & 1)
      ret = ret * a % mod;
    a = a * a % mod;
    x >>= 1;
  }
  return ret;
}
ll fac[maxn], inv[maxn];
ll init() {
  fac[0] = 1;
  for (int i = 1; i < maxn; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[maxn - 1] = qpow(fac[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
  return 0;
}
ll c(ll n, ll m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }
int main() {
  IOS;
  init();
  ll ans1, ans2;
  ll n, m;
  cin >> n >> m;
  if (n == 0 || n == 1)
    ans1 = 0;
  else
    ans1 = c(n, 2);
  if (m == 0 || m == 1)
    ans2 = 0;
  else
    ans2 = c(m, 2);
  cout << ans1 + ans2;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
// typedef pair<int, int> P;
// priority_queue<int, vector<int>, greater<int> > q;
int comb(int n, int m) {
  if (n - m < m)
    m = n - m;
  if (m == 0)
    return 1;
  return comb(n - 1, m - 1) * n / m;
}
int main() {
  IOS;
  int n, m;
  cin >> n >> m;
  if (n != 1 && m != 1)
    cout << comb(n, 2) + comb(m, 2);
  else {
    if ((n == 0 && m == 0) || (n == 1 && m == 1)) {
      cout << 0;
      return 0;
    } else if (n == 1 || n == 0) {
      cout << comb(m, 2);
    } else if (m == 1 || m == 0) {
      cout << comb(n, 2);
    }
  }
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define speedrap                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int be(int a, int b, int mod) {
  if (b == 0)
    return 1;
  if (b % 2 == 1)
    return (a * be(a, b - 1, mod)) % mod;
  else
    return (be(a, b / 2, mod) * be(a, b / 2, mod)) % mod;
}
const int mod = 998244353;
#define PI 3.1415926535
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
const int siz = 2 * (1e6 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int fact[siz];
int ifact[siz];
int bit[siz];
bool cmp(const int &a, const int &b) { return (abs(a - b) > 1); }

signed main() {
  // #ifndef ONLINE_JUDGE2
  // freopen("in.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  speedrap int n, m;
  cin >> n >> m;
  int sum = n * (n - 1) + m * (m - 1);
  sum /= 2;
  cout << sum << "\\n";
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define speedrap                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int be(int a, int b, int mod) {
  if (b == 0)
    return 1;
  if (b % 2 == 1)
    return (a * be(a, b - 1, mod)) % mod;
  else
    return (be(a, b / 2, mod) * be(a, b / 2, mod)) % mod;
}
const int mod = 998244353;
#define PI 3.1415926535
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
const int siz = 2 * (1e6 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int fact[siz];
int ifact[siz];
int bit[siz];
bool cmp(const int &a, const int &b) { return (abs(a - b) > 1); }

signed main() {
#ifndef ONLINE_JUDGE2

  freopen("in.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  speedrap int n, m;
  cin >> n >> m;
  int sum = n * (n - 1) + m * (m - 1);
  sum /= 2;
  cout << sum << "\\n";
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

long long int nChoosek(int n, int k) {
  if (k > n)
    return 0;
  if (k * 2 > n)
    k = n - k;
  if (k == 0)
    return 1;

  int result = n;
  for (int i = 2; i <= k; ++i) {
    result *= (n - i + 1);
    result /= i;
  }
  return result;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  long long int sum = 0;
  sum += nChoosek(N, 2);
  sum += nChoosek(M, 2);

  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

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

long long int factorial(int n) {
  long long int result = 1;
  for (int i = 2; i <= n; i++)
    result *= i;
  return result;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  long long int sum = 0;
  if (N == 2)
    sum += 1;
  else if (N > 2)
    sum += (factorial(N) / (2 * factorial(N - 2)));
  if (M == 2)
    sum += 1;
  else if (M > 2)
    sum += (factorial(M) / (2 * factorial(M - 2)));

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

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

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

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  cin >> n;
  cin >> m;
  int res;
  res = (n * (n - 1)) / (m * (m - 1));
  cout << res << '\\n';
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

long long factorial(long long n) {
  long long res = 1;
  for (long long i = 1; i < n + 1; i++) {
    res *= i;
  }
  return res;
}

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

Error: 0

Fixed submission:

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

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

int main(void) {
  int m, n;
  cin >> n >> m;
  long long res;
  cout << factorial(n) / (factorial(n - 2) * 2) +
              factorial(m) / (factorial(m - 2) * 2)
       << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: 0

Fixed submission:

// Code taken from geeksforgeeks

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fact(ll n);
ll nCr(ll n, ll r) {
  ll ans = fact(n) / (fact(r) * fact(n - r));
  return ans;
}

// Returns factorial of n
ll fact(ll n) {
  ll res = 1;
  for (ll i = 2; i <= n; i++)
    res = res * i;
  return res;
}

int main() {
  // 	string s, str, a1, a="", b1, b="";
  // 	cin>>s;
  // 	str=s;

  // 	reverse(str.begin(), str.end());
  // 	for(ll i = 0; i < (s.size()-1)/2; i++)
  // 	{
  // 		a+=s[i];
  // 	}
  // 	a1=a;
  // 	reverse(a1.begin(), a1.end());

  // 	for(ll i = (s.size()+3)/2 -1; i < s.size(); i++)
  // 	{
  // 		b+=s[i];
  // 	}
  // 	b1=b;
  // 	reverse(b1.begin(), b1.end());
  // 	if(s==str and b1==b and a1==a)
  // 		cout<<"Yes"<<endl;
  // 	else cout<<"No"<<endl;
  // ll l;
  // cin>>l;
  // double div=(l*1.0)/3;
  // double ans = pow(div, 3);
  // // cout<<ans<<endl;
  ll n, m, ans = 0;
  // cout <<fixed << setprecision(10)<<ans;
  cin >> n >> m;
  if (n >= 2)
    ans += nCr(n, 2);
  if (m >= 2)
    ans += nCr(m, 2);
  // cout << nCr(n, 2)+nCr(m, 2);
  cout << ans << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define cout(x) cout << x << endl;
// for (int i = 0; i < N; ++i) cin >> A[i];
typedef vector<int> vint;
typedef vector<long> vl;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef map<string, int> mapstri;
typedef map<string, int> mapii;

int main() {
  int N, M;
  cin >> N >> M;
  long long n_ue = 1;
  long long n_shita = 1;
  long long m_ue = 1;
  long long m_shita = 1;
  long long n_ans = 0;
  long long m_ans = 0;
  long long ans;
  if (N > 1) {
    for (int i = N - 1; i < N + 1; ++i) {
      n_ue *= i;
    }
    n_ans = n_ue / 2;
  }
  if (M > 1) {
    for (int i = M - 1; i < M + 1; ++i) {
      m_ue *= i;
    }
    m_ans = m_ue / 2;
  }
  ans = n_ans + m_ans;
  cout(ans);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define cout(x) cout << x << endl;
// for (int i = 0; i < N; ++i) cin >> A[i];
typedef vector<int> vint;
typedef vector<long> vl;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef map<string, int> mapstri;
typedef map<string, int> mapii;

int main() {
  int N, M;
  cin >> N >> M;
  long long n_ue = 1;
  long long n_shita = 1;
  long long m_ue = 1;
  long long m_shita = 1;
  long long n_ans = 0;
  long long m_ans = 0;
  long long ans;
  if (N > 1) {
    for (int i = 1; i < N + 1; ++i) {
      n_ue *= i;
    }
    for (int i = 1; i < N - 1; ++i) {
      n_shita *= i;
    }
    n_ans = n_ue / (n_shita * 2);
  }
  if (M > 1) {
    for (int i = 1; i < M + 1; ++i) {
      m_ue *= i;
    }
    for (int i = 1; i < M - 1; ++i) {
      m_shita *= i;
    }
    m_ans = m_ue / (m_shita * 2);
  }
  ans = n_ans + m_ans;
  cout(ans);
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

long long int f(int num) {

  if (num <= 1) {
    return 1;
  } else {
    return (num * f(num - 1));
  }
}

int combine(int n, int m) { return (n * (n - 1)) / 2; }

int main() {

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

  int n = 0, m = 0;
  cin >> n >> m;

  // cout << combine(13,2)<<endl;
  if (n <= 1 || m <= 1) {
    if (n <= 1 && m <= 1)
      cout << "0";
    else if (n <= 1) {
      cout << combine(m, 2);
    } else if (m <= 1) {
      cout << combine(n, 2);
    }
  } else {
    // cout <<"nnn="<<n<<"m="<<m<<endl;
    // cout <<"re="<< combine(n,2)<<" " <<combine(m,2)<<endl;
    cout << combine(n, 2) + combine(m, 2);
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

long long int f(int num) {

  if (num <= 1) {
    return 1;
  } else {
    return (num * f(num - 1));
  }
}

int combine(int n, int m) { return f(n) / (2 * f(n - 2)); }

int main() {

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

  int n = 0, m = 0;
  cin >> n >> m;

  // cout << combine(13,2)<<endl;
  if (n <= 1 || m <= 1) {
    if (n <= 1 && m <= 1)
      cout << "0";
    else if (n <= 1) {
      cout << combine(m, 2);
    } else if (m <= 1) {
      cout << combine(n, 2);
    }
  } else {
    // cout <<"nnn="<<n<<"m="<<m<<endl;
    // cout <<"re="<< combine(n,2)<<" " <<combine(m,2)<<endl;
    cout << combine(n, 2) + combine(m, 2);
  }

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

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};

vector<vector<long long>> comb(int n, int r) {
  vector<vector<long long>> v(n + 1, std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() {

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

  vector<vector<long long>> v;
  v = comb(100, 2);

  int ans = v[n][2] + v[m][2];
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

int main() {

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

  int ans = combi(n, 2) + combi(m, 2);

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

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

ll kaizyou(ll k);

int main() {
  ll N, M;
  ll even = 0, odd = 0;
  ll ans = 0;
  cin >> N >> M;
  if (N <= 1 && M <= 1) {
    cout << ans << endl;
    return 0;
  }
  if (2 <= N) {
    even = (N * (N - 1)) / 2; // nC2
    // cout << even << endl;
  }
  if (2 <= M) {
    odd = (M * (M - 1)) / 2; // mC2
    // cout << odd << endl;
  }

  ans = even + odd;
  cout << ans << endl;
}

ll kaizyou(ll k) {
  ll sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}

Error: 0

Fixed submission:

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

ll kaizyou(ll k);

int main() {
  ll N, M;
  ll even = 0, odd = 0;
  ll ans = 0;
  cin >> N >> M;
  if (N <= 1 && M <= 1) {
    return ans;
  }
  if (2 <= N) {
    even = kaizyou(N) / (2 * kaizyou(N - 2)); // nC2
    // cout << even << endl;
  }
  if (2 <= M) {
    odd = kaizyou(M) / (2 * kaizyou(M - 2)); // mC2
    // cout << odd << endl;
  }

  ans = even + odd;
  cout << ans << endl;
}

ll kaizyou(ll k) {
  ll sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n; // even is n
  int m; // odd is m
  cin >> n >> m;

  if (n == 1 && m == 1) {
    cout << 0 << endl;
    return 0;
  } else {
    int bunshi = 1;
    for (int i = 0; i < 2; i++) {
      bunshi *= (n + m - i);
    }
    int result = bunshi / 2;

    cout << result - n * m << endl;
    return 0;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int n; // even is n
  int m; // odd is m
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << 0 << endl;
    return 0;
  } else {
    int bunshi = 1;
    int bunbo = 1;
    for (int i = 1; i <= n + m; i++)
      bunshi *= i;
    for (int i = 1; i <= n + m - 2; i++)
      bunbo *= i;
    int result = bunshi / bunbo;
    result /= 2;

    cout << result - n * m << 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;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2;
}

Error: WA

Fixed submission:

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

int kaijou(int n) {
  int r = 1;
  for (int i = 0; i < n; i++) {
    r *= (i + 1);
  }
  return r;
}

int main() {
  int N, M;
  cin >> N >> M;
  int r;
  r = kaijou(N) / kaijou(N - 2) / 2 + kaijou(M) / kaijou(M - 2) / 2;
  cout << r;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int N, M;
  cin >> N >> M;
  // Nから二つ、Mから二つ
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}


Error: 0

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 nCtwo(int n) { return fact(n) / (fact(2) * fact(n - 2)); }

int main(void) {
  int N, M;
  cin >> N >> M;
  // Mから二つ、Nから二つ
  cout << nCtwo(N) + nCtwo(M) << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long fact(long long n) {
  if (n <= 1)
    return 1;
  return n * fact(n - 1);
}
long long nCr(long long n, long long r) {
  return fact(n) / (fact(r) * fact(n - r));
}
long long nCrModp(long long n, long long r, long long p) {
  long long C[r + 1];
  memset(C, 0, sizeof(C));

  C[0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = min(i, r); j > 0; j--)
      C[j] = (C[j] + C[j - 1]) % p;
  }
  return C[r];
}
int main() {
  long long a, b;
  cin >> a >> b;
  if (a < 2)
    a = 0;
  if (b < 2)
    b = 0;
  if (a != 0) {
    a = nCrModp(a, 2, 1000000007);
  }
  if (b != 0)
    b = nCrModp(b, 2, 1000000007);
  cout << a + b;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long fact(long long n) {
  if (n <= 1)
    return 1;
  return n * fact(n - 1);
}
long long nCr(long long n, long long r) {
  return fact(n) / (fact(r) * fact(n - r));
}
int main() {
  long long a, b;
  cin >> a >> b;
  if (a < 2)
    a = 0;
  if (b < 2)
    b = 0;
  if (a != 0) {
    a = nCr(a, 2);
  }
  if (b != 0)
    b = nCr(b, 2);
  cout << a + b;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  // int r=2;
  long ans1 = 1;
  long ans2 = 1;
  for (int i = n; i > n - 2; --i) {
    ans1 = ans1 * i;
  }
  ans1 = ans1 / 2;

  for (int i = m; i > m - 2; --i) {
    ans2 = ans2 * i;
  }
  ans2 = ans2 / 2;

  long ans = ans1 + ans2;

  cout << ans << endl;

  return 0;
}

Error: 1

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int r = 2;
  long ans1 = 1;
  long ans2 = 1;
  for (int i = n; i > n - r; --i) {
    ans1 = ans1 * i;
  }
  ans1 = ans1 / 2;

  for (int i = m; i > m - r; --i) {
    ans2 = ans2 * i;
  }
  ans2 = ans2 / 2;

  long ans = ans1 + ans2;

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fac(ll n) {
  ll ans = (n * (n - 1)) / 2;
  return ans;
}
int main() {
  ll n, m;
  cin >> n >> m;
  ll par = fac(n);
  ll im = fac(m);
  ll ans = par + im;
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fac(ll n) {
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
  }
  return ans;
}
int main() {
  ll n, m;
  cin >> n >> m;
  ll par = (fac(n));
  ll q = (fac(n - 2) * 2);
  if (q == 0) {
    q = 1;
  }
  par /= q;
  ll impar = fac(m);
  ll e = (fac(m - 2) * 2);
  if (e == 0) {
    e = 1;
  }
  impar /= e;
  ll res = par + impar;
  cout << res << endl;
  return 0;
}