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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ub upper_bound
#define int long long
#define vbe(sdk) sdk.begin(), sdk.end()
#define pb push_back
#define loop(i, a, b) for (int i = a; i < b; ++i)
#define rloop(i, a, b) for (int i = a; i >= b; --i)
#define mp make_pair
#define mod 1000000007
#define endl '\\n'
#define vvll vector<vector<int>>
#define vll vector<int>
#define mint map<int, int>
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int, int>
#define F first
#define S second
#define pi 3.14159265358979323846
using namespace std;

signed main() {
  int n, m;
  cin >> n >> m;
  if (n > 1 && m > 1) {
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << "\\n";
  } else if (n > 1) {
    cout << n * (n - 1) / 2 << "\\n";
  } else if (m > 1) {
    cout << m * (m - 1) / 2 << "\\n";
  } else {
    cout << "0\\n";
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ub upper_bound
#define int long long
#define vbe(sdk) sdk.begin(), sdk.end()
#define pb push_back
#define loop(i, a, b) for (int i = a; i < b; ++i)
#define rloop(i, a, b) for (int i = a; i >= b; --i)
#define mp make_pair
#define mod 1000000007
#define endl '\\n'
#define vvll vector<vector<int>>
#define vll vector<int>
#define mint map<int, int>
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int, int>
#define F first
#define S second
#define pi 3.14159265358979323846
using namespace std;

bool isprime(int n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;

  if (n % 2 == 0 || n % 3 == 0)
    return false;

  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;

  return true;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
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;
}

signed main() {
  int n, m;
  cin >> n >> m;
  if (n > 1 && m > 1) {
    cout << nCr(n, 2) * nCr(m, 0) + nCr(n, 0) * nCr(m, 2) << "\\n";
  } else if (n > 1) {
    cout << nCr(n, 2) << "\\n";
  } else if (m > 1) {
    cout << nCr(m, 2) << "\\n";
  } else {
    cout << "0\\n";
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
#define INF 1e8
#define EPS 1e-9
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define PI                                                                     \\
  acos(-1.0) // important constant; alternative #define PI (2.0 * acos(0.0))
ll factorial(int i) {
  if (i == 1 || i == 0)
    return 1;
  return i * factorial(i - 1);
}
int main() {
  ll n, m, sum = 0;
  cin >> n >> m;
  if (n >= 2)
    sum += n * (n - 1) / (2);
  if (m >= 2)
    sum += m * (m - 1) / (2);
  cout << sum << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
#define INF 1e8
#define EPS 1e-9
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define PI                                                                     \\
  acos(-1.0) // important constant; alternative #define PI (2.0 * acos(0.0))
ll factorial(int i) {
  if (i == 1 || i == 0)
    return 1;
  return i * factorial(i - 1);
}
int main() {
  ll n, m, sum = 0;
  cin >> n >> m;
  if (n >= 2)
    sum += factorial(n) / (factorial(2) * factorial(n - 2));
  if (m >= 2)
    sum += factorial(m) / (factorial(2) * factorial(m - 2));
  cout << sum << "\\n";
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

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

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

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

long long fact(int n) {
  long long ans = 1;
  for (int i = n; i > 0; i--) {
    ans *= i;
  }
  return ans;
}

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

  int n, m;
  cin >> n >> m;
  long long ans = fact(n) / (fact(n - 2) * 2) + fact(m) / (fact(m - 2) * 2);
  cout << ans;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int kaijou(int a) { return a * (a - 1); }

int main() {
  int N, M;
  cin >> N >> M;
  N = kaijou(N) / 2;
  M = kaijou(M) / 2;
  cout << N + M << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int kaijou(int a) { return a * kaijou(a - 1); }

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

/*******************************************
 * AUTHOR : Adnan Masroor :-)
 * NICK : adnanlari
 * COLLEGE : NIT Durgapur
 ********************************************/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll MOD = 1000000007, BMOD = 100000000700000;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif*/
  // the main code starts here

  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  if (n != 0 && n != 1)
    ans += n * (n - 1);
  if (m != 0 && m != 1)
    ans += m * (m - 1);
  cout << (ans / 2) << "\\n";

  return 0;
}

Error: WA

Fixed submission:

/*******************************************
 * AUTHOR : Adnan Masroor :-)
 * NICK : adnanlari
 * COLLEGE : NIT Durgapur
 ********************************************/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll MOD = 1000000007, BMOD = 100000000700000;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // the main code starts here

  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  if (n != 0 && n != 1)
    ans += n * (n - 1);
  if (m != 0 && m != 1)
    ans += m * (m - 1);
  cout << (ans / 2) << "\\n";

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

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define ALL(s) (s).begin(), (s).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define si set<int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define tc(t)                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  int t2 = 1;                                                                  \\
  while (t--)
#define _                                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
const ll MOD = 998244353;
const ll INF = 1 << 29;
const ll MAX_N = 1e6 + 7;

ll ncr(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;
      long long m = __gcd(p, k);
      p /= m;
      k /= m;

      n--;
      r--;
    }
  }

  else
    p = 1;

  return p;
}
int main() {
  _ int a, b;
  cin >> a >> b;
  ll ans = 0;

  if (a > 1) {
    ans += ncr(a, 2);
    // cout << ans << "\\n";
  }
  if (b > 1) {
    ans += ncr(b, 2);
  }

  cout << ans << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define ALL(s) (s).begin(), (s).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define si set<int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define tc(t)                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  int t2 = 1;                                                                  \\
  while (t--)
#define _                                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
const ll MOD = 998244353;
const ll INF = 1 << 29;
const ll MAX_N = 1e6 + 7;

ll fact(int n);

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

ll fact(int n) {
  ll res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i;
  return res;
}
int main() {
  _ int a, b;
  cin >> a >> b;
  ll ans = 0;

  if (a > 1) {
    ans += ncr(a, 2);
    // cout << ans << "\\n";
  }
  if (b > 1) {
    ans += ncr(b, 2);
  }

  cout << ans << "\\n";
}
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: WA

Fixed submission:

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

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

int main() {
  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;
}


Error: WA

Fixed submission:

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

int facctorialMethod(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 ans = 0;
  if (n >= 2) {
    ans += facctorialMethod(n) / (2 * facctorialMethod(n - 2));
  }
  if (m >= 2) {
    ans += facctorialMethod(m) / (2 * facctorialMethod(m - 2));
  }
  cout << ans;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

long double kaijo(long double x) {
  long double y = 1;
  for (long double i = x; i > 0; i--)
    y *= i;
  return y;
}

long double combination(long double a) { return kaijo(a) / (2 * kaijo(a - 2)); }

long double kazu(long double a) {
  if (a > 2) {
    return combination(a);
  } else if (a == 2) {
    return 1;
  } else {
    return 0;
  }
}

int main(void) {
  long double i, j, k, l;
  int N, M;
  std::cin >> N >> M;
  printf("%llu\\n", (unsigned long long)(kazu(N) + kazu(M) + 1E-14));
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

unsigned long long kaijo(unsigned long long x) {
  unsigned long long y = 1;
  for (unsigned long long i = x; i > 0; i--)
    y *= i;
  return y;
}

unsigned long long combination(unsigned long long a) {
  return kaijo(a) / (2 * kaijo(a - 2));
}

unsigned long long kazu(unsigned long long a) {
  if (a > 2) {
    return combination(a);
  } else if (a == 2) {
    return 1;
  } else {
    return 0;
  }
}

int main(void) {
  unsigned long long i, j, k, l;
  unsigned long long N, M;
  std::cin >> N >> M;
  printf("%llu\\n", kazu(N) + kazu(M));
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

// file creato da gio il 2020-03-25 09:50:14.759573

#include <bits/stdc++.h>
#define FAST

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \\
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;

int counter(int n) { return n * (n - 1) / 2; }

int main() {
  // freopen("output","w",stdout);
  // freopen("input","r",stdin);
#ifdef FAST
  ios::sync_with_stdio(0);
  cin.tie(0);
#endif

  int N, M;
  cin >> N >> M;
  cout << counter(N) + counter(M) << endl;
}

Error: 0

Fixed submission:

// file creato da gio il 2020-03-25 09:50:14.759573

#include <bits/stdc++.h>
#define FAST

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \\
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;

int counter(int n) {
  int sum = 0;
  for (int i = 1; i < n; i++) {
    sum += (n - i);
  }
  return sum;
}

int main() {
  // freopen("output","w",stdout);
  // freopen("input","r",stdin);
#ifdef FAST
  ios::sync_with_stdio(0);
  cin.tie(0);
#endif

  int N, M;
  cin >> N >> M;
  cout << counter(N) + counter(M) << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int m, n;
  long ans;
  while (cin >> m >> n) {
    ans = 0;
    long temp1 = m <= 1 ? 0 : ((m * (m - 1)) / 2);
    long temp2 = n <= 1 ? 0 : ((n * (n - 1)) / 2);
    ans += temp1;
    ans += temp2;
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

int main() {
  int m, n;
  long ans;
  while (cin >> m >> n) {
    ans = 0;
    long temp1 =
        m <= 1 ? 0 : (factorial(m) / (factorial(m - 2) * factorial(2)));
    long temp2 =
        n <= 1 ? 0 : (factorial(n) / (factorial(n - 2) * factorial(2)));
    ans += temp1;
    ans += temp2;
    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;
  cout << (N * N + M * M - N - M) / 2 << endl;
}

Error: 0

Fixed submission:

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

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

  int all = 1;
  int A = 1;

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

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

  cout << all / 2 / A - N * M << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

// aCb
int comb(int a) {
  int bunshi = 1;
  for (int i = 0; i < 2; i++) {
    bunshi *= (a - i);
  }

  return bunshi / 2;
}

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

  int result = 0;
  if (N > 1) {
    // n! / 2 * (N-2)!
    result += comb(N);
  }

  if (M > 1) {

    result += comb(M);
  }

  cout << result;

  return 0;
}

Error: WA

Fixed submission:

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

int facctorialMethod(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 result = 0;
  if (N > 1) {
    result +=
        facctorialMethod(N) / (facctorialMethod(2) * facctorialMethod(N - 2));
  }

  if (M > 1) {

    result +=
        facctorialMethod(M) / (facctorialMethod(2) * facctorialMethod(M - 2));
  }

  cout << result;

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

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

// マクロ //
#define rep(i, N) for (int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
  int t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

double distance(pii a, pii b) {
  double dist;
  dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
  return dist;
}

lint perm(int a) {
  lint perm = 1;
  for (int i = a; i >= 1; i--) {
    perm *= i;
  }
  return perm;
}

lint comb(lint n, lint m) { return perm(n) / (perm(n - m) * perm(m)); }

// 定数 //
#define pi acos(-1)
// End of Template //

int main() {

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

  lint N, M;
  cin >> N >> M;

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


Error: 0

Fixed submission:

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

// マクロ //
#define rep(i, N) for (int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
  int t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

double distance(pii a, pii b) {
  double dist;
  dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
  return dist;
}

lint perm(int a) {
  lint perm = 1;
  for (int i = a; i >= 1; i--) {
    perm *= i;
  }
  return perm;
}

lint comb(lint n, lint m) { return perm(n) / (perm(n - m) * perm(m)); }

// 定数 //
#define pi acos(-1)
// End of Template //

int main() {

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

  lint N, M;
  cin >> N >> M;

  cou(comb(N, 2) + comb(M, 2));
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

/**
        Language: C++ 11
        Author  : ebby21
**/

#include <bits/stdc++.h>

using namespace std;

#define FASTIO()                                                               \\
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define DEBUG(var) cerr << '\\n' << #var << "\\t:\\t" << var << '\\n'
#define FORF(i, L, U) for (ll i = (L); i <= (U); ++i)
#define FORR(i, U, L) for (ll i = (U); i >= (L); --i)
#define FORE(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int main() {
  FASTIO();
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  if (m >= 2) {
    ans += (m * (m - 1LL)) / 2;
  }
  if (n >= 2) {
    ans += (n * (n - 1LL)) / 2;
  }
  cout << ans << '\\n';
  return 0;
}


Error: WA

Fixed submission:

/**
        Language: C++ 11
        Author  : ebby21
**/

#include <bits/stdc++.h>

using namespace std;

#define FASTIO()                                                               \\
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define DEBUG(var) cerr << '\\n' << #var << "\\t:\\t" << var << '\\n'
#define FORF(i, L, U) for (ll i = (L); i <= (U); ++i)
#define FORR(i, U, L) for (ll i = (U); i >= (L); --i)
#define FORE(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int main() {
  FASTIO();
  int n, m;
  cin >> n >> m;
  vector<ll> fact(2, 1);
  FORF(i, 2, max(m, n)) { fact.push_back(fact[fact.size() - 1] * i); }
  ll ans = 0;
  if (n > 2)
    ans += fact[n] / (fact[2] * fact[n - 2]);
  if (m > 2)
    ans += fact[m] / (fact[2] * fact[m - 2]);
  cout << ans << '\\n';
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

// Mehul Mathur randi hai
// Murali big ghey
// RisHiH is slave
// Anamaya is Sexy
// Arihanth is gay

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

ll ncr(ll n, ll r) {
  long long p = 1, k = 1;

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

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

      long long m = __gcd(p, k);

      p /= m;
      k /= m;

      n--;
      r--;
    }
  } else
    p = 1;

  return p;
}

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

  ll ans = 0;

  if (m > 1) {
    ans = ncr(m, 2);
  }

  if (n > 1) {
    ans = ans + ncr(n, 2);
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

// Mehul Mathur randi hai
// Murali big ghey
// RisHiH is slave
// Anamaya is Sexy
// Arihanth is gay

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

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

  vector<ll> ncr(1000);

  ncr[0] = 1;
  for (int i = 1; i <= 1000; i++)
    ncr[i] = ncr[i - 1] * i;

  ll ans = 0;

  if (m > 1) {
    ans = ncr[m] / (ncr[m - 2] * 2);
  }

  if (n > 1) {
    ans = ans + (ncr[n] / (ncr[n - 2] * 2));
  }

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

#include <iostream>
#include <vector>

unsigned long long pascal(int n, int r, int dup) {
  int nn;
  unsigned long long *a =
      (unsigned long long *)calloc(n, sizeof(unsigned long long));
  unsigned long long retv;

  nn = (dup) ? (n + r - 1) : n;
  if (nn - r < r)
    r = nn - r;
  if (r == 0)
    return 1;
  if (r == 1)
    return nn;
  for (int i = 1; i < r; i++)
    a[i] = i + 2;
  for (int i = 3; i <= nn - r + 1; i++) {
    a[0] = i;
    for (int j = 1; j < r; j++)
      a[j] += a[j - 1];
  }
  retv = a[r - 1];
  free(a);

  return retv;
}

int main(void) {
  int n, m;
  std::cin >> n >> m;

  long long cnt = 0;
  cnt += pascal(n, 2, 0);
  cnt += pascal(m, 2, 0);

  std::cout << cnt << std::endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

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

int main(void) {
  int n, m;
  std::cin >> n >> m;

  int64_t cnt = 0;
  cnt += facctorial(n) / (2 * facctorial(n - 2));
  cnt += facctorial(m) / (2 * facctorial(m - 2));

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

#include <bits/stdc++.h>

using namespace std;

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

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  return 0;
}