prithivMLmods/Coder-Stat huggingface dataset:
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

const int mod = 1000000007;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int sub(int a, int b) { return (a -= b) >= 0 ? a : a + mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
void adds(int &a, int b) { a = add(a, b); }
void subs(int &a, int b) { a = sub(a, b); }
void muls(int &a, int b) { a = mul(a, b); }
void maxs(int &a, int b) { a = max(a, b); }
void mins(int &a, int b) { a = min(a, b); }
int pwr(int a, ll p) {
  if (p == 0)
    return 1;
  if (p & 1)
    return mul(a, pwr(a, p - 1));
  return pwr(mul(a, a), p / 2);
}
int inv(int a) { return pwr(a, mod - 2); }

const int maxn = 1000000;
int f[maxn + 1], fi[maxn + 1];
int ncr(int n, int r) { return mul(f[n], mul(fi[r], fi[n - r])); }

void precompute() {
  f[0] = 1;
  for (int i = 1; i <= maxn; ++i)
    f[i] = mul(f[i - 1], i);

  fi[maxn] = inv(f[maxn]);
  for (int i = maxn - 1; i >= 0; --i)
    fi[i] = mul(fi[i + 1], i + 1);
}

int n, k;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  precompute();
  for (int i = 1; i <= k; ++i)
    cout << mul(ncr(n - k + 1, i), ncr(k - 1, i - 1)) << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

const int mod = 1000000007;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int sub(int a, int b) { return (a -= b) >= 0 ? a : a + mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
void adds(int &a, int b) { a = add(a, b); }
void subs(int &a, int b) { a = sub(a, b); }
void muls(int &a, int b) { a = mul(a, b); }
void maxs(int &a, int b) { a = max(a, b); }
void mins(int &a, int b) { a = min(a, b); }
int pwr(int a, ll p) {
  if (p == 0)
    return 1;
  if (p & 1)
    return mul(a, pwr(a, p - 1));
  return pwr(mul(a, a), p / 2);
}
int inv(int a) { return pwr(a, mod - 2); }

const int maxn = 1000000;
int f[maxn + 1], fi[maxn + 1];
int ncr(int n, int r) {
  if (r > n)
    return 0;
  return mul(f[n], mul(fi[r], fi[n - r]));
}

void precompute() {
  f[0] = 1;
  for (int i = 1; i <= maxn; ++i)
    f[i] = mul(f[i - 1], i);

  fi[maxn] = inv(f[maxn]);
  for (int i = maxn - 1; i >= 0; --i)
    fi[i] = mul(fi[i + 1], i + 1);
}

int n, k;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  precompute();
  for (int i = 1; i <= k; ++i)
    cout << mul(ncr(n - k + 1, i), ncr(k - 1, i - 1)) << '\n';
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>

#define lli long long int

lli bigmod = 1000000007, memo[2010][2010];

lli dp(lli x, lli y) {
  if ((y == 0) || (x == y))
    return 1;
  if (memo[x][y] == -1)
    memo[x][y] = (dp(x - 1, y) + dp(x - 1, y - 1)) % bigmod;
  return memo[x][y];
}

int main() {
  lli n, k, ans;
  scanf("%lld %lld", &n, &k);
  memset(memo, -1, sizeof memo);
  for (lli i = 1; i <= k; i++) {
    ans = (dp(k - 1, i - 1) * dp(n - k + 1, i)) % bigmod;
    printf("%lld\n", ans);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>

#define lli long long int

lli bigmod = 1000000007, memo[2010][2010];

lli dp(lli x, lli y) {
  if (x < y)
    return 0;
  if ((y == 0) || (x == y))
    return 1;
  if (memo[x][y] == -1)
    memo[x][y] = (dp(x - 1, y) + dp(x - 1, y - 1)) % bigmod;
  return memo[x][y];
}

int main() {
  lli n, k, ans;
  scanf("%lld %lld", &n, &k);
  memset(memo, -1, sizeof memo);
  for (lli i = 1; i <= k; i++) {
    ans = (dp(k - 1, i - 1) * dp(n - k + 1, i)) % bigmod;
    printf("%lld\n", ans);
  }
  return 0;
}
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
from math import factorial

N, K = [int(_) for _ in input().split()]
# N = 10
MOD = 10**9 + 7

kaijo = [0] * (N + 1)
kaijo[0] = kaijo[1] = 1
for i in range(2, N + 1):
    kaijo[i] = (kaijo[i - 1] * i) % MOD

gyaku = [0] * (N + 1)
gyaku[0] = gyaku[1] = 1

for i in range(2, N + 1):
    # gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD
    gyaku[i] = pow(kaijo[i], MOD - 2, MOD)


def calc(n, k):
    # return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD
    return factorial(n) // (factorial(n - k) * factorial(k))


def solve():
    for i in range(1, K + 1):
        n = N - K + 1
        k = i
        print((calc(n, k) * calc(K - 1, i - 1)) % MOD)


solve()


Fixed submission:
from math import factorial

N, K = [int(_) for _ in input().split()]
# N = 10
MOD = 10**9 + 7

kaijo = [0] * (N + 1)
kaijo[0] = kaijo[1] = 1
for i in range(2, N + 1):
    kaijo[i] = (kaijo[i - 1] * i) % MOD

gyaku = [0] * (N + 1)
gyaku[0] = gyaku[1] = 1

for i in range(2, N + 1):
    # gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD
    gyaku[i] = pow(kaijo[i], MOD - 2, MOD)


def calc(n, k):
    # return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD
    return factorial(n) // (factorial(n - k) * factorial(k))


def solve():
    for i in range(1, K + 1):
        n = N - K + 1
        k = i
        if k <= n:
            print((calc(n, k) * calc(K - 1, i - 1)) % MOD)
        else:
            print(0)


solve()
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
from math import factorial as fac

N, K = map(int, input().split())


def func(n, k, r):
    return (
        fac(k - 1)
        * fac(n - k + 1)
        // (fac(k - r) * fac(r - 1) * fac(n - k - r + 1) * fac(r))
    )


for i in range(1, K + 1):
    print(func(N, K, i) % (10**9 + 7))


Fixed submission:
from math import factorial as fac

N, K = map(int, input().split())


def func(n, k, r):
    return (
        fac(k - 1)
        * fac(n - k + 1)
        // (fac(k - r) * fac(r - 1) * fac(n - k - r + 1) * fac(r))
    )


for i in range(1, K + 1):
    if N - K + 1 >= i:
        print(func(N, K, i) % (10**9 + 7))
    else:
        print(0)
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
# パスカルの三角形
N, K = map(int, input().split())

n = max(K - 1, N - K + 1)
c = [[0] * (n + 1) for _ in range(n + 1)]
c[0][0] = 1
for i in range(1, n + 1):
    ci = c[i]
    ci1 = c[i - 1]
    ci[0] = 1
    for j in range(1, i + 1):
        ci[j] = (ci1[j - 1] + ci1[j]) % 1000000007

result = []
for i in range(1, K + 1):
    result.append(c[K - 1][i - 1] * c[N - K + 1][i] % 1000000007)
print("\n".join(str(i) for i in result))


Fixed submission:
# パスカルの三角形
N, K = map(int, input().split())

n = max(K, N - K + 1)
c = [[0] * (n + 1) for _ in range(n + 1)]
c[0][0] = 1
for i in range(1, n + 1):
    ci = c[i]
    ci1 = c[i - 1]
    ci[0] = 1
    for j in range(1, i + 1):
        ci[j] = (ci1[j - 1] + ci1[j]) % 1000000007

result = []
for i in range(1, K + 1):
    result.append(c[K - 1][i - 1] * c[N - K + 1][i] % 1000000007)
print("\n".join(str(i) for i in result))
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long m = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  long a[n + 1][k + 1];
  for (int i = 0; i < n + 1; i++) {
    a[i][0] = 1;
  }
  for (int i = 0; i < k + 1; i++) {
    a[i][i] = 1;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j <= i; j++) {
      a[i][j] = (a[i - 1][j] + a[i - 1][j - 1]) % m;
    }
  }
  for (int i = 1; i <= k; i++) {
    cout << a[n - k + 1][i] * a[k - 1][i - 1] % m << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long m = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  long a[2002][2002];
  for (int i = 0; i < n + 1; i++) {
    a[i][0] = 1;
  }
  for (int i = 0; i < k + 1; i++) {
    a[i][i] = 1;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j <= i; j++) {
      a[i][j] = (a[i - 1][j] + a[i - 1][j - 1]) % m;
    }
  }
  for (int i = 1; i <= k; i++) {
    cout << a[n - k + 1][i] * a[k - 1][i - 1] % m << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll mod = 1e9 + 7;

ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}

// 階乗,factで初期化
vector<ll> tfact(1e7 + 1);
void fact(ll n) {
  for (ll i = 0; i <= n; i++) {
    if (i == 0) {
      tfact[i] = 1;
    } else {
      tfact[i] = tfact[i - 1] * i % mod;
    }
  }
}

// nCk 繰り返し高速
ll comb(ll n, ll k) {
  return tfact.at(n) * mpow(tfact.at(k), mod - 2) % mod *
         mpow(tfact.at(n - k), mod - 2) % mod;
}

int main() {
  ll n, k;
  cin >> n >> k;
  fact(n + 1);
  ll temp = 0;
  for (ll i = 1; i <= k; i++) {
    cout << comb(n - k + 1, i) % mod * comb(k + i - 1 - i, i - 1) % mod << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll mod = 1e9 + 7;

ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}

// 階乗,factで初期化
vector<ll> tfact(1e7 + 1);
void fact(ll n) {
  for (ll i = 0; i <= n; i++) {
    if (i == 0) {
      tfact[i] = 1;
    } else {
      tfact[i] = tfact[i - 1] * i % mod;
    }
  }
}

// nCk 繰り返し高速
ll comb(ll n, ll k) {
  return tfact.at(n) * mpow(tfact.at(k), mod - 2) % mod *
         mpow(tfact.at(n - k), mod - 2) % mod;
}

int main() {
  ll n, k;
  cin >> n >> k;
  fact(n + 1);
  ll temp = 0;
  for (ll i = 1; i <= k; i++) {
    if (n - k + 1 >= i) {
      cout << comb(n - k + 1, i) % mod * comb(k + i - 1 - i, i - 1) % mod
           << endl;
    } else {
      cout << 0 << endl;
    }
  }
}
Problem p02990 (C++)

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

long long mod = 1e9 + 7;

void comb(vector<vector<long long>> &vec) {
  for (size_t i = 0; i < vec.size(); i++) {
    vec[i][0] = 1;
    vec[i][i] = 1;
  }
  for (size_t i = 1; i < vec.size(); i++) {
    for (size_t j = 1; j < i; j++) {
      vec[i][j] = vec[i - 1][j - 1] + vec[i - 1][j];
      vec[i][j] %= mod;
    }
  }
}

int main() {
  long long n, k;
  cin >> n >> k;
  vector<vector<long long>> vec(n - k + 2, vector<long long>(n - k + 2, 0));
  comb(vec);
  for (int i = 1; i <= k; i++) {
    cout << (vec[n - k + 1][i] * vec[k - 1][i - 1]) % mod << endl;
  }
  return 0;
}


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

long long mod = 1e9 + 7;

void comb(vector<vector<long long>> &vec) {
  for (size_t i = 0; i < vec.size(); i++) {
    vec[i][0] = 1;
    vec[i][i] = 1;
  }
  for (size_t i = 1; i < vec.size(); i++) {
    for (size_t j = 1; j < i; j++) {
      vec[i][j] = vec[i - 1][j - 1] + vec[i - 1][j];
      vec[i][j] %= mod;
    }
  }
}

int main() {
  long long n, k;
  cin >> n >> k;
  vector<vector<long long>> vec(2005, vector<long long>(2005, 0));
  comb(vec);
  for (int i = 1; i <= k; i++) {
    cout << (vec[n - k + 1][i] * vec[k - 1][i - 1]) % mod << endl;
  }
  return 0;
}
Problem p02990 (C++)

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

const int mod = 1e9 + 7;

int C[3000][3000];

int c(int x, int y) {
  if (y == 0 || x == y)
    return 1;
  else if (C[x][y] > 0)
    return C[x][y];
  else
    return C[x][y] = (c(x - 1, y - 1) + c(x - 1, y)) % mod;
}

signed main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    cout << (c(n - k + 1, i + 1) * c(k - 1, i)) % mod << endl;
  }
}


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

const int mod = 1e9 + 7;

int C[3000][3000];

int c(int x, int y) {
  if (y == 0 || x == y)
    return 1;
  else if (C[x][y] > 0)
    return C[x][y];
  else
    return C[x][y] = (c(x - 1, y - 1) + c(x - 1, y)) % mod;
}

signed main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    if (n - k < i) {
      cout << 0 << endl;
      continue;
    }
    cout << (c(n - k + 1, i + 1) * c(k - 1, i)) % mod << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt, e) for (ll cnt = 0; cnt < e; cnt++)
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll INF = INT64_MAX;

ll i, j, k;
ll kaijou[2000 + 1];
ll gyakugen[2000 + 1];
long long ruijou(long long x, long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return ruijou(x * x % mod, y / 2);
  else
    return x * ruijou(x, y - 1) % mod;
}

ll combination(ll n, ll c) {
  return ((kaijou[n] * gyakugen[c]) % mod) * gyakugen[n - c] % mod;
}
ll mo(ll x) {
  ll ans = x % mod;
  if (x >= 0)
    return ans;
  return ans + mod;
}

int main() {
  ll N, K;
  cin >> N >> K;
  V kaisuu(K);
  rep(i, N + 1) {
    if (i == 0)
      kaijou[i] = 1;
    else
      kaijou[i] = (kaijou[i - 1] * i) % mod;
  }
  rep(i, N + 1) {
    if (i == 0)
      gyakugen[i] = 1;
    else
      gyakugen[i] = (gyakugen[i - 1] * ruijou(i, mod - 2)) % mod;
  }

  rep(i, K) {
    cout << mo(combination(N - K + 1, i + 1) * combination(K - 1, i)) << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt, e) for (ll cnt = 0; cnt < e; cnt++)
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll INF = INT64_MAX;

ll i, j, k;
ll kaijou[2000 + 1];
ll gyakugen[2000 + 1];
long long ruijou(long long x, long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return ruijou(x * x % mod, y / 2);
  else
    return x * ruijou(x, y - 1) % mod;
}

ll combination(ll n, ll c) {
  if (n < c)
    return 0;
  return ((kaijou[n] * gyakugen[c]) % mod) * gyakugen[n - c] % mod;
}
ll mo(ll x) {
  ll ans = x % mod;
  if (x >= 0)
    return ans;
  return ans + mod;
}

int main() {
  ll N, K;
  cin >> N >> K;
  V kaisuu(K);
  rep(i, N + 1) {
    if (i == 0)
      kaijou[i] = 1;
    else
      kaijou[i] = (kaijou[i - 1] * i) % mod;
  }
  rep(i, N + 1) {
    if (i == 0)
      gyakugen[i] = 1;
    else
      gyakugen[i] = (gyakugen[i - 1] * ruijou(i, mod - 2)) % mod;
  }

  rep(i, K) {
    cout << mo(combination(N - K + 1, i + 1) * combination(K - 1, i)) << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define llint long long int
#define LNUM 1000000007
#define MULT(x, y) (((x % LNUM) * (y % LNUM)) % LNUM)
#define SUM(x, y) (((x % LNUM) + (y % LNUM)) % LNUM)

llint combi_val[2002][2002];

void init() {
  for (int i = 0; i < 2002; i++) {
    for (int j = 0; j < 2002; j++) {
      combi_val[i][j] = -1;
    }
  }
}

llint combi(int n, int k) {
  if (combi_val[n][k] == -1) {
    if (n == k || k == 0)
      combi_val[n][k] = 1;
    else
      combi_val[n][k] = SUM(combi(n - 1, k - 1), combi(n - 1, k));
  }
  return combi_val[n][k];
}

int main(void) {

  init();

  int n, k;
  std::cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    std::cout << MULT(combi(n - k + 1, i), combi(k - 1, i - 1)) << std::endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define llint long long int
#define LNUM 1000000007
#define MULT(x, y) (((x % LNUM) * (y % LNUM)) % LNUM)
#define SUM(x, y) (((x % LNUM) + (y % LNUM)) % LNUM)

llint combi_val[2002][2002];

void init() {
  for (int i = 0; i < 2002; i++) {
    for (int j = 0; j < 2002; j++) {
      combi_val[i][j] = -1;
    }
  }
}

llint combi(int n, int k) {
  if (combi_val[n][k] == -1) {
    if (n == k || k == 0)
      combi_val[n][k] = 1;
    else
      combi_val[n][k] = SUM(combi(n - 1, k - 1), combi(n - 1, k));
  }
  return combi_val[n][k];
}

int main(void) {

  init();

  int n, k;
  std::cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    if (n - k + 1 < i)
      std::cout << 0 << std::endl;
    else
      std::cout << MULT(combi(n - k + 1, i), combi(k - 1, i - 1)) << std::endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e7 + 10;
int n, k;
int fac[N], inv[N];
template <typename T> inline void read(T &x) {
  T flg = 1;
  x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      flg = -flg;
    ch = getchar();
  }
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  x *= flg;
}
template <typename T> inline void write(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
inline int ksm(int b, int p) {
  int ans = 1;
  while (p) {
    if (p & 1)
      ans = ans * b % MOD;
    b = b * b % MOD;
    p >>= 1;
  }
  return ans;
}
inline void get_inv() {
  fac[0] = 1;
  inv[0] = 1;
  for (register int i = 1; i <= n; ++i)
    fac[i] = fac[i - 1] * i % MOD;
  inv[n] = ksm(fac[n], MOD - 2);
  for (register int i = n - 1; i >= 1; --i)
    inv[i] = inv[i + 1] % MOD * (i + 1) % MOD;
}
inline int C(int n, int m) {
  return fac[n] % MOD * inv[m] % MOD * inv[n - m] % MOD;
}
signed main() {
  read(n);
  read(k);
  get_inv();
  for (register int i = 1; i <= k; ++i)
    write(C(n - k + 1, i) * C(k - 1, i - 1) % MOD), puts("");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e7 + 10;
int n, k;
int fac[N], inv[N];
template <typename T> inline void read(T &x) {
  T flg = 1;
  x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      flg = -flg;
    ch = getchar();
  }
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  x *= flg;
}
template <typename T> inline void write(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
inline int ksm(int b, int p) {
  int ans = 1;
  while (p) {
    if (p & 1)
      ans = ans * b % MOD;
    b = b * b % MOD;
    p >>= 1;
  }
  return ans;
}
inline void get_inv() {
  fac[0] = 1;
  inv[0] = 1;
  for (register int i = 1; i <= n; ++i)
    fac[i] = fac[i - 1] * i % MOD;
  inv[n] = ksm(fac[n], MOD - 2);
  for (register int i = n - 1; i >= 1; --i)
    inv[i] = inv[i + 1] % MOD * (i + 1) % MOD;
}
inline int C(int n, int m) {
  if (m > n)
    return 0;
  if (m == n)
    return 1;
  return fac[n] % MOD * inv[m] % MOD * inv[n - m] % MOD;
}
signed main() {
  read(n);
  read(k);
  get_inv();
  for (register int i = 1; i <= k; ++i)
    write(C(n - k + 1, i) * C(k - 1, i - 1) % MOD), puts("");
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3 + 7;
const int maxm = 2e6 + 7;
const ll mod = 1e9 + 7;
int n, m, k;

ll f[maxn], inv[maxn], sinv[maxn];
ll cc(ll a, ll b) {
  if (a == b || b == 0)
    return 1;
  return f[a] * sinv[a - b] % mod * sinv[b] % mod;
}
int main() {
  scanf("%d%d", &n, &k);
  m = n - k;
  f[0] = 1;
  for (int i = 1; i < maxn; i++)
    f[i] = f[i - 1] * i % mod;
  inv[0] = inv[1] = 1;
  for (int i = 2; i < maxn; i++)
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  sinv[0] = 1;
  for (int i = 1; i < maxn; i++)
    sinv[i] = sinv[i - 1] * inv[i] % mod;
  for (int i = 1; i < maxn; i++)
    assert(f[i] * sinv[i] % mod == 1);

  for (int i = 1; i <= k; i++) {
    printf("%lld\n", cc(m + 1, i) * cc(k - 1, i - 1) % mod);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3 + 7;
const int maxm = 2e6 + 7;
const ll mod = 1e9 + 7;
int n, m, k;

ll f[maxn], inv[maxn], sinv[maxn];
ll cc(ll a, ll b) {
  if (a < b)
    return 0;
  if (a == b || b == 0)
    return 1;
  return f[a] * sinv[a - b] % mod * sinv[b] % mod;
}
int main() {
  scanf("%d%d", &n, &k);
  m = n - k;
  f[0] = 1;
  for (int i = 1; i < maxn; i++)
    f[i] = f[i - 1] * i % mod;
  inv[0] = inv[1] = 1;
  for (int i = 2; i < maxn; i++)
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  sinv[0] = 1;
  for (int i = 1; i < maxn; i++)
    sinv[i] = sinv[i - 1] * inv[i] % mod;
  for (int i = 1; i < maxn; i++)
    assert(f[i] * sinv[i] % mod == 1);

  for (int i = 1; i <= k; i++) {
    printf("%lld\n", cc(m + 1, i) * cc(k - 1, i - 1) % mod);
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

const ll dev = (ll)(1e9) + 7;

vector<ll> fac(2001);  // n!(mod M)
vector<ll> ifac(2001); // k!^{M-2} (mod M)

ll mpow(ll x,
        ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % dev;
    x = x * x % dev;
    n = n >> 1;
  }
  return ans;
}

ll comb(ll a, ll b) { // aCbをmod計算
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % dev;
  return tmp * fac[a] % dev;
}

int main() {
  int n, k;

  cin >> n;
  cin >> k;

  ll ret = 0;

  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 2001; i++) {
    fac[i + 1] = fac[i] * (i + 1) % dev; // n!(mod M)
    ifac[i + 1] = ifac[i] * mpow(i + 1, dev - 2) %
                  dev; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }

  for (size_t i = 1; i <= k; ++i) {
    ll co = comb(n - k + 1, i);
    ll rem = comb(k - 1, i - 1);
    ret = (co * rem) % dev;

    cout << ret << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

const ll dev = (ll)(1e9) + 7;

vector<ll> fac(10000);  // n!(mod M)
vector<ll> ifac(10000); // k!^{M-2} (mod M)

ll mpow(ll x,
        ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % dev;
    x = x * x % dev;
    n = n >> 1;
  }
  return ans;
}

ll comb(ll a, ll b) { // aCbをmod計算
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % dev;
  return tmp * fac[a] % dev;
}

int main() {
  int n, k;

  cin >> n;
  cin >> k;

  ll ret = 0;

  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 2001; i++) {
    fac[i + 1] = fac[i] * (i + 1) % dev; // n!(mod M)
    ifac[i + 1] = ifac[i] * mpow(i + 1, dev - 2) %
                  dev; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }

  for (size_t i = 1; i <= k; ++i) {
    ll co = comb(n - k + 1, i);
    ll rem = comb(k - 1, i - 1);
    ret = (co * rem) % dev;

    cout << ret << endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main() {
  const int MOD = 1000000007;

  long long N, K;
  cin >> N >> K;

  vector<long long> kaijou(2010, 1);
  for (int i = 1; i <= 2000; i++)
    kaijou.at(i) = kaijou.at(i - 1) * i % MOD;

  for (int i = 1; i <= K; i++) {
    long long bunbo = kaijou.at(N - K + 1) * kaijou.at(K - 1) % MOD;
    long long bunshi = kaijou.at(N - K + 1 - i) * kaijou.at(i) % MOD *
                       kaijou.at(K - i) % MOD * kaijou.at(i - 1) % MOD;
    cout << bunbo * modinv(bunshi, MOD) % MOD << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main() {
  const int MOD = 1000000007;

  long long N, K;
  cin >> N >> K;

  vector<long long> kaijou(2010, 1);
  for (int i = 1; i <= 2000; i++)
    kaijou.at(i) = kaijou.at(i - 1) * i % MOD;

  for (int i = 1; i <= K; i++) {
    if (N - K + 1 < i) {
      cout << 0 << endl;
      continue;
    }
    long long bunbo = kaijou.at(N - K + 1) * kaijou.at(K - 1) % MOD;
    long long bunshi = kaijou.at(N - K + 1 - i) * kaijou.at(i) % MOD *
                       kaijou.at(K - i) % MOD * kaijou.at(i - 1) % MOD;
    cout << bunbo * modinv(bunshi, MOD) % MOD << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define mod 1000000007
#define pb push_back
using namespace std;
typedef pair<int, int> pii;

typedef long long ll;
ll factx[22222];
ll factxx[22222];
ll xxcal(ll n, ll x) {
  if (x == 0)
    return 1;
  return x % 2 == 0 ? xxcal((n * n) % mod, x / 2) : (n * xxcal(n, x - 1) % mod);
}
ll ncr(ll n, ll r) {
  ll a = factx[n];
  a *= factxx[r];
  a %= mod;
  a *= factxx[n - r];
  a %= mod;
  return a;
}

int main() {
  factx[0] = 1;
  factxx[0] = xxcal(factx[0], mod - 2);
  for (ll i = 1; i <= 2222; i++) {
    factx[i] = i * factx[i - 1] % mod;
    factxx[i] = xxcal(factx[i], mod - 2);
  }

  long long int n, k;

  cin >> n >> k;

  for (int i = 0; i < k; i++) {
    cout << (ncr(k - 1, i) * ncr(n - k + 1, i + 1)) % mod << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define mod 1000000007
#define pb push_back
using namespace std;
typedef pair<int, int> pii;

typedef long long ll;
ll factx[22222];
ll factxx[22222];
ll xxcal(ll n, ll x) {
  if (x == 0)
    return 1;
  return x % 2 == 0 ? xxcal((n * n) % mod, x / 2) : (n * xxcal(n, x - 1) % mod);
}
ll ncr(ll n, ll r) {
  if (n < r)
    return 0;
  ll a = factx[n];
  a *= factxx[r];
  a %= mod;
  a *= factxx[n - r];
  a %= mod;
  return a;
}

int main() {
  factx[0] = 1;
  factxx[0] = xxcal(factx[0], mod - 2);
  for (ll i = 1; i <= 2222; i++) {
    factx[i] = i * factx[i - 1] % mod;
    factxx[i] = xxcal(factx[i], mod - 2);
  }

  long long int n, k;

  cin >> n >> k;

  for (int i = 0; i < k; i++) {
    cout << (ncr(k - 1, i) * ncr(n - k + 1, i + 1)) % mod << endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) { return (!b ? a : gcd(b, a % b)); }
bool cmp(int a, int b) { return a > b; }
const ll N = 5e5 + 10;
const ll mod = 1e9 + 7;

ll fac[N];

ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}

void init() {
  fac[0] = 1;
  for (ll i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
}

ll inv(ll a) { return binpow(a, mod - 2); }

ll A(ll n, ll m) { return fac[n] * inv(fac[n - m]) % mod; }

ll C(ll n, ll m) { return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod; }

// const ll mod = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
const ld pi = 3.141592653589793;

void solve() {
  ll n, k;
  cin >> n >> k;
  init();
  for (ll i = 1; i <= k; i++) {
    ll ans = C(n - k + 1, i) * C(k - 1, i - 1);
    ans %= mod;
    cout << ans << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) { return (!b ? a : gcd(b, a % b)); }
bool cmp(int a, int b) { return a > b; }
const ll N = 5e5 + 10;
const ll mod = 1e9 + 7;

ll fac[N];

ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}

void init() {
  fac[0] = 1;
  for (ll i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
}

ll inv(ll a) { return binpow(a, mod - 2); }

ll A(ll n, ll m) { return fac[n] * inv(fac[n - m]) % mod; }

ll C(ll n, ll m) { return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod; }

// const ll mod = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
const ld pi = 3.141592653589793;

void solve() {
  ll n, k;
  cin >> n >> k;
  init();
  for (ll i = 1; i <= k; i++) {
    if (n - k + 1 < i) {
      cout << 0 << endl;
      continue;
    }
    ll ans = C(n - k + 1, i) * C(k - 1, i - 1);
    ans %= mod;
    cout << ans << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1 << 30;
int comb[2010][2010];

void comb_table(int n) {
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j == 0 or j == i) {
        comb[i][j] = 1;
      } else {
        comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % int(1e9 + 7);
      }
    }
  }
}

int main() {
  int n, k;
  cin >> n >> k;
  comb_table(2005);
  for (int m = 1; m <= k; m++) {
    ll red = ((comb[n - k - 1][m - 1] * 2) % int(1e9 + 7) +
              (comb[n - k - 1][m - 2] + comb[n - k - 1][m]) % int(1e9 + 7)) %
             int(1e9 + 7);
    ll blue = (comb[k - 1][m - 1]) % int(1e9 + 7);
    ll ans = (red * blue) % int(1e9 + 7);
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1 << 30;
int comb[2010][2010];

void comb_table(int n) {
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j == 0 or j == i) {
        comb[i][j] = 1;
      } else {
        comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % int(1e9 + 7);
      }
    }
  }
}

int main() {
  int n, k;
  cin >> n >> k;
  comb_table(2005);
  if (n == k) {
    for (int m = 1; m <= k; m++) {
      if (m == 1)
        cout << 1 << endl;
      else
        cout << 0 << endl;
    }
  } else {
    for (int m = 1; m <= k; m++) {
      ll red;
      if (m == 1) {
        red = ((comb[n - k - 1][m - 1] * 2) % int(1e9 + 7) +
               (comb[n - k - 1][m]) % int(1e9 + 7)) %
              int(1e9 + 7);
      } else {
        red = ((comb[n - k - 1][m - 1] * 2) % int(1e9 + 7) +
               (comb[n - k - 1][m - 2] + comb[n - k - 1][m]) % int(1e9 + 7)) %
              int(1e9 + 7);
      }
      ll blue = (comb[k - 1][m - 1]) % int(1e9 + 7);
      ll ans = (red * blue) % int(1e9 + 7);
      cout << ans << endl;
    }
  }
}
Problem p02990 (C++)

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

const i64 MOD = 1e9 + 7;

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main() {
  vector<i64> f(4010, 1);
  for (i64 i = 2; i < 4010; i++)
    f[i] = f[i - 1] * i % MOD;
  i64 n, k;
  cin >> n >> k;
  for (i64 i = 1; i <= k; i++) {
    i64 b = k - i, r = n - k - (i - 1);
    cerr << b << " " << r << " " << f[b + i - 1] / f[b] / f[i - 1] << " "
         << f[r + i] / f[r] / f[i] << endl;
    cout << (((f[b + i - 1] * modinv((f[b] * f[i - 1]) % MOD, MOD)) % MOD) *
             ((f[r + i] * modinv((f[r] * f[i]) % MOD, MOD)) % MOD)) %
                MOD
         << endl;
  }
  return 0;
}


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

const i64 MOD = 1e9 + 7;

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main() {
  vector<i64> f(4010, 1);
  for (i64 i = 2; i < 4010; i++)
    f[i] = f[i - 1] * i % MOD;
  i64 n, k;
  cin >> n >> k;
  for (i64 i = 1; i <= k; i++) {
    i64 b = k - i, r = n - k - (i - 1);
    if (0 <= r)
      cout << (((f[b + i - 1] * modinv((f[b] * f[i - 1]) % MOD, MOD)) % MOD) *
               ((f[r + i] * modinv((f[r] * f[i]) % MOD, MOD)) % MOD)) %
                  MOD
           << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
Problem p02990 (C++)

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

using namespace std;
typedef long long ll;

#define ZERO_IQ                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define debug(x, y)                                                            \
  cerr << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl
#define debug2(x, y, z)                                                        \
  cerr << (#x) << " " << (#y) << " " << (#z) << " is " << (x) << " " << (y)    \
       << " " << (z) << endl
#define watch(x) cerr << (#x) << " is " << (x) << endl
const ll mod = 1e9 + 7;
vector<ll> fact(2003), inv(2003);

ll fp(ll base, ll exp) {
  if (exp == 0)
    return 1;
  ll ans = fp(base, exp / 2);
  ans = (ans * ans) % mod;
  if (exp % 2 != 0)
    ans = (ans * (base % mod)) % mod;
  return ans;
}

void calcFacAndInv(ll n) {
  fact[0] = inv[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
    inv[i] = fp(fact[i], mod - 2);
  }
}

ll ncr(ll n, ll r) {
  if (n < r)
    return 0;
  return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

int main() {
  ll n, k;
  cin >> n >> k;
  calcFacAndInv(2003);
  for (int i = 1; i <= k; ++i) {
    cout << 1LL * ((ncr(n - k + 1, i) * ncr(k - 1, i - 1)) % mod) << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ZERO_IQ                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define debug(x, y)                                                            \
  cerr << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl
#define debug2(x, y, z)                                                        \
  cerr << (#x) << " " << (#y) << " " << (#z) << " is " << (x) << " " << (y)    \
       << " " << (z) << endl
#define watch(x) cerr << (#x) << " is " << (x) << endl
const ll mod = 1e9 + 7;
vector<ll> fact(2004), inv(2004);

ll fp(ll base, ll exp) {
  if (exp == 0)
    return 1;
  ll ans = fp(base, exp / 2);
  ans = (ans * ans) % mod;
  if (exp % 2 != 0)
    ans = (ans * (base % mod)) % mod;
  return ans;
}

void calcFacAndInv(ll n) {
  fact[0] = inv[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
    inv[i] = fp(fact[i], mod - 2);
  }
}

ll ncr(ll n, ll r) {
  if (n < r)
    return 0;
  return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

int main() {
  ll n, k;
  cin >> n >> k;
  calcFacAndInv(2003);
  for (int i = 1; i <= k; ++i) {
    cout << 1LL * ((ncr(n - k + 1, i) * ncr(k - 1, i - 1)) % mod) << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a, ll b, ll mod) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 7;

ll fac[MAXN];
ll inv(ll x) { return qpow(x, mod - 2, mod); }
ll cal(int n, int m) {
  if (m < n)
    return 0;
  return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i <= 200000; ++i) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    ll res = 1;
    res *= cal(k - 1, i - 1);
    res %= mod;
    res *= cal(n - k + 1, i);
    res %= mod;
    cout << res << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a, ll b, ll mod) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 7;

ll fac[MAXN];
ll inv(ll x) { return qpow(x, mod - 2, mod); }
ll cal(int n, int m) {
  if (m > n)
    return 0;
  return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i <= 200000; ++i) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    ll res = 1;
    res *= cal(k - 1, i - 1);
    res %= mod;
    res *= cal(n - k + 1, i);
    res %= mod;
    cout << res << endl;
  }
  return 0;
}
Problem p02990 (C++)

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

using namespace std;

#define rep(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define drep(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define debug(x) cout << #x << " = " << x << endl

const int Mod = 1e9 + 7;

int n, k;

long long f[5005];

long long Pow(long long a, int b) {
  long long res = 1;
  while (b) {
    if (b & 1)
      res = res * a % Mod;
    a = a * a % Mod;
    b >>= 1;
  }
  return res;
}

long long C(int m, int n) {
  return 1LL * f[n] * Pow(f[m], Mod - 2) % Mod * Pow(f[n - m], Mod - 2) % Mod;
}

int main() {
  f[0] = 1;
  rep(i, 1, 3000) f[i] = f[i - 1] * i % Mod;

  scanf("%d%d", &n, &k);

  rep(i, 1, k) { printf("%lld\n", C(i - 1, k - 1) * C(i, n - k + 1) % Mod); }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define drep(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define debug(x) cout << #x << " = " << x << endl

const int Mod = 1e9 + 7;

int n, k;

long long f[5005];

long long Pow(long long a, int b) {
  long long res = 1;
  while (b) {
    if (b & 1)
      res = res * a % Mod;
    a = a * a % Mod;
    b >>= 1;
  }
  return res;
}

long long C(int m, int n) {
  if (n < m)
    return 0;
  return 1LL * f[n] * Pow(f[m], Mod - 2) % Mod * Pow(f[n - m], Mod - 2) % Mod;
}

int main() {
  f[0] = 1;
  rep(i, 1, 3000) f[i] = f[i - 1] * i % Mod;

  scanf("%d%d", &n, &k);

  rep(i, 1, k) { printf("%lld\n", C(i - 1, k - 1) * C(i, n - k + 1) % Mod); }

  return 0;
}
Problem p02990 (C++)

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

using namespace std;
using ll = long long;
constexpr long long MOD = 1e9 + 7;
long long factrial[10000];
long long Repeat(long long a, long long cnt) {
  if (cnt == 0)
    return 1LL;
  if (cnt % 2 == 1) {
    long long x = Repeat(a, cnt / 2);
    return (((a * x) % MOD) * x) % MOD;
  } else {
    long long x = Repeat(a, cnt / 2);
    return (x * x) % MOD;
  }
}

long long fact(long long a) {
  if (a == 0)
    return 1LL;
  else if (factrial[a] != 0)
    return factrial[a];
  else
    return factrial[a] = (a * fact(a - 1)) % MOD;
}

long long comb(long long a, long long b) {
  long long fa, fb, fab;
  fa = fact(a);
  fb = fact(b);
  fab = fact(a - b);
  fb = Repeat(fb, MOD - 2);
  fab = Repeat(fab, MOD - 2);
  return (((fa * fb) % MOD) * fab) % MOD;
}

int main() {
  ll N, K;
  cin >> N >> K;
  for (ll i = 1; i <= K; i++) {
    cout << comb(K - 1, i - 1) * comb(N - K + 1, i) % MOD << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
constexpr long long MOD = 1e9 + 7;
long long factrial[10000];
long long Repeat(long long a, long long cnt) {
  if (cnt == 0)
    return 1LL;
  if (cnt % 2 == 1) {
    long long x = Repeat(a, cnt / 2);
    return (((a * x) % MOD) * x) % MOD;
  } else {
    long long x = Repeat(a, cnt / 2);
    return (x * x) % MOD;
  }
}

long long fact(long long a) {
  if (a == 0)
    return 1LL;
  else if (factrial[a] != 0)
    return factrial[a];
  else
    return factrial[a] = (a * fact(a - 1)) % MOD;
}

long long comb(long long a, long long b) {
  long long fa, fb, fab;
  fa = fact(a);
  fb = fact(b);
  fab = fact(a - b);
  fb = Repeat(fb, MOD - 2);
  fab = Repeat(fab, MOD - 2);
  return (((fa * fb) % MOD) * fab) % MOD;
}

int main() {
  ll N, K;
  cin >> N >> K;
  for (ll i = 1; i <= K; i++) {
    if (N - K + 1 >= i)
      cout << comb(K - 1, i - 1) * comb(N - K + 1, i) % MOD << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int MOD = 1000000007;
  int N, K;
  cin >> N >> K;
  unordered_map<int, vector<long long int>> comb;
  comb[1].push_back(1LL);
  comb[1].push_back(1LL);
  for (int i = 2; i <= max(N - K + 1, K - 1); i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i) {
        comb[i].push_back(1LL);
      } else {
        long long int value = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
        comb[i].push_back(value);
      }
    }
  }
  // for (int i = 1; i <= N; i++) {
  //     auto vec = comb[i];
  //     for (auto v: vec) {
  //         cout << v << ", ";
  //     }
  //     cout << endl;
  // }

  long long int ans;
  for (int l = 1; l <= K; l++) {
    if (l > N - K + 1) {
      ans = 0;
    } else {
      // N-K+1_C_l * (K + l - 1)_C_K
      ans = comb[N - K + 1][l] * comb[K - 1][l - 1] % MOD;
    }
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int MOD = 1000000007;
  int N, K;
  cin >> N >> K;
  unordered_map<int, vector<long long int>> comb;
  comb[0].push_back(1LL);
  comb[1].push_back(1LL);
  comb[1].push_back(1LL);
  for (int i = 2; i <= max(N - K + 1, K - 1); i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i) {
        comb[i].push_back(1LL);
      } else {
        long long int value = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
        comb[i].push_back(value);
      }
    }
  }
  // for (int i = 1; i <= N; i++) {
  //     auto vec = comb[i];
  //     for (auto v: vec) {
  //         cout << v << ", ";
  //     }
  //     cout << endl;
  // }

  long long int ans;
  for (int l = 1; l <= K; l++) {
    if (l > N - K + 1) {
      ans = 0;
    } else {
      // N-K+1_C_l * (K + l - 1)_C_K
      ans = comb[N - K + 1][l] * comb[K - 1][l - 1] % MOD;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL << 60)

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO puts("NO\n")
#define No puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// ax+by=1の解
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

// a^k mod p
int modpow(int a, int k, int p) {
  int ans = 1;
  while (k > 0) {
    if (k % 2 == 1) {
      ans *= a;
      ans %= p;
    }
    a = (a * a) % p;
    k = k / 2;
  }
  return ans;
}

// mod mでのaの逆数
ll mod_inverse(ll a, ll m) {
  return modpow(a, m - 2, m);
  //	ll x, y;
  //	extgcd(a, m, x, y);
  //	return (m + x % m) % m;
}

int fac[20001];

// nCr mod p
ll combination(int n, int r, int p) {
  if (r == 0 || r == n)
    return 1;
  //	if (r > n / 2) r = n - r;
  return (fac[n] * mod_inverse(fac[r], p) % p) * mod_inverse(fac[n - r], p) % p;
}

signed main() {

  fac[0] = fac[1] = 1;
  for (int i = 2; i <= 20000; i++)
    fac[i] = (fac[i - 1] * i) % mod;

  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    cout << combination(N - K + 1, i, mod) * combination(K - 1, i - 1, mod) %
                mod
         << endl;
  }

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL << 60)

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO puts("NO\n")
#define No puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// ax+by=1の解
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

// a^k mod p
int modpow(int a, int k, int p) {
  int ans = 1;
  while (k > 0) {
    if (k % 2 == 1) {
      ans *= a;
      ans %= p;
    }
    a = (a * a) % p;
    k = k / 2;
  }
  return ans;
}

// mod mでのaの逆数
ll mod_inverse(ll a, ll m) {
  return modpow(a, m - 2, m);
  //	ll x, y;
  //	extgcd(a, m, x, y);
  //	return (m + x % m) % m;
}

int fac[20001];

// nCr mod p
ll combination(int n, int r, int p) {
  if (r == 0 || r == n)
    return 1;
  if (n < r)
    return 0;
  //	if (r > n / 2) r = n - r;
  return (fac[n] * mod_inverse(fac[r], p) % p) * mod_inverse(fac[n - r], p) % p;
}

signed main() {

  fac[0] = fac[1] = 1;
  for (int i = 2; i <= 20000; i++)
    fac[i] = (fac[i - 1] * i) % mod;

  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    cout << combination(N - K + 1, i, mod) * combination(K - 1, i - 1, mod) %
                mod
         << endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>

const int N = 2005, mod = 1e9 + 7;
int fact[N] = {1}, inv[N] = {1};
int pow_mod(int a, int b) {
  if (b == 0) {
    return 1;
  }
  int nesf = pow_mod(a, b / 2);
  if (b % 2 == 0) {
    return (nesf * nesf) % mod;
  } else {
    return a * nesf % mod * nesf % mod;
  }
}
int comb(int n, int k) { return fact[n] * inv[k] % mod * inv[n - k] % mod; }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  for (int i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
    inv[i] = pow_mod(fact[i], mod - 2);
  }
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cout << comb(n - k + 1, i) * comb(k - 1, i - 1) % mod << "\n";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>

const int N = 2005, mod = 1e9 + 7;
int fact[N] = {1}, inv[N] = {1};
int pow_mod(int a, int b) {
  if (b == 0) {
    return 1;
  }
  int nesf = pow_mod(a, b / 2);
  if (b % 2 == 0) {
    return (nesf * nesf) % mod;
  } else {
    return a * nesf % mod * nesf % mod;
  }
}
int comb(int n, int k) {
  if (k > n)
    return 0ll;
  return fact[n] * inv[k] % mod * inv[n - k] % mod;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  for (int i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
    inv[i] = pow_mod(fact[i], mod - 2);
  }
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cout << comb(n - k + 1, i) * comb(k - 1, i - 1) % mod << "\n";
  }
}