Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/kombinatorika-aynan-k-joyida

Exactly k in place

Medium 1000 ms 128 MB 60%
Share

In a permutation of the numbers $1, 2, \dots, n$, the $i$-th element is said to stay in its place if $p_{i} = i$. How many permutations have exactly $k$ elements in their places? Print the answer modulo $10^{9} + 7$.

A permutation: the elements left in place are highlighted, the rest have moved

Input

One line with two integers: $n$ and $k$.

Output

One integer — the number of permutations modulo $10^{9} + 7$.

Note

$1 \le n \le 10^{6}$
$0 \le k \le n$

Examples

Input #1
4 2
Output #1
6
Input #2
3 2
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.