// Validator #include "testlib.h" #include #include #include #include using namespace std; using mint = atcoder::modint1000000007; // atcoder::static_modint

, P: prime number template struct acl_fac { std::vector facs, facinvs; acl_fac(int N) { assert(-1 <= N and N < modint::mod()); facs.resize(N + 1, 1); for (int i = 1; i <= N; i++) facs.at(i) = facs.at(i - 1) * i; facinvs.assign(N + 1, facs.back().inv()); for (int i = N; i > 0; i--) facinvs.at(i - 1) = facinvs.at(i) * i; } modint ncr(int n, int r) const { if (n < 0 or r < 0 or n < r) return 0; return facs.at(n) * facinvs[r] * facinvs[n - r]; } }; int main(int argc, char **argv) { registerValidation(argc, argv); int N = inf.readInt(2, 4000); inf.readSpace(); int M = inf.readInt(0, 4000); inf.readEoln(); inf.readEof(); acl_fac fac(N + M); vector precalc(N + 1, vector(M + 1)); precalc.at(0).at(0) = 1; for (int n = 0; n <= N; n++) { for (int m = 0; m <= M; m++) { if (n + m - 1 >= 0) precalc.at(n).at(m) = fac.ncr(n + m - 1, n - 1); if (m >= 2) precalc.at(n).at(m) += precalc.at(n).at(m - 2); } } mint ret = 0; if (N % 2 == 0) { int half = (N - 1) / 2; for (int nnonzero = 0; nnonzero <= half * 2; nnonzero++) { mint coeff = 0; for (int npos = 0; npos <= half; npos++) { int nneg = nnonzero - npos; if (nneg < 0 or nneg > half) continue; coeff += fac.ncr(N - 1, npos) * fac.ncr(N - 1 - npos, nneg); } mint tmp = 0; for (int b0 = 0; b0 <= M; b0++) { if (M - nnonzero - b0 < 0) continue; tmp += precalc.at(nnonzero).at(M - nnonzero - b0) * (b0 == 0 ? 1 : 2); } ret += tmp * coeff; } } else { for (int npos = 0; npos <= N / 2; npos++) { for (int nneg = 0; nneg <= N / 2; nneg++) { int nnonzero = npos + nneg; if (M - nnonzero < 0) continue; ret += fac.ncr(N, nnonzero) * fac.ncr(nnonzero, npos) * precalc.at(nnonzero).at(M - nnonzero); } } for (int npos = 0; npos <= N / 2; npos++) { for (int nneg = 0; nneg <= N / 2; nneg++) { int nnonzero = npos + nneg; int m = M - npos - (N - nneg); if (m < 0) continue; ret += fac.ncr(N, nnonzero) * fac.ncr(nnonzero, npos) * precalc.at(nnonzero).at(m) * 2; } } for (int npos = 0; npos <= N / 2; npos++) { for (int nneg = 0; nneg <= N / 2; nneg++) { const int nnonzero = npos + nneg; int m = M - (N - nnonzero) - max(npos, nneg) * 2; if (m < 0) continue; ret -= fac.ncr(N, nnonzero) * fac.ncr(nnonzero, npos) * precalc.at(nnonzero).at(m); } } } cout << ret.val() << '\n'; }