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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005
ll n, a, b, f[N], g = 1, mod = 1e9 + 7, fac[N], inv[N], size[N];
vector<int> v[N];
ll pows(ll x, ll y) {
  ll ans = 1;
  while (y) {
    if (y & 1)
      ans = ans * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
void pre(ll x, ll fa) {
  size[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int h = v[x][i];
    if (h == fa)
      continue;
    pre(h, x);
    size[x] += size[h];
  }
  g = g * size[x] % mod;
}
void dfs(ll x, ll fa) {
  for (int i = 0; i < v[x].size(); i++) {
    int h = v[x][i];
    if (h == fa)
      continue;
    f[h] = f[x] * (n - size[h]) % mod * pows(size[h], mod - 2) % mod;
    dfs(h, x);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  ll nl = 1;
  for (int i = 1; i <= n; i++)
    nl = nl * i % mod;
  pre(1, 1);
  f[1] = g;
  dfs(1, 1);
  for (int i = 1; i <= n; i++)
    printf("%lld\\n", nl * pows(f[i], mod - 2) % mod);
}

Error: 0

Fixed submission:

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

inline int read() {
  int sum = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      ff = -1;
    ch = getchar();
  }
  while (isdigit(ch))
    sum = sum * 10 + (ch ^ 48), ch = getchar();
  return sum * ff;
}

const int N = 1e5 + 5;
const int mo = 998244353;

int n, m, ans, siz[N], f[N], inv[N], jc[N];
vector<int> G[N];

inline int ksm(int x, int y) {
  int ret = 1ll;
  while (y) {
    if (y & 1)
      ret = ret * x % mo;
    x = x * x % mo;
    y >>= 1ll;
  }
  return ret;
}

inline int C(int x, int y) {
  return jc[x] % mo * inv[x - y] % mo * inv[y] % mo;
}

inline void dfs(int u, int fa) {
  f[u] = 1, siz[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa)
      continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
  int sum = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa)
      continue;
    f[u] = (f[u] * C(siz[u] - sum - 1, siz[v]) % mo * f[v] + mo) % mo;
    sum += siz[v];
  }
}

inline void dp(int u, int fa) {
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa)
      continue;
    int las =
        (f[u] * ksm(C(n - 1, siz[v]), mo - 2) % mo) * ksm(f[v], mo - 2) % mo;
    f[v] = f[v] * C(n - 1, n - siz[v]) % mo * las % mo;
    dp(v, u);
  }
}

