Parentheses and brackets P36384


Statement
 

pdf   zip

Suppose that you have xx pairs of parentheses and yy pairs of brackets. In how many ways can you correctly put the parentheses and brackets?

For example, there are 15 ways with x=2x = 2 and y=1y = 1:

()()[] ()[()] (()[]) ([()]) [()]()
()([]) (())[] (([])) []()() [()()]
()[]() ([])() ([]()) [](()) [(())]

The number of combinations grows very fast with xx and yy. Therefore, make the calculations modulo a given natural number mm.

Input

Input consists of several cases. Every case has xx, yy and mm. Suppose 0x500 \le x \le 50, 0y500 \le y \le 50, and 2m1082 \le m \le 10^8.

Output

For every case, print the number of correct ways to place xx pairs of parentheses and yy pairs of brackets, modulo mm.

Public test cases
  • 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
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++