Problem p03820 (C++)

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

using namespace std;

typedef long long LL;

struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
#define fin "\n"

#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)

template <typename T> inline void chmin(T &l, T r) { l = min(l, r); }

template <typename T> inline void chmax(T &l, T r) { l = max(l, r); }

template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &it : v)
    is >> it;
  return is;
}
const int MOD = 1e9 + 7;
#define SZ 2123
LL comb[2 * SZ][2 * SZ];
LL C[SZ][SZ];
struct latte {
  latte() {
    REP(i, 2 * SZ) comb[i][0] = comb[i][i] = 1;
    FOR(i, 2, 2 * SZ) {
      FOR(j, 1, 2 * SZ) {
        comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
      }
    }
    REP(i, SZ) REP(j, SZ) C[i][j] = 0;
    C[0][0] = 1;
    REP(i, SZ - 1) {
      FOR(j, 0, SZ - 1) {
        C[i + 1][j + 1] += C[i][j];
        C[i + 1][0] += MOD - C[i][j];
      }
      for (int j = SZ - 1; j > 0; j--)
        (C[i + 1][j - 1] += C[i + 1][j]) %= MOD;
    }
  }
} malta;

inline LL nHr(LL n, LL r) {
  // if(r<0||n<r)return 0;
  return comb[n + r - 1][r];
}
int main() {
  int N, K;
  cin >> N >> K;
  LL res = 0;
  if (N == K)
    return -1;
  REP(i, K) {
    int n = i;
    int r = K - i - 1;
    LL ans = 0;
    REP(j, n + 1)
    ans += C[n][j] * nHr(j + 1, r) % MOD;
    ans %= MOD;
    (res += ans * comb[N - n - 2][r] % MOD) %= MOD;
  }
  REP(i, N - K - 1)(res <<= 1) %= MOD;
  cout << res << endl;
  return 0;
}


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

using namespace std;

typedef long long LL;

struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
#define fin "\n"

#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)

template <typename T> inline void chmin(T &l, T r) { l = min(l, r); }

template <typename T> inline void chmax(T &l, T r) { l = max(l, r); }

template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &it : v)
    is >> it;
  return is;
}
const int MOD = 1e9 + 7;
#define SZ 2123
LL comb[2 * SZ][2 * SZ];
LL C[SZ][SZ];
struct latte {
  latte() {
    REP(i, 2 * SZ) comb[i][0] = comb[i][i] = 1;
    FOR(i, 2, 2 * SZ) {
      FOR(j, 1, 2 * SZ) {
        comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
      }
    }
    REP(i, SZ) REP(j, SZ) C[i][j] = 0;
    C[0][0] = 1;
    REP(i, SZ - 1) {
      FOR(j, 0, SZ - 1) {
        C[i + 1][j + 1] += C[i][j];
        C[i + 1][0] += MOD - C[i][j];
      }
      for (int j = SZ - 1; j > 0; j--)
        (C[i + 1][j - 1] += C[i + 1][j]) %= MOD;
    }
  }
} malta;

inline LL nHr(LL n, LL r) {
  // if(r<0||n<r)return 0;
  return comb[n + r - 1][r];
}
int main() {
  int N, K;
  cin >> N >> K;
  LL res = 0;
  if (N == K) {
    REP(i, N)
    res += C[N - 1][i];
    res %= MOD;
  } else {
    REP(i, K) {
      int n = i;
      int r = K - i - 1;
      LL ans = 0;
      REP(j, n + 1)
      ans += C[n][j] * nHr(j + 1, r) % MOD;
      ans %= MOD;
      (res += ans * comb[N - n - 2][r] % MOD) %= MOD;
    }
  }
  REP(i, N - K - 1)(res <<= 1) %= MOD;
  cout << res << endl;
  return 0;
}