#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 N×MN×M rectangle, divided into N×MN×M small square regions of size 1×11×1 (you can think of the cake as an NN-row by MM-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 1,2,31, 2, 3. 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 KK-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 10610^6. If no valid scheme exists, output 00.

Input Format

The input consists of three lines. The first line: N,MN, M; The second line: KK; The third line: MM integers, representing the jam arrangement of the KK-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 3\texttt{2 3}
1 2\texttt{1 2}
2 3\texttt{2 3}
3 1\texttt{3 1}
2 3\texttt{2 3}
3 2\texttt{3 2}
2 2
1
2 3

3

Data Range and Hints

For 30% of the data, 1N×M201≤N×M≤20; For 60% of the data, 1N1000,1M31≤N≤1000, 1≤M≤3; For 100% of the data, 1N10000,1M51≤N≤10000, 1≤M≤5.