Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) for (lli i = 0; i < n; i++)
#define repb(i, n) for (lli i = n - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(), X.end()
#define iterate(X) for (it = X.begin(); it != X.end(); it++)
#define mod 1000000007
lli combi(lli n, lli k) {
  lli ans = 1;
  k = k > n - k ? n - k : k;
  lli j = 1;
  for (; j <= k; j++, n--) {
    if (n % j == 0) {
      ans *= n / j;
    } else if (ans % j == 0) {
      ans = ans / j * n;
    } else {
      ans = (ans * n) / j;
    }
  }
  return ans;
}
lli gcd(lli a, lli b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
lli findlcm(vector<lli> arr, lli n) {
  lli ans = arr[0];
  for (lli i = 1; i < n; i++)
    ans = (((arr[i] * ans)) / (gcd(arr[i], ans)));

  return ans;
}
lli power(lli x, lli y) {
  lli res = 1; // Initialize result

  x = x % mod; // Update x if it is more than or
               // equal to p

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % mod;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % mod;
  }
  return res;
}

// Returns n^(-1) mod p
lli modInverse(lli n) { return power(n, mod - 2); }

// Returns nCr % p using Fermat's little
// theorem.
lli fac[4001];
lli nCrModPFermat(lli n, lli r) {
  // Base case
  if (r == 0)
    return 1;

  // Fill factorial array so that we
  // can find all factorial of r, n
  // and n-r

  return (((fac[n] * modInverse(fac[r])) % mod) * modInverse(fac[n - r]) %
          mod) %
         mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli n, k;
  cin >> n >> k;
  fac[0] = 1;
  for (lli i = 1; i <= n + k; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    // cout<<fac[i]<<" ";
  }
  // cout<<"\n";
  lli red = n - k;
  lli blue = k;
  lli now = (red + 1);
  cout << now << "\n";
  for (lli mov = 2; mov <= k; mov++) {
    lli red_b = red - (mov - 1);
    now = ((nCrModPFermat(blue - mov + mov - 1, mov - 1)) *
           (nCrModPFermat(red_b + mov + 1 - 1, mov))) %
          mod;
    cout << now << "\n";
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) for (lli i = 0; i < n; i++)
#define repb(i, n) for (lli i = n - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(), X.end()
#define iterate(X) for (it = X.begin(); it != X.end(); it++)
#define mod 1000000007
lli combi(lli n, lli k) {
  lli ans = 1;
  k = k > n - k ? n - k : k;
  lli j = 1;
  for (; j <= k; j++, n--) {
    if (n % j == 0) {
      ans *= n / j;
    } else if (ans % j == 0) {
      ans = ans / j * n;
    } else {
      ans = (ans * n) / j;
    }
  }
  return ans;
}
lli gcd(lli a, lli b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
lli findlcm(vector<lli> arr, lli n) {
  lli ans = arr[0];
  for (lli i = 1; i < n; i++)
    ans = (((arr[i] * ans)) / (gcd(arr[i], ans)));

  return ans;
}
lli power(lli x, lli y) {
  lli res = 1; // Initialize result

  x = x % mod; // Update x if it is more than or
               // equal to p

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % mod;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % mod;
  }
  return res;
}

// Returns n^(-1) mod p
lli modInverse(lli n) { return power(n, mod - 2); }

// Returns nCr % p using Fermat's little
// theorem.
lli fac[4001];
lli nCrModPFermat(lli n, lli r) {
  // Base case
  if (r == 0)
    return 1;

  // Fill factorial array so that we
  // can find all factorial of r, n
  // and n-r

  return (((fac[n] * modInverse(fac[r])) % mod) * modInverse(fac[n - r]) %
          mod) %
         mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli n, k;
  cin >> n >> k;
  fac[0] = 1;
  for (lli i = 1; i <= n + k; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    // cout<<fac[i]<<" ";
  }
  // cout<<"\n";
  lli red = n - k;
  lli blue = k;
  lli now = (red + 1);
  cout << now << "\n";
  for (lli mov = 2; mov <= k; mov++) {
    if (mov <= n - k + 1) {
      lli red_b = red - (mov - 1);
      now = ((nCrModPFermat(blue - mov + mov - 1, mov - 1)) *
             (nCrModPFermat(red_b + mov + 1 - 1, mov))) %
            mod;
      cout << now << "\n";
    } else
      cout << "0\n";
  }
  return 0;
}