Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define read() freopen("in.txt", "r", stdin)
#define write() freopen("out.txt", "w", stdout)
#define sf(n) scanf("%d", &n)
#define sfd(n) scanf("%lf", &n)
#define sl(x) scanf("%I64d", &x)
#define sfl(n) scanf("%lld", &n)
#define sfc(n) scanf(" %c", &n)
#define sful(n) scanf("%llu", &n)
#define ull unsigned long long int
#define endll printf("\n")
#define pf printf
#define pi acos(-1.0)
#define eps 1e-10
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define xx first
#define yy second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MP make_pair
#define ll long long
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int N, int pos) { return (bool)(N & (1LL << pos)); }
ll Set(unsigned int N, int pos) { return N = N | (1LL << pos); }
#define cnd tree[idx]
#define lnd tree[idx << 1]
#define rnd tree[(idx << 1) + 1]
#define lndp (idx << 1), (b), ((b + e) >> 1)
#define rndp ((idx << 1) + 1), (((b + e) >> 1) + 1), (e)
#define inf 1999999999
#define MX 100005
#define mod 1000000007
#define mod1 1000000009
#define var int ii, i, j, k, z = 0, c = 0, t, x, y, l, r, mid
int dx[8] = {0, 0, 1, -1, -1, 1, 1, -1}; // 8 direction
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

bool chk(int x, int pos) { return (bool)(x & (1 << pos)); }
int Set(int x, int pos) { return x = x | (1 << pos); }
int clr(int x, int pos) { return x = x & ~(1 << pos); }

ll int n, m, a[5000];

ll bigmod(ll x, ll y) {
  if (y == 0)
    return 1;
  ll n = bigmod(x, y >> 1);
  n = (n * n) % mod;
  if (y & 1)
    n = (n * x) % mod;
  return n;
}

ll ncr(ll n, ll r) {
  ll x = (a[r] * a[n - r]) % mod;
  x = bigmod(x, mod - 2);
  x *= a[n];
  x %= mod;
  return x;
}

int main() {
  ll var;
  a[0] = 1;
  for (i = 1; i <= 5000; i++) {
    a[i] = a[i - 1] * i;
    a[i] %= mod;
  }
  sfl(n);
  sfl(k);
  m = n - k;
  for (i = 1; i <= k; i++) {
    z = ncr(k - 1, i - 1) * ncr(m + 1, i);
    z %= mod;
    cout << z << endl;
  }
}


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

#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define read() freopen("in.txt", "r", stdin)
#define write() freopen("out.txt", "w", stdout)
#define sf(n) scanf("%d", &n)
#define sfd(n) scanf("%lf", &n)
#define sl(x) scanf("%I64d", &x)
#define sfl(n) scanf("%lld", &n)
#define sfc(n) scanf(" %c", &n)
#define sful(n) scanf("%llu", &n)
#define ull unsigned long long int
#define endll printf("\n")
#define pf printf
#define pi acos(-1.0)
#define eps 1e-10
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define xx first
#define yy second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MP make_pair
#define ll long long
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int N, int pos) { return (bool)(N & (1LL << pos)); }
ll Set(unsigned int N, int pos) { return N = N | (1LL << pos); }
#define cnd tree[idx]
#define lnd tree[idx << 1]
#define rnd tree[(idx << 1) + 1]
#define lndp (idx << 1), (b), ((b + e) >> 1)
#define rndp ((idx << 1) + 1), (((b + e) >> 1) + 1), (e)
#define inf 1999999999
#define MX 100005
#define mod 1000000007
#define mod1 1000000009
#define var int ii, i, j, k, z = 0, c = 0, t, x, y, l, r, mid
int dx[8] = {0, 0, 1, -1, -1, 1, 1, -1}; // 8 direction
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

bool chk(int x, int pos) { return (bool)(x & (1 << pos)); }
int Set(int x, int pos) { return x = x | (1 << pos); }
int clr(int x, int pos) { return x = x & ~(1 << pos); }

ll int n, m, a[5000];

ll bigmod(ll x, ll y) {
  if (y == 0)
    return 1;
  ll n = bigmod(x, y >> 1);
  n = (n * n) % mod;
  if (y & 1)
    n = (n * x) % mod;
  return n;
}

ll ncr(ll n, ll r) {
  if (n < r)
    return 0;
  ll x = (a[r] * a[n - r]) % mod;
  x = bigmod(x, mod - 2);
  x *= a[n];
  x %= mod;
  return x;
}

int main() {
  ll var;
  a[0] = 1;
  for (i = 1; i <= 5000; i++) {
    a[i] = a[i - 1] * i;
    a[i] %= mod;
  }
  sfl(n);
  sfl(k);
  m = n - k;
  for (i = 1; i <= k; i++) {
    z = ncr(k - 1, i - 1) * ncr(m + 1, i);
    z %= mod;
    cout << z << endl;
  }
}