signed main() {
  n = read();
  jc[0] = inv[0] = 1;
  for (int i = 1; i <= n; i++)
    jc[i] = jc[i - 1] * i % mo;
  for (int i = 1; i <= n; i++)
    inv[i] = ksm(jc[i], mo - 2) % mo;
  for (int i = 1; i < n; i++) {
    int x, y;
    x = read(), y = read();
    G[x].pb(y);
    G[y].pb(x);
  }
  dfs(1, 0);
  dp(1, 0);
  for (int i = 1; i < n; i++)
    printf("%lld\\n", f[i] % mo);
  printf("%lld\\n", f[n - 1]);
  return 0;
}
Problem p02728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
int N;
vector<vector<int>> G;
vector<ll> fact, invfact;
vector<map<int, pair<int, ll>>> memo;
ll modpow(ll x, int y) {
  ll r = 1;
  while (y > 0) {
    if (y & 1)
      (r *= x) %= mod;
    (x *= x) %= mod;
    y >>= 1;
  }
  return r;
}
pair<int, ll> f(int p, int q) {
  if (memo[p].count(q))
    return memo[p][q];
  int res1 = 1;
  ll res2 = 1;
  if (memo[p].count(N)) {
    res1 = memo[p][N].first;
    res2 = memo[p][N].second;
    (res2 *= invfact[res1 - 1]) %= mod;
    auto pp = f(q, p);
    res1 -= pp.first;
    (res2 *= modpow(pp.second, mod - 2)) %= mod;
    (res2 *= fact[pp.first]) %= mod;
    (res2 *= fact[res1 - 1]) %= mod;
  } else {
    for (const auto &x : G[p])
      if (x != q) {
        auto pp = f(x, p);
        res1 += pp.first;
        (res2 *= pp.second) %= mod;
        (res2 *= invfact[pp.first]) %= mod;
      }
    (res2 *= fact[res1 - 1]) %= mod;
  }
  // cerr << p << " " << q << " " << res1 << " " << res2 << endl;
  return memo[p][q] = {res1, res2};
}
int main() {
  cin >> N;
  G.resize(N);
  fact.resize(N + 1);
  invfact.resize(N + 1);
  fact[0] = invfact[0] = 1;
  for (int i = 1; i <= N; ++i) {
    fact[i] = fact[i - 1] * i % mod;
    invfact[i] = modpow(fact[i], mod - 2);
  }
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  memo.resize(N);

  vector<pair<int, int>> hoge;
  for (int i = 0; i < N; ++i)
    hoge.push_back({(int)G[i].size(), i});
  sort(hoge.rbegin(), hoge.rend());

  vector<int> res(N);
  for (auto pp : hoge) {
    int i = pp.second;
    res[i] = f(i, N).second;
  }
  for (int i = 0; i < N; ++i) {
    cout << res[i] << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
int N;
vector<vector<int>> G;
vector<ll> fact, invfact;
vector<map<int, pair<int, ll>>> memo;
pair<int, ll> f(int p, int q) {
  if (memo[p].count(q))
    return memo[p][q];
  int res1 = 1;
  ll res2 = 1;
  for (const auto &x : G[p])
    if (x != q) {
      auto pp = f(x, p);
      res1 += pp.first;
      (res2 *= pp.second) %= mod;
      (res2 *= invfact[pp.first]) %= mod;
    }
  (res2 *= fact[res1 - 1]) %= mod;
  // cerr << p << " " << q << " " << res1 << " " << res2 << endl;
  return memo[p][q] = {res1, res2};
}
ll modpow(ll x, int y) {
  ll r = 1;
  while (y > 0) {
    if (y & 1)
      (r *= x) %= mod;
    (x *= x) %= mod;
    y >>= 1;
  }
  return r;
}
int main() {
  cin >> N;
  G.resize(N);
  fact.resize(N + 1);
  invfact.resize(N + 1);
  fact[0] = invfact[0] = 1;
  for (int i = 1; i <= N; ++i) {
    fact[i] = fact[i - 1] * i % mod;
    invfact[i] = modpow(fact[i], mod - 2);
  }
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  memo.resize(N);
  for (int i = 0; i < N; ++i) {
    auto p = f(i, N);
    cout << p.second << endl;
  }
}
Problem p02728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define N (int)3e5
using namespace std;
int n;
struct Edge {
  int v, nxt;
} edge[N << 1];
int fst[N], ecnt;
void add_edge(int u, int v) {
  edge[ecnt].v = v, edge[ecnt].nxt = fst[u], fst[u] = ecnt++;
}
void init_e() { memset(fst, -1, sizeof(fst)); }

int ksm(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1)
      (ret *= x) %= MOD;
    (x *= x) %= MOD;
    y >>= 1;
  }
  return ret;
}

int inv(int x) { return ksm(x, MOD - 2); }

int sz[N], dp1[N], dp2[N];
void DP1(int u, int f) {
  sz[u] = 1;
  dp1[u] = 1;
  for (int e = fst[u]; e != -1; e = edge[e].nxt) {
    int v = edge[e].v;
    if (v == f)
      continue;
    DP1(v, u);
    sz[u] += sz[v];
    (dp1[u] *= dp1[v]) %= MOD;
  }
  (dp1[u] *= sz[u]) %= MOD;
  //	cout << u << " " << dp1[u] << endl;
}
void DP2(int u, int f) {
  if (u != 1)
    dp2[u] = dp2[f] * (n - sz[u]) % MOD * inv(sz[u]) % MOD;
  //	cout << u << " " << dp2[u] << endl;
  for (int e = fst[u]; e != -1; e = edge[e].nxt) {
    int v = edge[e].v;
    if (v == f)
      continue;
    DP2(v, u);
  }
}

signed main() {
  init_e();

  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    add_edge(u, v);
    add_edge(v, u);
  }

  DP1(1, 0);
  dp2[1] = dp1[1];
  DP2(1, 0);

  int tmp = 1;
  for (int i = 1; i <= n; i++)
    (tmp *= i) %= MOD;

  for (int i = 1; i <= n; i++)
    cout << (1ll * tmp * inv(dp2[i]) % MOD) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define N (int)2e5
