Problem:
Score : 500 points

Problem Statement

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 1

3 2

Sample Output 1

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.

Sample Input 2

200000 1000000000

Sample Output 2

607923868

Print the count modulo (10^9 + 7).

Sample Input 3

15 6

Sample Output 3

22583772

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::io::{stdin, Read};
const MOD: usize = 1000000007;

fn gcd(a: usize, b: usize) -> usize {
    match b {
        0 => a,
        _ => gcd(b, a % b),
    }
}

fn powmod(base: usize, exp: usize, m: usize) -> usize {
    let b: Vec<bool> = format!("{:b}", exp)
        .chars()
        .map(|x| x.to_digit(10).unwrap() != 0)
        .collect();
    let mut v = 1;
    for bi in b {
        v *= v;
        v %= m;
        if bi {
            v *= base;
            v %= m
        }
    }
    return v % m;
}

fn invmod(x: usize, m: usize) -> usize {
    powmod(x, m - 2, m)
}

fn prime_factors(x: usize) -> Vec<usize> {
    let mut res = vec![];
    let mut y = x;
    let mut p = 2;
    let upper = (y as f64).sqrt() as usize;
    while y > 1 && p <= upper {
        match y % p {
            0 => {
                res.push(p);
                y /= p;
            }
            _ => {
                p += 1;
            }
        }
    }
    if y > 1 {
        res.push(y)
    }
    return res;
}

fn get_factorials(n: usize, m: usize) -> Vec<usize> {
    let mut res = vec![0; n as usize];
    res[0] = 1;
    for i in 1..(n as usize) {
        res[i] = (res[i - 1] * (i as usize)) % m;
    }
    res
}

fn get_facinvs(n: usize, m: usize, facts: &Vec<usize>) -> Vec<usize> {
    let mut res = vec![0; n];
    res[n - 1] = invmod(facts[n - 1], m);
    for i in (0..(n - 1)).rev() {
        res[i] = (res[i + 1] * (i + 1)) % m;
    }
    res
}

fn combmod(a: usize, b: usize, m: usize, facts: &Vec<usize>, invs: &Vec<usize>) -> usize {
    if a < b {
        0
    } else {
        (((facts[a as usize] * invs[b as usize]) % m) * invs[(a - b) as usize]) % m
    }
}

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: ident) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let (n, k): (usize, usize) = parse!(it, 2);
    let r = if k > n { 0 } else { n - k };
    let facts = get_factorials(200100, MOD);
    let invs = get_facinvs(200100, MOD, &facts);
    let mut ret = 0;
    for i in 0..std::cmp::min(k + 1, n) {
        let a = combmod(n, i, MOD, &facts, &invs);
        let b = combmod(n - 1, n - i - 1, MOD, &facts, &invs);
        ret += (a * b) % MOD;
        ret %= MOD;
    }
    println!("{}", ret % MOD);
}