atcoder#ARC081B. [ABC071D] Coloring Dominoes
[ABC071D] Coloring Dominoes
Score : points
Problem Statement
We have a board with a grid. Snuke covered the board with dominoes without overlaps. Here, a domino can cover a or square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo .
The arrangement of the dominoes is given to you as two strings and in the following manner:
- Each domino is represented by a different English letter (lowercase or uppercase).
- The -th character in represents the domino that occupies the square at the -th row from the top and -th column from the left.
Constraints
- and consist of lowercase and uppercase English letters.
- and represent a valid arrangement of dominoes.
Input
Input is given from Standard Input in the following format:
Output
Print the number of such ways to paint the dominoes, modulo .
3
aab
ccb
6
There are six ways as shown below:
1
Z
Z
3
Note that it is not always necessary to use all the colors.
52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
958681902