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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(a, b) for (ll i = a; i <= b; i++)
#define show(x) cout << x << "\\n"
#define vr vector<ll>
ll fact(ll n);

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

// Returns factorial of n
ll fact(ll n) {
  ll res = 1;
  for (ll i = 2; i <= n; i++)
    res = res * i;
  return res;
}
int main() {
  ll n, m;
  cin >> n >> m;
  if (n < 2 && m >= 2) {
    ll temp = (m - 1) * m / 2;
    show(temp);
  } else if (m < 2 && n >= 2) {
    ll temp = (n - 1) * n / 2;
    show(temp);
  } else if (n < 2 && m < 2) {
    show("0");
  } else {
    ll temp = ((n - 1) * n + (m - 1) * m) / 2;
    show(temp);
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(a, b) for (ll i = a; i <= b; i++)
#define show(x) cout << x << "\\n"
#define vr vector<ll>
ll fact(ll n);

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

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

#include <stdio.h>

int main() {
  long long n, m, ans = 0;
  scanf("%lld%lld", &n, &m);
  while (n > 1)
    ans += --n;
  while (m > 1)
    ans += --m;
  printf("%lld", ans);
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  long long n, m, ans = 0;
  scanf("%lld%lld", &n, &m);
  while (n != 1)
    ans += --n;
  while (m != 1)
    ans += --m;
  printf("%lld", ans);
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;

  if (n == 1 && m != 1) {
    cout << m * (m - 1) / 2 << endl;
  }

  if (n != 1 && m == 1) {
    cout << n * (n - 1) / 2 << endl;
  }

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

Error: TLE

Fixed submission:

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

uintmax_t combination(unsigned int x, unsigned int r) {
  if (r * 2 > x)
    r = x - r;
  uintmax_t dividend = 1;
  uintmax_t divisor = 1;
  for (unsigned int i = 1; i <= r; ++i) {
    dividend *= (x - i + 1);
    divisor *= i;
  }
  return dividend / divisor;
}

#include <iostream>
int main() {
  int n, m;
  cin >> n >> m;

  if (n == 1 && m != 1) {
    std::cout << combination(m, 2) << endl;
  }

  if (n != 1 && m == 1) {
    std::cout << combination(n, 2) << endl;
  } else {
    std::cout << combination(n, 2) + combination(m, 2) << endl;
  }
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

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

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

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

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

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

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


Error: WA

Fixed submission:

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

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

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

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>
typedef long long ll;
typedef long double ld;

using namespace std;

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

  ll count = 0;
  ll n, m;
  cin >> n >> m;

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;

using namespace std;

ll fact(ll n);

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

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

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

  ll count = 0;
  ll n, m;
  cin >> n >> m;

  if (n >= 2)
    count += nCr(n, 2);
  if (m >= 2)
    count += nCr(m, 2);

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

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

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int fact(long long int n) {
  long long int res = 1;
  for (long long int i = 2; i <= n; i++) {
    res = res * i;
  }
  return res;
}
long long int nCr(long long int n, long long int r) {
  return fact(n) / (fact(r) * fact(n - r));
}

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

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long

const int N = 2e5 + 5;
int n, m;

int32_t main() {
  IOS;
  cin >> n >> m;

  int ans = 0;

  if (n >= 2)
    ans += (n * (n - 1)) / 2;
  if (m >= 2)
    ans += (m * (m - 1)) / 2;
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long

const int N = 2e5 + 5;
int n, m;
int fact[101] = {0};

int32_t main() {
  IOS;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i <= 100; i++) {
    fact[i] = i * fact[i - 1];
  }

  if (n >= 2)
    ans += (fact[n] / (fact[n - 2] * 2));
  if (m >= 2)
    ans += (fact[m] / (fact[m - 2] * 2));
  cout << ans;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long long c1 = 0, c2 = 0;
  if (n >= 2) {
    c1 = (n * (n - 1)) / 2;
  }
  if (m >= 2) {
    c2 = (m * (m - 1)) / 2;
  }
  cout << c1 + c2;
}

Error: WA

Fixed submission:

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> v(101);
  for (int i = 1; i < 101; i++) {
    v.at(i) = v.at(i - 1) + i;
  }
  int n, m, ans = 0;
  cin >> n >> m;
  if (n >= 2) {
    ans += v.at(n - 1);
  }
  if (m >= 2) {
    ans += v.at(m - 1);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, ans = 0;
  cin >> n >> m;
  if (n >= 2) {
    ll a = 1;
    ll b = 1;
    for (ll i = 1; i <= n; i++) {
      a *= i;
    }
    for (ll i = 1; i <= n - 2; i++) {
      b *= i;
    }
    ans += a / (b * 2);
  }
  if (m >= 2) {
    ll a = 1;
    ll b = 1;
    for (ll i = 1; i <= m; i++) {
      a *= i;
    }
    for (ll i = 1; i <= m - 2; i++) {
      b *= i;
    }
    ans += a / (b * 2);
  }
  cout << ans << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

long long n, m;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> m;

  long long ansn, ansm;

  ansn = n * (n - 1) / 2;
  ansm = m * (m - 1) / 2;

  cout << ansn + ansm;

  return 0;
}


Error: WA

Fixed submission:

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

long long n, m;

long long fac(long long x) {
  long long ans = 1;

  for (int i = 1; i <= x; i++) {
    ans *= i;
  }
  return ans;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> m;

  long long ansn, ansm;

  ansn = fac(n) / (2 * fac(n - 2));
  ansm = fac(m) / (2 * fac(m - 2));

  cout << ansn + ansm;

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

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

long long combinations(int n) {
  int k = 2;
  ll top = 1;
  for (int i = n; i > 1 && i > n - k; i--) {
    top *= i;
  }
  return top / k;
}

int main() {
  int n, m;
  cin >> n >> m;
  int total = combinations(n) + combinations(m);
  printf("%d\\n", total);
}


Error: 0

Fixed submission:

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

long long combinations(int n) {
  int k = 2;
  ll top = 1;
  for (int i = 2; i <= n; i++) {
    top *= i;
  }
  ll bottom = 1;
  for (int i = 2; i <= n - k; i++) {
    bottom *= i;
  }
  return top / (k * bottom);
}

int main() {
  int n, m;
  cin >> n >> m;
  int total = combinations(n) + combinations(m);
  printf("%d\\n", total);
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

ll bc(ll n, ll k) {
  ll C[k + 1];
  memset(C, 0, sizeof(C));

  C[0] = 1; // nC0 is 1

  for (ll i = 1; i <= n; i++) {

    for (ll j = min(i, k); j > 0; j--)
      C[j] = C[j] + C[j - 1];
  }
  return C[k];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, m;
  cin >> n >> m;
  cout << (bc(n, 2) + bc(m, 2)) << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define allc c.begin(), c.end()
#define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(allc, x) != c.end())
using namespace std;
#define ll long long

ll fact(ll n);

ll nCr(ll n, ll r) { return fact(n) / (fact(r) * fact(n - r)); }
ll fact(ll n) {
  ll res = 1;
  for (ll i = 2; i <= n; i++)
    res = res * i;
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, m;
  cin >> n >> m;
  cout << (nCr(n, 2) + nCr(m, 2)) << 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) + m * (m - 1)) / 2 << endl;
}

Error: WA

Fixed submission:

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

//	string s;
//	getline(cin, s);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

int faktorial(int n) // mmebuat fungsi faktorial, dan menghasilkan suatu nilai
{
  if (n == 0 || n == 1) {
    return 1;
  } else {
    return (n * faktorial(n - 1));
  }
}
int kombinasi(int a, int b,
              int comb) // Membuat prosedural kombinasi b dari a objek yang ada
{
  comb = (faktorial(a)) / (faktorial(b) * faktorial(a - b));
  //	cout << comb;
  return comb;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N, M, combinasigenap, combinasiganjil; // N = genap, M = ganjil
  cin >> N;
  cin >> M;
  //	cout << faktorial(N) << endl;
  //	cout << faktorial(M) << endl;
  if (N > 1 && M > 1) {
    cout << kombinasi(N, 2, combinasigenap) + kombinasi(M, 2, combinasiganjil);
  } else if (N < 2 && M > 1) {
    cout << kombinasi(M, 2, combinasiganjil);
  } else if (M < 2 && N > 1) {
    cout << kombinasi(N, 2, combinasigenap);
  } else if (N < 2 && M < 2) {
    cout << 0;
  }
  // cout << combinasigenap << endl;
  //	cout << kombinasi(M,2,combinasiganjil) << endl;
  // cout << combinasiganjil;
  // cout << TOTAL;

  // Type Your Body of Code Here
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   // 最大値を求める
#define MIN(x) *min_element(ALL(x))   // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 // πの値
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素

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

int main() {
  ll N, K;
  cin >> N >> K;
  cout << cbn(N, 2) + cbn(K, 2);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   // 最大値を求める
#define MIN(x) *min_element(ALL(x))   // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 // πの値
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素

void comb(vector<vector<long long int>> &v) {
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
    }
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<long long int>> v(N + 1, vector<long long int>(N + 1, 0));
  comb(v);
  cout << v[N][2] + v[M][2];
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int count(int i) {
  int result = 0;
  for (int j = 1; j < i; j++) {
    result += j;
  }
  return result;
}
int main() {

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

  cout << count(n) + count(m);
}


Error: TLE

Fixed submission:

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

int main() {

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

  for (int i = 1; n > 0; i++) {
    count += n - i;
  }
  for (int i = 1; m > 0; i++) {
    count += m - i;
  }
  cout << count;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  long long int ans = 0;

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

  ans += (n * (n - 1)) / 2;
  ans += (m * (m - 1)) / 2;

  cout << ans << endl;
}

Error: -11

Fixed submission:

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

long long int fact(long long int n) {

  if (n == 0)
    return 1;

  return n * fact(n - 1);
}

long long int comb(long long int n, long long int r) {

  return (fact(n) / (fact(r) * fact(n - r)));
}

long long int fun(long long int n, long long int m) {

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

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

int kaijou(int n) {
  long j = 1;
  for (int i = 1; i <= n; i++) {
    j *= i;
  }
  return j;
}
int nCr(int n, int r) {
  if (n - r == 0 || r == 0) {
    return 1;
  } else {
    return kaijou(n) / (kaijou(n - r) * kaijou(r));
  }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  if (N == 1 && M == 1) {
    cout << 0 << endl;
  } else if (N < 2) {
    cout << test(M) << endl;
  } else if (M < 2) {
    cout << test(N) << endl;
  } else {
    cout << test(N) + test(M) << endl;
  }
}


Error: 0

Fixed submission:

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

int kaijou(int n) {
  long j = 1;
  for (int i = 1; i <= n; i++) {
    j *= i;
  }
  return j;
}
int nCr(int n, int r) {
  if (n - r == 0 || r == 0) {
    return 1;
  } else {
    return kaijou(n) / (kaijou(n - r) * kaijou(r));
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  if (N == 1 && M == 1) {
    cout << 0 << endl;
  } else if (N < 2) {
    cout << nCr(M, 2) << endl;
  } else if (M < 2) {
    cout << nCr(N, 2) << endl;
  } else {
    cout << nCr(N, 2) + nCr(M, 2) << 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;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long long int i = 1;
  long long int j = 1;
  long long int p1 = 1;
  long long int p2 = 1;
  long long int c1 = n - 2;
  long long int c2 = m - 2;

  if (n + m >= 2) {

    while (n > 0) {
      i = n * i;
      n--;
    }

    while (m > 0) {
      j = m * j;
      m--;
    }
    if (c1 >= 0 && c2 >= 0) {
      while (c1 > 0) {
        p1 = c1 * p1;
        c1--;
      }
      while (c2 > 0) {
        p2 = c2 * p2;
        c2--;
      }
    }
  }
  p2 = p2 * 2;
  p1 = p1 * 2;

  int o;
  o = i / p1;

  int o1;
  o1 = j / p2;

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

#include <iostream>
using namespace std;

int main() {

  int a, b, p, N, M;
  cin >> N >> M;
  if (N < 2 && M < 2) {
    p = 0;
    cout << '0';
  }

  if (N + M > 2) {
    a = (N * (N - 1)) / 2;
    b = (M * (M - 1)) / 2;

    if (N > 2 && M > 2) {
      p = a + b;
      cout << p;
    }
    if (N < 2) {
      cout << b;
    }
    if (M < 2) {
      cout << a;
    }
  }

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int Fact(int x) {
  if (x == 1 || x == 0)
    return 1;
  return (x * Fact(x - 1));
}
int main() {

  int a, b, p, N, M, c, d;
  cin >> N >> M;
  if (N + M > 2) {
    a = Fact(N);
    b = Fact(M);

    if (N < 2 && M < 2) {
      p = 0;
      cout << p;
    }
    if (N > 2 && M > 2) {
      c = Fact(N - 2);
      d = Fact(M - 2);
      p = (a / (c * 2)) + (b / (d * 2));
      cout << p;
    }
    if (N < 2) {
      d = Fact(M - 2);
      p = (b / (d * 2));
      cout << p;
    }
    if (M < 2) {
      c = Fact(N - 2);
      p = (a / (c * 2));
      cout << p;
    }
  }
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  int N; // even
  int M; // odd
  unsigned sum;
  scanf("%d%d", &N, &M);
  sum = (N * N + M * M - M - N) >> 1;
  printf("%d\\n", sum);
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int N; // even
  int M; // odd
  unsigned sum;
  while (scanf("%d%d", &N, &M)) {
    sum = (N * N + M * M - M - N) >> 1;
    printf("%d\\n", sum);
  }
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

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

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

  if (n <= 1 && m <= 1) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;

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

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


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

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

ll kai(ll n) {
  ll kk = 1;
  while (n >= 1) {
    kk *= n;
    n--;
  }
  return kk;
}

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

  if (n <= 1 && m <= 1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;

  if (n >= 2) {
    ans += kai(n) / 2 / kai(n - 2);
  }
  if (m >= 2) {
    ans += kai(m) / 2 / kai(m - 2);
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

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

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

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

int comb(int n, int r) {
  if (n < r) {
    return 0;
  } else {
    return fact(n) / (fact(n - r) * fact(r));
  }
}

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

#include <iostream>

using namespace std;

long long int f(int n) {
  long long int res = 1;
  int x = n;
  for (; n > x - 2; n--)
    res *= n;
  return res;
}

int main(void) {
  long long int N, M;
  long long int ans = 0;
  cin >> N >> M;
  ans = f(N) / 2;
  ans += f(M) / 2;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

long long int f(int n) {
  long long int res = 1;
  for (; n >= 1; n--)
    res *= n;
  return res;
}

int main(void) {
  int N, M;
  long long int ans = 0;
  cin >> N >> M;
  ans = f(N) / (2 * f(N - 2));
  ans += f(M) / (2 * f(M - 2));
  cout << ans << endl;
  return 0;
}