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

#include <algorithm>
#include <cctype>
#include <cfloat>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
// #include<conio.h>
#define ReadFile freopen("input.txt", "r", stdin)
#define WriteFile freopen("output.txt", "w", stdout)
#define MEGA_MIND                                                              \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define M_PI 3.14159265358979323846
#define mod 1000000007
#define endl "\\n"
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;

const int N = 5e6 + 5, inf = 2e9;

ll nCr(int n, int r) {
  ll ans = 1;
  ll rFact = 2;
  for (ll i = n - r + 1; i <= n; i++) {
    ans = (ans % mod * i % mod) % mod;
    if (ans % rFact == 0 && rFact <= r) {
      ans = (ans % mod / rFact % mod) % mod;
      rFact++;
    }
  }
  return ans;
}
int main() {
  MEGA_MIND

  int n, m;
  cin >> n >> m;
  cout << nCr(n, 2) + nCr(m, 2) << endl;

  return 0;
}

Error: 0

Fixed submission:

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

ll fact[10006], inv[10006];

void calcFacAndInv(ll n) {
  fact[0] = inv[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = (i * fact[i - 1]);
    //  inv[i] = fp(fact[i], mod - 2);
  }
}
int main() {
  calcFacAndInv(110);
  ll even, odd;
  cin >> even >> odd;
  ll sum = 0;
  //  cout << fact[4] << " " << fact[2] << endl;
  if (even >= 2)
    sum += (fact[even] / (fact[2] * fact[even - 2]));
  if (odd >= 2)
    sum += (fact[odd] / (fact[2] * fact[odd - 2]));
  cout << sum << endl;

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


#include <stdio.h>
int main() {
  int n, m, ans = 0;
  scanf("%d%d", &n, &m);
  if (n >= 2)
    ans += n * (n - 1) / 2;
  if (m >= 2)
    ans += m * (m - 1) / 2;
  printf("%d\\n", ans);
  return 0;
}


Error: WA

Fixed submission:


#include <stdio.h>

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

int main() {

  long long int n, m, i, x = 0;
  scanf("%lld%lld", &m, &n);

  if (m >= 2)
    x += factorial(m) / (factorial(m - 2) * factorial(2));

  if (n >= 2)
    x += factorial(n) / (factorial(n - 2) * factorial(2));

  printf("%lld", x);
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long int a, b, j, k;
  cin >> a >> b;
  j = (a * (a - 1)) / 2;
  k = (b * (b - 1)) / 2;
  cout << j + k << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
long long int fact(long long int n) {
  if (n <= 0 || n == 1)
    return 1;
  else
    return n * fact(n - 1);
}
int main() {
  long long int a, b, j, k;
  cin >> a >> b;
  j = fact(a) / (2 * fact(a - 2));
  k = fact(b) / (2 * fact(b - 2));
  cout << j + k << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
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;
long long int fact(long long int n) {
  if (n > 1) {
    long long int factor = 1;
    for (int i = 2; i <= n; i++)
      factor = factor * i;
    return factor;
  } else
    return 1;
}
int main() {
  long long int n, m, nC2, mC2;
  cin >> n >> m;
  nC2 = fact(n) / (2 * fact(n - 2));
  mC2 = fact(m) / (2 * fact(m - 2));
  cout << nC2 + mC2 << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
#define INF INT_MAX
using namespace std;

int N, M;

int main() {
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
#define INF INT_MAX
using namespace std;

int n, m;
long long a = 1, b = 1, c = 1, d = 1;
long long ans;

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    a *= i;
  }
  for (int i = 1; i <= m; i++) {
    b *= i;
  }
  for (int i = 1; i <= n - 2; i++) {
    c *= i;
  }
  for (int i = 1; i <= m - 2; i++) {
    d *= i;
  }
  ans = (a / (2 * c)) + (b / (2 * d));
  cout << ans << endl;

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

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

unsigned c(unsigned n, unsigned 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() {

  int N, M;
  long long comb1, comb2;
  cin >> N >> M;

  comb1 = N >= 2 ? c(N, 2) : 0;
  comb2 = M >= 2 ? c(M, 2) : 0;

  cout << comb1 + comb2 << endl;
  return 0;
}


Error: 0

Fixed submission:

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

long fact(int n);

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

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

int main() {

  int N, M;
  long comb1, comb2;
  cin >> N >> M;

  comb1 = N >= 2 ? nCr(N, 2) : 0;
  comb2 = M >= 2 ? nCr(M, 2) : 0;

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

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

int combination(int x) {
  if (x <= 1) {
    return 0;
  }
  int ret = 1;
  for (int i = 1; i <= x; i++) {
    ret *= i;
    if (i <= x - 2) {
      ret /= i;
    }
  }
  return ret / 2;
}

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

Error: WA

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

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

#include <bits/stdc++.h>
#define int long long int
#define endl "\\n"
using namespace std;
int printNcR(int n, int r) {

  if (n < r)
    return 0;
  // p holds the value of n*(n-1)*(n-2)...,
  // k holds the value of r*(r-1)...
  long long p = 1, k = 1;

  // C(n, r) == C(n, n-r),
  // choosing the smaller value
  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);

      // dividing by gcd, to simplify product
      // division by their gcd saves from the overflow
      p /= m;
      k /= m;

      n--;
      r--;
    }

    // k should be simplified to 1
    // as C(n, r) is a natural number
    // (denominator should be 1 ) .
  }

  else
    p = 1;

  // if our approach is correct p = ans and k =1
  return p;
  // cout << p << endl;
}
void solve() {
  // Enter your code here Tanmay:)
  int n, m;
  cin >> n >> m;
  int x = printNcR(n, 2) + printNcR(m, 2);
  cout << x << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
/*
int eulortotent(int n)
     {
    //Enter your code here Tanmay:)
    int total=n;
        for(int p=2;p*p<=n;p++)
        {
            if (n%p==0)
        {
            total /= p;
            total *= (p-1);
            while ( n % p == 0 )
                n /= p;
        }
    }

    if(n>1)
    {
        total/=n;
        total*=(n-1);
    }

  return total;
}
*/

Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #define int long long int
#define endl "\\n"
using namespace std;
long long int fact(int n);

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

// Returns factorial of n
long long int fact(int n) {
  long long int res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i;
  return res;
}
void solve() {
  // Enter your code here Tanmay:)
  int n, m;
  cin >> n >> m;
  long long int x = nCr(n, 2) + nCr(m, 2);
  cout << x << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
/*
int eulortotent(int n)
     {
    //Enter your code here Tanmay:)
    int total=n;
        for(int p=2;p*p<=n;p++)
        {
            if (n%p==0)
        {
            total /= p;
            total *= (p-1);
            while ( n % p == 0 )
                n /= p;
        }
    }

    if(n>1)
    {
        total/=n;
        total*=(n-1);
    }

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

// by The_One_Solver
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
long long n, m, f = 1, c = 1, h = 1, odd = 1;
int main() {

  cin >> n >> m;

  cout << (n > 1 ? (n * (n - 1)) / 2 : 0) + (m > 1 ? (m * (m - 1)) / 2 : 0)
       << endl;
}


Error: WA

Fixed submission:

// by The_One_Solver
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
long long n, m, f = 1, c = 1, h = 1, odd = 1;
int main() {

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    c *= i;
    if (i <= (n - 2))
      f *= i;
  }
  for (int i = 1; i <= m; i++) {
    odd *= i;
    if (i <= m - 2)
      h *= i;
  }
  cout << (c / (f * 2)) + (odd / (h * 2));
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define int long long int
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\\n", x)
#define pl(x) printf("%lld\\n", x)
#define ps(s) printf("%s\\n", s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
#define BLK 555
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
int mpow(int base, int exp);
void ipgraph(int m);
const int mod = 1000000007;
const int N = 2e5 + 5, M = N;
//=========================================

int32_t main() {

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

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

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

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define int long long int
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\\n", x)
#define pl(x) printf("%lld\\n", x)
#define ps(s) printf("%s\\n", s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
#define BLK 555
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
int mpow(int base, int exp);
void ipgraph(int m);
const int mod = 1000000007;
const int N = 2e5 + 5, M = N;
//=========================================

int32_t 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 n, m;
  cin >> n >> m;

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

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

#include <iostream>

using namespace std;

int main() {
  long int n, m, s = 0, k = 0, x[1000], l = 1, d = 2;
  cin >> n >> m;
  for (long int j = 1; j <= m; j++) {
    x[k] = l;
    k = k + 1;
    l = l + 2;
  }
  for (long int i = 1; i <= n; i++) {
    x[k] = d;
    k = k + 1;
    d = d + 2;
  }

  for (long int i = 0; i < k; i++) {
    for (long int j = i + 1; j < k; j++)
      if (x[i] == x[j])
        continue;
      else if ((x[i] + x[j]) % 2 == 0)
        s = s + 1;
  }
  cout << s;
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, m, s = 0, k = 0, x[100], l = 1, d = 2;
  cin >> n >> m;
  for (int j = 1; j <= m; j++) {
    x[k] = l;
    k = k + 1;
    l = l + 2;
  }
  for (int i = 1; i <= n; i++) {
    x[k] = d;
    k = k + 1;
    d = d + 2;
  }

  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++)
      if (x[i] == x[j])
        continue;
      else if ((x[i] + x[j]) % 2 == 0)
        s = s + 1;
  }
  cout << s;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;
const int mod = 1000000007;

int combi(int n, int 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;
  // vector<int> A(N);
  // for(int i=0; i<N; i++){cin>>A[i];}
  // vector<vector<int>> A(N,vector<int>(M));
  // for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
  // sort(A.begin(),A.end());
  // for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  // for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  if (N <= 1 && M <= 1)
    cout << 0 << endl;
  else if (N <= 1)
    cout << combi(M, 2) << endl;
  else if (M <= 1)
    cout << combi(N, 2) << endl;
  else
    cout << combi(N, 2) + combi(M, 2) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;
const int mod = 1000000007;

int combi(int n, int 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;
  // vector<int> A(N);
  // for(int i=0; i<N; i++){cin>>A[i];}
  // vector<vector<int>> A(N,vector<int>(M));
  // for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
  // sort(A.begin(),A.end());
  // for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  // for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  if (N == 0 && M == 0)
    cout << 0 << endl;
  else if (N == 0)
    cout << combi(M, 2) << endl;
  else if (M == 0)
    cout << combi(N, 2) << endl;
  else
    cout << combi(N, 2) + combi(M, 2) << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;

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

long long nPr(int n, int r) {
  if (r > n) {
    return 0;
  }
  r = r > (n - r) ? (n - r) : r;
  int _ = n - r;
  long long res = 1;
  while (n > _) {
    res *= n;
    n--;
  }
  return res;
}

long long nCr(int n, int r) {
  if (r > n) {
    return 0;
  }
  r = r > (n - r) ? (n - r) : r;
  return nPr(n, r) / fact(r);
}

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

  long long res = nCr(N, 2) + nCr(M, 2);
  cout << res << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>

using namespace std;

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

long long nPr(int n, int r) { return fact(n) / fact(n - r); }

long long nCr(int n, int r) { return nPr(n, r) / fact(r); }

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

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

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

#define ll long long
#define int ll

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

  int even = (n * (n - 1)) / 2;
  if (even < 0) {
    even = 0;
  }

  int odd = (m * (m - 1)) / 2;
  if (odd < 0) {
    odd = 0;
  }

  cout << even + odd << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define ll long long
#define int ll

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

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

#include <iostream>
#include <stdlib.h>

using namespace std;

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

Error: 1

Fixed submission:


#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  return (n * (n - 1)) / 2 + (m * (m - 1)) / 2;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, sum = 0, sum1 = 0, sum2 = 0;
  cin >> n >> m;
  int i;
  for (i = n - 1; i >= 0; i--) {
    sum1 = sum1 + i;
  }
  for (i = m - 1; i >= 0; i--) {
    sum2 = sum2 + i;
  }
  sum = sum1 + sum2;

  cout << sum << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

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

int main() {

  long long int n, m, i, x = 0;

  cin >> m;
  cin >> n;
  if (m >= 2)
    x += factorial(m) / (factorial(m - 2) * factorial(2));

  if (n >= 2)
    x += factorial(n) / (factorial(n - 2) * factorial(2));

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

#include <stdio.h>
int main() {

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

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int n, m, pass[105], temp1 = 2, temp2 = 1, idx = 0, ans, ctr = 0;

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

  for (int i = 0; i < n; i++) {
    pass[idx++] = temp1;
    temp1 += 2;
  }
  for (int i = 0; i < m; i++) {
    pass[idx++] = temp2;
    temp2 += 2;
  }

  for (int i = 0; i < n + m; i++) {
    for (int j = 0; j < n + m; j++) {
      if (i != j) {
        ans = pass[i] + pass[j];
        if (ans % 2 == 0) {
          ++ctr;
        }
      }
    }
  }
  if (ctr == 0) {
    printf("0\\n");
  } else {
    printf("%d\\n", ctr / 2);
  }
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int N, M;

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

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


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N, M;

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

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

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

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

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

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for (auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
  int n, m;
  cin >> n >> m;
  cout << (n * (n - 1) + m * (m - 1)) / 2;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define int long long
using namespace std;
int kaijo(int x) {
  if (x == 0)
    return 1;
  else
    return (x * kaijo(x - 1));
}
signed main() {
  int n, m;
  cin >> n >> m;
  // cout << (kaijo(n) / (2 * kaijo(n - 2))) + (kaijo(m) / (2 * kaijo(m - 2)));
  if ((n == 1 || n == 0) && (m != 1 && m != 0))
    cout << (kaijo(m) / (2 * kaijo(m - 2)));
  else if ((n != 1 && n != 0) && (m == 1 || m == 0))
    cout << (kaijo(n) / (2 * kaijo(n - 2)));
  else if ((n == 1 || n == 0) && (m == 1 || m == 0))
    cout << 0;
  else
    cout << (kaijo(n) / (2 * kaijo(n - 2))) + (kaijo(m) / (2 * kaijo(m - 2)));
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

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

int facctorialMethod(int k) {
  ll sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
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;
typedef long long ll;

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

ll facctorialMethod(ll k) {
  ll sum = 1;
  for (ll i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
int main() {
  ll n, m;
  cin >> n >> m;
  cout << facctorialMethod(n) / (2 * facctorialMethod(n - 2)) +
              facctorialMethod(m) / (2 * facctorialMethod(m - 2))
       << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

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

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

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

  int odd = 0, even = 0;

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

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

  int ans = even + odd;

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

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

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

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

  int odd = 0, even = 0;

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

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

  int ans = even + odd;

  cout << ans << endl;
}