using namespace std;
int n;
struct Edge {
  int v, nxt;
} edge[N << 1];
int fst[N], ecnt;
void add_edge(int u, int v) {
  edge[ecnt].v = v, edge[ecnt].nxt = fst[u], fst[u] = ecnt++;
}
void init_e() { memset(fst, -1, sizeof(fst)); }

ll ksm(int x, int y) {
  ll ret = 1;
  while (y) {
    if (y & 1)
      ret = 1ll * ret * x % MOD;
    x = 1ll * x * x % MOD;
    y >>= 1;
  }
  return ret;
}

map<int, ll> mp;
ll inv(int x) {
  if (mp.find(x) != mp.end())
    return mp[x];
  return mp[x] = ksm(x, MOD - 2);
}

int sz[N];
ll dp1, dp2[N];
void DP1(int u, int f) {
  sz[u] = 1;
  for (int e = fst[u]; e != -1; e = edge[e].nxt) {
    int v = edge[e].v;
    if (v == f)
      continue;
    DP1(v, u);
    sz[u] += sz[v];
  }
  dp1 = 1ll * dp1 * sz[u] % MOD;
  //	cout << u << " " << dp1[u] << endl;
}
void DP2(int u, int f) {
  if (u != 1)
    dp2[u] = 1ll * dp2[f] * (n - sz[u]) % MOD * inv(sz[u]) % MOD;
  //	cout << u << " " << dp2[u] << endl;
  for (int e = fst[u]; e != -1; e = edge[e].nxt) {
    int v = edge[e].v;
    if (v == f)
      continue;
    DP2(v, u);
  }
}

int main() {
  init_e();

  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }

  dp1 = 1;
  DP1(1, 0);
  dp2[1] = dp1;
  DP2(1, 0);

  ll tmp = 1;
  for (int i = 1; i <= n; i++)
    tmp = 1ll * tmp * i % MOD;

  for (int i = 1; i <= n; i++)
    printf("%lld\\n", 1ll * tmp * inv(dp2[i]) % MOD);

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

#include <bits/stdc++.h>

#define MAXN 200010
#define ll long long

using namespace std;

const int mod = 1e9 + 7;

int n, tot;

ll product = 1;

int head[MAXN], siz[MAXN];

ll f[MAXN];

struct edge {
  int to, next;
} e[MAXN * 2];

void add_edge(int x, int y) {
  e[++tot].to = y;
  e[tot].next = head[x];
  head[x] = tot;
  return;
}

ll qp(ll a, ll b) {
  ll res = 1, base = a;
  while (b) {
    if (b & 1)
      res = (res * base) % mod;
    base = (base * base) % mod;
    b >>= 1;
  }

  return res;
}

void dfs1(int x, int fa) {
  siz[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa)
      continue;
    dfs1(v, x);
    siz[x] += siz[v];
  }

  f[1] = (1ll * f[1] * siz[x]) % mod;
  return;
}

void dfs2(int x, int fa) {
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa)
      continue;
    f[v] =
        (1ll * f[x] * (1ll * (n - siz[v]) * qp(siz[v], mod - 2) % mod)) % mod;
    dfs2(v, x);
  }

  return;
}

int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }

  f[1] = 1;
  dfs1(1, 0);
  dfs2(1, 0);

  for (int i = 1; i <= n; i++) {
    product = (1ll * product * i) % mod;
  }
  for (int i = 1; i <= n; i++) {
    printf("%lld\\n", (ll)(1ll * product * qp(f[i], mod - 2)) % mod);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define MAXN 100010
#define ll long long

using namespace std;

const int mod = 1e9 + 7;

int n, tot;

ll product = 1;

int head[MAXN], siz[MAXN];

ll f[MAXN];

struct edge {
  int to, next;
} e[MAXN * 2];

void add_edge(int x, int y) {
  e[++tot].to = y;
  e[tot].next = head[x];
  head[x] = tot;
  return;
}

ll qp(ll a, ll b) {
  ll res = 1, base = a;
  while (b) {
    if (b & 1)
      res = (res * base) % mod;
    base = (base * base) % mod;
    b >>= 1;
  }

  return res;
}

void dfs1(int x, int fa) {
  siz[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa)
      continue;
    dfs1(v, x);
    siz[x] += siz[v];
  }

  f[1] = (1ll * f[1] * siz[x]) % mod;
  return;
}

