#include #define rep(i,n) for(int i=0;i ; const int INF = 1e9; const int MOD = 1000000007; const int MAX = 1000000; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } //順列を計算 long long PER(int n,int k){ if(n < k) return 0; if(n < 0 || k < 0) return 0; return (fac[n] * finv[n-k]) % MOD; } long long modpow(long long a, long long b,long long mod){ bitset<40> bit(b); string s = bit.to_string(); long long ret = 1; for (int i = 0;i< s.length(); ++i){ ret = (ret * ret) % mod; if(s[i]-'0') ret = (ret * a) % mod; } return ret; } long long inverse(long long x,long long mod){ return modpow(x,mod-2,mod); } int main(){ COMinit(); ll n,k; cin >> n >> k; if(k==1){ cout << ((n+1)*n*(n-1))/2 << endl; return 0; } ll ans = 0; ll res = (PER(n-1,k) + ((COM(n-2,k-2) * fac[k])%MOD * inv[2])%MOD)%MOD; for(ll i=1;i