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

#include <iostream>
#include <stdio.h>
using namespace std;

long long int combination(int n, int lb) {
  if (n > lb)
    return (n * combination(n - 1, lb));
  else
    return (1);
}

int main() {

  long long int m, n;
  cin >> n >> m;
  long long int n_odd, n_even;
  n_odd = 0;
  n_even = 0;
  if (n > 1) {
    n_even = combination(n, n - 2) / 2;
  }
  if (m > 1) {
    n_odd = combination(m, m - 2) / 2;
  }
  cout << n_odd + n_even;
  return (0);
}

Error: WA

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

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

int main() {

  long long int m, n;
  cin >> n >> m;
  long long int n_odd, n_even;
  n_odd = 0;
  n_even = 0;
  if (n > 1) {
    n_even = factorial(n) / (factorial(n - 2) * 2);
  }
  if (m > 1) {
    n_odd = factorial(m) / (factorial(m - 2) * 2);
  }
  cout << n_odd + n_even;
  return (0);
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#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

*/


Error: WA

Fixed submission:

#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

*/
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define REPI(x) for (int i = 0; i < x; i++)
#define REPJ(x) for (int j = 0; j < x; j++)

#define REPISE (s, e) for (int i = s, i < e; i++)
#define REPJSE (s, e) for (int j = s, j < e; j++)

using namespace std;

int main() {
  int M, N;
  long long resn = 1, resm = 1;
  cin >> N >> M;

  for (int i = 1; i <= 2; i++) {
    if (N >= 0) {
      resn *= N;
      N--;
    }

    if (M >= 0) {
      resm *= M;
      M--;
    }
  }
  cout << resn / 2 + resm / 2 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REPI(x) for (int i = 0; i < x; i++)
#define REPJ(x) for (int j = 0; j < x; j++)

#define REPISE (s, e) for (int i = s, i < e; i++)
#define REPJSE (s, e) for (int j = s, j < e; j++)

using namespace std;

long long fact(int n) {
  long long res = 1;
  if (n == 0)
    return res;

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

long long comb(int n, int m) {
  if (n < m) {
    return 0;
  }
  return fact(n) / fact(n - m) / fact(m);
}

int main() {
  int M, N;
  cin >> N >> M;
  cout << comb(N, 2) + comb(M, 2) << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  // f.clear();
  int n, m;
  cin >> n >> m;
  int a = max(n, m);
  // func(a);
  // cout<<a<<endl;
  long long num1 = 0;
  long long num2 = 0;

  if (n >= 2) {
    num1 = n * (n - 1) / 2;
  }
  if (m >= 2) {
    num2 = m * (m - 1) / 2;
  }

  cout << num1 + num2 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<long long> f;
void func(int n) {
  long long a = 1;
  f.push_back(1);
  for (int i = 1; i <= n; i++) {
    a *= i;
    f.push_back(a);
  }
}
int main() {
  f.clear();
  int n, m;
  cin >> n >> m;
  int a = max(n, m);
  func(a);
  // cout<<a<<endl;
  long long num1 = 0;
  long long den1 = 0;
  long long num2 = 0;
  long long den2 = 0;
  if (n >= 2) {
    num1 = f[n];
    den1 = f[n - 2];
    num1 = num1 / (2 * den1);
  }
  if (m >= 2) {
    num2 = f[m];
    den2 = f[m - 2];
    num2 = num2 / (2 * den2);
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int M, N, a, b, value;
  cin >> N >> M;
  --N;
  --M;
  a = (N * (N + 1)) / 2;
  b = (M * (M + 1)) / 2;
  value = a + b;
  cout << value;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int fact(int n) {
  int s = 1;
  for (int i = 1; i <= n; i++) {
    s = s * i;
  }
  return s;
}
int main() {
  int N, M, a, b, c, d, value;
  cin >> N >> M;
  a = fact(N);
  b = fact(N - 2);
  c = fact(M);
  d = fact(M - 2);
  value = (a / (2 * b)) + (c / (2 * d));
  cout << value;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int comb(int N, int r) {
  if (r == 1) {
    return N;
  } else if (N == r) {
    return 1;
  } else {
    return comb(N - 1, r) + comb(N - 1, r - 1);
  }
}

int main() {
  int N, M;
  int ans = 0;

  cin >> N >> M;

  if (N >= 2) {
    ans += comb(N, 2);
  }
  if (M >= 2) {
    ans += comb(M, 2);
  }

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

  cout << ans << endl;

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int comb(int N, int r) {
  if (r == 1) {
    return N;
  } else if (N == r) {
    return 1;
  } else {
    return comb(N - 1, r) + comb(N - 1, r - 1);
  }
}

int main() {
  int N, M;
  int ans;

  cin >> N >> M;

  if (N + M > 2) {
    ans = comb(N, 2) + comb(M, 2);
  } else if (N == 2 || M == 2) {
    ans = 1;
  } else {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: 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;
}

Error: WA

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, verdict: Runtime Error

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


Error: 0

Fixed submission:

#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;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error


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

int main() {
  int n, m, s1 = 0, s2 = 0;
  cin >> n >> m;
  if (n >= 2) {
    s1 = (n * (n - 1)) / 2;
  }
  if (m >= 2) {
    s2 = (m * (m - 1)) / 2;
  }
  cout << s1 + s2;
}


Error: WA

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
long long int fact(int n) {
  long long int f = 1;
  for (int i = 1; i <= n; i++) {
    f = f * i;
  }
  return f;
}
long long int C(int n, int r) {
  long long int s;
  if (n >= r) {
    s = fact(n) / ((fact(r)) * (fact(n - r)));
  } else {
    s = 0;
  }
  return s;
}

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

#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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() {
  unsigned n, m;
  cin >> n >> m;
  uintmax_t ans = 0;
  if (n >= 2)
    ans += combination(n, 2);
  if (m >= 2)
    ans += combination(m, 2);
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

long combination(unsigned int n, unsigned int r) {
  if (r * 2 > n)
    r = n - r;
  long dividend = 1;
  long 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;
  long ans = 0;
  if (n != 1)
    ans += combination(n, 2);
  if (m != 1)
    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 factorial(int n, int op = 0) {
  int result = 1;

  if (n < 0) {
    cout << "caution: n must be positive number." << endl;
  }

  if (n == 0) {
    return result;
  }

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

int comb(int x, int y) {
  if (y > x) {
    return 0;
  }

  int result = factorial(x, x - y) / factorial(y);
  return result;
}

int main() {
  int n;
  int m;

  cin >> n >> m;

  // cout << "n: " << n << endl;
  // cout << "m: " << m << endl;
  // cout << "comb(n, 2): " << comb(n, 2) << endl;
  // cout << "comb(m, 2): " << comb(m, 2) << endl;

  double result = comb(n, 2) + comb(m, 2);

  cout << result;

  return 0;
}


Error: WA

Fixed submission:

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

int factorial(int n) {
  int result = 1;

  if (n < 0) {
    cout << "caution: n must be positive number." << endl;
  }

  if (n == 0) {
    return result;
  }

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

int comb(int x, int y) {
  if (y > x) {
    return 0;
  }
  int a = factorial(x);
  int b = factorial(y);
  int c = factorial(x - y);

  // cout << a << "/" << b << "/" <<c << endl;

  int result = a / b / c;
  return result;
}

int main() {
  int n;
  int m;

  cin >> n >> m;

  // cout << "n: " << n << endl;
  // cout << "m: " << m << endl;

  // cout << "comb(n, 2): " << comb(n, 2) << endl;
  // cout << "comb(m, 2): " << comb(m, 2) << endl;

  double result = comb(n, 2) + comb(m, 2);

  cout << result;

  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)

long nCr(int n, int r) {
  long ans = 1;
  for (int i = n; i > n - r; --i) {
    ans = ans * i;
  }
  for (int i = 1; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}

int main() {

  int N, M;

  cin >> N >> M;

  int n = nCr(N, 2);

  int m = nCr(M, 2);

  cout << n + m;
  return 0;
}

Error: WA

Fixed submission:

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

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

int main() {

  int N, M;

  cin >> N >> M;

  int n = fac(N) / (2 * fac(N - 2));

  int m = fac(M) / (2 * fac(M - 2));

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

#include <bits/stdc++.h>

using namespace std;

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

Error: WA

Fixed submission:

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

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

int main() {
  long long int n, m, sum = 0, comb = 0;
  cin >> n >> m;
  if (n >= 2) {
    comb = fact(n) / (fact(2) * fact(n - 2));
    sum = sum + comb;
    cout << comb << endl;
  }
  if (m >= 2) {
    comb = fact(m) / (fact(2) * fact(m - 2));
    sum = sum + comb;
    cout << comb << endl;
  }
  cout << sum << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a, b;
  cin >> a >> b;
  long long total = 0;
  for (int i = a - 1; i > 0; i--)
    total += i;
  for (int i = b - 1; i > 0; i--)
    total += i;
  cout << total;
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b;
  cin >> a >> b;
  long long total = 0;
  for (int i = a - 1; a > 0; i--)
    total += i;
  for (int i = b - 1; b > 0; i--)
    total += i;
  cout << total;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define li(ini) for (ull i = ini;; i++)
#define lfi(i, ini, r) for (ull i = ini; i < r; i++)
#define lfd(i, ini, r) for (ull i = ini; i >= r; i--)
#define lit(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define l(v) for (ull b : v)
#define sorta(v) sort(v.begin(), v.end())
#define sortd(v) sort(v.begin(), v.end(), greater<>())
#define vf(i) v[i].first
#define vs(i) v[i].second
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define en "\\n"

using namespace std;

vector<ll> v;
vector<ll> s;

int main() {
  fast_io

      ll x = 0,
         res = 0, t = 0, i = 0, j = 0, m = 0, n = 0, a = 0, b = 0, c = 0, d = 0,
         sum = 0, flag = 0, flag1 = 1, cont = 0, k = 0;
  // cout<<INT_MIN<<en;

  cin >> n >> m;
  ll proM = 0, proN = 0;
  proN = (n * (n - 1)) / 2;
  proM = (m * (m - 1)) / 2;
  cout << proN + proM << en;

  return 0;
}


Error: 0

Fixed submission:


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define li(ini) for (ull i = ini;; i++)
#define lfi(i, ini, r) for (ull i = ini; i < r; i++)
#define lfd(i, ini, r) for (ull i = ini; i >= r; i--)
#define lit(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define l(v) for (ull b : v)
#define sorta(v) sort(v.begin(), v.end())
#define sortd(v) sort(v.begin(), v.end(), greater<>())
#define vf(i) v[i].first
#define vs(i) v[i].second
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define en "\\n"

using namespace std;

vector<ll> v;
vector<ll> s;
ll fact(ll n) {
  if (n == 0) {
    return 1;
  } else {
    return n * fact(n - 1);
  }
}

int main() {
  fast_io

      ll x = 0,
         res = 0, t = 0, i = 0, j = 0, m = 0, n = 0, a = 0, b = 0, c = 0, d = 0,
         sum = 0, flag = 0, flag1 = 1, cont = 0, k = 0;
  // cout<<INT_MIN<<en;

  cin >> n >> m;
  ll proM = 0, proN = 0;

  if (n < 2 && m < 2) {
    cout << "0" << en;
  } else if (n < 2 && m >= 2) {
    proM = fact(m) / (2 * fact(m - 2));
    cout << proM << en;
  } else if (n >= 2 && m < 2) {
    proN = fact(n) / (2 * fact(n - 2));
    cout << proN << en;
  } else if (m >= 2 && n >= 2) {
    proN = fact(n) / (2 * fact(n - 2));
    proM = fact(m) / (2 * fact(m - 2));
    cout << proN + proM << en;
  }

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

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

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

  int ans = 0;
  int f_n = n >= 2 ? (n * (n - 1)) / 2 : 0;
  int f_m = m >= 2 ? (m * (m - 1)) / 2 : 0;

  ans += (f_n + f_m);

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

Error: 0

Fixed submission:

// abc159_a.cc
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll dp[105] = {0};

ll factorial(ll a) {
  if (a <= 1)
    return 1;
  if (dp[a] != 0)
    return dp[a];
  else
    return dp[a] = (a * factorial(a - 1));
}

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

  ll ans = 0;
  ll f_n = (n >= 2 ? factorial(n) / (factorial(n - 2) * 2) : 0);
  ll f_m = (m >= 2 ? factorial(m) / (factorial(m - 2) * 2) : 0);

  ans += (f_n + f_m);

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

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

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


Error: TLE

Fixed submission:

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

int printNcR(int n, int r) {

  long long p = 1, k = 1;

  if (n - r < r)
    r = n - r;

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

      // gcd of p, k
      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;
  int result = printNcR(n, 2) + printNcR(m, 2);
  cout << result;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for (intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for (intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for (intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin, (x).end()
#define m0(x) memset(x, 0, sizeof(x))
#define fill(x, y) memset(x, y, sizeof(x))
#define length(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, length(a)) cin >> a[i]
#define ccin(i, j, a) rep(i, length(a)) rep(j, length(a[i])) cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define sqrtl sqrt
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9 + 7;
const ld eps = 1.0e-14; //-9
void fp(bool flag) {
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
intl kai(intl k) {
  intl a = 1;
  for (intl i = 1; i <= k; i++) {
    a *= i;
    debug(a);
  }
  return a;
}
int main() {
  intl 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 intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for (intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for (intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for (intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin, (x).end()
#define m0(x) memset(x, 0, sizeof(x))
#define fill(x, y) memset(x, y, sizeof(x))
#define length(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, length(a)) cin >> a[i]
#define ccin(i, j, a) rep(i, length(a)) rep(j, length(a[i])) cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define sqrtl sqrt
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9 + 7;
const ld eps = 1.0e-14; //-9
void fp(bool flag) {
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
intl kai(intl k) {
  if (!k)
    return 1;
  intl a = 1;
  for (int i = 2; i <= k; i++) {
    a *= i;
  }
  return a;
}
int main() {
  intl n, m;
  cin >> n >> m;
  cout << kai(n) / 2 / kai(n - 2) + kai(m) / 2 / kai(m - 2) << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

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

int64_t combination(unsigned int n, unsigned int r) {
  if (r * 2 > n)
    r = n - r;
  int64_t dividend = 1;
  int64_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;
  cout << combination(n, 2) + combination(m, 2) << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int comb(int n, int k) {
  int r = 1;
  for (int d = 1; d <= k; ++d) {
    r *= n--;
    r /= d;
  }
  return r;
}

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

Error: TLE

Fixed submission:

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

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 a = combination(N, 2), b = combination(M, 2);
  cout << a + b << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, n) for (int i = 0; i < n; i++)

int combi(int n, int r) {
  int num = 1;
  for (int i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main() {
  int n, m;
  cin >> n >> m;
  cout << combi(n, 2) + combi(m, 2) << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < n; i++)

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;
  cout << combi(n, 2) + combi(m, 2) << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  // while(1){
  int e, o, ans = 0;
  cin >> e >> o;
  int even, odd;
  for (int i = e - 1; i >= 1; i--) {
    ans = ans + i;
  }
  for (int i = o - 1; i >= 1; i--) {
    ans = ans + i;
  }
  cout << ans << endl;
  //}
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  while (1) {
    int e, o, ans = 0;
    cin >> e >> o;
    int even, odd;
    for (int i = e - 1; i >= 1; i--) {
      ans = ans + i;
    }
    for (int i = o - 1; i >= 1; i--) {
      ans = ans + i;
    }
    cout << ans << endl;
  }
}