Ms. Daisy teaches a class of boys and girls that need to line up every morning to take attendance. Ms. Daisy thinks that a line is "balanced" if at least one of the boys is equidistant from two of the girls in the line. For example, a girl-boy-boy-girl line is not balanced because both boys are closer to one of the girls, but a girl-girl-boy-boy-girl line is balanced because the first boy is equidistant from the first and last girls.
Ms. Daisy likes it when the students form a balanced line. Can you help her figure out the number of balanced lines that the students can form? Two lines are considered distinct if at least one student has a different position in each line.
Input Specification
The standard input contains 10 datasets. Each dataset contains two integers , .
For the first four datasets, .
Output Specification
For each data set, output the number of balanced lines that can be formed, modulo .
Note: modulo is the remainder of .
Sample Input (Three Datasets Shown)
1 2
2 2
3 2
Sample Output
2
8
48
Explanation of Sample Output
In the first case, a balanced line must have a girl, then the boy, and then the other girl. Either girl can come first, which gives us two balanced lines. In the second case, a balanced line has either a boy-girl-boy-girl pattern or a girl-boy-girl-boy pattern. In the third case, an example balanced line would have a girl-boy-boy-boy-girl pattern (the boy in the middle is equidistant from the two girls).
Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org
Comments