AtCoder Beginner Contest 156 - Roaming

There is a building with n rooms, numbered 1 to n.
We can move from any room to any other room in the building.
Let us call the following event a move: a person in some room i goes to another room j~ (i \neq j).
Initially, there was one person in each room in the building.
After that, we know that there were exactly k moves happened up to now.
We are interested in the number of people in each of the n rooms now. How many combinations of numbers of people in the n rooms are possible?
Find the count modulo (10^9 + 7).

-----Constraints-----
 - All values in input are integers.
 - 3 \leq n \leq 2 \times 10^5
 - 2 \leq k \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
n k

-----Output-----
Print the number of possible combinations of numbers of people in the n rooms now, modulo (10^9 + 7).

-----Sample Input-----
3 2

-----Sample Output-----
10

Let c_1, c_2, and c_3 be the number of people in Room 1, 2, and 3 now, respectively. There are 10 possible combination of (c_1, c_2, c_3):
 - (0, 0, 3)
 - (0, 1, 2)
 - (0, 2, 1)
 - (0, 3, 0)
 - (1, 0, 2)
 - (1, 1, 1)
 - (1, 2, 0)
 - (2, 0, 1)
 - (2, 1, 0)
 - (3, 0, 0)
For example, (c_1, c_2, c_3) will be (0, 1, 2) if the person in Room 1 goes to Room 2 and then one of the persons in Room 2 goes to Room 3.

Difficulty: MEDIUM

Starter code:

Solutions:
def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
(N, K) = map(int, input().split())
n = N * 2
r = min(N, K + 1)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
ans = 0
for i in range(r):
	ans += cmb(N, i, mod) * cmb(N - 1, i, mod)
if K == 1:
	ans -= 1
print(ans % mod)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
ans = 0
coma = 1
comb = 1
for i in range(min(k + 1, n)):
	ans += coma * comb
	ans %= mod
	coma *= (n - i) * pow(i + 1, mod - 2, mod)
	coma %= mod
	comb *= (n - i - 1) * pow(i + 1, mod - 2, mod)
	comb %= mod
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7

def inv(x):
	return pow(x, mod - 2, mod)
N = 2 * 10 ** 5
Fact = [0 for i in range(N + 1)]
Finv = [0 for i in range(N + 1)]
Fact[0] = 1
for i in range(N):
	Fact[i + 1] = Fact[i] * (i + 1) % mod
Finv[N] = inv(Fact[N])
for i in range(N - 1, -1, -1):
	Finv[i] = (i + 1) * Finv[i + 1] % mod

def C(a, b):
	return Fact[a] * (Finv[b] * Finv[a - b]) % mod % mod
ans = 0
for i in range(min(n, k + 1)):
	ans += C(n, i) * C(n - 1, i) % mod
	ans %= mod
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fac = [1]
for i in range(1, 2 * n + 1):
	fac.append(fac[-1] * i % mod)
inv = [pow(fac[-1], mod - 2, mod)]
for i in range(2 * n, 0, -1):
	inv.append(inv[-1] * i % mod)
inv = inv[::-1]

def comb(n, r):
	if n < 1 or n < r:
		return 0
	return fac[n] * inv[r] * inv[n - r] % mod
ret = comb(n + n - 1, n)
for i in range(1, n - k):
	ret -= comb(n - 1, k + i) * comb(n, k + i)
	ret %= mod
print(ret % mod)


