eolymp
bolt
Try our new interface for solving problems
Problems

Permutations with given distance

Permutations with given distance

Butt-head has n volumes of his favourite Encyclopedia For Stupid Teenagers. The volumes are numbered from \textbf{1} to \textbf{n} and arranged in a row. He doesn’t like strict order, but he dislikes complete chaos as well. Butt-head counts the \textit{distance} of volumes’ pertmutation as the sum of differences between number and position for all volumes. In other words, if the permutation is (\textbf{i_1}, \textbf{i_2}, ... \textbf{i_n}), where \textbf{i_k} (1 ≤ \textbf{k} ≤ \textbf{n}) denotes the number of volume on \textbf{k}-th place, then its distance will be |\textbf{i_1}--1|+|\textbf{i_2}--2|+...+|\textbf{i_n}--\textbf{n}|. Butt-head has a favourite number \textbf{d}, and he wants to arrange the Encyclopedia volumes so, that the distance will be equal to \textbf{d}. In how many ways can he do this? \InputFile First line of input contains the quantity of tests \textbf{T} (\textbf{1} ≤ \textbf{T} ≤ \textbf{100}). Each of the next \textbf{T} lines contains data for one test: the quantity of volumes \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{50}) and the required distance \textbf{d} (\textbf{0} ≤ \textbf{d} ≤ \textbf{10000}), separated by a space. Numbers \textbf{n}, \textbf{d} are integer. \OutputFile Output \textbf{T} lines of the form "\textbf{Case} #\textbf{A}: \textbf{B}", where \textbf{A} is the number of test (beginning from \textbf{1}), \textbf{B} is the quantity of permutations of \textbf{n} volumes with distance \textbf{d}, taken modulo \textbf{100007}.
Time limit 0.5 seconds
Memory limit 64 MiB
Input example #1
5
2 0
2 2
4 1
4 2
4 6
Output example #1
Case #1: 1
Case #2: 1
Case #3: 0
Case #4: 3
Case #5: 9