Score : $600$ points
Given are an integer $N$ and four characters $c_{\mathrm{AA}}$, $c_{\mathrm{AB}}$, $c_{\mathrm{BA}}$, and $c_{\mathrm{BB}}$.
Here, it is guaranteed that each of those four characters is A
or B
.
Snuke has a string $s$, which is initially AB
.
Let $|s|$ denote the length of $s$. Snuke can do the four kinds of operations below zero or more times in any order:
A
, $s_{i+1}$ = A
and insert $c_{\mathrm{AA}}$ between the $i$-th and $(i+1)$-th characters of $s$.A
, $s_{i+1}$ = B
and insert $c_{\mathrm{AB}}$ between the $i$-th and $(i+1)$-th characters of $s$.B
, $s_{i+1}$ = A
and insert $c_{\mathrm{BA}}$ between the $i$-th and $(i+1)$-th characters of $s$.B
, $s_{i+1}$ = B
and insert $c_{\mathrm{BB}}$ between the $i$-th and $(i+1)$-th characters of $s$.Find the number, modulo $(10^9+7)$, of strings that can be $s$ when Snuke has done the operations so that the length of $s$ becomes $N$.
A
or B
.Input is given from Standard Input in the following format:
$N$ $c_{\mathrm{AA}}$ $c_{\mathrm{AB}}$ $c_{\mathrm{BA}}$ $c_{\mathrm{BB}}$
Print the number, modulo $(10^9+7)$, of strings that can be $s$ when Snuke has done the operations so that the length of $s$ becomes $N$.
4 A B B A
2
ABAB
and ABBB
.1000 B B B B
1