// Validator #include "testlib.h" #include #include #include #include using namespace std; 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[i] = facs[i - 1] * i; facinvs.assign(N + 1, facs.back().inv()); for (int i = N; i > 0; i--) facinvs[i - 1] = facinvs[i] * i; } modint ncr(int n, int r) const { if (n < 0 or r < 0 or n < r) return 0; return facs[n] * facinvs[r] * facinvs[n - r]; } modint operator[](int i) const { return facs[i]; } modint finv(int i) const { return facinvs[i]; } }; using mint = atcoder::modint1000000007; acl_fac fac(1000000); int main(int argc, char **argv) { registerValidation(argc, argv); int N = inf.readInt(1, 1000000); inf.readSpace(); int M = inf.readInt(0, N); inf.readEoln(); inf.readEof(); acl_fac fac(N); vector ncrs(N + 1); for (int i = 0; i < int(ncrs.size()); i++) ncrs[i] = fac.ncr(N, i); vector ncr_cums(ncrs.size() + 1); for (int i = 0; i < int(ncrs.size()); i++) ncr_cums[i + 1] = ncr_cums[i] + ncrs[i]; mint ret = 0; auto add_closed = [&](int l, int r) { if (l > r) return; l = max(l, 0); r = min(r, N); ret += ncr_cums[r + 1] - ncr_cums[l]; }; for (int h = 1; h <= N; h++) { if (M - (N - M) >= h) { add_closed(M, N); } else { int l = h + (N - h + 1) / 2; add_closed(l, N); if ((N - h) % 2) { add_closed(l, l - 1 + l - M); } else { add_closed(l + 1, l + l - M); } } } const int K = N - M; for (int h = 1; h <= K; h++) { const int l = h + (N - h + 1) / 2; if (l <= K) { add_closed(l, K); if ((N - h) % 2) { add_closed(l, N); } else { add_closed(l + 1, N); } } else { add_closed(h + N - K, N); } } for (int i = M; i <= N; i++) ret += fac.ncr(N, i) * N; cout << ret.val() << '\n'; }