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

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

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define pw(b, p) pow(b, p) + 0.1

// void file(){

//	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 fact(int n){
//	if(n==0 || n==1)
//		return 1;
//	else return n*fact(n-1);
// }

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

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

Error: 0

Fixed submission:

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

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define pw(b, p) pow(b, p) + 0.1

// void file(){

//	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 fact(int n) {
  if (n == 0 || n == 1)
    return 1;
  else
    return n * fact(n - 1);
}

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

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

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

// Returns value of Binomial Coefficient C(n, k)
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);
}

/* Driver code*/
int main() {
  int n, m;
  cin >> n >> m;
  int x;
  if ((n == 0 || n == 1) && (m == 0 || m == 1))
    x = 0;
  else if (n == 0 || n == 1)
    x = binomialCoeff(m, 2);
  else if (m == 0 || m == 1)
    x = binomialCoeff(n, 2);
  else
    x = binomialCoeff(n, 2) + binomialCoeff(m, 2);
  cout << x << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

// Returns value of Binomial Coefficient C(n, k)
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);
}

/* Driver code*/
int main() {
  int n, m;
  cin >> n >> m;
  int x;
  x = binomialCoeff(n, 2) + binomialCoeff(m, 2);
  cout << x << 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 << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int fact(int n);

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

// Returns factorial of n
int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i;
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  cout << nCr(n, 2) + nCr(m, 2) << "\\n";
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
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 <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int combination(int n, int r) {
  if (n == 1)
    return (0);
  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() {
  int n, m;
  cin >> n >> m;

  cout << combination(n, 2) + combination(m, 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;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

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

int main() {
  int n, m;
  long long ans1, ans2;
  cin >> n >> m;
  ans1 = factorial(n) / (factorial(2) * factorial(n - 2));
  ans2 = factorial(m) / (factorial(2) * factorial(m - 2));

  cout << ans1 + ans2;

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

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

// long long Factorial(int n) {
//     long long product = 1;
//     for(int i=2;i<=n;i++)
//         product *= i;
//     return product;
// }

int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  long long res = ((n * (n - 1)) / 2) + ((m * (m - 1)) / 2);
  cout << res << endl;
}

Error: 0

Fixed submission:

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

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

int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  long long res = Factorial(n) / (2 * Factorial(n - 2)) +
                  Factorial(m) / (2 * Factorial(m - 2));
  cout << res << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \\
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \\
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

void solve(ll N, ll M) {
  ll r = (N * (N - 1)) / 2;
  ll l = (M * (M - 1)) / 2;

  ll result = r + l;
  cout << result << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  solve(N, M);
  return 0;
}


Error: 0

Fixed submission:

#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \\
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \\
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

// map<ll, ll> f;

ll fact(ll n, ll ans) {
  if (n <= 1)
    return ans;
  return fact(n - 1, ans * n);
}

void solve(ll N, ll M) {
  ll r1 = fact(N, 1);
  ll r2 = fact(N - 2, 1);
  ll r = r1 / (r2 * 2);
  ll l1 = fact(M, 1);
  ll l2 = fact(M - 2, 1);
  ll l = l1 / (l2 * 2);

  ll result = r + l;
  cout << result << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  solve(N, M);
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  int n_ans = 0;
  int m_ans = 0;
  for (int i = 1; i < n; i++) {
    n_ans += n - i;
  }

  for (int i = 1; i < m; i++) {
    m_ans += m - i;
  }
  cout << n_ans + m_ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  ll n_ans = 1;
  ll n_ans_2 = 1;
  ll m_ans = 1;
  ll m_ans_2 = 1;

  if (n <= 1) {
    n_ans = 0;
  } else {
    for (int i = 1; i <= n; i++) {
      n_ans = n_ans * i;
    }

    for (int i = 1; i <= (n - 2); i++) {
      n_ans_2 = n_ans_2 * i;
    }

    n_ans = n_ans / (2 * n_ans_2);
  }

  if (m <= 1) {
    m_ans = 0;
  } else {
    for (int i = 1; i <= m; i++) {
      m_ans = m_ans * i;
    }

    for (int i = 1; i <= (m - 2); i++) {
      m_ans_2 = m_ans_2 * i;
    }

    m_ans = m_ans / (2 * m_ans_2);
  }

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

Error: WA

Fixed submission:

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

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

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

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

#include <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <float.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;

int digitsSum(int x) {
  int ans = 0;
  while (1) {
    ans += x % 10;
    x /= 10;
    if (x < 1) {
      break;
    }
  }
  return ans;
}

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 <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <float.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;

int main() {

  long long N, M, ans, all, d, odd;
  cin >> N >> M;

  all = 1;

  for (int i = 1; i <= (N + M); i++) {
    all *= i;
  }

  d = 2;

  for (int i = 1; i <= (N + M - 2); i++) {
    d *= i;
  }

  all = all / d;

  odd = N * M;

  ans = all - odd;

  cout << ans << endl;

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

#include <iostream>
using namespace std;

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

  cout << ans;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int kaijyo(int x) {
  if (x == 0) {
    return 1;
  } else {
    return x * kaijyo(x - 1);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  if (n != 1) {
    ans += kaijyo(n) / 2 / kaijyo(n - 2);
  }
  if (m != 1) {
    ans += kaijyo(m) / 2 / kaijyo(m - 2);
  }

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

int calcNumOfCombination(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 a, b;
  cin >> a >> b;

  int c = 0;
  if (a >= 2 && b >= 2) {
    c = calcNumOfCombination(a, 2) + calcNumOfCombination(b, 2);
  } else if (a >= 2 && b < 2) {
    c = calcNumOfCombination(a, 2);
  } else if (a < 2 && b >= 2) {
    c = calcNumOfCombination(b, 2);
  }
  cout << c << endl;

  return 0;
}

Error: -8

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

int cal(int n, int m) {
  int num = 1;
  rep(i, m) { num *= (n - i) / (i - 1); }
  return num;
}
int main() {
  int a, b;
  cin >> a >> b;

  int c = 0;
  if (a >= 2 && b >= 2) {
    c = cal(a, 2) + cal(b, 2);
  } else if (a >= 2 && b < 2) {
    c = cal(a, 2);
  } else if (a < 2 && b >= 2) {
    c = cal(b, 2);
  }
  cout << c << endl;

  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)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre() {}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  pre();

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

  return 0;
}


Error: -6
34b04f5b-f608-406f-b4c7-d9bed1b5de40.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/C++/s051183622.cpp:39: int main(): Assertion `0' failed.


Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre() {}

void solve() {
  int n;
  cin >> n;
  if (n % 2)
    cout << "NO\\n";
  else
    cout << "YES\\n";
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  pre();

  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2;
  assert(0);

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

#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

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

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

ll fac(ll a) {
  if (a <= 1)
    return 1;
  else
    return fac(a - 1) * a;
}

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

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

  if (n <= 1 && m <= 1)
    cout << 0 << endl;
  else if (n <= 1)
    cout << M << endl;
  else if (m <= 1)
    cout << N << endl;
  else
    cout << N + M << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

int even_num, odd_num;

int main() {

  cin >> even_num >> odd_num;

  int even_c = 0, odd_c = 0;

  if (even_num < 2) {
    even_c = 0;
  } else {
    even_c = (even_num * (even_num - 1)) / 2;
  }

  if (odd_num < 2) {
    odd_c = 0;
  } else {
    odd_c = (odd_num * (odd_num - 1)) / 2;
  }

  /*
  cout << kaijo_a << endl;
  cout << kaijo_c << endl;
  cout << even_c << endl;
  cout << odd_c << endl;
  */
  cout << even_c + odd_c << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int even_num, odd_num;

int main() {

  cin >> even_num >> odd_num;

  int even_c = 0, odd_c = 0;
  int64_t kaijo_a = 1, kaijo_b = 1, kaijo_c = 1, kaijo_d = 1;

  for (int i = 1; i <= even_num; i++) {
    kaijo_a *= i;
  }
  for (int i = 1; i <= odd_num; i++) {
    kaijo_b *= i;
  }
  for (int i = 1; i <= even_num - 2; i++) {
    kaijo_c *= i;
  }
  for (int i = 1; i <= odd_num - 2; i++) {
    kaijo_d *= i;
  }

  even_c = kaijo_a / (kaijo_c * 2);
  odd_c = kaijo_b / (kaijo_d * 2);

  if (even_num < 2) {
    even_c = 0;
  }
  if (odd_num < 2) {
    odd_c = 0;
  }
  /*
  cout << kaijo_a << endl;
  cout << kaijo_c << endl;
  cout << even_c << endl;
  cout << odd_c << endl;
  */
  cout << even_c + odd_c << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
#define int long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
int32_t main() {
  int m, n;
  cin >> n >> m;
  int ans = n * (n - 1) / 2;
  int ans1 = m * (m - 1) / 2;
  cout << ans + ans1;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#define int long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
int fact(int k) {
  int p = 1;
  for (int i = 2; i <= k; i++) {
    p = p * i;
  }
  return p;
}
int32_t main() {
  int m, n;
  cin >> n >> m;
  int ans = (fact(n) / (2 * fact(n - 2)));
  int ans1 = (fact(m) / (2 * fact(m - 2)));
  cout << ans + ans1;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int n, m, nc2, mc2;

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

  nc2 = 0.5 * n * (n - 1);
  mc2 = 0.5 * m * (m - 1);

  printf("%d", nc2 + mc2);

  return 0;
}


Error: WA

Fixed submission:

#include <stdio.h>
int fact(int);
int main(void) {
  int n, m, nc2, mc2;
  scanf("%d", &n);
  scanf("%d", &m);

  if (n == 1)
    nc2 == 0;
  else if (m == 1)
    mc2 = 0;
  else {

    nc2 = fact(n) / (fact(2) * fact(n - 2));
    mc2 = fact(m) / (fact(2) * fact(m - 2));
  }
  printf("%d", nc2 + mc2);

  return 0;
}
int fact(int n) {
  int i, f = 1;
  for (i = 1; i <= n; i++) {
    f = f * i;
  }
  return f;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

  int64_t sum1 = 0;
  if (N < 2) {
    sum1 = 0;
  } else if (N == 2) {
    sum1 = 1;
  } else {
    sum1 = N * (N - 1) / 2;
  }

  int64_t sum2 = 0;
  if (M < 2) {
    sum2 = 0;
  } else if (M == 2) {
    sum2 = 1;
  } else {
    sum2 = M * (M - 1) / 2;
  }

  cout << sum1 + sum2 << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int64_t fact(int64_t n) {
  if (n == 1 || n == 0) {
    return 1;
  }
  int64_t sum = 1;
  for (int64_t i = n; i > 0; i--) {
    sum *= i;
  }
  return sum;
}

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

  int64_t sum1 = 0;
  if (N < 2) {
    sum1 = 0;
  } else if (N == 2) {
    sum1 = 1;
  } else {
    sum1 = fact(N) / (fact(N - 2) * 2);
  }

  int64_t sum2 = 0;
  if (M < 2) {
    sum2 = 0;
  } else if (M == 2) {
    sum2 = 1;
  } else {
    sum2 = fact(M) / (fact(M - 2) * 2);
  }

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

#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl "\\n"
ll fact(int a) {
  if (a == 0)
    return 1;
  return a * fact(a - 1);
}
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;

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

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl "\\n"
ll fact(int a) {
  if (a == 0)
    return 1;
  return a * fact(a - 1);
}
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  cout << fact(n) / (2 * fact(n - 2)) + fact(m) / (2 * fact(m - 2));

  return 0;
}