#Q174. 「一本通 5.4 练习 1」涂抹果酱
「一本通 5.4 练习 1」涂抹果酱
Description
Tyvj's second anniversary celebration is approaching, and Sam wants to make a big cake for Tyvj. The top view of the cake is an rectangle, divided into small square regions of size (you can think of the cake as an -row by -column matrix). The cake is quickly made, but a plain cake certainly doesn't look good! So, Sam plans to spread jam on the top surface of the cake. There are three types of jam: red, green, and blue, with the corresponding numbers . To ensure the cake's visual appeal, Admin has issued a strict command: adjacent regions must not use the same type of jam. However, before receiving this command, Sam had already applied jam to the -th row of the cake and cannot modify it. Now Sam wants to know: how many ways are there to apply the jam that will satisfy Admin? Please output the number of valid schemes modulo . If no valid scheme exists, output .
Input Format
The input consists of three lines. The first line: ; The second line: ; The third line: integers, representing the jam arrangement of the -th row. Detailed meanings of the letters are as described in the problem statement. See the sample for further clarification.
Output Format
Output only one line, the total number of feasible schemes.
Sample 1
| Sample 1 | Sample 2 | Sample 3 |
|---|---|---|
| |
|
|
2 2
1
2 3
3
Data Range and Hints
For 30% of the data, ; For 60% of the data, ; For 100% of the data, .