import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) class Combination(object): def __init__(self, N, con): self.fac = [0] * (N + 1) self.inv = [0] * (N + 1) self.finv = [0] * (N + 1) self.fac[0], self.fac[1] = 1, 1 self.inv[1] = 1 self.finv[0], self.finv[1] = 1, 1 # 前計算 for i in range(2, N + 1): self.fac[i] = self.fac[i - 1] * i % con self.inv[i] = self.inv[con % i] * (con - (con // i)) % con self.finv[i] = self.finv[i - 1] * self.inv[i] % con def com(self, N, k): return (self.fac[N] * self.finv[k] * self.finv[N - k]) % con #処理内容 def main(): N, K = getlist() ans = 0 C = Combination(N, con) if K == 1: ans = int((N + 1) * (N - 1) * N // 2) print(ans) return for i in range(1, N): ans += i * int(K * (K - 1) // 2) * C.fac[N - 2] * C.finv[N - K] ans += i * C.fac[N - 1] * C.finv[N - 1 - K] ans += N * C.fac[N - 1] * C.finv[N - 1 - K] print(ans % con) if __name__ == '__main__': main()