void dfs2(int x, int fa) {
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa)
      continue;
    f[v] =
        (1ll * f[x] * (1ll * (n - siz[v]) * qp(siz[v], mod - 2) % mod)) % mod;
    dfs2(v, x);
  }

  return;
}

int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }

  f[1] = 1;
  dfs1(1, 0);
  dfs2(1, 0);

  for (int i = 1; i <= n; i++) {
    product = (1ll * product * i) % mod;
  }
  for (int i = 1; i <= n; i++) {
    printf("%lld\\n", (ll)(1ll * product * qp(f[i], mod - 2)) % mod);
  }
  return 0;
}
Problem p02728 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

int pw(int x, int y) {
  int r = 1;
  while (y) {
    if (y & 1)
      r = 1ll * r * x % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return r;
}
int inv(int x) { return pw(x, mod - 2); }

int n;
vector<int> adj[200005];
int dad[200005];
int sz[200005];
int ans[200005];
int add = 1;

void dfs(int u) {
  sz[u] = 1;
  for (auto v : adj[u]) {
    if (v == dad[u])
      continue;
    dad[v] = u;
    dfs(v);
    sz[u] += sz[v];
  }
  add = 1ll * add * inv(sz[u]) % mod;
}
void dfs2(int u) {
  ans[u] = add;
  for (auto v : adj[u]) {
    if (v == dad[u])
      continue;
    int save = add;
    add = 1ll * add * sz[v] % mod;
    add = 1ll * add * inv(n - sz[v]) % mod;
    dfs2(v);
    add = save;
  }
}

int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i)
    add = 1ll * add * i % mod;
  dfs(1);
  dfs2(1);
  for (int i = 1; i <= n; i++)
    cout << ans[i] << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

int pw(int x, int y) {
  int r = 1;
  while (y) {
    if (y & 1)
      r = 1ll * r * x % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return r;
}
int inv(int x) { return pw(x, mod - 2); }

int n;
vector<int> adj[200005];
int dad[200005];
int sz[120005];
int ans[200005];
int add = 1;

void dfs(int u) {
  sz[u] = 1;
  for (auto v : adj[u]) {
    if (v == dad[u])
      continue;
    dad[v] = u;
    dfs(v);
    sz[u] += sz[v];
  }
  add = 1ll * add * inv(sz[u]) % mod;
}
void dfs2(int u) {
  ans[u] = add;
  for (auto v : adj[u]) {
    if (v == dad[u])
      continue;
    int save = add;
    add = 1ll * add * sz[v] % mod;
    add = 1ll * add * inv(n - sz[v]) % mod;
    dfs2(v);
    add = save;
  }
}

int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i)
    add = 1ll * add * i % mod;
  dfs(1);
  dfs2(1);
  for (int i = 1; i <= n; i++)
    cout << ans[i] << "\\n";
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define lh long double
#define f(a, b, i) for (ll i = a; i < b; i++)

int main() {

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

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define lh long double
#define f(a, b, i) for (ll i = a; i < b; i++)

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m;
  cin >> n >> m;
  cout << (n * (n - 1) + m * (m - 1)) / 2;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ll n, m;
  cin >> n >> m;
  cout << m * (m - 1) / 2 + n * (n - 1) / 2;
}

Error: WA

Fixed submission:

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

#include <bits/stdc++.h>

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

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

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

Error: -11

Fixed submission:

#include <iostream>

int main(int argc, char **argv) {

  int n = atoi(argv[1]);
  int m = atoi(argv[2]);

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

  std::cout << ans << std::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;
  return 0;
}

Error: 1

Fixed submission:

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

int main() {
  ll n, m;
  cin >> n >> m;
  ll s1, s2, ans;
  s1 = n * (n - 1);
  s2 = m * (m - 1);
  ans = s1 + s2;
  return ans / 2;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}


Error: TLE

Fixed submission:

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

