import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { new Main().run(); } long pow(long a, long n) { long ret = 1; for (; n > 0; n >>= 1, a = a * a % MOD) { if (n % 2 == 1) { ret = ret * a % MOD; } } return ret; } long inv(long a) { return pow(a, MOD - 2); } final long MOD = (long) 1e9 + 7; void run() throws Exception { Scanner sc = new Scanner(System.in); long N = sc.nextInt(); long K = sc.nextInt(); long P = 1; for (long i = 0; i < K; ++i) { P = P * (N - 1 - i) % MOD; } long sum = N * (N + 1) % MOD * inv(2) % MOD; long ans = P * sum % MOD; P = 1; for (long i = N - 2; i >= 1; --i) { P = P * i % MOD; } for (long i = K - 2; i >= 1; --i) { P = P * inv(i) % MOD; } for (long i = N - 2 - (K - 2); i >= 1; --i) { P = P * inv(i) % MOD; } for (long i = 1; i <= K; ++i) { P = P * i % MOD; } P = P * inv(2) % MOD; sum = (sum - N + MOD) % MOD; ans = (ans + P * sum % MOD) % MOD; System.out.println(ans); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }