# a^n mod p
def exp_by_sq(a, n, p):
    if n == 0:
        exp = 1
    elif n == 1:
        exp = a % p
    elif  n % 2 == 0:
        exp = exp_by_sq(a * a % p, n // 2, p)
    else:
        exp = a * exp_by_sq(a * a % p, (n - 1) // 2, p) % p
    return exp % p

# 入力
n, k = [int(x) for x in input().split()]

p = 10 ** 9 + 7
# Find n * sum_{j = 0..m}{(n choose j)^2 * (n - j)}
m = min(n, k)
# 最初の2項
binom = n # n choose 1  mod p
ans = n * ((n * n - n + 1) % p) % p  # (n choose 0)^2 * (n - 0) + (n choose 1)^2 * (n - 1)
inv = [0, 1]
inv_n = exp_by_sq(n, p - 2, p)  # n^(-1) mod p

for i in range(2, m + 1):
    inv_i = ( inv[p % i] * (p - p//i) ) % p  # inverse of i
    inv.append(inv_i)
    binom = (binom * (n - i + 1) % p) * inv_i % p
    ans = (ans + (binom * binom % p) * (n - i)) % p

ans = ans * inv_n % p
print(ans) def exp_by_sq(a, n, p):
    if n == 0:
        exp = 1
    elif n == 1:
        exp = a % p
    elif  n % 2 == 0:
        exp = exp_by_sq(a * a % p, n // 2, p)
    else:
        exp = a * exp_by_sq(a * a % p, (n - 1) // 2, p) % p
    return exp % p

# 入力 exp_by_sq if n == 0:
        exp = 1
    elif n == 1:
        exp = a % p
    elif  n % 2 == 0:
        exp = exp_by_sq(a * a % p, n // 2, p)
    else:
        exp = a * exp_by_sq(a * a % p, (n - 1) // 2, p) % p
     n == 0 n 0 exp = 1 exp 1 elif n == 1:
        exp = a % p
     n == 1 n 1 exp = a % p exp a % p a p elif  n % 2 == 0:
        exp = exp_by_sq(a * a % p, n // 2, p)
     n % 2 == 0 n % 2 n 2 0 exp = exp_by_sq(a * a % p, n // 2, p) exp exp_by_sq(a * a % p, n // 2, p) exp_by_sq a * a % p a * a a a p n // 2 n 2 p exp = a * exp_by_sq(a * a % p, (n - 1) // 2, p) % p exp a * exp_by_sq(a * a % p, (n - 1) // 2, p) % p a * exp_by_sq(a * a % p, (n - 1) // 2, p) a exp_by_sq(a * a % p, (n - 1) // 2, p) exp_by_sq a * a % p a * a a a p (n - 1) // 2 n - 1 n 1 2 p p return exp % p exp % p exp p a a n n p p int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n, k = [int(x) for x in input().split()] n [int(x) for x in input().split()] k p = 10 ** 9 + 7 p 10 ** 9 + 7 10 ** 9 10 9 7 m = min(n, k) m min(n, k) min n k binom = n binom n ans = n * ((n * n - n + 1) % p) % p ans n * ((n * n - n + 1) % p) % p n * ((n * n - n + 1) % p) n (n * n - n + 1) % p n * n - n + 1 n * n - n n * n n n n 1 p p inv = [0, 1] inv [0, 1] 0 1 inv_n = exp_by_sq(n, p - 2, p) inv_n exp_by_sq(n, p - 2, p) exp_by_sq n p - 2 p 2 p for i in range(2, m + 1):
    inv_i = ( inv[p % i] * (p - p//i) ) % p  # inverse of i
    inv.append(inv_i)
    binom = (binom * (n - i + 1) % p) * inv_i % p
    ans = (ans + (binom * binom % p) * (n - i)) % p i range(2, m + 1) range 2 m + 1 m 1 inv_i = ( inv[p % i] * (p - p//i) ) % p inv_i ( inv[p % i] * (p - p//i) ) % p inv[p % i] * (p - p//i) inv[p % i] inv p % i p i p - p//i p p//i p i p inv.append(inv_i) inv.append inv append inv_i binom = (binom * (n - i + 1) % p) * inv_i % p binom (binom * (n - i + 1) % p) * inv_i % p (binom * (n - i + 1) % p) * inv_i binom * (n - i + 1) % p binom * (n - i + 1) binom n - i + 1 n - i n i 1 p inv_i p ans = (ans + (binom * binom % p) * (n - i)) % p ans (ans + (binom * binom % p) * (n - i)) % p ans + (binom * binom % p) * (n - i) ans (binom * binom % p) * (n - i) binom * binom % p binom * binom binom binom p n - i n i p ans = ans * inv_n % p ans ans * inv_n % p ans * inv_n ans inv_n p print(ans) print ans k = [int(x) for x in input().split()] [int(x) for x in input().split()] k ans = ans * inv_n % p ans * inv_n % p ans def exp_by_sq(a, n, p):
    if n == 0:
        exp = 1
    elif n == 1:
        exp = a % p
    elif  n % 2 == 0:
        exp = exp_by_sq(a * a % p, n // 2, p)
    else:
        exp = a * exp_by_sq(a * a % p, (n - 1) // 2, p) % p
    return exp % p

# 入力 def exp_by_sq(a, n, p):
    if n == 0:
        exp = 1
    elif n == 1:
        exp = a % p
    elif  n % 2 == 0:
        exp = exp_by_sq(a * a % p, n // 2, p)
    else:
        exp = a * exp_by_sq(a * a % p, (n - 1) // 2, p) % p
    return exp % p

# 入力 exp_by_sq inv = [0, 1] [0, 1] inv binom = (binom * (n - i + 1) % p) * inv_i % p (binom * (n - i + 1) % p) * inv_i % p binom inv_i = ( inv[p % i] * (p - p//i) ) % p ( inv[p % i] * (p - p//i) ) % p inv_i ans = (ans + (binom * binom % p) * (n - i)) % p (ans + (binom * binom % p) * (n - i)) % p ans inv_n = exp_by_sq(n, p - 2, p) exp_by_sq(n, p - 2, p) inv_n n, k = [int(x) for x in input().split()] [int(x) for x in input().split()] n m = min(n, k) min(n, k) m binom = n n binom p = 10 ** 9 + 7 10 ** 9 + 7 p ans = n * ((n * n - n + 1) % p) % p n * ((n * n - n + 1) % p) % p ans
# a^n mod p
def exp_by_sq(a, n, p):
    if n == 0:
        exp = 1
    elif n == 1:
        exp = a % p
    elif  n % 2 == 0:
        exp = exp_by_sq(a * a % p, n // 2, p)
    else:
        exp = a * exp_by_sq(a * a % p, (n - 1) // 2, p) % p
    return exp % p

# 入力
n, k = [int(x) for x in input().split()]

p = 10 ** 9 + 7
# Find n * sum_{j = 0..m}{(n choose j)^2 * (n - j)}
m = min(n, k)
# 最初の2項
binom = n # n choose 1  mod p
ans = n * ((n * n - n + 1) % p) % p  # (n choose 0)^2 * (n - 0) + (n choose 1)^2 * (n - 1)
inv = [0, 1]
inv_n = exp_by_sq(n, p - 2, p)  # n^(-1) mod p

for i in range(2, m + 1):
    inv_i = ( inv[p % i] * (p - p//i) ) % p  # inverse of i
    inv.append(inv_i)
    binom = (binom * (n - i + 1) % p) * inv_i % p
    ans = (ans + (binom * binom % p) * (n - i)) % p

ans = ans * inv_n % p
print(ans)
