import scala.annotation.tailrec import scala.io.StdIn.* import scala.math.* object ModInt: opaque type ModInt = Long extension (value: Long) inline def asModInt(using inline mod: Int): ModInt = value % mod extension (value: Int) inline def asModInt(using inline mod: Int): ModInt = value % mod trait Converter[T]: inline def convert(value: T)(using inline mod: Int): ModInt inline given Converter[Int] with override inline def convert(value: Int)(using inline mod: Int) = value.asModInt inline given Converter[Long] with override inline def convert(value: Long)(using inline mod: Int) = value.asModInt inline given Converter[ModInt] with override inline def convert(value: ModInt)(using inline mod: Int) = value extension (modInt: ModInt) inline def asLong(using inline mod: Int): Long = (modInt + mod) % mod inline def inverse(using inline mod: Int): ModInt = modInt.powMod(mod - 2) inline def powMod(exp: Long)(using inline mod: Int): ModInt = var result = 1L var base = modInt var e = exp while e > 0 do if (e & 1) == 1 then result = result * base % mod base = base * base % mod e >>= 1 result inline def powMod(exp: Int)(using inline mod: Int): ModInt = powMod(exp.toLong) extension [L: Converter, R: Converter] (left: L) inline def +(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) + summon[Converter[R]].convert(right)).asModInt inline def -(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) - summon[Converter[R]].convert(right)).asModInt inline def *(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right)).asModInt inline def /(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right).inverse).asModInt @main def main = import ModInt.* inline given mod: Int = 1000000007 val Array(n, k) = readLine().split(' ').map(_.toInt) val factorial = Array.fill(n + 1){1.asModInt} for i <- 2 to n do factorial(i) = i * factorial(i - 1) val inverse = factorial.clone() inverse(n) = inverse(n).inverse for i <- n to 2 by -1 do inverse(i - 1) = i * inverse(i) def combination(n: Int, r: Int): ModInt = factorial(n) * inverse(r) * inverse(n - r) var current = (k + n - 1 to k by -1).foldLeft(1.asModInt){_ * _} * inverse(n) val maxLt = min(n - 1, k - 1) var result = current for lt <- 1 to maxLt do current = current * (k - lt) * (n - lt) / ((k + n - lt).asModInt * lt) result += current println(result.asLong)