An unknown sequence consists of colors numbered from to .
For each , consider the prefix . Let be the length of its longest suffix containing at most two distinct colors. A suffix consists of the last several elements of the prefix.
You are given and . Count the color sequences that produce exactly these reports, modulo .
Two sequences are different if they differ at any position. If no sequence satisfies the reports, the answer is .
The sequence may use at most two colors. Of the sequences, exactly use all three colors.
The three positions must have pairwise different colors, giving sequences.
Only the sequence is possible.
Every sequence over two colors satisfies the reports, giving sequences.