#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint1000000007; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } #define N_MAX 1000002 mint inv[N_MAX],fac[N_MAX],finv[N_MAX]; void init(){ const ll MOD = mint::mod(); fac[0]=1;fac[1]=1; finv[0]=1;finv[1]=1; inv[1]=1; for(int i=2;i class Cumsum{ public: Cumsum(vector v): v(v){ n = v.size(); v_cumsum = vector(n+1, T(0)); for(int i = 0; i < n; i++) v_cumsum[i+1] = v_cumsum[i]+v[i]; } /** * v[l] + ... + v[r-1] */ T sum(int l, int r){ if(r <= l) return T(0); if(r > n) r = n; if(l < 0) l = 0; return v_cumsum[r]-v_cumsum[l]; } private: int n; vector v; vector v_cumsum; }; mint naive(int n, int m){ mint ans = 0; for(int i = m; i <= n; i++){ int j = n-i; int sum = i-j; ans += n*comb(n, i); ans += abs(sum)*comb(n, i); int l = max(1, -sum); // debug_value(sum) for(int x = 1; x <= j; x++){ if(i+x <= j) continue; ans += comb(n, j-x)*2; // debug_value(comb(n, j-x)) } } return ans; } mint solve(int n, int m){ mint ans = 0; vector v(n+1); for(int i = 0; i <= n; i++) v[i] = comb(n, i); auto cumsum = Cumsum(v); for(int i = m; i <= n; i++){ int j = n-i; int sum = i-j; ans += n*comb(n, i); ans += abs(sum)*comb(n, i); ans += 2*cumsum.sum(0, min(j, i)); } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; init(); int n, m; cin >> n >> m; // cout << naive(n, m) << endl; cout << solve(n, m) << endl; }