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 .
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T10:28:42.528Z
© Jutge.org, 2006–2026.
https://jutge.org