QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#2153. HILO

Statistics

Bessie knows a number $x+0.5$ where $x$ is some integer between $0$ to $N$, inclusive ($1≤N≤5000$).

Elsie is trying to guess this number. She can ask questions of the form "is $i$ high or low?" for some integer $i$ between $1$ and $N$, inclusive. Bessie responds by saying "HI!" if $i$ is greater than $x+0.5$, or "LO!" if $i$ is less than $x+0.5$.

Elsie comes up with the following strategy for guessing Bessie's number. Before making any guesses, she creates a list of N numbers, where every number from $1$ to $N$ occurs exactly once (in other words, the list is a permutation of size $N$.) Then, she goes through the list, guessing numbers that appear in the list in order. However, Elsie skips any unnecessary guesses. That is, if Elsie is about to guess some number $i$ and Elsie previously guessed some $j < i$ such that Bessie responded with "HI!," Elsie will not guess $i$ and will move on to the next number in the list. Similarly, if she is about to guess some number $i$ and she previously guessed some $j > i$ such that Bessie responded with "LO!," Elsie will not guess $i$ and will move on to the next number in the list. It can be proven that using this strategy, Elsie always uniquely determines $x$ regardless of the permutation she creates.

If we concatenate all of Bessie's responses of either "HI" or "LO" into a single string $S$, the number of times Bessie says "HILO" is the number of length $4$ substrings of $S$ that are equal to "HILO."

Bessie knows that Elsie will use this strategy and has already chosen the value of $x$, but she does not know what permutation Elsie will use. Your goal is to compute the sum of the number of times Bessie says "HILO" over all permutations that Elsie could possibly choose, modulo $10^9+7$.

Input Format

The only line of input contains $N$ and $x$.

Output Format

The total number of HILOs modulo $10^9+7$.

Examples

Input 1

4 2

Output 1

17

In this test case, Bessie's number is $2.5$.

For example, if Elsie's permutation is $(4,1,3,2)$, then Bessie will say "HILOHILO," for a total of two "HILO"s. As another example, if Elsie's permutation is $(3,1,2,4)$, then Bessie will say "HILOLO," for a total of one "HILO."

Input 2

60 10

Output 2

508859913

Make sure to output the sum modulo 109+7.

Scoring

  • Test cases 3-10 satisfy $N≤50$.
  • Test cases 11-18 satisfy $N≤500$.
  • Test cases 19-26 satisfy no additional constraints.

Problem credits: Richard Qi

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.