In the event of technical difficulties with Szkopuł, please contact us via email at szkopul@fri.edu.pl.
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Ramesses II has just returned victorious from battle. To commemorate his victory, he has 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 plants and papyrus plants, since they symbolize Upper and Lower Egypt respectively.
The garden must contain exactly plants. Also, it must be balanced: in any contiguous section of the garden, the numbers of lotus and papyrus plants must not differ by more than 2.
A garden can be represented as a string of letters 'L' (lotus) and 'P' (papirus). For example, for there are 14 possible balanced gardens. In alphabetical order, these are: LLPLP, LLPPL, LPLLP, LPLPL, LPLPP, LPPLL, LPPLP, PLLPL, PLLPP, PLPLL, PLPLP, PLPPL, PPLLP, and PPLPL.
The possible balanced gardens of a certain length can be ordered alphabetically, and then numbered starting from 1. For example, for , garden number 12 is the garden PLPPL.
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 some given integer .
Note that for solving the task, the value of has no importance other than simplifying computations.
;
.
Your program must read from the standard input the following data:
Your program must write to the standard output a single line containing one integer between and (inclusive), the number assigned to the garden described in the input, modulo .
In inputs worth a total of 40 points, will not exceed 40.
For the input data:
5 7 PLPPL
the correct result is:
5
The actual number assigned to PLPPL is 12. So, the output is 12 modulo 7, which is 5.
For the input data:
12 10000 LPLLPLPPLPLL
the correct result is:
39