int combi(int n, int r) {
  if (r == 0 || r == n)
    return (1);
  else if (r == 1)
    return (n);
  return (combi(n - 1, r - 1) + combi(n - 1, r));
}
int main() {
  int n, m;
  cin >> n >> m;
  cout << combi(n, 2) + combi(m, 2) << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

ll fact(ll n) {
  if (n == 0)
    return 1;
  return n * fact(n - 1);
}

ll comb(ll n, ll r) {
  if (r > n)
    return 0;
  return fact(n) / (fact(n - r) * fact(r));
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m;
  cin >> n >> m;

  cout << comb(n, 2) + comb(m, 2) << "\\n";

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

/*
Author- Aasav Badera
Time- Sun Mar 22 17:30:45 2020
*/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define s second
#define mii map<ll, ll>
#define dbg(x)                                                                 \\
  { cerr << #x << ": " << x << endl; }
#define dbg2(x, y)                                                             \\
  { cerr << #x << ": " << x << " , " << #y << ": " << y << endl; }
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define pii pair<ll, ll>
#define ppb pop_back
#define f first
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define si set<ll>
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll) x.size()
#define hell 1000000007
#define mp make_pair
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define inf 1e18L + 1
#define endl '\\n'
using namespace std;
#define N 300005

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll tests = 1;
  // cin >> tests;
  while (tests--) {
    ll n, m;
    cin >> n >> m;
    ll ans = n * (n - 1) + m * (m - 1);
    ans /= 2;
    cout << ans;
  }
  return 0;
}

Error: WA

Fixed submission:

/*
Author- Aasav Badera
Time- Sun Mar 22 17:30:45 2020
*/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define s second
#define mii map<ll, ll>
#define dbg(x)                                                                 \\
  { cerr << #x << ": " << x << endl; }
#define dbg2(x, y)                                                             \\
  { cerr << #x << ": " << x << " , " << #y << ": " << y << endl; }
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define pii pair<ll, ll>
#define ppb pop_back
#define f first
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define si set<ll>
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll) x.size()
#define hell 1000000007
#define mp make_pair
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define inf 1e18L + 1
#define endl '\\n'
using namespace std;
#define N 300005

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  ll tests = 1;
  // cin >> tests;
  while (tests--) {
    ll n, m;
    cin >> n >> m;
    ll ans = n * (n - 1) + m * (m - 1);
    ans /= 2;
    cout << ans;
  }
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

#define int long long
#define val(x) cout << #x << " equals to " << x << endl
#define F first
#define S second
#define pb push_back

const int N = 2e6 + 7;
const int INF = 1e18;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

#ifndef ONLINE_JUDGE
  // freopen("/home/emrey/Coding/IO/in.txt", "r", stdin);
  // freopen("/home/emrey/Coding/IO/out.txt", "w", stdout);
#endif

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


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

#define int long long
#define val(x) cout << #x << " equals to " << x << endl
#define F first
#define S second
#define pb push_back

const int N = 2e6 + 7;
const int INF = 1e18;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

#ifndef ONLINE_JUDGE
  freopen("/home/emrey/Coding/IO/in.txt", "r", stdin);
  // freopen("/home/emrey/Coding/IO/out.txt", "w", stdout);
#endif

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

#include <iostream>

int main() {
  int n = 0;
  int m = 0;
  std::cin >> n >> m;

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

  return 0;
}

Error: -8

Fixed submission:

#include <iostream>

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

int main() {
  const int r = 2;
  int n = 0;
  int m = 0;
  std::cin >> n >> m;
  long long N = 0, M = 0;
  if (n > 1) {
    long long nf = factorial(n);
    long long nr = factorial(n - r);
    N = nf / (2 * nr);
  }
  if (m > 1) {
    long long mf = factorial(m);
    long long mr = factorial(m - r);
    M = mf / (2 * mr);
  }

  std::cout << N + M;

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

#include <iostream>
using namespace std;
long long nc2(int s) {
  long long x = 1;
  for (int i = 2; i < s; i++) {
    x += i;
  }
  return x;
}
int main() {

  int n, m, b, g;
  cin >> n >> m;
  if (n == 0 || n == 1) {
    b = 0;
    if (m == 0 || m == 1) {
      g = 0;
    } else
      g = nc2(m);
  } else if (m == 0 || m == 1) {
    g = 0;
    if (n == 0 || n == 1) {
      b = 0;
    } else
      b = nc2(n);
  } else {
    b = nc2(n);
    g = nc2(m);
  }
  cout << b + g;
  return 0;
}

Error: WA

Fixed submission:

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

unsigned long long fact(int n);

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

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

// Driver code
int main() {
  int n, m, r = 2;
  cin >> n >> m;
  cout << nCr(n, r) + nCr(m, r);
  return 0;
}