Suppose that you have pairs of parentheses and pairs of brackets. In how many ways can you correctly put the parentheses and brackets?
For example, there are 15 ways with and :
()()[] |
()[()] |
(()[]) |
([()]) |
[()]() |
()([]) |
(())[] |
(([])) |
[]()() |
[()()] |
()[]() |
([])() |
([]()) |
[](()) |
[(())] |
The number of combinations grows very fast with and . Therefore, make the calculations modulo a given natural number .
Input consists of several cases. Every case has , and . Suppose , , and .
For every case, print the number of correct ways to place pairs of parentheses and pairs of brackets, modulo .
Input
2 1 1000000 1 2 1000000 1 2 4 0 0 1000000 1 0 1000000 2 0 1000000 3 0 1000000 6 6 100000000 6 6 1000 50 50 100000000
Output
15 15 3 1 1 2 5 92203088 88 24825920