#USACOC2211C. HILO
HILO
Description
Bessie knows a number where is some integer between to inclusive.
Elsie is trying to guess this number. She can ask questions of the form "is high or low?" for some integer between and inclusive. Bessieresponds by saying "HI!" if is greater than , or "LO!" if is lessthan .
Elsie comes up with the following strategy for guessing Bessie's number. Beforemaking any guesses, she creates a list of numbers, where every number from to occurs exactly once (in other words, the list is a permutation ofsize .) Then, she goes through the list, guessing numbers that appear in thelist in order. However, Elsie skips any unnecessary guesses. That is, if Elsieis about to guess some number and Elsie previously guessed some suchthat Bessie responded with "HI!," Elsie will not guess and will move on tothe next number in the list. Similarly, if she is about to guess some number and she previously guessed some such that Bessie responded with "LO!,"Elsie will not guess and will move on to the next number in the list. It canbe proven that using this strategy, Elsie always uniquely determines regardless of the permutation she creates.
If we concatenate all of Bessie's responses of either "HI" or "LO" into a singlestring the number of times Bessie says "HILO" is the number of length substrings of that are equal to "HILO."
Bessie knows that Elsie will use this strategy and has already chosen the valueof , but she does not know what permutation Elsie will use. Your goal is tocompute the sum of the number of times Bessie says "HILO" over all permutationsthat Elsie could possibly choose, modulo .
Input Format
The only line of input contains and .
Output Format
The total number of HILOs modulo .
4 2
4 2
In this test case, Bessie's number is .
For example, if Elsie's permutation is , then Bessie will say"HILOHILO," for a total of two "HILO"s. As another example, if Elsie'spermutation is , then Bessie will say "HILOLO," for a total of one"HILO."
60 10
60 10
Scoring
- Test cases 3-10 satisfy $N\le 50$.
- Test cases 11-18 satisfy $N\le 500$.
- Test cases 19-26 satisfy no additional constraints.
Problem Credit
Problem credits: Richard Qi