Linear Garden#277

Linear Garden

1.5 seconds
64 megabytes
Easy

Ramesses II has just returned victorious from battle. To commemorate his victory, he decided to build a majestic garden. The garden will contain a long line of plants that will run all the way from his palace at Luxor to the temple of Karnak. It will consist only of lotus and papyrus plants, since they symbolize Upper and Lower Egypt respectively.

The garden must contain exactly plants. Additionally, it must be balanced: in any contiguous section of the garden, the numbers of lotus and papyrus plants must not differ by more than .

The garden can be represented as a string of letters 'L' (lotus) and 'P' (papyrus). For example, for n = 5, there are possible balanced gardens. In alphabetical order, these are: , , , , , , , , , , , , and .

The possible balanced gardens of a certain length can be ordered alphabetically and then numbered starting from . For example, for n = 5, garden number is .

Write a program that, given the number of plants and a string that represents a balanced garden, calculates the number assigned to this garden modulo a given integer . Note that for the solution, the value of has no relevance other than simplifying computations. It is known that 1 \leq n \leq 1\ 000\ 000, 7 \leq m \leq 10\ 000\ 000.

Input

Your program should read from standard input in the following format: - The first line contains the integer , the number of plants in the garden. - The second line contains the integer . - The third line contains a string of characters 'L' (lotus) or 'P' (papyrus) representing a balanced garden.

Output

Your program should output one integer from to m-1, inclusive: the number assigned to the garden described in the input, calculated modulo .

Examples

Example 1

Loading
Loading