from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque, Counter
from operator import mul
import copy
import heapq
(n, k) = list(map(int, input().split()))
m = 4 * 10 ** 5
mod = 10 ** 9 + 7
fact = [0] * (m + 5)
fact_inv = [0] * (m + 5)
inv = [0] * (m + 5)
fact[0] = fact[1] = 1
fact_inv[0] = fact_inv[1] = 1
inv[1] = 1
for i in range(2, m + 5):
	fact[i] = fact[i - 1] * i % mod
	inv[i] = mod - inv[mod % i] * (mod // i) % mod
	fact_inv[i] = fact_inv[i - 1] * inv[i] % mod

def cmb(n, k, mod):
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod
if k >= n - 1:
	print(cmb(2 * n - 1, n - 1, mod) % mod)
else:
	ans = 0
	for i in range(0, k + 1):
		ans += cmb(n, i, mod) * cmb(n - 1, n - i - 1, mod) % mod
		ans %= mod
	print(ans)


def solve():
	mod = 10 ** 9 + 7
	(n, k) = map(int, input().split())
	m = min(n - 1, k)
	ans = 1
	dp0 = [1] * (m + 1)
	dp1 = [1] * (m + 1)
	for i in range(1, m + 1):
		dp0[i] = dp0[i - 1] * (n - i + 1) * pow(i, mod - 2, mod) % mod
		dp1[i] = dp1[i - 1] * (n - i) * pow(i, mod - 2, mod) % mod
		ans += dp0[i] * dp1[i] % mod
		ans %= mod
	return ans
print(solve())


(n, k) = map(int, input().split())
Mod = 10 ** 9 + 7
f = [1] * (2 * n + 1)
for i in range(2, 2 * n + 1):
	f[i] = f[i - 1] * i % Mod

def f_inverse(i):
	return pow(f[i], Mod - 2, Mod)
f_inv = [f_inverse(i) for i in range(2 * n + 1)]

def comb(n, i):
	return f[n] * f_inv[i] * f_inv[n - i] % Mod
Ans = 0
for x in range(0, min(k + 1, n)):
	Ans = (Ans + comb(n, x) * comb(n - 1, x)) % Mod
print(Ans)


def main():
	(n, k) = map(int, input().split())
	MOD = 10 ** 9 + 7

	def pre(n, MOD):
		a = 1
		for i in range(1, n + 1):
			a = a * i % MOD
		an = a
		b = pow(a, MOD - 2, MOD)
		bs = [1] * (n + 1)
		bs[n] = b
		for i in range(n, 1, -1):
			b = b * i % MOD
			bs[i - 1] = b
		return (an, bs)
	(a, b) = pre(n - 1, MOD)
	ans = 1
	for i in range(1, min(n - 1, k) + 1):
		s = a * n * b[i] % MOD
		s = s * b[n - i] % MOD
		s = s * a * b[n - i - 1] % MOD
		s = s * b[i] % MOD
		ans += s
		ans %= MOD
	print(ans)
main()


def nCr_frL(n, r, mod):
	ret = [1, n % mod]
	for i in range(2, r + 1):
		inv = pow(i, mod - 2, mod)
		ret.append(ret[-1] * (n - i + 1) * inv % mod)
	return ret
(N, K) = map(int, input().split())
MOD = 10 ** 9 + 7
com1 = nCr_frL(N, N, MOD)
com2 = nCr_frL(N - 1, N - 1, MOD)
if K > N - 1:
	K = N - 1
ans = 0
for m in range(K + 1):
	ans += com1[m] * com2[N - m - 1] % MOD
print(ans % MOD)


(n, k) = list(map(int, input().split()))
mod = 1000000007
b = mod - 2
blis = []
c = 0
while b > 0:
	if b & 1 == 1:
		blis.append(c)
	c += 1
	b >>= 1

def modinv(a):
	if a == 1:
		return 1
	else:
		res = 1
		li = []
		for _ in range(c):
			li.append(a % mod)
			a = a * a % mod
		for item in blis:
			res = res * li[item] % mod
		return res
if k >= n:
	L = 2 * n - 1
	ansbunsi = 1
	for j in range(n - 1):
		ansbunsi = ansbunsi * L % mod
		L -= 1
	ansbunbo = 1
	L = n - 1
	for j in range(n - 1):
		ansbunbo = ansbunbo * L % mod
		L -= 1
	ansbunbo = modinv(ansbunbo)
	print(ansbunsi * ansbunbo % mod)
else:
	kaijou = [1, 1]
	for j in range(2, n):
		kaijou.append(kaijou[-1] * j % mod)
	ans = 0
	for m in range(k + 1):
		ansbunsi = kaijou[n - 1] ** 2 * n % mod
		ansbunbo = kaijou[n - m - 1] * kaijou[m] % mod
		ansbunbo = ansbunbo * ansbunbo % mod * (n - m) % mod
		ansbunbo = modinv(ansbunbo)
		ans += ansbunbo * ansbunsi % mod
		ans %= mod
	print(ans)


import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
mod = 10 ** 9 + 7
(n, k) = list(map(int, input().split()))
fac = [1] * (n + 1)
inv = [1] * (n + 1)
for i in range(1, n + 1):
	fac[i] = fac[i - 1] * i % mod
inv[n] = pow(fac[n], mod - 2, mod)
for i in range(n, 0, -1):
	inv[i - 1] = inv[i] * i % mod

def cmb(n, r):
	if r < 0 or r > n:
		return 0
	return fac[n] * inv[r] % mod * inv[n - r] % mod
ans = 0
k = min(k, n - 1)
for i in range(k + 1):
	ans += cmb(n, i) * cmb(n - 1, i) % mod
print(ans % mod)


(n, k) = map(int, input().split())
mod = pow(10, 9) + 7
n_ = 4 * 10 ** 5 + 5
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
	fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
	rev[i] = rev[i + 1] * (i + 1) % mod

def cmb(n, r):
	if n <= 0 or r < 0 or r > n:
		return 0
	return fun[n] * rev[r] % mod * rev[n - r] % mod
if n <= k - 1:
	print(cmb(2 * n - 1, n))
else:
	answer = 0
	for m in range(k + 1):
		answer += cmb(n, m) * cmb(n - 1, m) % mod
		answer %= mod
	print(answer)


mod = 10 ** 9 + 7
(n, k) = map(int, input().split())
fact = [1] * (2 * n + 1)
inv = [1] * (2 * n + 1)
invf = [1] * (2 * n + 1)
for i in range(2, 2 * n + 1):
	fact[i] = fact[i - 1] * i % mod
	inv[i] = -inv[mod % i] * (mod // i) % mod
	invf[i] = invf[i - 1] * inv[i] % mod
count = 0
for i in range(min(n, k + 1)):
	c = fact[n] * invf[n - i] * invf[i] % mod
	count += c * fact[n - 1] * invf[n - i - 1] * invf[i] % mod
	count %= mod
print(count)


def prepare(n, mod):
	fac = [1]
	for i in range(1, n + 1):
		fac.append(fac[-1] * i % mod)
	rec = pow(fac[-1], mod - 2, mod)
	den = [1 for _ in range(n + 1)]
	den[n] = rec
	for i in range(n - 1, 0, -1):
		rec = rec * (i + 1) % mod
		den[i] = rec
	return (fac, den)

def comb_mod(n, r, mod, fac, den):
	return fac[n] * den[r] * den[n - r] % mod
(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
(fac, den) = prepare(2 * n - 1, mod)
if k >= n - 1:
	print(comb_mod(2 * n - 1, n, mod, fac, den))
else:
	ans = 0
	for i in range(k + 1):
		ans += comb_mod(n - 1, i, mod, fac, den) * comb_mod(n, i, mod, fac, den)
		ans %= mod
	print(ans)


SIZE = 4 * 10 ** 5 + 1
MOD = 10 ** 9 + 7
SIZE += 1
inv = [0] * SIZE
fac = [0] * SIZE
finv = [0] * SIZE
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2, SIZE):
	inv[i] = MOD - MOD // i * inv[MOD % i] % MOD
	fac[i] = fac[i - 1] * i % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD

def choose(n, r):
	if 0 <= r <= n:
		return fac[n] * finv[r] % MOD * finv[n - r] % MOD
	else:
		return 0

def chofuku(ball, box):
	return choose(box + ball - 1, box)
(N, K) = list(map(int, input().split()))
ans = 0
for i in range(min(N, K + 1)):
	ans += choose(N, i) * chofuku(N - i, i) % MOD
print(ans % MOD)


def combinations(n, k, mod):
	(x, y) = (1, 1)
	for i in range(k):
		x = x * (n - i) % mod
		y = y * (i + 1) % mod
	return x * pow(y, mod - 2, mod) % mod
mod = 10 ** 9 + 7
(n, k) = map(int, input().split())

def cmap(n, k):
	x = [1]
	y = [1]
	c = [1]
	for i in range(k + 1):
		x.append(x[i] * (n - i) % mod)
		y.append(y[i] * (i + 1) % mod)
		c.append(x[i + 1] * pow(y[i + 1], mod - 2, mod) % mod)
	return c
nc = cmap(n, n - 1)
n1c = cmap(n - 1, n - 2)
ans = 0
for i in range(min(n - 1, k) + 1):
	ans = (ans + nc[i] * n1c[i]) % mod
print(ans)


def memfact(a, m):
	temp = 1
	yield temp
	for i in range(1, a + 1):
		temp = temp * i % m
		yield temp

def comb(n, r, m):
	if r == 0:
		return 1
	return memf[n] * pow(memf[r], m - 2, m) * pow(memf[n - r], m - 2, m)
(n, k) = map(int, open(0).read().split())
dp = [0] * n
dp[0] = 1
m = 1000000007
dp[1] = n * (n - 1) % m
memf = []
mfappend = memf.append
for x in memfact(n, m):
	mfappend(x)
for i in range(2, min(k + 1, n)):
	dp[i] = (dp[i - 1] + comb(n, i, m) * comb(n - 1, i, m)) % m
print((dp[min(n - 1, k)] + 1) % m)


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 7)
	from collections import Counter, deque
	from itertools import combinations, permutations, accumulate, groupby, product
	from bisect import bisect_left, bisect_right
	from heapq import heapify, heappop, heappush
	import math
	mod = 10 ** 9 + 7
	max_n = 2 * 10 ** 5
	(fac, inv) = ([1] * (max_n + 1), [0] * (max_n + 1))
	for i in range(2, max_n + 1):
		fac[i] = fac[i - 1] * i % mod
	inv[-1] = pow(fac[-1], mod - 2, mod)
	for i in range(max_n, 0, -1):
		inv[i - 1] = inv[i] * i % mod

	def ncr(n, r):
		return fac[n] * inv[r] * inv[n - r] % mod
	(n, k) = list(map(int, input().split()))
	res = 0
	for i in range(n):
		if i > k:
			continue
		res += ncr(n, i) * ncr(n - 1, i)
		res %= mod
	print(res)

def __starting_point():
	main()
__starting_point()


(n, k) = list(map(int, input().split()))
mod = 10 ** 9 + 7
f = [1] * (n + 1)
inv = [1] * (n + 1)
for i in range(1, n + 1):
	f[i] = f[i - 1] * i % mod
inv[n] = pow(f[n], mod - 2, mod)
for i in range(n, 0, -1):
	inv[i - 1] = inv[i] * i % mod

def nCr(n, r):
	if r < 1:
		return 1
	return f[n] * inv[r] % mod * inv[n - r] % mod
ans = 0
for i in range(min(k, n - 1) + 1):
	ans = (ans + nCr(n, i) * nCr(n - 1, i)) % mod
print(ans)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [Scanner.string() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [Scanner.int() for i in range(n)]
MOD = int(1000000000.0) + 7

def solve():
	MAX = 2 * 10 ** 5 + 10
	fac = [0] * MAX
	inv = [0] * MAX
	finv = [0] * MAX
	fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1
	for i in range(2, MAX):
		fac[i] = fac[i - 1] * i % MOD
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD

	def cmb(n, k):
		if n < k:
			return 0
		if n < 0 or k < 0:
			return 0
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
	(N, K) = Scanner.map_int()
	ans = 0
	for i in range(min(N - 1, K) + 1):
		ans += cmb(N, i) * cmb(N - 1, i)
		ans %= MOD
	print(ans)

def main():
	solve()

def __starting_point():
	main()
__starting_point()


(n, k) = list(map(int, input().split()))
mod = 10 ** 9 + 7
k = min(k, n - 1)

def choose(n, r):
	x = 1
	y = 1
	for i in range(1, r + 1):
		x = x * (n - i + 1) % mod
		y = y * i % mod
	return x * pow(y, mod - 2, mod) % mod
kaijo = [1]
for i in range(1, n + 1):
	kaijo.append(kaijo[i - 1] * i % mod)
ans = 0
for i in range(k + 1):
	ans += kaijo[n] * pow(kaijo[i] * kaijo[n - i], mod - 2, mod) * kaijo[n - 1] * pow(kaijo[i] * kaijo[n - 1 - i], mod - 2, mod)
	ans = ans % mod
print(ans % mod)


import sys
import math
import collections
import bisect
import itertools
import fractions
import copy
import decimal
import queue
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
ni = lambda : int(sys.stdin.readline())
ns = lambda : list(map(int, sys.stdin.readline().split()))
na = lambda : list(map(int, sys.stdin.readline().split()))

def main():

	def prepare(n, MOD):
		f = 1
		factorials = [1]
		for m in range(1, n + 1):
			f *= m
			f %= MOD
			factorials.append(f)
		inv = pow(f, MOD - 2, MOD)
		invs = [1] * (n + 1)
		invs[n] = inv
		for m in range(n, 1, -1):
			inv *= m
			inv %= MOD
			invs[m - 1] = inv
		return (factorials, invs)
	(n, k) = ns()
	(facts, invs) = prepare(n, MOD)
	ans = 0
	for ki in range(min(n, k + 1)):
		zero_comb = facts[n] * invs[ki] * invs[n - ki] % MOD
		nonzero_comb = facts[n - 1] * invs[ki] * invs[n - 1 - ki] % MOD
		ans += zero_comb * nonzero_comb % MOD
		ans %= MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


nn = 404040
P = 10 ** 9 + 7
fa = [1] * (nn + 1)
fainv = [1] * (nn + 1)
for i in range(nn):
	fa[i + 1] = fa[i] * (i + 1) % P
fainv[-1] = pow(fa[-1], P - 2, P)
for i in range(nn)[::-1]:
	fainv[i] = fainv[i + 1] * (i + 1) % P
C = lambda a, b: fa[a] * fainv[b] * fainv[a - b] % P if 0 <= b <= a else 0
(N, K) = map(int, input().split())
if K >= N - 1:
	print(C(2 * N - 1, N))
else:
	s = 0
	for i in range(K + 1):
		s = (s + C(N, i) * C(N - 1, i)) % P
	print(s)


MOD = 10 ** 9 + 7
MAX = int(200000.0)

def div(a, b):
	return a * pow(b, MOD - 2, MOD) % MOD
FACT = [1] * (MAX + 1)
for i in range(1, MAX + 1):
	FACT[i] = i * FACT[i - 1] % MOD
INV = [1] * (MAX + 1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
	INV[i - 1] = INV[i] * i % MOD

def main():
	(n, k) = map(int, input().split())
	ans = 0
	for i in range(min(n - 1, k) + 1):
		tmp = FACT[n] * INV[i] * INV[n - i] % MOD
		tmp = tmp * FACT[n - 1] * INV[n - i - 1] * INV[i] % MOD
		ans = (ans + tmp) % MOD
	print(ans)
main()


mod = 10 ** 9 + 7
f = [1]
for i in range(10 ** 6):
	f += [f[-1] * (i + 1) % mod]

def comb(a, b):
	return f[a] * pow(f[b], mod - 2, mod) * pow(f[a - b], mod - 2, mod) % mod
(n, k) = map(int, input().split())
ans = comb(n * 2 - 1, n - 1)
if k >= n - 1:
	print(ans)
	exit()
for i in range(n - 1, k, -1):
	anss = comb(n - 1, i) * comb(n, n - i) % mod
	ans = ans + (mod - anss)
	ans %= mod
print(ans)


MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, n, mod):
		self.f = [1]
		self.mod = mod
		for j in range(1, n + 1):
			self.f.append(self.f[-1] * j % mod)
		self.i = [pow(self.f[-1], mod - 2, mod)]
		for j in range(n, 0, -1):
			self.i.append(self.i[-1] * j % mod)
		self.i.reverse()

	def factorial(self, j):
		return self.f[j]

	def ifactorial(self, j):
		return self.i[j]

	def comb(self, n, k):
		return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0
(N, K) = map(int, input().split())
K = min(K, N - 1)
F = Factorial(N + 1, MOD)
ans = 0
for k in range(K + 1):
	tmp = F.comb(N, k) * F.factorial(N - 1) * F.ifactorial(N - 1 - k) * F.ifactorial(k)
	ans += tmp % MOD
	ans %= MOD
print(ans)


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(n, k) = list(map(int, readline().split()))
	COM_MAX = n
	(fac, finv, inv) = ([0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1))
	fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1
	for i in range(2, COM_MAX + 1):
		fac[i] = fac[i - 1] * i % MOD
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD

	def com(n, r):
		if n < 0 or r < 0 or n < r:
			return 0
		return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD
	ans = 0
	for r in range(min(n, k + 1)):
		ans = (ans + com(n, r) * com(n - 1, r)) % MOD
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


N = 2 * 10 ** 5 + 3
mod = 10 ** 9 + 7
fac = [1] * (N + 1)
for i in range(1, N + 1):
	fac[i] = fac[i - 1] * i % mod
inv_fac = [1] * (N + 1)
inv_fac[N] = pow(fac[N], mod - 2, mod)
for i in range(N - 1, 0, -1):
	inv_fac[i] = inv_fac[i + 1] * (i + 1) % mod

def nCr(n, r):
	if n <= 0 or r < 0 or r > n:
		return 0
	return fac[n] * inv_fac[r] % mod * inv_fac[n - r] % mod
(n, k) = map(int, input().split())

def count(n, x):
	ret = nCr(n, x) * nCr(n - 1, n - x - 1) % mod
	return ret
ans = 0
x = 0
if k == 1:
	x = 1
while x <= k and x < n:
	ans = (ans + count(n, x)) % mod
	x += 1
print(ans)


import sys
(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
f = [1]
for i in range(1, 2 * n + 1):
	f.append(f[-1] * i % mod)

def comb(n, r):
	return f[n] * (pow(f[r], mod - 2, mod) * pow(f[n - r], mod - 2, mod) % mod) % mod
ans = comb(2 * n - 1, n)
if n - 1 <= k:
	print(ans)
	sys.exit()
j = 0
for i in range(k + 1, n)[::-1]:
	ans -= comb(n, n - i) * comb(n - 1, j) % mod
	ans %= mod
	j += 1
print(ans)


(n, k) = list(map(int, input().split()))
mod = 10 ** 9 + 7

def modinv(x):
	return pow(x, mod - 2, mod)
ans = 1
comb1 = 1
comb2 = 1
for i in range(1, min(n - 1, k) + 1):
	comb1 *= (n - i + 1) * modinv(i)
	comb2 *= (n - i) * modinv(i)
	comb1 %= mod
	comb2 %= mod
	ans += comb1 * comb2
	ans %= mod
print(ans)


def inv(a, m=10 ** 9 + 7):
	b = m
	(x, lastx) = (0, 1)
	(y, lasty) = (1, 0)
	while b != 0:
		q = a // b
		(a, b) = (b, a % b)
		(x, lastx) = (lastx - q * x, x)
		(y, lasty) = (lasty - q * y, y)
	return lastx % m
mod = 10 ** 9 + 7
(n, k) = map(int, input().split())
k = min(k, n - 1)
frac = [1]
for i in range(1, n + 1):
	frac.append(frac[-1] * i % mod)
ans = 0
for i in range(k + 1):
	tmp = inv(frac[i] ** 2 % mod * frac[n - i] * frac[n - 1 - i] % mod)
	ans += tmp
	ans %= mod
ans = ans * frac[n] * frac[n - 1] % mod
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
list_size = 4 * 10 ** 5 + 1
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size - 1):
	f_list[i + 1] = f_list[i] * (i + 1) % mod
f_r_list[-1] = pow(f_list[-1], mod - 2, mod)
for i in range(list_size - 2, -1, -1):
	f_r_list[i] = f_r_list[i + 1] * (i + 1) % mod

def comb(n, r, mod):
	if n < r or r < 0:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return f_list[n] * f_r_list[n - r] * f_r_list[r] % mod
if k < n - 1:
	ans = 0
	for i in range(k + 1):
		ans += comb(n - 1, i, mod) * comb(n, i, mod) % mod
	print(ans % mod)
else:
	print(comb(2 * n - 1, n, mod) % mod)


(N, K) = map(int, input().split())

def cmb(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p
p = 10 ** 9 + 7
n = 2 * 10 ** 5
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, n + 1):
	fact.append(fact[-1] * i % p)
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)
zeros = min(K, N - 1)
ans = 1
for i in range(1, zeros + 1):
	ans += cmb(N, i, p) * cmb(i + N - i - 1, i, p) % p
	ans %= p
print(ans)


(n, K) = map(int, input().split())
MOD = 10 ** 9 + 7
fac = [1 for k in range(200010)]
inv = [1 for k in range(200010)]
finv = [1 for k in range(200010)]
for k in range(2, 200010):
	fac[k] = fac[k - 1] * k % MOD
	inv[k] = (MOD - inv[MOD % k] * (MOD // k)) % MOD
	finv[k] = finv[k - 1] * inv[k] % MOD

def nCr(n, r):
	return fac[n] * finv[r] * finv[n - r] % MOD
ans = 0
for i in range(min(n, K + 1)):
	ans += nCr(n, i) * nCr(n - 1, n - i - 1)
	ans %= MOD
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
MAX_N = 10 ** 6
fact = [1]
fact_inv = [0] * (MAX_N + 4)
for i in range(MAX_N + 3):
	fact.append(fact[-1] * (i + 1) % mod)
fact_inv[-1] = pow(fact[-1], mod - 2, mod)
for i in range(MAX_N + 2, -1, -1):
	fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod

def f(n, k, mod):
	return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod
ans = 0
a = min(k, n - 1)
ans = 0
for i in range(a + 1):
	d = f(n, i, mod) * f(n - 1, i, mod)
	ans += d % mod
	ans %= mod
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
lim = n
fcl = [1] * (lim + 1)
for i in range(1, lim + 1):
	fcl[i] = fcl[i - 1] * i % mod

def comb(x, y, p):
	return fcl[x] * pow(fcl[y], p - 2, p) % p * pow(fcl[x - y], p - 2, p) % p
ans = 0
for i in range(min(n, k + 1)):
	ans += comb(n - 1, n - i - 1, mod) * comb(n, i, mod)
	ans %= mod
print(ans)


class Facts:

	def __init__(self, mod=10 ** 9 + 7, n_max=1):
		self.mod = mod
		self.n_max = n_max
		self.fact = [1, 1]
		self.inv = [0, 1]
		self.factinv = [1, 1]
		if 1 < n_max:
			self.setup_table(n_max)

	def cmb(self, n, r):
		if r < 0 or n < r:
			return 0
		if self.n_max < n:
			self.setup_table(n)
		return self.fact[n] * (self.factinv[r] * self.factinv[n - r] % self.mod) % self.mod

	def factorial(self, n):
		if self.n_max < n:
			self.setup_table(n)
		return self.fact[n]

	def hom(self, n, k):
		return self.cmb(n + k - 1, k)

	def prm(self, n, k):
		if self.n_max < n:
			self.setup_table(n)
		return self.fact[n] * self.factinv[n - k] % self.mod

	def setup_table(self, t):
		for i in range(self.n_max + 1, t + 1):
			self.fact.append(self.fact[-1] * i % self.mod)
			self.inv.append(-self.inv[mod % i] * (self.mod // i) % self.mod)
			self.factinv.append(self.factinv[-1] * self.inv[-1] % self.mod)
		self.n_max = t
mod = 10 ** 9 + 7
(n, k) = list(map(int, input().split()))
ans = 0
f = Facts(mod)
for i in range(0, min(n - 1, k) + 1):
	ans += f.cmb(n, i) * f.hom(n - i, i) % mod
	if ans >= mod:
		ans -= mod
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
mod = 10 ** 9 + 7

class Mod:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		self.modinv = self.__make_modinv_list(n_max)
		(self.fac, self.facinv) = self.__make_factorial_list(n_max)

	def comb(self, n, r):
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def factorial(self, n):
		return self.fac[n]

	def factorial_inv(self, n):
		return self.facinv[n]

	def __make_factorial_list(self, n):
		fac = [1]
		facinv = [1]
		for i in range(1, n + 1):
			fac.append(fac[i - 1] * i % self.mod)
			facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
		return (fac, facinv)

	def __make_modinv_list(self, n):
		modinv = [0] * (n + 1)
		modinv[1] = 1
		for i in range(2, n + 1):
			modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
		return modinv

def solve():
	(n, k) = list(map(int, input().split()))
	k = min(n - 1, k)
	m = Mod(n)
	ans = 0
	for i in range(k + 1):
		ans += m.comb(n - 1, n - 1 - i) * m.comb(n, i)
		ans %= mod
	print(ans)

def __starting_point():
	solve()
__starting_point()


(n, k) = map(int, input().split())
mod = 1000000007
fac = [1] * (n + 1)
inv = [1] * (n + 1)
for i in range(2, n + 1):
	fac[i] = fac[i - 1] * i % mod
	inv[i] = pow(fac[i], mod - 2, mod)

def nCk(n, k):
	return fac[n] * inv[k] % mod * inv[n - k] % mod
ans = 0
for i in range(min(k + 1, n)):
	ans += nCk(n, i) * nCk(n - 1, i) % mod
	ans %= mod
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7

def modinv(a, mod=10 ** 9 + 7):
	return pow(a, mod - 2, mod)
fac = [0] * (n + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, n + 1):
	fac[i] = fac[i - 1] * i % mod

def combi(n, r, mod=10 ** 9 + 7):
	return fac[n] * modinv(fac[r]) % mod * modinv(fac[n - r]) % mod
ans = 0
for i in range(min(k + 1, n)):
	ans += combi(n, i) * combi(n - 1, n - i - 1) % mod
	ans %= mod
print(ans % mod)


(N, K) = map(int, input().split())
K = min(N - 1, K)
fact = [1 for _ in range(200001)]
inv = [1 for _ in range(200001)]
fact_inv = [1 for _ in range(200001)]
mod = 10 ** 9 + 7
for i in range(2, 200001):
	fact[i] = fact[i - 1] * i % mod
	inv[i] = mod - inv[mod % i] * (mod // i) % mod
	fact_inv[i] = fact_inv[i - 1] * inv[i] % mod
dp = [0] * N
for i in range(N):
	f1 = fact[N] * fact_inv[N - i] * fact_inv[i] % mod
	f2 = fact[N - 1] * fact_inv[N - i - 1] * fact_inv[i] % mod
	f = f1 * f2 % mod
	if i == 0:
		dp[i] = f
	else:
		dp[i] = (dp[i - 1] + f) % mod
print(dp[K])


import sys
import numpy as np
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
MOD = 10 ** 9 + 7

def cmb(n, k):
	if k < 0 or k > n:
		return 0
	return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD

def cumprod(arr, MOD):
	L = len(arr)
	Lsq = int(L ** 0.5 + 1)
	arr = np.resize(arr, Lsq ** 2).reshape(Lsq, Lsq)
	for n in range(1, Lsq):
		arr[:, n] *= arr[:, n - 1]
		arr[:, n] %= MOD
	for n in range(1, Lsq):
		arr[n] *= arr[n - 1, -1]
		arr[n] %= MOD
	return arr.ravel()[:L]

def make_fact(U, MOD):
	x = np.arange(U, dtype=np.int64)
	x[0] = 1
	fact = cumprod(x, MOD)
	x = np.arange(U, 0, -1, dtype=np.int64)
	x[0] = pow(int(fact[-1]), MOD - 2, MOD)
	fact_inv = cumprod(x, MOD)[::-1]
	return (fact, fact_inv)
U = 10 ** 6
(fact, fact_inv) = make_fact(U, MOD)
(N, K) = lr()
K = min(K, N - 1)
x = fact[N] * fact_inv[0:K + 1] % MOD * fact_inv[N - K:N + 1][::-1] % MOD
y = fact[N - 1] * fact_inv[0:K + 1] % MOD * fact_inv[N - K - 1:N][::-1] % MOD
answer = (x * y % MOD).sum()
print(answer % MOD)


(n, k) = map(int, input().split())
fact = [1]
for i in range(1, 2 * n):
	fact.append(fact[i - 1] * (i + 1) % (10 ** 9 + 7))
factinv = []
for i in range(n):
	factinv.append(pow(fact[i], 10 ** 9 + 5, 10 ** 9 + 7))
if k == 1:
	print(n * (n - 1) % (10 ** 9 + 7))
elif k >= n - 1:
	print(fact[2 * n - 2] * factinv[n - 1] * factinv[n - 2] % (10 ** 9 + 7))
else:
	ans = 1
	for i in range(k):
		ans = (ans + fact[n - 1] * factinv[i] * factinv[n - i - 2] * fact[n - 2] * factinv[i] * factinv[n - i - 3]) % (10 ** 9 + 7)
	print(ans)


(N, K) = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 0
S = [0] * (2 * 10 ** 5 + 1)
S[1] = 1
for i in range(2, 2 * 10 ** 5 + 1):
	S[i] = S[MOD % i] * (MOD - int(MOD / i)) % MOD
if N - 1 <= K:
	ans = 1
	num = 2 * N - 1
	for i in range(N - 1):
		ans *= (num - i) * S[i + 1]
		ans %= MOD
	print(ans % MOD)
else:
	S1 = [1] * N
	S2 = [1] * N
	for i in range(1, N):
		S1[i] = S1[i - 1] * (N + 1 - i) * S[i] % MOD
		S2[i] = S2[i - 1] * (N - i) * S[i] % MOD
	ans = 0
	for i in range(K + 1):
		ans += S1[i] * S2[N - 1 - i]
		ans %= MOD
	print(ans)


MOD = 10 ** 9 + 7

def prepare(n, MOD):
	f = 1
	factorials = [1]
	for m in range(1, n + 1):
		f *= m
		f %= MOD
		factorials.append(f)
	inv = pow(f, MOD - 2, MOD)
	invs = [1] * (n + 1)
	invs[n] = inv
	for m in range(n, 1, -1):
		inv *= m
		inv %= MOD
		invs[m - 1] = inv
	return (factorials, invs)

def comb(n, r, factorials, invs):
	return factorials[n] * invs[r] * invs[n - r] % MOD

def main():
	(n, k) = list(map(int, input().split()))
	(factorials, invs) = prepare(n, MOD)
	ans = 0
	for m in range(min(k, n - 1) + 1):
		ans += comb(n - 1, m, factorials, invs) * comb(n, m, factorials, invs)
		ans %= MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


def prepare(m, mod=10 ** 9 + 7):
	fac = [1] * (m + 1)
	inv = [1] * (m + 1)
	for i in range(1, m + 1):
		fac[i] = fac[i - 1] * i % mod
	inv[-1] = pow(fac[-1], mod - 2, mod)
	for i in range(m - 1, -1, -1):
		inv[i] = inv[i + 1] * (i + 1) % mod
	return (fac, inv)
(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
(fac, inv) = prepare(n)

def cmb(n, r):
	assert n >= r >= 0
	return fac[n] * inv[n - r] * inv[r] % mod
ans = 0
for i in range(min(n, k + 1)):
	ans += cmb(n, i) * cmb(n - 1, i)
	ans %= mod
print(ans % mod)


MAX = 4 * 10 ** 5
bikkuri = [1]
mod = 10 ** 9 + 7
for i in range(1, MAX + 1):
	bikkuri.append(bikkuri[-1] * i % mod)

def Comb(n, k):
	ans = bikkuri[n] * pow(bikkuri[k], mod - 2, mod) * pow(bikkuri[n - k], mod - 2, mod)
	ans %= mod
	return ans
(n, k) = map(int, input().split())
if n - 1 <= k:
	ans = Comb(2 * n - 1, n)
	print(ans)
else:
	tmp = 0
	for i in range(k + 1):
		tmp += Comb(n, i) * Comb(n - 1, i)
		tmp %= mod
	print(tmp)


(n, k) = list(map(int, input().split()))

def cmb(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p
p = 10 ** 9 + 7
N = 2 * 10 ** 5
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % p)
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)
MAX = min(n - 1, k)
dp = [0] * (MAX + 1)
dp[0] = 1
ans = 1
for i in range(1, MAX + 1):
	ans += cmb(n, i, p) * cmb(n - i + i - 1, i, p)
	ans %= p
print(ans)


def main():
	(n, k) = map(int, input().split())
	MOD = 10 ** 9 + 7
	ans = 0
	k1 = 1
	k2 = 1
	for i in range(min(k + 1, n)):
		ans += k1 * k2
		ans %= MOD
		k1 *= (n - i) * pow(i + 1, MOD - 2, MOD)
		k1 %= MOD
		k2 *= (n - 1 - i) * pow(i + 1, MOD - 2, MOD)
		k2 %= MOD
	print(int(ans))
main()


(n, k) = map(int, input().split())
p = 10 ** 9 + 7
answer = 0
nCi = 1
n_1Ci = 1
for i in range(min(k + 1, n)):
	answer += nCi * n_1Ci
	answer %= p
	deno = pow(i + 1, p - 2, p)
	nCi *= (n - i) * deno
	nCi %= p
	n_1Ci *= (n - i - 1) * deno
	n_1Ci %= p
print(answer)


def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
N = 2 * 10 ** 5 + 1
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
(a, b) = map(int, input().split())
c = min(a, b)
s = 0
for i in range(0, c + 1):
	s += cmb(a, i, 10 ** 9 + 7) * cmb(a - 1, i, 10 ** 9 + 7)
print(s % (10 ** 9 + 7))


class Combination:

	def __init__(self, size, mod=10 ** 9 + 7):
		self.size = size + 2
		self.mod = mod
		self.fact = [1, 1] + [0] * size
		self.factInv = [1, 1] + [0] * size
		self.inv = [0, 1] + [0] * size
		for i in range(2, self.size):
			self.fact[i] = self.fact[i - 1] * i % self.mod
			self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
			self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

	def npr(self, n, r):
		if n < r or n < 0 or r < 0:
			return 0
		return self.fact[n] * self.factInv[n - r] % self.mod

	def ncr(self, n, r):
		if n < r or n < 0 or r < 0:
			return 0
		return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

	def nhr(self, n, r):
		return self.ncr(n + r - 1, n - 1)

	def factN(self, n):
		if n < 0:
			return 0
		return self.fact[n]
(N, K) = list(map(int, input().split()))
K = min(K, N)
MOD = 10 ** 9 + 7
comb = Combination(N + 100)
ans = 0
for k in range(K + 1):
	ans += comb.ncr(N, k) * comb.nhr(N - k, k)
	ans %= MOD
print(ans)


import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7

@lru_cache(None)
def combination(n, k):
	if k == 0:
		return 1
	else:
		return combination(n, k - 1) * (n - k + 1) % MOD * pow(k, MOD - 2, MOD) % MOD
(n, k) = map(int, input().split())
s = 0
for m in range(0, min(k + 1, n)):
	s += combination(n, min(m, n - m)) * combination(n - 1, min(m, n - m - 1))
	s %= MOD
print(s)


class Factorial:

	def __init__(self, max_fact, mod):
		f = [1] * (max_fact + 1)
		for idx in range(2, max_fact + 1):
			f[idx] = f[idx - 1] * idx
			f[idx] %= mod
		if mod > max_fact:
			fi = [pow(f[-1], mod - 2, mod)]
			for idx in range(max_fact, 0, -1):
				fi += [fi[-1] * idx % mod]
			fi = fi[::-1]
		else:
			fi = [pow(n, mod - 2, mod) for n in f]
		self.mod = mod
		self.f = f
		self.fi = fi

	def factorial(self, n):
		return self.f[n]

	def factorial_inverse(self, n):
		return self.fi[n]

	def combination(self, n, r):
		f = self.f
		fi = self.fi
		return f[n] * fi[r] * fi[n - r] % self.mod

	def permutation(self, n, r):
		return self.f[n] * self.fi[n - r] % self.mod

	def homogeneous_product(self, n, r):
		f = self.f
		fi = self.fi
		return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod
max_fact = 4 * 10 ** 5 + 100
mod = 10 ** 9 + 7
fact_instance = Factorial(max_fact, mod)
comb_repl = fact_instance.homogeneous_product
comb = fact_instance.combination
(N, K) = [int(_) for _ in input().split()]
ans = 0
for r in range(min(N - 1, K) + 1):
	ans += comb(N, r) * comb_repl(N - r, r)
	ans %= mod
print(ans)


(n, k) = map(int, input().split())
MOD = 10 ** 9 + 7
N = n * 2
fac = [1] * (N + 1)
for i in range(1, N + 1):
	fac[i] = fac[i - 1] * i % MOD
ifac = [pow(fac[N], MOD - 2, MOD)] * (N + 1)
for i in range(N, 0, -1):
	ifac[i - 1] = ifac[i] * i % MOD
ans = 0
if k >= n - 1:
	ans = fac[n + n - 1] * ifac[n] * ifac[n - 1] % MOD
else:
	for i in range(k + 1):
		if i > n:
			break
		tmp = fac[n] * ifac[n - i] * ifac[i] % MOD
		tmp = tmp * fac[i + n - i - 1] * ifac[n - i - 1] * ifac[i] % MOD
		ans = (ans + tmp) % MOD
print(ans)


(n, k) = map(int, input().split())
mod = 1000000007

def comb(n, k):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * finv[k] % mod * finv[n - k] % mod
fac = [1] * (n + 1)
finv = [1] * (n + 1)
for i in range(1, n + 1):
	fac[i] = fac[i - 1] * i % mod
	finv[i] = pow(fac[i], mod - 2, mod)
ans = 0
for i in range(min(k + 1, n)):
	ans += comb(n, i) * comb(n - 1, i) % mod
	ans %= mod
print(ans)


mod = 10 ** 9 + 7
comb1 = 1
comb2 = 1
(N, K) = map(int, input().split())
k = min(K, N - 1)
x = 0
for i in range(k):
	comb1 = comb1 * (N - i) * pow(i + 1, mod - 2, mod) % mod
	comb2 = comb2 * (N - 1 - i) * pow(i + 1, mod - 2, mod) % mod
	x += comb1 * comb2 % mod
print((x + 1) % mod)


(n, k) = map(int, input().split())
k = min(k, n - 1)
mod = 10 ** 9 + 7
ans = 1
z0 = 1
z1 = 1

def inv(x):
	y = 1
	while x != 1:
		y *= mod // x + 1
		y %= mod
		x -= mod % x
	return y
for i in range(k):
	z0 *= n - i
	z0 %= mod
	z0 *= inv(i + 1)
	z0 %= mod
	z1 *= n - 1 - i
	z1 %= mod
	z1 *= inv(i + 1)
	z1 %= mod
	ans += z0 * z1
	ans %= mod
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fact = [0] * (n + 1)
inv = [0] * (n + 1)
(fact[0], fact[1]) = (1, 1)
(inv[0], inv[1]) = (1, 1)
for i in range(2, n + 1):
	fact[i] = fact[i - 1] * i % mod
for i in range(2, n + 1):
	inv[i] = inv[i - 1] * pow(i, mod - 2, mod) % mod
if k >= n:
	k = n - 1

def C(a, b):
	out = fact[a]
	out *= inv[b]
	out %= mod
	out *= inv[a - b]
	out %= mod
	return out
ans = 0
for m in range(k + 1):
	ans += C(n, m) * C(n - 1, n - m - 1) % mod
	ans %= mod
print(ans)


(n, k) = map(int, input().split())

def calc(n, m):
	y = [1] * (n + 1)
	for i in range(n):
		y[i + 1] = y[i] * (i + 1) % m
	return y

def calc2(n, a, m, y):
	x = y[a] * y[n - a] % m
	return y[n] * pow(x, m - 2, m) % m
m = 10 ** 9 + 7
y = calc(2 * n - 1, m)
if k >= n - 1:
	print(calc2(2 * n - 1, n - 1, m, y))
else:
	s = 0
	for i in range(n - k - 1):
		s += calc2(n - 1, i, m, y) * calc2(n, i + 1, m, y)
	print((calc2(2 * n - 1, n - 1, m, y) - s) % m)


mod = 10 ** 9 + 7
MAX = 4 * 10 ** 5 + 100
g1 = [1, 1]
for i in range(2, MAX + 1):
	num_1 = g1[-1] * i % mod
	g1.append(num_1)

def cmb(n, r):
	return g1[n] * pow(g1[r], mod - 2, mod) * pow(g1[n - r], mod - 2, mod) % mod
(N, K) = map(int, input().split())
ans = cmb(2 * N - 1, N)
if K >= N:
	print(ans)
else:
	num = cmb(N, N - K - 1)
	S = 0
	for i in range(N - K - 1, 0, -1):
		S = (S + cmb(N - 1, i - 1) * cmb(N, i)) % mod
	ans = (ans - S) % mod
	print(ans)


(n, k) = map(int, input().split())
p = 10 ** 9 + 7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, 2 * 10 ** 5 + 1):
	g1.append(g1[-1] * i % p)
	inverse.append(-inverse[p % i] * (p // i) % p)
	g2.append(g2[-1] * inverse[-1] % p)

def cmb(n, r):
	return g1[n] * g2[r] * g2[n - r] % p
ans = 0
for m in range(min(n - 1, k) + 1):
	ans += cmb(n, m) * cmb(n - 1, n - m - 1) % p
print(ans % p)


from collections import defaultdict

def mod_inv(a, m):
	return pow(a, m - 2, m)

def combination(a, b):
	if b > a - b:
		return combination(a, a - b)
	ans = fact[a] * ifact[b] * ifact[a - b]
	return ans
MOD = 10 ** 9 + 7
(n, k) = map(int, input().split())
k = min(k, n - 1)
fact = defaultdict(int)
fact[0] = 1
ifact = defaultdict(int)
ifact[0] = 1
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i
	fact[i] %= MOD
	ifact[i] = mod_inv(fact[i], MOD)
	ifact[i] %= MOD
ans = 0
for i in range(k + 1):
	ans += combination(n, i) * combination(n - i - 1 + i, i)
	ans %= MOD
print(ans % MOD)


(n, k) = map(int, input().split())
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10 ** 9 + 7

def COMinit():
	for i in range(2, n + 10):
		fac.append(fac[-1] * i % Mod)
		inv.append(-inv[Mod % i] * (Mod // i) % Mod)
		finv.append(finv[-1] * inv[-1] % Mod)

def COM(n, k):
	if n < 0 or k < 0 or n < k:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % Mod) % Mod
COMinit()
ans = 0
for i in range(min(n, k) + 1):
	ans += COM(n, i) * COM(n - 1, n - i - 1)
	ans %= Mod
print(ans)


import sys
N_MAX = 200000 + 5
sys.setrecursionlimit(N_MAX)
MOD = 10 ** 9 + 7
fac = [1, 1]
facinv = [1, 1]
inv = [0, 1]
for i in range(2, N_MAX + 1):
	fac.append(fac[-1] * i % MOD)
	inv.append(-inv[MOD % i] * (MOD // i) % MOD)
	facinv.append(facinv[-1] * inv[-1] % MOD)

def cmb(n, r):
	if r < 0 or r > n:
		return 0
	return fac[n] * facinv[r] * facinv[n - r] % MOD

def main():
	(n, k) = list(map(int, sys.stdin.readline().rstrip().split()))
	k = min(n, k)
	ans = 0
	for m in range(k + 1):
		empty = cmb(n, m)
		member = cmb(n - 1, n - m - 1)
		ans += empty * member % MOD
		ans %= MOD
	print(ans)
main()


import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
	(N, K) = (int(_) for _ in input().split())
	fact = [0] * (N + 1)
	ifact = [0] * (N + 1)
	for i in range(N + 1):
		if i == 0:
			fact[i] = 1
			continue
		fact[i] = i * fact[i - 1]
		fact[i] %= MOD
	ifact[N] = pow(fact[N], MOD - 2, MOD)
	for i in range(N)[::-1]:
		ifact[i] = (i + 1) * ifact[i + 1] % MOD
	ret = 0
	for m in range(min(K, N - 1) + 1):
		ret += fact[N] * ifact[m] * ifact[N - m] % MOD * (fact[N - 1] * ifact[N - m - 1] * ifact[m]) % MOD
		ret %= MOD
	print(ret % MOD)
	return

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
R = 200010
f = [1] * R
p = 1
for i in range(1, R):
	p = f[i] = p * i % mod
finv = [1] * R
p = finv[-1] = pow(f[-1], mod - 2, mod)
for i in range(R - 2, 0, -1):
	p = finv[i] = p * (i + 1) % mod

def comb(n, k):
	return f[n] * finv[n - k] * finv[k] % mod
ans = 0
for m in range(min(k, n - 1) + 1):
	x = comb(n, m)
	y = comb(n - 1, m)
	ans += x * y % mod
print(ans % mod)


(n, k) = map(int, input().split())
m = min(k, n - 1)
mod = 10 ** 9 + 7
A = [0] * (m + 1)
B = [0] * (m + 1)
for i in range(m + 1):
	if i == 0:
		A[0] = 1
		B[0] = 1
	else:
		A[i] = A[i - 1] * (n - i + 1) * pow(i, mod - 2, mod) % mod
		B[i] = B[i - 1] * (n - i) * pow(i, mod - 2, mod) % mod
ans = 0
for i in range(m + 1):
	ans = (ans + A[i] * B[i]) % mod
print(ans % mod)


(n, k) = list(map(int, input().split()))
p = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, n + 1):
	fact.append(fact[-1] * i % p)
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)

def cmb(n, r, p):
	if n < r:
		return 0
	else:
		r = min(r, n - r)
		return fact[n] * factinv[r] * factinv[n - r] % p
res = []
for i in range(n):
	res.append(cmb(n, i, p) * cmb(n - 1, i, p) % p)
if n > k:
	print(sum(res[:k + 1]) % p)
else:
	print(sum(res) % p)


(n, k) = map(int, input().split())
M = 10 ** 9 + 7
if k >= n - 1:
	fac = [1] + [0] * (2 * n - 1)
	for i in range(1, 2 * n):
		fac[i] = fac[i - 1] * i % M
	comb = lambda p, q: fac[p] * pow(fac[q], M - 2, M) * pow(fac[p - q], M - 2, M) % M
	y = comb(2 * n - 1, n - 1)
else:
	y = 1
	(c1, c2) = (1, 1)
	for i in range(1, k + 1):
		p = pow(i, M - 2, M)
		c1 = c1 * (n + 1 - i) * p % M
		c2 = c2 * (n - i) * p % M
		y += c1 * c2 % M
print(y % M)


(n, k) = map(int, input().split())
mod = 1000000007

def pow(x, n):
	ret = 1
	while n > 0:
		if n & 1 == 1:
			ret = ret * x % mod
		x = x * x % mod
		n //= 2
	return ret
fac = [1]
inv = [1]
for i in range(n * 2):
	fac.append(fac[-1] * (i + 1) % mod)
	inv.append(pow(fac[-1], mod - 2))

def cmb(n, k):
	if k < 0 or k > n:
		return 0
	return fac[n] * inv[k] * inv[n - k] % mod
x = max(0, n - k - 1)
ret = cmb(n * 2 - 1, n - 1)
for i in range(x):
	ret = (ret - cmb(n, i + 1) * cmb(n - 1, i)) % mod
print(ret)


(n, k) = map(int, input().split())
p = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, 2 * n):
	fact.append(fact[-1] * i % p)
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)

def cmb(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p
rlt = 0
m = min(n, k + 1)
for i in range(m):
	rlt += cmb(n - 1, n - 1 - i, p) * cmb(n, i, p) % p
	rlt %= p
print(rlt)


import sys

def input():
	return sys.stdin.readline().strip()
MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)

class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		self.modinv = self.make_modinv_list(n_max)
		(self.fac, self.facinv) = self.make_factorial_list(n_max)

	def __call__(self, n, r):
		if n < r:
			return 0
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def make_factorial_list(self, n):
		fac = [1]
		facinv = [1]
		for i in range(1, n + 1):
			fac.append(fac[i - 1] * i % self.mod)
			facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
		return (fac, facinv)

	def make_modinv_list(self, n):
		modinv = [0] * (n + 1)
		modinv[1] = 1
		for i in range(2, n + 1):
			modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
		return modinv

def main():
	(N, K) = list(map(int, input().split()))
	answer = 0
	if K >= N - 1:
		cmb = Combination(2 * N + 1)
		answer = cmb(N * 2 - 1, N - 1)
	else:
		cmb = Combination(N)
		for i in range(K + 1):
			answer += cmb(N, i) * cmb(N - 1, N - 1 - i)
	print(answer % MOD)

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline

def read():
	(N, K) = list(map(int, input().strip().split()))
	return (N, K)

def binom_preprocess(n, MOD=10 ** 9 + 7):
	f = [0 for i in range(n + 1)]
	invf = [0 for i in range(n + 1)]
	f[0] = 1
	f[1] = 1
	invf[0] = 1
	invf[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] * i % MOD
	invf[n] = pow(f[n], MOD - 2, MOD)
	for i in range(n, 2, -1):
		invf[i - 1] = invf[i] * i % MOD
	return (f, invf)

def binom(n, k, f, invf, MOD=10 ** 9 + 7):
	if n < k or n < 0 or k < 0:
		return 0
	else:
		return f[n] * invf[k] % MOD * invf[n - k] % MOD

def solve(N, K, MOD=10 ** 9 + 7):
	(f, invf) = binom_preprocess(N, MOD)
	ans = 0
	for k in range(0, min(N, K + 1)):
		ans += binom(N, k, f, invf, MOD) * binom(N - 1, k, f, invf, MOD)
		ans %= MOD
	return ans

def __starting_point():
	inputs = read()
	print('{}'.format(solve(*inputs)))
__starting_point()


M = 10 ** 9 + 7
(n, k) = map(int, input().split())
a = c = p = 1
for i in range(1, min(n, k + 1)):
	c = c * (n - i + 1) * (n - i) % M
	p = p * i * i % M
	a += c * pow(p, M - 2, M)
print(a % M)


def main():
	mod = 1000000007
	(n, k) = map(int, input().split())
	m = 2 * n
	Fact = [1]
	for i in range(1, m + 1):
		Fact.append(Fact[i - 1] * i % mod)
	Finv = [0] * (m + 1)
	Finv[-1] = pow(Fact[-1], mod - 2, mod)
	for i in range(m - 1, -1, -1):
		Finv[i] = Finv[i + 1] * (i + 1) % mod

	def comb(n, r):
		if n < r:
			return 0
		return Fact[n] * Finv[r] * Finv[n - r] % mod
	if k >= n - 1:
		return comb(2 * n - 1, n - 1)
	ans = 1
	for i in range(1, k + 1):
		ans += comb(n, i) * comb(n - 1, n - i - 1)
		ans %= mod
	return ans
print(main())


(n, k) = map(int, input().split())
P = 10 ** 9 + 7
ans = 1
nCl = 1
n1Cl = 1
for l in range(1, min(k + 1, n)):
	nCl = nCl * (n + 1 - l) * pow(l, P - 2, P) % P
	n1Cl = n1Cl * (n - l) * pow(l, P - 2, P) % P
	ans = (ans + nCl * n1Cl) % P
print(ans)


nmax = 3 * 10 ** 5
mod = 10 ** 9 + 7
fac = [1] * nmax
finv = [1] * nmax
inv = [1] * nmax

def ncr_pre():
	for i in range(2, nmax):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod

def ncr(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fac[n] * (finv[r] * finv[n - r] % mod) % mod
ncr_pre()
(n, k) = map(int, input().split())
ans = 0
for i in range(min(n, k + 1)):
	ans += ncr(n, i) * ncr(i + n - i - 1, i)
	ans %= mod
print(ans)


def modinv(a, m):
	return pow(a, m - 2, m)
(n, k) = map(int, input().split())
P = 10 ** 9 + 7
if n - 1 <= k:
	N = n + min(n - 1, k)
	ans = 1
	for i in range(1, n):
		ans = ans * (N + 1 - i) * modinv(i, P) % P
else:
	ans = 1
	nCl = 1
	n1Cl = 1
	for l in range(1, k + 1):
		nCl = nCl * (n + 1 - l) * modinv(l, P) % P
		n1Cl = n1Cl * (n - l) * modinv(l, P) % P
		ans = (ans + nCl * n1Cl) % P
print(ans)


(N, K) = map(int, input().split())
mod = 10 ** 9 + 7
MAX = N + 10
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX

def cominit():
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, MAX):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod

def cmb(n, r):
	if n < 0 or r < 0 or r > n:
		return 0
	if r > n / 2:
		r = n - r
	return fac[n] * (finv[r] * finv[n - r] % mod) % mod
cominit()
ans = 0
for i in range(min(K + 1, N)):
	ans += cmb(N, i) * cmb(N - 1, i)
	ans %= mod
print(ans)


(n, k) = map(int, input().split())
MOD = 10 ** 9 + 7

def comb(n, m, p=10 ** 9 + 7):
	buf = perm[n] * inv[m]
	buf %= MOD
	buf *= inv[n - m]
	buf %= MOD
	return buf

def inv_mod(a):
	return pow(a, MOD - 2, MOD)
perm = [1] * (2 * n + 1)
for i in range(1, 2 * n + 1):
	perm[i] = perm[i - 1] * i
	perm[i] %= MOD
inv = [1] * (2 * n + 1)
inv[-1] = inv_mod(perm[-1])
for i in range(2 * n - 1, -1, -1):
	inv[i] = inv[i + 1] * (i + 1)
	inv[i] %= MOD
buf = comb(2 * n - 1, n)
for j in range(k + 1, n):
	x = comb(n, j) * comb(n - 1, j)
	x %= MOD
	buf -= x
	buf %= MOD
print(buf)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [Scanner.string() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [Scanner.int() for i in range(n)]

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127

def solve():
	(N, K) = Scanner.map_int()
	MOD = int(1000000000.0) + 7
	MAX = 200010
	fac = [0] * MAX
	finv = [0] * MAX
	inv = [0] * MAX
	fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1
	for i in range(2, MAX):
		fac[i] = fac[i - 1] * i % MOD
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD

	def cmb(n, k):
		if n < k:
			return 0
		if n < 0 or k < 0:
			return 0
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
	ans = 0
	for m in range(0, min(K, N - 1) + 1):
		a = cmb(N, m)
		b = cmb(N - 1, m)
		ans += a * b
		ans %= MOD
	print(ans)

def main():
	solve()

def __starting_point():
	main()
__starting_point()


MOD = 10 ** 9 + 7
(n, k) = map(int, input().split())
zero_end = min(n, k + 1)
inv_mod = [pow(i, MOD - 2, MOD) for i in range(zero_end)]
comb_mod1 = [1] * zero_end
comb_mod2 = [1] * zero_end
for i in range(1, zero_end):
	comb_mod1[i] = comb_mod1[i - 1] * (n - i + 1) * inv_mod[i] % MOD
	comb_mod2[i] = comb_mod2[i - 1] * (n - i) * inv_mod[i] % MOD
ans = 0
for i in range(zero_end):
	ans = ans + comb_mod1[i] * comb_mod2[i] % MOD
print(ans % MOD)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
m = min(n - 1, k)
ans = 0
f = [1]
fi = [1]
for i in range(n):
	f.append(f[i] * (i + 1) % mod)
	fi.append(pow(f[i + 1], mod - 2, mod))

def comb_mod(n, r, mod):
	return f[n] * fi[r] * fi[n - r] % mod
for m in range(m + 1):
	ans += comb_mod(n, m, mod) * comb_mod(n - 1, m, mod) % mod
print(ans % mod)


import sys
sysread = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import math

def run():
	(n, k) = map(int, input().split())
	mod = 10 ** 9 + 7
	ret = 0
	inv = generate_inv(n, mod)
	if k >= n - 1:
		k = n - 1
	left = 1
	right = 1
	ret = 1
	for h in range(1, k + 1):
		right *= (n - h) * inv[h]
		right %= mod
		left *= (n - h + 1) * inv[h]
		left %= mod
		ret += right * left
		ret %= mod
	print(ret)

def generate_inv(n, mod):
	ret = [0, 1]
	for i in range(2, n + 1):
		next = -ret[mod % i] * (mod // i)
		next %= mod
		ret.append(next)
	return ret

def comb_mod(n, a, mod):
	up = 1
	down = 1
	for i in range(a):
		up *= n - i
		up %= mod
		down *= i + 1
		down %= mod
	down = pow_mod(down, mod - 2, mod)
	return up * down % mod

def pow_mod(n, k, mod):
	res = 1
	while True:
		if k // 2 >= 1:
			if k % 2 == 1:
				res = res * n % mod
			n = n ** 2 % mod
			k = k // 2
		else:
			break
	return n * res % mod

def __starting_point():
	run()
__starting_point()


(n, k) = list(map(int, input().split()))
mod = 10 ** 9 + 7

def prepare():
	fact = []
	f = 1
	for m in range(1, n):
		f *= m
		f %= mod
	fact.append(f)
	f *= n
	f %= mod
	fact.append(f)
	factinv = [1, 1]
	inv = [0, 1]
	for i in range(2, n + 1):
		inv.append(-inv[mod % i] * (mod // i) % mod)
		factinv.append(factinv[-1] * inv[-1] % mod)
	return (fact, factinv)

def cmb(a, r, p):
	if r < 0 or n < r:
		return 0
	if a == 1:
		return f[a] * v[r] * v[n - r] % mod
	else:
		return f[a] * v[r] * v[n - r - 1] % mod
(f, v) = prepare()
ans = 1
for i in range(1, min(k + 1, n)):
	ans += cmb(0, i, mod) * cmb(1, i, mod)
	ans %= mod
print(ans)


def main():
	import sys
	sys.setrecursionlimit(10 ** 9)
	input = sys.stdin.readline
	(n, k) = map(int, input().split())
	mod = 1000000007

	def make_fact(n):
		fact = [1] * (n + 1)
		ifact = [1] * (n + 1)
		for i in range(1, n + 1):
			fact[i] = fact[i - 1] * i % mod
		ifact[n] = pow(fact[n], mod - 2, mod)
		for i in range(n, 0, -1):
			ifact[i - 1] = ifact[i] * i % mod
		return (fact, ifact)
	(fact, ifact) = make_fact(n)

	def comb(n, k):
		if k < 0 or k > n:
			return 0
		return fact[n] * ifact[k] * ifact[n - k] % mod
	ans = 0
	if k > n - 1:
		k = n - 1
	for i in range(k + 1):
		ans = (ans + comb(n, i) * comb(n - 1, i)) % mod
	print(ans)
main()


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fact = [1] * (n + 1)
ans = 0
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i
	fact[i] %= mod
invfact = [1] * (n + 1)
invfact[-1] = pow(fact[-1], mod - 2, mod)
for i in range(n - 1, 0, -1):
	invfact[i] = invfact[i + 1] * (i + 1) % mod

def C(x, y):
	if x <= y:
		return 1
	return fact[x] * invfact[y] * invfact[x - y] % mod
for i in range(min(k + 1, n)):
	ans += C(n, i) * C(n - 1, n - i - 1)
	ans %= mod
print(ans)


import sys
input = sys.stdin.buffer.readline
MOD = 10 ** 9 + 7
MAXN = 2 * 10 ** 5 + 5
f = [1]
for i in range(MAXN):
	f.append(f[-1] * (i + 1) % MOD)

def nCr(n, r, mod=MOD):
	return f[n] * pow(f[r], mod - 2, mod) * pow(f[n - r], mod - 2, mod) % mod
(n, k) = map(int, input().split())
ans = 0
for m in range(min(n - 1, k) + 1):
	ans += nCr(n, m) * nCr(n - 1, n - m - 1) % MOD
	ans %= MOD
print(ans)


MOD = 10 ** 9 + 7
inpl = lambda : list(map(int, input().split()))

def inv_mod(a, p=10 ** 9 + 7):
	p = abs(p)
	a %= p
	stack = []
	p0 = p
	while a > 1:
		(d, a, p) = (p // a, p % a, a)
		stack.append(d)
	(x, y) = (1, 0)
	while stack:
		d = stack.pop()
		(x, y) = (y - d * x, x)
	return x % p0
(n, k) = inpl()
if k >= n:
	k = n - 1
ans = 1
t = 1
for i in range(k):
	t *= (n - 1 - i) * (n - i)
	t %= MOD
	j = inv_mod(i + 1)
	t *= j * j % MOD
	ans += t
	ans %= MOD
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
n_max = 4 * (10 ** 5 + 1)
(F, FI) = ([0] * (n_max + 1), [0] * (n_max + 1))
(F[0], FI[0]) = (1, 1)
for i in range(n_max):
	F[i + 1] = F[i] * (i + 1) % mod
FI[n_max - 1] = pow(F[n_max - 1], mod - 2, mod)
for i in reversed(range(n_max - 1)):
	FI[i] = FI[i + 1] * (i + 1) % mod

def comb(x, y):
	return F[x] * FI[x - y] * FI[y] % mod
if k >= n - 1:
	print(comb(2 * n - 1, n))
else:
	ans = 1
	for i in range(k):
		ans = (ans + comb(n, i + 1) * comb(n - 1, i + 1)) % mod
	print(ans)


(n, k) = list(map(int, input().split()))
mod = 1000000007
fac = [1]
inv = [1]
for i in range(n * 2):
	fac.append(fac[-1] * (i + 1) % mod)
	inv.append(pow(fac[-1], mod - 2, mod))

def cmb(n, k):
	if k < 0 or k > n:
		return 0
	return fac[n] * inv[k] % mod * inv[n - k] % mod
ret = 0
for m in range(min(k + 1, n)):
	ret = (ret + cmb(n, m) * cmb(n - 1, n - m - 1) % mod) % mod
print(ret)


(n, k) = map(int, input().split())
m = 10 ** 9 + 7
p = 1
for i in range(1, n + 1):
	p = p * (2 * n - i) * pow(i, m - 2, m) % m
if k >= n:
	print(p)
else:
	(c, d) = (1, 1)
	for i in range(1, k + 1):
		c = c * (n - i) * pow(i, m - 2, m) % m
	for i in range(1, k + 1):
		d = d * (n - i + 1) * pow(i, m - 2, m) % m
	for i in range(k + 1, n):
		c = c * (n - i) * pow(i, m - 2, m) % m
		d = d * (n - i + 1) * pow(i, m - 2, m) % m
		p = (p - c * d) % m
	print(p)


class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		f = 1
		self.fac = fac = [f]
		for i in range(1, n_max + 1):
			f = f * i % mod
			fac.append(f)
		f = pow(f, mod - 2, mod)
		self.facinv = facinv = [f]
		for i in range(n_max, 0, -1):
			f = f * i % mod
			facinv.append(f)
		facinv.reverse()

	def __call__(self, n, r):
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def nCr(self, n, r):
		if not 0 <= r <= n:
			return 0
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def nPr(self, n, r):
		if not 0 <= r <= n:
			return 0
		return self.fac[n] * self.facinv[n - r] % self.mod

	def nHr(self, n, r):
		if n == 0 and r > 0 or r < 0:
			return 0
		return self.fac[n + r - 1] * self.facinv[r] % self.mod * self.facinv[n - 1] % self.mod

def resolve():
	MOD = 10 ** 9 + 7
	(N, K) = list(map(int, input().split()))
	r = min(N - 1, K)
	cmb = Combination(N)
	ans = 0
	for i in range(r + 1):
		ans += cmb.nCr(N, i) * cmb.nHr(N - i, i)
		ans %= MOD
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(n, k) = map(int, input().split())
MOD = 10 ** 9 + 7

def prepare(n, MOD):
	facts = [1] * (n + 1)
	for i in range(1, n + 1):
		facts[i] = facts[i - 1] * i % MOD
	invs = [1] * (n + 1)
	_invs = [1] * (n + 1)
	invs[n] = pow(facts[n], MOD - 2, MOD)
	for i in range(0, n)[::-1]:
		invs[i] = invs[i + 1] * (i + 1) % MOD
	return (facts, invs)
ans = 0
(facts, invs) = prepare(n, MOD)
for i in range(1 + min(n - 1, k)):
	ans += facts[n] * invs[i] * invs[n - i] * facts[n - 1] * invs[n - i - 1] * invs[i]
	ans %= MOD
print(ans)


[N, K] = list(map(int, input().split()))
mod = pow(10, 9) + 7
kaijo = [1]
for i in range(1, N + 1):
	kaijo.append(kaijo[i - 1] * i % mod)
s = 0
for m in range((K + 1) * (N > K) + N * (K >= N)):
	s += kaijo[N] * pow(kaijo[m] * kaijo[N - m], mod - 2, mod) % mod * (kaijo[N - 1] * pow(kaijo[m] * kaijo[N - 1 - m], mod - 2, mod)) % mod
	s = s % mod
print(s)


(n, k) = map(int, input().split())
k = min(k, n - 1)
MOD = 1000000007
fact = [1] * (n + 1)
ifact = [0] * (n + 1)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i % MOD
ifact[n] = pow(fact[n], MOD - 2, MOD)
for i in range(n, 0, -1):
	ifact[i - 1] = ifact[i] * i % MOD

def comb(n, k):
	if k < 0 or k > n:
		return 0
	return fact[n] * ifact[k] * ifact[n - k] % MOD
ans = 0
for i in range(k + 1):
	ans += comb(n, i) * comb(n - 1, i)
	ans %= MOD
print(ans)


p = 10 ** 9 + 7

def pow(x, m):
	if m == 0:
		return 1
	if m == 1:
		return x
	if m % 2 == 0:
		return pow(x, m // 2) ** 2 % p
	else:
		return x * pow(x, (m - 1) // 2) ** 2 % p % p
(n, k) = map(int, input().split())
A = [1 for _ in range(n + 1)]
for i in range(2, n + 1):
	A[i] = i * A[i - 1] % p
B = [1 for _ in range(n + 1)]
B[n] = pow(A[n], p - 2)
for i in range(n - 1, 1, -1):
	B[i] = B[i + 1] * (i + 1) % p
cnt = 0
for i in range(min(k, n - 1) + 1):
	a = A[n] * B[n - i] * B[i] % p
	b = A[n - 1] * B[n - 1 - i] * B[i] % p
	cnt = (cnt + a * b) % p
print(cnt)


(n, k) = list(map(int, input().split()))
mod = int(1000000000.0 + 7)

def init_cmb(Nmax):
	g1 = [1, 1]
	g2 = [1, 1]
	inverse = [0, 1]
	for i in range(2, Nmax + 1):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	return (g1, g2)
(g1, g2) = init_cmb(n + 10)

def cmb(n, r, modn=mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % modn
ans = 0
for i in range(min(k + 1, n)):
	wk = cmb(n, i) * cmb(n - 1, n - i - 1) % mod
	ans = (ans + wk) % mod
print(ans)


def cmb(n, r, mod):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % mod
mod = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % mod)
	inv.append(-inv[mod % i] * (mod // i) % mod)
	factinv.append(factinv[-1] * inv[-1] % mod)
(n, k) = map(int, input().split())
ans = 0
for i in range(0, min(n, k + 1)):
	ans = (ans + cmb(n, i, mod) * cmb(n - 1, i, mod)) % mod
print(ans)


(n, k) = map(int, input().split())
m = 10 ** 9 + 7
k = min(k, n - 1)
(t, c, h) = (1, 1, 1)
for i in range(1, k + 1):
	p = pow(i, m - 2, m)
	c = c * (n - i + 1) * p % m
	h = h * (n - i) * p % m
	t = (t + c * h) % m
print(t % m)


import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7

class CmbMod:

	def __init__(self, n, p):
		self.n = n
		self.p = p
		self.fact = [1, 1]
		self.factinv = [1, 1]
		self.inv = [0, 1]

	def cmb_mod(self, n, r):
		(numer, denom) = (1, 1)
		for i in range(r):
			numer = numer * (n - i) % self.p
			denom = denom * (i + 1) % self.p
		return numer * pow(denom, self.p - 2, self.p) % self.p

	def prep(self):
		for i in range(2, self.n + 1):
			self.fact.append(self.fact[-1] * i % self.p)
			self.inv.append(-self.inv[self.p % i] * (self.p // i) % self.p)
			self.factinv.append(self.factinv[-1] * self.inv[-1] % self.p)

	def cmb_mod_with_prep(self, n, r):
		if r < 0 or n < r:
			return 0
		r = min(r, n - r)
		return self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.p

def resolve():
	(n, k) = list(map(int, input().split()))
	k = min(n - 1, k)
	cmb = CmbMod(n, mod)
	cmb.prep()
	res = 0
	for i in range(k + 1):
		res += cmb.cmb_mod_with_prep(n, i) * cmb.cmb_mod_with_prep(n - 1, i) % mod
		res %= mod
	print(res)

def __starting_point():
	resolve()
__starting_point()


mod = 10 ** 9 + 7
(n, k) = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
inv_t = [0, 1]
for i in range(2, n + 2):
	inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
a = n
b = n - 1
for i in range(1, min(n, k) + 1):
	ans += a * b % mod
	a = a * (n - i) * inv_t[i + 1] % mod
	b = b * (n - i - 1) * inv_t[i + 1] % mod
	ans %= mod
if k > 1:
	ans += 1
print(ans % mod)


(n, k) = map(int, input().split())
P = 10 ** 9 + 7

class FactInv:

	def __init__(self, N, P):
		fact = []
		ifact = []
		fact = [1] * (N + 1)
		ifact = [0] * (N + 1)
		for i in range(1, N):
			fact[i + 1] = fact[i] * (i + 1) % P
		ifact[-1] = pow(fact[-1], P - 2, P)
		for i in range(N, 0, -1):
			ifact[i - 1] = ifact[i] * i % P
		self.fact = fact
		self.ifact = ifact
		self.P = P

	def comb(self, n, k):
		return self.fact[n] * self.ifact[k] * self.ifact[n - k] % self.P
C = FactInv(2 * n + 10, P)
ans = 0
for i in range(0, min(k + 1, n)):
	ans += C.comb(n, i) * C.comb(n - 1, n - i - 1) % P
	ans %= P
print(ans)


(N, K) = map(int, input().split())
MOD = 10 ** 9 + 7
max_n = 2 * 10 ** 5
fac = [1] * (max_n + 1)
inv = [1] * (max_n + 1)
ifac = [1] * (max_n + 1)
for n in range(2, max_n + 1):
	fac[n] = fac[n - 1] * n % MOD
	inv[n] = MOD - inv[MOD % n] * (MOD // n) % MOD
	ifac[n] = ifac[n - 1] * inv[n] % MOD

def comb(n, k):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * ifac[k] * ifac[n - k] % MOD
print(sum([comb(N, k) * comb(N - 1, k) % MOD for k in range(min(N, K) + 1)]) % MOD)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, n + 1):
	g1.append(g1[-1] * i % mod)
	inv.append(-inv[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inv[-1] % mod)

def comb(n, r):
	if r < 0 or r > n:
		return 0
	return g1[n] * g2[r] * g2[n - r] % mod
li = []
for i in range(min(k, n - 1) + 1):
	li.append(comb(n - 1, i))
ans = 0
pre = 0
for cur in li:
	ans += (pre + cur) * cur
	pre = cur
print(ans % mod)


(n, k) = map(int, input().split())
c1 = 1
c2 = 1
mod = 10 ** 9 + 7
ans = 0
for i in range(min(n, k + 1)):
	ans += c1 * c2
	c1 *= (n - i) * pow(i + 1, mod - 2, mod)
	c1 %= mod
	c2 *= (n - i - 1) * pow(i + 1, mod - 2, mod)
	c2 %= mod
print(ans % mod)


MOD = 1000000007

def solve(n: int, k: int):
	fact = [1] * (n + 1)
	inv_fact = [1] * (n + 1)
	for i in range(1, n + 1):
		fact[i] = i * fact[i - 1] % MOD
	inv_fact[-1] = pow(fact[-1], MOD - 2, MOD)
	for i in range(n - 1, 0, -1):
		inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD

	def comb(n, r, MOD=MOD):
		return fact[n] * inv_fact[n - r] * inv_fact[r] % MOD
	ans = 0
	for i in range(min(k, n - 1) + 1):
		ans += comb(n, i) * comb(n - 1, i) % MOD
		ans %= MOD
	return ans
(n, k) = list(map(int, input().split()))
print(solve(n, k))


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7

def cmb(n, r, mod):
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % mod

def h(n, r, mod):
	return cmb(n + r - 1, r, mod)

def makefact(n, mod):
	fact = [1, 1]
	factinv = [1, 1]
	inv = [0, 1]
	for i in range(2, n + 1):
		fact.append(fact[-1] * i % mod)
		inv.append(-inv[mod % i] * (mod // i) % mod)
		factinv.append(factinv[-1] * inv[-1] % mod)
	return (fact, factinv)
(fact, factinv) = makefact(n, mod)
ans = 0
for i in range(min(n, k + 1)):
	ans = (ans + cmb(n, i, mod) * h(n - i, i, mod)) % mod
print(ans)


from collections import *
from itertools import *
from bisect import *
import copy
(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fac = [0, 1]
for i in range(2, 2 * n + 1):
	fac.append(fac[i - 1] * i % mod)
ifac = [pow(i, mod - 2, mod) for i in fac]

def comb(a, b):
	if a >= 0 and b == 0:
		return 1
	if a < b or a < 0:
		return 0
	return fac[a] * ifac[a - b] * ifac[b] % mod
count = 1
for m in range(1, min(k + 1, n)):
	count = (count + comb(n, m) * comb(n - 1, n - m - 1)) % mod
print(count)


mod = int(1000000000.0) + 7
maxf = 500000

def make_fact(n, k):
	tmp = n
	perm = [i for i in range(k)]
	L = [0 for _ in range(k)]
	for i in range(k):
		L[i] = tmp % (i + 1)
		tmp //= i + 1
	LL = [0 for _ in range(k)]
	for i in range(k):
		LL[i] = perm[L[-i - 1]]
		for j in range(L[-i - 1] + 1, k):
			perm[j - 1] = perm[j]
	return LL

def doubling(n, m, modulo=mod):
	y = 1
	base = n
	tmp = m
	while tmp != 0:
		if tmp % 2 == 1:
			y *= base
			if modulo > 0:
				y %= modulo
		base *= base
		if modulo > 0:
			base %= modulo
		tmp //= 2
	return y

def inved(a, modulo=mod):
	(x, y, u, v, k, l) = (1, 0, 0, 1, a, modulo)
	while l != 0:
		(x, y, u, v) = (u, v, x - u * (k // l), y - v * (k // l))
		(k, l) = (l, k % l)
	return x % modulo
fact = [1 for _ in range(maxf + 1)]
invf = [1 for _ in range(maxf + 1)]
for i in range(maxf):
	fact[i + 1] = fact[i] * (i + 1) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
	invf[i - 1] = invf[i] * i % mod
(n, k) = map(int, input().split())
S = 0
if n <= k + 1:
	print(fact[2 * n - 1] * invf[n] * invf[n - 1] % mod)
else:
	S = 0
	for i in range(min(n, k + 1)):
		S += invf[i] * invf[i] * invf[n - i - 1] * invf[n - i] % mod
		S %= mod
	print(S * fact[n - 1] * fact[n] % mod)


MAX_NUM = 2 * 10 ** 5 + 10
MOD = 10 ** 9 + 7
fac = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv = [0 for _ in range(MAX_NUM)]
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, MAX_NUM):
	fac[i] = fac[i - 1] * i % MOD
	inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD
(n, k) = map(int, input().split())
sum = 1
t = 1
for i in range(min(n, k)):
	t = t * (n - i) % MOD * (n - i - 1) % MOD
	t = t * inv[i + 1] % MOD * inv[i + 1] % MOD
	sum = (sum + t) % MOD
print(sum)


def main():
	(n, k) = map(int, input().split())
	mod = pow(10, 9) + 7
	g1 = [1, 1]
	g2 = [1, 1]
	inv = [0, 1]
	for i in range(2, n + 1):
		g1.append(g1[-1] * i % mod)
		inv.append(-inv[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inv[-1] % mod)

	def combi(n, r):
		r = min(r, n - r)
		return g1[n] * g2[r] * g2[n - r] % mod
	if k >= n - 1:
		k = n - 1
	ans = 1
	for i in range(1, k + 1):
		ans += combi(n, i) * combi(n - 1, n - i - 1) % mod
	return ans % mod
print(main())


(n, k) = map(int, input().split())
mod = pow(10, 9) + 7
(c1, c2) = (1, 1)
(n1, n2) = (n, n - 1)
ans = 1
for r in range(1, min(k + 1, n)):
	c1 = c1 * n1 * pow(r, mod - 2, mod) % mod
	c2 = c2 * n2 * pow(r, mod - 2, mod) % mod
	n1 -= 1
	n2 -= 1
	ans += c1 * c2 % mod
	ans %= mod
print(ans)


(n, k) = map(int, input().split())
if n - 1 < k:
	k = n - 1
mod = 10 ** 9 + 7
cmb1 = [1] * (n + 1)
cmb2 = [1] * n
x = [0] * (n + 1)

def Pow(a, n):
	if n == 0:
		return 1
	if n % 2 == 0:
		return Pow(a, n // 2) ** 2 % mod
	else:
		return Pow(a, n - 1) * a % mod
for i in range(1, n + 1):
	x[i] = Pow(i, mod - 2)
for i in range(1, n + 1):
	cmb1[i] = cmb1[i - 1] * (n + 1 - i) % mod * x[i] % mod
for i in range(1, n):
	cmb2[i] = cmb2[i - 1] * (n - i) % mod * x[i] % mod
ans = 0
for i in range(k + 1):
	ans = (cmb1[i] * cmb2[i] % mod + ans) % mod
print(ans)


class Calc:

	def __init__(self, max_value, mod):
		fact = [-1] * (max_value + 1)
		fact[0] = 1
		fact[1] = 1
		for x in range(2, max_value + 1):
			fact[x] = x * fact[x - 1] % mod
		invs = [1] * (max_value + 1)
		invs[max_value] = pow(fact[max_value], mod - 2, mod)
		for x in range(max_value - 1, 0, -1):
			invs[x] = invs[x + 1] * (x + 1) % mod
		self.fact = fact
		self.invs = invs
		self.mod = mod

	def combination(self, n, r):
		if n - r < r:
			return self.combination(n, n - r)
		if r < 0:
			return 0
		if r == 0:
			return 1
		if r == 1:
			return n
		return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod

	def factorial(self, n):
		return self.fact[n]

def main():
	MOD = 10 ** 9 + 7
	(N, K) = list(map(int, input().split()))
	K = min(K, N)
	calc = Calc(max_value=N * 2, mod=MOD)
	ans = 0
	for v in range(K + 1):
		ans = (ans + calc.combination(N, v) * calc.combination(v + (N - v) - 1, v)) % MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


M = 10 ** 9 + 7
(n, k) = map(int, input().split())
from functools import lru_cache

@lru_cache(None)
def f(x):
	if x:
		return x * f(x - 1) % M
	return 1
l = [f(i) for i in range(n + 1)]
a = 0
for i in range(min(n, k + 1)):
	c = l[n] * l[n - 1] % M
	p = l[i] ** 2 * l[n - i] * l[n - i - 1] % M
	a += c * pow(p, M - 2, M)
print(a % M)


DIV = 10 ** 9 + 7
n = 10 ** 6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
	g1.append(g1[-1] * i % DIV)
	inverse.append(-inverse[DIV % i] * (DIV // i) % DIV)
	g2.append(g2[-1] * inverse[-1] % DIV)

def nCr(n, r, DIV):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % DIV
(N, K) = map(int, input().split())
ans = 0
for i in range(min(K, N - 1) + 1):
	a = nCr(N, i, DIV)
	b = nCr(N - 1, i, DIV)
	ans += a * b % DIV
	ans %= DIV
print(ans)


def main():
	(n, kk) = map(int, input().split())
	mod = 10 ** 9 + 7
	fact = [1, 1]
	for i in range(2, 2 * 10 ** 5 + 1):
		fact.append(fact[-1] * i % mod)

	def nCr(n, r, mod=10 ** 9 + 7):
		return pow(fact[n - r] * fact[r] % mod, mod - 2, mod) * fact[n] % mod
	ans = [1]
	for k in range(1, n):
		ans.append(nCr(n - 1, k) * nCr(n, k) % mod)
	print(sum(ans[:min(kk + 1, n)]) % mod)
main()


mod = 10 ** 9 + 7
(n, k) = map(int, input().split())
ans = 0
comb1 = 1
comb2 = 1
for i in range(min(k + 1, n)):
	ans += comb1 * comb2
	ans %= mod
	comb1 *= (n - i) * pow(i + 1, mod - 2, mod)
	comb1 %= mod
	comb2 *= (n - 1 - i) * pow(i + 1, mod - 2, mod)
	comb2 %= mod
print(ans)


def main():
	(N, k) = map(int, input().split())
	MAX_N = 3 * 10 ** 5
	MOD = 10 ** 9 + 7
	fac = [0] * MAX_N
	inv = [0] * MAX_N
	finv = [0] * MAX_N
	fac[0] = 1
	fac[1] = 1
	inv[1] = 1
	finv[0] = 1
	finv[1] = 1

	def com_init():
		for i in range(2, MAX_N):
			fac[i] = fac[i - 1] * i % MOD
			inv[i] = -(MOD // i) * inv[MOD % i] % MOD
			finv[i] = finv[i - 1] * inv[i] % MOD

	def com(n, k):
		if n < 0:
			return 0
		elif k > n:
			return 0
		return fac[n] * finv[n - k] % MOD * finv[k] % MOD
	k = min(k, N - 1)
	ans = 1
	com_init()
	for i in range(1, k + 1):
		ans += com(N, i) * com(N - 1, N - i - 1)
		ans %= MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


import math
import sys
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
(n, k) = map(int, input().split())
k = min(k, n - 1)
fact = [1]
for i in range(1, 10 ** 6):
	fact.append(fact[i - 1] * i % MOD)
inv = [None] * 10 ** 6

def inv_fact(n):
	if inv[n] == None:
		inv[n] = pow(fact[n], MOD - 2, MOD)
	return inv[n]

def comb(n, r):
	return fact[n] * inv_fact(n - r) * inv_fact(r) % MOD
ans = 0
for i in range(k + 1):
	ans = (ans + comb(n - 1, i) * comb(n, i)) % MOD
print(ans)


(n, k) = list(map(int, input().split()))
import sys
sys.setrecursionlimit(2147483647)

def cmb(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p
p = 10 ** 9 + 7
N = 2 * n + 1
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % p)
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)
ans = 1
if k > n:
	ans = cmb(n + n - 1, n, p)
else:
	for i in range(1, k + 1):
		ans += cmb(n, i, p) * cmb(n - 1, n - i - 1, p) % p
print(ans % p)


(N, K) = map(int, input().split())
MOD = 10 ** 9 + 7
fac = [1] * (N + 1)
rev = [1] * (N + 1)
for i in range(1, N + 1):
	fac[i] = i * fac[i - 1] % MOD
	rev[i] = pow(fac[i], MOD - 2, MOD)
comb = lambda a, b: fac[a] * rev[a - b] * rev[b] % MOD
ans = 0
for i in range(1 + min(N - 1, K)):
	ans += comb(N, i) * comb(N - 1, i)
ans %= MOD
print(ans)


MOD = 1000000007
(n, k) = map(int, input().split())
nCk = 1
ans = 1
if k > n - 1:
	k = n - 1
for i in range(1, k + 1, 1):
	nCk = nCk * (n - i + 1) % MOD * pow(i, 1000000005, 1000000007) % MOD
	ans = (ans % MOD + nCk * nCk % MOD * (n - i) % MOD * pow(n, 1000000005, 1000000007) % MOD % MOD) % MOD
print(ans)


U = 2 * 10 ** 5
mod = 10 ** 9 + 7

class Combination:

	def __init__(self, N, MOD=10 ** 9 + 7):
		self.MOD = MOD
		(self.fact, self.inv) = self._make_factorial_list(N)

	def __call__(self, n, k):
		if k < 0 or k > n:
			return 0
		res = self.fact[n] * self.inv[k] % self.MOD
		res = res * self.inv[n - k] % self.MOD
		return res

	def _make_factorial_list(self, N):
		fact = [1] * (N + 1)
		inv = [1] * (N + 1)
		MOD = self.MOD
		for i in range(1, N + 1):
			fact[i] = fact[i - 1] * i % MOD
		inv[N] = pow(fact[N], MOD - 2, MOD)
		for i in range(N, 0, -1):
			inv[i - 1] = inv[i] * i % MOD
		return (fact, inv)

def __starting_point():
	(N, K) = map(int, input().split())
	comb = Combination(U + 5, mod)
	ans = 1
	for i in range(1, min(K + 1, N)):
		vacant = comb(N, i)
		person = comb(N - 1, i)
		ans = (ans + vacant * person % mod) % mod
	print(ans)
__starting_point()


def prepare(n, MOD):
	f = 1
	factorials = [1]
	for m in range(1, n + 1):
		f *= m
		f %= MOD
		factorials.append(f)
	inv = pow(f, MOD - 2, MOD)
	invs = [1] * (n + 1)
	invs[n] = inv
	for m in range(n, 1, -1):
		inv *= m
		inv %= MOD
		invs[m - 1] = inv
	return (factorials, invs)
MOD = 10 ** 9 + 7
(fact, fact_inv) = prepare(3 * 10 ** 5, MOD)
(n, k) = map(int, input().split())
k = min(n - 1, k)
ans = 1
for i in range(1, k + 1):
	z = fact[n] * fact_inv[i] % MOD * fact_inv[n - i] % MOD
	p = fact[n - 1] * fact_inv[n - i - 1] % MOD * fact_inv[i] % MOD
	ans += z * p % MOD
	ans %= MOD
print(ans)


(N, K) = map(int, input().split())
MOD = 10 ** 9 + 7
MAXN = N + 5
fac = [1, 1] + [0] * MAXN
finv = [1, 1] + [0] * MAXN
inv = [0, 1] + [0] * MAXN
for i in range(2, MAXN + 2):
	fac[i] = fac[i - 1] * i % MOD
	inv[i] = -inv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD

def comb(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

def nhr(n, r):
	return comb(n + r - 1, r)
ans = 0
K = min(K, N - 1)
for i in range(K + 1):
	ans += comb(N, i) * nhr(N - i, i)
	ans %= MOD
print(ans)


(n, k) = map(int, input().split())
MOD = 10 ** 9 + 7
FAC = [1]
INV = [1]
for i in range(1, 2 * n + 1):
	FAC.append(FAC[i - 1] * i % MOD)
	INV.append(pow(FAC[-1], MOD - 2, MOD))

def nCr(n, r):
	return FAC[n] * INV[n - r] * INV[r]
ans = 0
for i in range(min(n - 1, k) + 1):
	ans += nCr(n, i) * nCr(n - 1, n - i - 1)
	ans %= MOD
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
k = min(k, n - 1)
ans = 1
g = 1
h = 1
for i in range(k):
	g *= (n - i) * pow(i + 1, mod - 2, mod)
	g %= mod
	h *= (n - 1 - i) * pow(i + 1, mod - 2, mod)
	h %= mod
	ans += g * h % mod
	ans %= mod
print(ans)


(n, k) = map(int, input().split())
MOD = 10 ** 9 + 7
fact = [0] * (n + 1)
inv_fact = [0] * (n + 1)
fact[0] = 1
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i % MOD
inv_fact[n] = pow(fact[n], MOD - 2, MOD)
for i in range(n, 0, -1):
	inv_fact[i - 1] = inv_fact[i] * i % MOD

def nCk(n, k):
	return fact[n] * inv_fact[k] * inv_fact[n - k] % MOD
ans = 1
for i in range(1, n):
	if i > k:
		break
	ans += nCk(n, i) * nCk(n - 1, n - i - 1) % MOD
print(ans % MOD)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
U = 4 * 10 ** 5 + 1
MOD = 10 ** 9 + 7
fact = [1] * (U + 1)
fact_inv = [1] * (U + 1)
for i in range(1, U + 1):
	fact[i] = fact[i - 1] * i % MOD
fact_inv[U] = pow(fact[U], MOD - 2, MOD)
for i in range(U, 0, -1):
	fact_inv[i - 1] = fact_inv[i] * i % MOD

def comb(n, k):
	if k < 0 or k > n:
		return 0
	x = fact[n]
	x *= fact_inv[k]
	x %= MOD
	x *= fact_inv[n - k]
	x %= MOD
	return x
if n - 1 <= k:
	print(comb(2 * n - 1, n - 1))
else:
	ans = 0
	for i in range(1 + k):
		ans += comb(n, i) * comb(n - 1, n - i - 1)
		ans %= mod
	print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, n + 1):
	fac.append(fac[-1] * i % mod)
	inv.append(-inv[mod % i] * (mod // i) % mod)
	finv.append(finv[-1] * inv[-1] % mod)
ans = 0
for i in range(min(n - 1, k) + 1):
	com1 = fac[n] * finv[i] * finv[n - i] % mod
	com2 = fac[n - 1] * finv[i] * finv[n - i - 1] % mod
	mul = com1 * com2 % mod
	ans = (ans + mul) % mod
print(ans)


(n, k) = map(int, input().split())
p = pow(10, 9) + 7
li = [1] * (n + 2)
counter = 0
k = min(k, n - 1)
for a in range(1, n + 1):
	li[a] = a * li[a - 1] % p

def comb(a, b):
	if b < 1:
		return 1
	return li[a] * pow(li[b], p - 2, p) * pow(li[a - b], p - 2, p)
for i in range(k + 1):
	counter += comb(n, i) * comb(n - 1, i) % p
print(counter % p)


def comb_list(n, r, mod):
	ret = [1]
	for i in range(1, r + 1):
		ret.append(ret[-1] * (n + 1 - i) * pow(i, mod - 2, mod) % mod)
	return ret
(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
r = min(k, n - 1)
ans = 0
nCl = comb_list(n, r, mod)
n1Cl = comb_list(n - 1, r, mod)
for i in range(r + 1):
	ans = (ans + nCl[i] * n1Cl[i]) % mod
print(ans)


MOD = 10 ** 9 + 7
fac = [1] * (5 * 10 ** 5 + 1)
for i in range(len(fac) - 1):
	fac[i + 1] = fac[i] * (i + 1) % MOD
(n, k) = map(int, input().split())
if k >= n:
	print(fac[2 * n] * pow(2, MOD - 2, MOD) * pow(fac[n], MOD - 2, MOD) ** 2 % MOD)
else:
	ans = 0
	for i in range(k + 1):
		ans += fac[n - 1] * pow(fac[i], MOD - 2, MOD) * pow(fac[n - i - 1], MOD - 2, MOD) * fac[n] * pow(fac[n - i], MOD - 2, MOD) * pow(fac[i], MOD - 2, MOD) % MOD
	print(ans % MOD)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
FACT = [1]
for i in range(1, 5 * 10 ** 5 + 1):
	FACT.append(FACT[-1] * i % mod)
FACT_INV = [pow(FACT[-1], mod - 2, mod)]
for i in range(5 * 10 ** 5, 0, -1):
	FACT_INV.append(FACT_INV[-1] * i % mod)
FACT_INV.reverse()

def Combi(a, b):
	if 0 <= b <= a:
		return FACT[a] * FACT_INV[b] * FACT_INV[a - b] % mod
	else:
		return 0
ANS = 0
for i in range(min(k + 1, n)):
	ANS += Combi(n - 1, n - i - 1) * Combi(n, i)
print(ANS % mod)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
m = 4 * 10 ** 5 + 500
fac = [1] * (m + 1)
facinv = [1] * (m + 1)
for i in range(1, m + 1):
	fac[i] = fac[i - 1] * i % mod
	facinv[i] = facinv[i - 1] * pow(i, -1, mod) % mod

def nCk(n, k):
	return fac[n] * facinv[k] * facinv[n - k] % mod
if k > n - 2:
	print(nCk(2 * n - 1, n))
else:
	ans = 0
	for i in range(k + 1):
		ans = (ans + nCk(n - 1, i) * nCk(n, i)) % mod
	print(ans)


(n, k) = map(int, input().strip().split())
k = min(k, n - 1)
MOD = 10 ** 9 + 7

def modInv(x, m=10 ** 9 + 7):
	return pow(x, m - 2, m)

class combMod:

	def __init__(self, maxN, mod=10 ** 9 + 7):
		self.maxN = maxN
		self.mod = mod
		self.fac = [None] * (maxN + 1)
		self.ifac = [None] * (maxN + 1)

	def calc_fact(self):
		self.fac[0] = 1
		for i in range(1, self.maxN + 1):
			self.fac[i] = self.fac[i - 1] * i % self.mod
		self.ifac[-1] = modInv(self.fac[-1])
		for i in range(self.maxN, 0, -1):
			self.ifac[i - 1] = self.ifac[i] * i % self.mod

	def modnCr(self, n, r, mod=None):
		if mod is None:
			mod = self.mod
		denom = self.fac[n]
		numer = self.ifac[r] * self.ifac[n - r] % mod
		return denom * numer % mod
combMod = combMod(2 * n + 1)
combMod.calc_fact()
ans = 0
for ki in range(k + 1):
	ans += combMod.modnCr(n, ki) * combMod.modnCr(n - ki - 1 + ki, ki) % MOD
print(ans % MOD)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fact = [1]
finv = [1]
for i in range(1, 2 * n):
	fact.append(fact[i - 1] * i % mod)
	finv.append(pow(fact[i], mod - 2, mod))
if n - 1 <= k:
	print(fact[2 * n - 1] * finv[n] * finv[n - 1] % mod)
	exit()
ans = 0
for i in range(k + 1):
	ans += fact[n] * finv[n - i] * finv[i] * fact[n - 1] * finv[n - 1 - i] * finv[i]
	ans %= mod
print(ans)


(n, k) = map(int, input().split())
k = min(k, n - 1)
mod = 10000 * 100000 + 7

def mpow(a, b, m=100000 * 10000 + 7):
	ret = 1
	while b > 0:
		if b & 1:
			ret = ret * a % m
		a = a * a % m
		b >>= 1
	return ret
fact = [1] * (n + 1)
ifact = [1] * (n + 1)
for i in range(2, n + 1):
	fact[i] = fact[i - 1] * i % mod
ifact[n] = mpow(fact[n], mod - 2)
for i in range(n - 1, 1, -1):
	ifact[i] = (i + 1) * ifact[i + 1] % mod

def nCr(n, r):
	if r == 0 or r == n:
		return 1
	val = fact[n] * ifact[r] % mod
	return val * ifact[n - r] % mod
ans = 0
for h in range(k + 1):
	ans = (ans + nCr(n, h) * nCr(n - 1, n - h - 1) % mod) % mod
print(ans)


import sys
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
(n, k) = map(int, input().split())
if k >= n - 1:
	k = n - 1
inv_table = [0] + [1]
for i in range(2, k + 1):
	inv_table += [inv_table[MOD % i] * (MOD - int(MOD / i)) % MOD]
comb_sum = 1
fact = 1
comb1 = 1
comb2 = 1
for i in range(1, k + 1):
	comb1 = comb1 * (n - i + 1) * inv_table[i] % MOD
	comb2 = comb2 * (n - i) * inv_table[i] % MOD
	comb = comb1 * comb2 % MOD
	comb_sum += comb
print(comb_sum % MOD)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
bikkuri = [0 for i in range(2 * n + 5)]
bikkuri[0] = 1
gyaku = [0 for i in range(2 * n + 5)]
gyaku[0] = 1
for i in range(1, 2 * n + 5):
	bikkuri[i] = i * bikkuri[i - 1] % mod
	gyaku[i] = pow(bikkuri[i], mod - 2, mod)

def comb(a, b):
	return bikkuri[a] * gyaku[b] % mod * gyaku[a - b] % mod
if n <= k:
	ans = comb(2 * n - 1, n) % mod
elif k == 1:
	ans = n * n - 1
	ans %= mod
else:
	ans = 0
	for i in range(k + 1):
		if i == 0:
			ans += 1
			ans %= mod
		else:
			ans += comb(n, n - i) * comb(n - 1, i)
			ans %= mod
print(ans)


(N, K) = list(map(int, input().split()))
MOD = 10 ** 9 + 7
MAX_N = 10 ** 6 + 5
fact = [0] * MAX_N
fact_inv = [0] * MAX_N
fact[0] = 1
for i in range(MAX_N - 1):
	fact[i + 1] = fact[i] * (i + 1) % MOD
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for i in range(MAX_N - 2, -1, -1):
	fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD

def comb(n, k):
	return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD
if K >= N:
	print(comb(2 * N - 1, N - 1))
	return
ans = 1
for i in range(1, K + 1):
	ans += comb(N, i) * comb(N - 1, i) % MOD
	ans %= MOD
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
numer = [1] * (n + 1)
demon = [1] * (n + 1)
for i in range(1, n + 1):
	numer[i] = numer[i - 1] * i % mod
demon[n] = pow(numer[n], mod - 2, mod)
for i in range(n, 0, -1):
	demon[i - 1] = demon[i] * i % mod

def nCr(n, r):
	if r < 1:
		return 1
	return numer[n] * demon[r] % mod * demon[n - r] % mod
ans = 0
for i in range(min(k, n - 1) + 1):
	ans = (ans + nCr(n, i) * nCr(n - 1, i)) % mod
print(ans)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float('inf')
(n, k) = map(int, input().split())
MOD = 10 ** 9 + 7

def comb(n, k, mod):
	if n < 0 or k < 0 or n < k:
		return 0
	if n == 0 or k == 0:
		return 1
	k = k if k <= n - k else n - k
	x = 1
	y = 1
	for i in range(k):
		x = x * (n - i) % mod
		y = y * (i + 1) % mod
	return x * pow(y, mod - 2, mod) % mod
fac = [1, 1]
inv = [0, 1]
finv = [1, 1]
for i in range(2, 2 * n + 1):
	fac.append(fac[-1] * i % MOD)
	inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD)
	finv.append(finv[-1] * inv[-1] % MOD)

def comb_mod(n, r, m):
	if n < 0 or r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fac[n] * finv[n - r] * finv[r] % m
if k >= n - 1:
	ans = comb_mod(2 * n - 1, n, MOD)
	print(ans % MOD)
elif k == 1:
	print(n * (n - 1) % MOD)
else:
	ans = 0
	for i in range(k + 1):
		ans += comb_mod(n - 1, i, MOD) * comb_mod(n, i, MOD)
	print(ans % MOD)


(n, k) = map(int, input().split())
F = 200005
mod = 10 ** 9 + 7
fact = [1] * F
inv = [1] * F
for i in range(2, F):
	fact[i] = fact[i - 1] * i % mod
inv[F - 1] = pow(fact[F - 1], mod - 2, mod)
for i in range(F - 2, 1, -1):
	inv[i] = inv[i + 1] * (i + 1) % mod
ans = 1
for i in range(1, min(n, k + 1)):
	comb = fact[n] * inv[i] * inv[n - i] % mod
	h = fact[n - 1] * inv[i] * inv[n - 1 - i] % mod
	ans = (ans + comb * h) % mod
print(ans)


(n, k) = map(int, input().split())
k = min(k, n - 1)
p = 10 ** 9 + 7
size = n + 100
f_list = [1] * size
if_list = [1] * size
for i in range(1, size):
	f_list[i] = f_list[i - 1] * i % p
	if_list[i] = pow(f_list[i], p - 2, p)

def cmb(n, r):
	return f_list[n] * if_list[r] * if_list[n - r] % p
ans = 1
for i in range(1, k + 1):
	ans += cmb(n, i) * cmb(n - 1, i)
	ans = ans % p
print(ans)


import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product

def I():
	return int(sys.stdin.readline())

def MI():
	return list(map(int, sys.stdin.readline().split()))

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LI2(N):
	return [list(map(int, sys.stdin.readline().split())) for i in range(N)]

def LSI():
	return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N):
	return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]

def ST():
	return sys.stdin.readline().rstrip()

def LST():
	return sys.stdin.readline().rstrip().split()

def LST2(N):
	return [sys.stdin.readline().rstrip().split() for i in range(N)]

def FILL(i, h):
	return [i for j in range(h)]

def FILL2(i, h, w):
	return [FILL(i, w) for j in range(h)]

def FILL3(i, h, w, d):
	return [FILL2(i, w, d) for j in range(h)]

def FILL4(i, h, w, d, d2):
	return [FILL3(i, w, d, d2) for j in range(h)]

def sisha(num, digit):
	return Decimal(str(num)).quantize(Decimal(digit), rounding=ROUND_HALF_UP)
MOD = 1000000007
INF = float('inf')
sys.setrecursionlimit(10 ** 6 + 10)

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = MOD
N = 5 * 10 ** 5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
(N, K) = MI()
ans = cmb(2 * N - 1, N - 1, MOD)
if K < N - 1:
	for i in range(K + 1, N):
		ans -= cmb(N, i, MOD) * cmb(N - 1, i, MOD)
print(ans % MOD)


(n, k) = map(int, input().split())
MOD = int(1000000000.0 + 7)
max_zero_num = min(n - 1, k)
kai = [1] * (n + 1)
gyaku_kai = [1] * (n + 1)
for i in range(n):
	kai[i + 1] = kai[i] * (i + 1) % MOD
	gyaku_kai[i + 1] = pow(kai[i + 1], MOD - 2, MOD) % MOD
answer = 0
for zero_num in range(max_zero_num + 1):
	answer = (answer + kai[n] * gyaku_kai[n - zero_num] * gyaku_kai[zero_num] * kai[n - 1] * gyaku_kai[n - 1 - zero_num] * gyaku_kai[zero_num]) % MOD
print(answer)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7

def cmb(n, r, mod):
	return A[n] * B[n - r] * B[r] % mod
A = [1, 1]
B = [1, 1]
for i in range(n):
	A.append(A[-1] * (i + 2) % mod)
	B.append(B[-1] * pow(i + 2, mod - 2, mod) % mod)
if k < n:
	ans = 0
	for i in range(k + 1):
		ans = (ans + cmb(n, i, mod) * cmb(n - 1, i, mod)) % mod
	print(ans)
else:
	ans = 0
	for i in range(n):
		ans = (ans + cmb(n, i, mod) * cmb(n - 1, i, mod)) % mod
	print(ans)


(n, k) = map(int, input().split())
k = min(n - 1, k)
mod = 10 ** 9 + 7
fact = [1] * (n + 1)
ifact = [1] * (n + 1)
for i in range(n):
	fact[i + 1] = fact[i] * (i + 1) % mod
	ifact[i + 1] = pow(fact[i + 1], mod - 2, mod)

def comb(x, y):
	if y < 0 or y > x:
		return 0
	return fact[x] * ifact[x - y] * ifact[y] % mod
ans = 0
for i in range(k + 1):
	ans += comb(n, i) * comb(n - 1, n - i - 1) % mod
	ans %= mod
print(ans)


def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
size = 4 * 10 ** 5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, size + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
(n, k) = map(int, input().split())
k = min(k, n - 1)
ans = 0
for m in range(k + 1):
	ans += cmb(n, m, mod) * cmb(n - 1, n - m - 1, mod)
ans %= mod
print(ans)


(N, K) = map(int, input().split())
mod = 10 ** 9 + 7
n = N * 2
fact = [1] * (n + 1)
rfact = [1] * (n + 1)
r = 1
for i in range(1, n + 1):
	fact[i] = r = r * i % mod
rfact[n] = r = pow(fact[n], mod - 2, mod)
for i in range(n, 0, -1):
	rfact[i - 1] = r = r * i % mod

def comb(n, k):
	return fact[n] * rfact[k] * rfact[n - k] % mod
if N <= K + 1:
	print(comb(n - 1, N))
else:
	ans = (1 + N * (N - 1)) % mod
	for i in range(2, K + 1):
		mini_ans = comb(N, i) * comb(N - 1, N - i - 1) % mod
		ans = (ans + mini_ans) % mod
	print(ans)


mod = 10 ** 9 + 7
(n, k) = map(int, input().split())
ans = 1
coef1 = n
coef2 = n - 1
for i in range(1, min(k + 1, n)):
	tmp = 1
	tmp *= coef1
	tmp %= mod
	tmp *= coef2
	tmp %= mod
	ans += tmp
	ans %= mod
	coef1 *= n - i
	coef1 %= mod
	coef1 *= pow(i + 1, mod - 2, mod)
	coef1 %= mod
	coef2 *= n - 1 - i
	coef2 %= mod
	coef2 *= pow(i + 1, mod - 2, mod)
	coef2 %= mod
print(ans)


MOD = 10 ** 9 + 7

def getModInv(a, b):
	return 1 if a == 1 else (1 - b * getModInv(b % a, a)) // a % b
(N, K) = map(int, input().split())
(t1, t2) = (1, 1)
(s1, s2) = (1, 1)
for m in range(1, min(K, N - 1) + 1):
	t1 = t1 * (N - m) * (N - m + 1) % MOD
	t2 = t2 * m ** 2 % MOD
	s1 = (s1 * t2 + s2 * t1) % MOD
	s2 = s2 * t2 % MOD
print(s1 * getModInv(s2, MOD) % MOD)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
ans = 0
fac = [1]
for i in range(n + 1):
	r = fac[i] * (i + 1) % mod
	fac.append(r)

def c(x, y):
	if x < y:
		return 0
	r = pow(fac[y] * fac[x - y] % mod, mod - 2, mod)
	return r * fac[x] % mod
for i in range(min(k, n) + 1):
	kari = c(n, i)
	kari *= c(n - 1, i)
	ans += kari
	ans %= mod
print(ans)


def modpow(a, n, mod):
	res = 1
	while n > 0:
		if n & 1:
			res = res * a % mod
		a = a * a % mod
		n >>= 1
	return res
(n, k) = map(int, input().split())
MOD = 1000000007
if n - 1 > k:
	ans = 1
	com1 = 1
	com2 = 1
	for i in range(k):
		com1 = com1 * (n - 1 - i) * modpow(i + 1, MOD - 2, MOD) % MOD
		com2 = com2 * (n - i) * modpow(i + 1, MOD - 2, MOD) % MOD
		ans += com1 * com2
	print(ans % MOD)
else:
	ans = 1
	for i in range(n - 1):
		ans = ans * (n * 2 - 1 - i) * modpow(i + 1, MOD - 2, MOD) % MOD
	print(ans % MOD)


mo = 10 ** 9 + 7
(n, k) = map(int, input().split())

def rev(u):
	return pow(u, mo - 2, mo)

def C(p, q):
	ans = 1
	for i in range(q):
		ans = ans * (p - i) % mo
	for i in range(q):
		ans = ans * rev(i + 1) % mo
	return (ans + mo) % mo
if k >= n - 1:
	print(C(2 * n - 1, n))
	exit()
(u, v) = (1, 1)
ans = 1
for i in range(k):
	u = u * (n - 1 - i) * rev(i + 1) % mo
	v = v * (n - i) * rev(i + 1) % mo
	ans = (ans + u * v) % mo
print(ans)


(n, k) = map(int, input().split())
MOD = 10 ** 9 + 7
SIZE = 10 ** 5 * 2 + 1
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
(fact[0], fact[1]) = (1, 1)
inv[1] = 1
(finv[0], finv[1]) = (1, 1)
for i in range(2, SIZE):
	fact[i] = fact[i - 1] * i % MOD
	inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD

def combination(n, r):
	if n < 0 or r < 0 or n < r:
		return 0
	return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
k = min(k, n - 1)
ans = 0
for i in range(k + 1):
	ans += combination(n, i) * combination(n - 1, i)
	ans %= MOD
print(ans)


(n, k) = map(int, input().split())
factorial = [1]
for i in range(1, 2 * n):
	factorial.append(factorial[i - 1] * (i + 1) % (10 ** 9 + 7))
inv = []
for i in range(n):
	inv.append(pow(factorial[i], 10 ** 9 + 5, 10 ** 9 + 7))
if k >= n - 1:
	print(factorial[2 * n - 2] * inv[n - 1] * inv[n - 2] % (10 ** 9 + 7))
else:
	ans = 1
	for i in range(k):
		ans = (ans + factorial[n - 1] * inv[i] * inv[n - i - 2] * factorial[n - 2] * inv[i] * inv[n - i - 3]) % (10 ** 9 + 7)
	if k == 1:
		ans -= 1
	print(ans)


def i1():
	return int(input())

def i2():
	return [int(i) for i in input().split()]
mod = 10 ** 9 + 7

def bp(a, n):
	r = 1
	while n:
		if n % 2:
			r = r * a % mod
		a = a * a % mod
		n >>= 1
	return r
[n, k] = i2()
if n <= k:
	x = 1
	for i in range(n - 1):
		x *= 2 * n - 1 - i
		x %= mod
	y = 1
	for i in range(n - 1):
		y *= i + 1
		y %= mod
	print(x * bp(y, 10 ** 9 + 5) % mod)
else:
	x = 1
	y = 1
	t = 1
	for i in range(k):
		t *= i + 1
		t %= mod
		y *= n - 1 - i
		y %= mod
		y *= n - i
		y %= mod
		c = bp(t, 10 ** 9 + 5)
		x += y * c * c
		x %= mod
	print(x)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
if n <= k:
	l = 2 * n - 1
	inverse = [0, 1]
	g = [1, 1]
	for i in range(2, n):
		l *= 2 * n - i
		l %= mod
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g.append(g[-1] * inverse[-1] % mod)
	print(l * g[-1] % mod)
else:
	h = [1, 1]
	g = [1, 1]
	inverse = [0, 1]
	for i in range(2, 2 * n + 1):
		h.append(h[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g.append(g[-1] * inverse[-1] % mod)
	comb = lambda a, b: h[a] * g[b] * g[a - b] % mod
	t = [comb(n, i) * comb(n - 1, i) % mod for i in range(k + 1)]
	print(sum(t) % mod)


P = 10 ** 9 + 7
N = 700000
inv = [0] + [1]
finv = [1] + [1]
fac = [1] + [1]
for i in range(2, N + 1):
	inv += [inv[P % i] * (P - int(P / i)) % P]
	fac += [fac[i - 1] * i % P]
	finv += [finv[i - 1] * inv[i] % P]

def comb(a, b):
	if a < b:
		return 0
	return fac[a] * (finv[b] * finv[a - b] % P) % P
(n, k) = list(map(int, input().split()))
ans = 0
num = min(n - 1, k) + 1
for i in range(num):
	heya = n - i
	ret = comb(n, i)
	person = n - heya
	ret = ret * comb(person + heya - 1, person) % P
	ans += ret
print(ans % P)


def pow(x, n, mod=None):
	ret = 1
	while n > 0:
		if n % 2 == 1:
			ret = ret * x % mod
		x = x * x % mod
		n >>= 1
	return ret
(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fact = [None] * (1 + n)
finv = [None] * (1 + n)
fact[0] = 1
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i % mod
finv[n] = pow(fact[n], mod - 2, mod=mod)
for i in range(n, 0, -1):
	finv[i - 1] = finv[i] * i % mod

def comb(n, k):
	tmp = finv[n - k] * finv[k] % mod
	return tmp * fact[n] % mod
ans = 0
for m in range(min(n, k + 1)):
	ans = (ans + comb(n, m) * comb(n - 1, m)) % mod
print(ans)


(N, K) = map(int, open(0).read().split())
MAX = 5 * 10 ** 5
MOD = 10 ** 9 + 7
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
	fac[i] = fac[i - 1] * i % MOD
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(range(1, MAX + 1)):
	finv[i - 1] = finv[i] * i % MOD

def comb(n, k):
	return fac[n] * finv[n - k] * finv[k]

def rep_perm(n, k):
	return comb(n + k - 1, k)
ans = 0
for k in range(0, min(N, K + 1)):
	ans += comb(N, k) * rep_perm(N - k, k)
	ans %= MOD
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7

def comb(n, r):
	if n < r:
		return 0
	if n < 0 or k < 0:
		return 0
	return fa[n] * fi[r] % mod * fi[n - r] % mod
fa = [1] * (n + 1)
fi = [1] * (n + 1)
for i in range(1, n + 1):
	fa[i] = fa[i - 1] * i % mod
	fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(min(k, n - 1) + 1):
	ans += comb(n, i) * comb(n - 1, i) % mod
print(ans % mod)


MOD = 10 ** 9 + 7
(N, K) = list(map(int, input().split()))

def getFacts(n, MOD):
	facts = [1] * (n + 1)
	for x in range(2, n + 1):
		facts[x] = facts[x - 1] * x % MOD
	return facts
facts = getFacts(2 * N, MOD)

def getInvFacts(n, MOD):
	invFacts = [0] * (n + 1)
	invFacts[n] = pow(facts[n], MOD - 2, MOD)
	for x in reversed(list(range(n))):
		invFacts[x] = invFacts[x + 1] * (x + 1) % MOD
	return invFacts
invFacts = getInvFacts(2 * N, MOD)

def getComb(n, k, MOD):
	if n < k:
		return 0
	return facts[n] * invFacts[k] * invFacts[n - k] % MOD
ans = 0
for x in range(min(K, N - 1) + 1):
	ans += getComb(N, x, MOD) * getComb(N - 1, x, MOD)
	ans %= MOD
print(ans)


class Combination:

	def __init__(self, mod, max_num):
		self.mod = mod
		self.fac = [0] * max_num
		self.finv = [0] * max_num
		self.inv = [0] * max_num
		(self.fac[0], self.fac[1]) = (1, 1)
		(self.finv[0], self.finv[1]) = (1, 1)
		self.inv[1] = 1
		for i in range(2, max_num):
			self.fac[i] = self.fac[i - 1] * i % mod
			self.inv[i] = mod - self.inv[mod % i] * (mod // i) % mod
			self.finv[i] = self.finv[i - 1] * self.inv[i] % mod

	def calc(self, n, k):
		if n < k:
			return 0
		if n < 0 or k < 0:
			return 0
		return self.fac[n] * (self.finv[k] * self.finv[n - k] % self.mod) % self.mod
(n, k) = list(map(int, input().split()))
com = Combination(1000000007, 500000)
ret = 1
min_val = min(n, k)
for i in range(1, min_val + 1):
	if i != n:
		ret += com.calc(n, i) * com.calc(n - 1, i)
		ret %= 10 ** 9 + 7
	else:
		ret += 0
print(ret)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fact = [1]
fact_inv = [0] * (n + 1)
for i in range(n):
	fact.append(fact[-1] * (i + 1) % mod)
fact_inv[-1] = pow(fact[-1], mod - 2, mod)
for i in range(n - 1, -1, -1):
	fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod
ans = 0
for i in range(min(n - 1, k) + 1):
	com1 = fact[n] * fact_inv[i] * fact_inv[n - i] % mod
	com2 = fact[n - 1] * fact_inv[i] * fact_inv[n - i - 1] % mod
	mul = com1 * com2 % mod
	ans = (ans + mul) % mod
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fra = [1] * (2 * n + 2)
inv = [1] * (2 * n + 2)
t = 1
for i in range(1, 2 * n + 2):
	t *= i
	t %= mod
	fra[i] = t
t = pow(fra[2 * n + 1], mod - 2, mod)
for i in range(2 * n + 1, 0, -1):
	inv[i] = t
	t *= i
	t %= mod

def comb(n, r):
	return fra[n] * inv[n - r] * inv[r] % mod
if n <= k:
	print(comb(2 * n - 1, n))
	quit()
ans = 0
for i in range(min(n, k) + 1):
	ans += comb(n, i) * comb(n - 1, i)
	ans %= mod
print(ans)


class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		f = 1
		self.fac = fac = [f]
		for i in range(1, n_max + 1):
			f = f * i % mod
			fac.append(f)
		f = pow(f, mod - 2, mod)
		self.facinv = facinv = [f]
		for i in range(n_max, 0, -1):
			f = f * i % mod
			facinv.append(f)
		facinv.reverse()

	def __call__(self, n, r):
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def C(self, n, r):
		if not 0 <= r <= n:
			return 0
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def P(self, n, r):
		if not 0 <= r <= n:
			return 0
		return self.fac[n] * self.facinv[n - r] % self.mod

	def H(self, n, r):
		if n == 0 and r > 0 or r < 0:
			return 0
		return self.fac[n + r - 1] * self.facinv[r] % self.mod * self.facinv[n - 1] % self.mod

	def rising_factorial(self, n, r):
		return self.fac[n + r - 1] * self.facinv[n - 1] % self.mod

	def stirling_first(self, n, k):
		if n == k:
			return 1
		if k == 0:
			return 0
		return (self.stirling_first(n - 1, k - 1) + (n - 1) * self.stirling_first(n - 1, k)) % self.mod

	def stirling_second(self, n, k):
		if n == k:
			return 1
		return self.facinv[k] * sum(((-1) ** (k - m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k + 1))) % self.mod

	def balls_and_boxes_3(self, n, k):
		return sum(((-1) ** (k - m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k + 1))) % self.mod

	def bernoulli(self, n):
		if n == 0:
			return 1
		if n % 2 and n >= 3:
			return 0
		return -pow(n + 1, self.mod - 2, self.mod) * sum((self.C(n + 1, k) * self.bernoulli(k) % self.mod for k in range(n))) % self.mod

	def faulhaber(self, k, n):
		return pow(k + 1, self.mod - 2, self.mod) * sum((self.C(k + 1, j) * self.bernoulli(j) % self.mod * pow(n, k - j + 1, self.mod) % self.mod for j in range(k + 1))) % self.mod

	def lah(self, n, k):
		return self.C(n - 1, k - 1) * self.fac[n] % self.mod * self.facinv[k] % self.mod

	def bell(self, n, k):
		return sum((self.stirling_second(n, j) for j in range(1, k + 1))) % self.mod

def main():
	(N, K) = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	sign = 1
	L = []
	comb = Combination(202020)
	ans = 0
	for n_zeroes in range(min(K + 1, N)):
		a = comb.C(N, n_zeroes) * comb.H(N - n_zeroes, n_zeroes) % mod
		ans += a
	print(ans % mod)
main()


(n, k) = map(int, input().split())
D = 10 ** 9 + 7
up = [1] * (n + 1)
down = [0] * (n + 1)
for i in range(1, n + 1):
	up[i] = up[i - 1] * i % D
down[n] = pow(up[n], D - 2, D)
for i in range(n, 0, -1):
	down[i - 1] = down[i] * i % D

def cmd(n, r, D):
	if r < 0 or r > n:
		return 0
	else:
		return up[n] * down[r] * down[n - r] % D
A = 0
k = min(k, n - 1)
t = 0
while t <= k:
	A = (A + cmd(n - 1, t, D) * cmd(n, t, D)) % D
	t = t + 1
print(A)


import sys
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def input():
	return sys.stdin.readline().strip()

class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		self.modinv = self.make_modinv_list(n_max)
		(self.fac, self.facinv) = self.make_factorial_list(n_max)

	def __call__(self, n, r):
		if n < r:
			return 0
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def make_factorial_list(self, n):
		fac = [1]
		facinv = [1]
		for i in range(1, n + 1):
			fac.append(fac[i - 1] * i % self.mod)
			facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
		return (fac, facinv)

	def make_modinv_list(self, n):
		modinv = [0] * (n + 1)
		modinv[1] = 1
		for i in range(2, n + 1):
			modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
		return modinv

def main():
	(N, K) = list(map(int, input().split()))
	comb = Combination(n_max=10 ** 5 * 4 + 10)
	if N <= K:
		ans = comb(2 * N - 1, N)
	elif K == 1:
		ans = comb(N, 1) * comb(N - 1, 1)
	else:
		ans = 0
		for m in range(K + 1):
			ans += comb(N, m) * comb(N - 1, m)
			ans %= MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
fact = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, 2 * n + 1):
	fact.append(fact[-1] * i % mod)
	inv.append(inv[mod % i] * (mod - mod // i) % mod)
	finv.append(finv[-1] * inv[-1] % mod)

def nCr(n, r, mod):
	return fact[n] * finv[r] * finv[n - r] % mod

def nHr(n, r, mod):
	return nCr(n + r - 1, r, mod)
ans = 0
m = min(k, n - 1)
for i in range(m + 1):
	ans += nCr(n, i, mod) * nHr(n - i, i, mod) % mod
print(ans % mod)


mod = 10 ** 9 + 7
(n, k) = map(int, input().split())
binomial = [1]
cum = 1
for i in range(1, n + 2):
	cum *= i
	cum = cum % mod
	binomial.append(cum)
inv = []
tmp = pow(cum, mod - 2, mod)
inv.append(tmp)
for j in range(n + 1, 0, -1):
	tmp = j * tmp % mod
	inv.append(tmp)
inv.reverse()

def comb(n, k):
	return binomial[n] * inv[n - k] % mod * inv[k] % mod if n >= k else 0
k = min(k, n - 1)
ans = 0
for m in range(k + 1):
	tmp = comb(n, m) * binomial[n - 1] * inv[n - 1 - m] * inv[m]
	ans += tmp % mod
ans %= mod
print(ans)


from collections import defaultdict as dd
(N, k) = map(int, input().split())
res = 0
fact = [0] * (N + 1)
ifact = [0] * (N + 1)
inv = [0] * (N + 1)
p = 10 ** 9 + 7
dic = dd(int)

def combination(n, fact, ifact):
	fact[0] = 1
	fact[1] = 1
	ifact[0] = 1
	ifact[1] = 1
	inv[1] = 1
	for i in range(2, n + 1):
		fact[i] = fact[i - 1] * i % p
		inv[i] = p - inv[p % i] * (p // i) % p
		ifact[i] = ifact[i - 1] * inv[i] % p

def op(n, k):
	if (n, k) in dic.keys():
		return dic[n, k]
	if k < 0 or k > n or n < 0:
		return 0
	dic[n, k] = fact[n] * ifact[k] * ifact[n - k] % (10 ** 9 + 7)
	return dic[n, k]
combination(N, fact, ifact)
for t in range(0, min(k, N - 1) + 1):
	res += op(N - 1, N - t - 1) * op(N, t) % p
print(res % p)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
factorial = [1]
inverse = [1]
for i in range(1, 2 * n):
	factorial.append(factorial[-1] * i % mod)
	inverse.append(pow(factorial[-1], mod - 2, mod))

def comb(n, r, mod):
	if n < r or r < 0:
		return 0
	elif r == 0:
		return 1
	return factorial[n] * inverse[r] * inverse[n - r] % mod
if k >= n - 1:
	print(comb(2 * n - 1, n - 1, mod))
else:
	sikiri = n - 1
	basho = 2 * n - 1
	ans = 0
	for i in range(k + 1):
		ans = (ans + comb(n, i, mod) * comb(sikiri, sikiri - i, mod)) % mod
	print(ans)


from sys import stdin
readline = stdin.readline
(N, K) = map(int, readline().split())
mod = 10 ** 9 + 7
fact = [1] * (2 * N)
finv = [1] * (2 * N)
inv = [1] * (2 * N)
inv[0] = 0
for i in range(2, 2 * N):
	fact[i] = fact[i - 1] * i % mod
	inv[i] = -inv[mod % i] * (mod // i) % mod
	finv[i] = finv[i - 1] * inv[i] % mod

def com(N, K, mod):
	if K < 0 or N < K:
		return 0
	return fact[N] * finv[K] * finv[N - K] % mod
if N - 1 <= K:
	print(com(2 * N - 1, N, mod))
else:
	res = 0
	for m in range(K + 1):
		res += com(N, m, mod) * com(N - 1, m, mod)
		res %= mod
	print(res)


(N, K) = map(int, input().split())
mod = 10 ** 9 + 7
K = min(K, N - 1)
fact = [1]
facinv = [1]
for i in range(1, N + 1):
	fact.append(fact[-1] * i % mod)

def nCr(n, r):
	num = fact[n]
	div = fact[r] * fact[n - r] % mod
	return num * pow(div, mod - 2, mod) % mod
move = [0] * (N + 1)
move[0] = 1
for i in range(1, N + 1):
	x = nCr(N, i) * nCr(N - 1, N - i - 1) % mod
	move[i] = x
for i in range(1, N):
	move[i] = (move[i - 1] + move[i]) % mod
ans = move[K]
print(ans)


(n, k) = map(int, input().split())
mod = 10 ** 9 + 7
ans = 1
comb = 1
H = 1
for i in range(1, min(n, k + 1)):
	tmp = 1
	comb *= n - i + 1
	comb %= mod
	comb *= pow(i, mod - 2, mod)
	comb %= mod
	tmp *= comb
	tmp %= mod
	H *= n - i
	H %= mod
	H *= pow(i, mod - 2, mod)
	H %= mod
	tmp *= H
	tmp %= mod
	ans += tmp
	ans %= mod
print(ans)


def comb(n, r):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % MOD
MOD = 10 ** 9 + 7
MAXN = 400000 + 10
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, MAXN + 1):
	g1.append(g1[-1] * i % MOD)
	inverse.append(-inverse[MOD % i] * (MOD // i) % MOD)
	g2.append(g2[-1] * inverse[-1] % MOD)
(N, K) = map(int, input().split())
if K >= N - 1:
	print(comb(N * 2 - 1, N))
else:
	ans = 1
	for i in range(1, K + 1):
		ans = (ans + comb(N - 1, i) * comb(N, i) % MOD) % MOD
	print(ans)


(n, k) = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 1 % mod
left_combination = 1
right_combination = 1
for i in range(1, min(k, n - 1) + 1):
	left_combination = left_combination * (n + 1 - i) * pow(i, mod - 2, mod) % mod
	right_combination = right_combination * (n - i) * pow(i, mod - 2, mod) % mod
	ans = (ans + left_combination * right_combination % mod) % mod
print(ans)


m = 10 ** 9 + 7
f = [1]
(n, k) = map(int, input().split())
for i in range(10 ** 6):
	f += [f[i] * (i + 1) % m]

def c(a, b):
	return f[a] * pow(f[b], m - 2, m) * pow(f[a - b], m - 2, m) % m
s = c(n * 2 - 1, n - 1)
if k > n - 2:
	print(s)
else:
	print((s + (m - sum((c(n - 1, i) * c(n, n - i) for i in range(n - 1, k, -1))) % m)) % m)