Problem p02729 (C++) — buggy submission, verdict: Runtime Error

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//* vamsicool007    You are never wrong to do the right thing    vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#include <bits/stdc++.h>
using namespace std;
#define flash                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N = 200005;
vector<int> vis(N);
vector<vector<int>> adj(N);
void dfs(int v) {
  vis[v] = 1;
  for (auto i : adj[v]) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  return;
}
bool isPrime(ll n) {
  if (n < 2)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
ll power(ll x, ll y) {
  ll res = 1;
  x = x;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}
ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll max(ll a, ll b) {
  ll ans = a > b ? a : b;
  return ans;
}
ll min(ll a, ll b) {
  ll ans = a < b ? a : b;
  return ans;
}
int root(int a[], int i) {
  while (a[i] != i) {
    a[i] = a[a[i]];
    i = a[i];
  }
  return i;
}
void unionn(int a[], int i, int j) {
  int root_i = root(a, i);
  int root_j = root(a, j);
  a[root_i] = root_j;
  return;
}
void fun() {
#ifndef ONLINE_JUDGE
  freopen("infile.txt", "r", stdin);
  freopen("oufile.txt", "w", stdout);
#endif
}

int nCr(int n, int r, int p) {
  // The array C is going to store last row of
  // pascal triangle at the end. And last entry
  // of last row is nCr
  int C[r + 1];
  memset(C, 0, sizeof(C));

  C[0] = 1; // Top row of Pascal Triangle

  // One by constructs remaining rows of Pascal
  // Triangle from top to bottom
  for (int i = 1; i <= n; i++) {
    // Fill entries of current row using previous
    // row values
    for (int j = min(i, r); j > 0; j--)

      // nCj = (n-1)Cj + (n-1)C(j-1);
      C[j] = (C[j] + C[j - 1]) % p;
  }
  return C[r];
}

// Lucas Theorem based function that returns nCr % p
// This function works like decimal to binary conversion
// recursive function.  First we compute last digits of
// n and r in base p, then recur for remaining digits
int nCrModpLucas(int n, int r, int p) {
  // Base case
  if (r == 0)
    return 1;

  // Compute last digits of n and r in base p
  int ni = n % p, ri = r % p;

  // Compute result for last digits computed above, and
  // for remaining digits.  Multiply the two results and
  // compute the result of multiplication in modulo p.
  return (nCrModpLucas(n / p, r / p, p) * // Last digits of n and r
          nCr(ni, ri, p)) %
         p; // Remaining digits
}

signed main() {
  flash;
  // fun();
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int s = 0;
    if (n >= 2)
      s = s + nCr(n, 2, mod);
    if (m >= 2)
      s = s + nCr(m, 2, mod);
    cout << s;
  }
  return 0;
}

Error: WA

Fixed submission:

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//* vamsicool007    You are never wrong to do the right thing    vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#include <bits/stdc++.h>
using namespace std;
#define flash                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N = 200005;
vector<int> vis(N);
vector<vector<int>> adj(N);
void dfs(int v) {
  vis[v] = 1;
  for (auto i : adj[v]) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  return;
}
bool isPrime(ll n) {
  if (n < 2)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
ll power(ll x, ll y) {
  ll res = 1;
  x = x;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}
ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll max(ll a, ll b) {
  ll ans = a > b ? a : b;
  return ans;
}
ll min(ll a, ll b) {
  ll ans = a < b ? a : b;
  return ans;
}
int root(int a[], int i) {
  while (a[i] != i) {
    a[i] = a[a[i]];
    i = a[i];
  }
  return i;
}
void unionn(int a[], int i, int j) {
  int root_i = root(a, i);
  int root_j = root(a, j);
  a[root_i] = root_j;
  return;
}

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

// Returns factorial of n

signed main() {
  flash;
  // fun();
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int s = 0;
    if (n >= 2)
      s = s + nCr(n, 2);
    if (m >= 2)
      s = s + nCr(m, 2);
    cout << s;
  }
  return 0;
}