#include using namespace std; using ll = long long; const ll MOD = 1000000007; ll modpow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll calc(int n, int k) { ll res = (n >= 0 && k >= 0); for (int i = 0; i < k; i++) { if (n - i < 0) break; (res *= (n - i)) %= MOD; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, K; cin >> n >> K; ll div2 = (MOD + 1) / 2; ll foo = calc(n - 1, K); ll bar = calc(n - 2, K - 2); ll ans = (foo * n % MOD + (foo + K * (K - 1) % MOD * div2 % MOD * bar % MOD) % MOD * n % MOD * (n - 1) % MOD * div2 % MOD) % MOD; cout << ans << endl; return 0; }