Ms. Daisy teaches a class of
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:
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