Codeforces Round 678 (Div. 2)
C
Binary Search
Codeforces
1500
原题
← BD →
翻译中…

Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudocode of the algorithm is as follows:

翻译中…

image

翻译中…

Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down).

翻译中…

Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find $x$!

翻译中…

Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size $n$ such that the algorithm finds $x$ in them. A permutation of size $n$ is an array consisting of $n$ distinct integers between $1$ and $n$ in arbitrary order.

翻译中…

Help Andrey and find the number of permutations of size $n$ which contain $x$ at position $pos$ and for which the given implementation of the binary search algorithm finds $x$ (returns true). As the result may be extremely large, print the remainder of its division by $10^9+7$.

翻译中…

Input

翻译中…

The only line of input contains integers $n$, $x$ and $pos$ ($1 \le x \le n \le 1000$, $0 \le pos \le n - 1$) — the required length of the permutation, the number to search, and the required position of that number, respectively.

翻译中…

Output

翻译中…

Print a single number — the remainder of the division of the number of valid permutations by $10^9+7$.

翻译中…

Note

翻译中…

All possible permutations in the first test case: $(2, 3, 1, 4)$, $(2, 4, 1, 3)$, $(3, 2, 1, 4)$, $(3, 4, 1, 2)$, $(4, 2, 1, 3)$, $(4, 3, 1, 2)$.

翻译中…

样例

Input #1
4 1 2
Output #1
6
InputCopy OutputCopy
Input #2
123 42 24
Output #2
824071958
InputCopy OutputCopy
题目信息
题号
1436C
时间限制
1 s
内存限制
256 MB
标签
二分
组合数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。