AtCoder Beginner Contest 071
D
Coloring Dominoes
AtCoder
⌀ 1165
原题
← C→
翻译中…

Problem Statement

翻译中…

We have a board with a $2 \times N$ grid. Snuke covered the board with $N$ dominoes without overlaps. Here, a domino can cover a $1 \times 2$ or $2 \times 1$ 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 $1000000007$.

翻译中…

The arrangement of the dominoes is given to you as two strings $S_1$ and $S_2$ in the following manner:

翻译中…
  • Each domino is represented by a different English letter (lowercase or uppercase).
  • The $j$-th character in $S_i$ represents the domino that occupies the square at the $i$-th row from the top and $j$-th column from the left.
翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 52$
  • $|S_1| = |S_2| = N$
  • $S_1$ and $S_2$ consist of lowercase and uppercase English letters.
  • $S_1$ and $S_2$ represent a valid arrangement of dominoes.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
S_1
S_2

翻译中…

Output

翻译中…

Print the number of such ways to paint the dominoes, modulo $1000000007$.

翻译中…

样例

Input #1
3
aab
ccb
Output #1
6
There are six ways as shown below: ![image](https://atcoder.jp/img/arc081/899673bd23529f4fb5e41c6e7d5bc372.png)
Input #2
1
Z
Z
Output #2
3
Note that it is not always necessary to use all the colors.
Input #3
52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
Output #3
958681902
题目信息
题号
arc081_b
时间限制
2 s
内存限制
256 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。