#ARC108D. [ARC108D] AB

[ARC108D] AB

Score : 600600 points

Problem Statement

Given are an integer NN and four characters cAAc_{\mathrm{AA}}, cABc_{\mathrm{AB}}, cBAc_{\mathrm{BA}}, and cBBc_{\mathrm{BB}}. Here, it is guaranteed that each of those four characters is A or B.

Snuke has a string ss, which is initially AB.

Let s|s| denote the length of ss. Snuke can do the four kinds of operations below zero or more times in any order:

  1. Choose ii such that 1i<s1 \leq i < |s|, sis_{i} = A, si+1s_{i+1} = A and insert cAAc_{\mathrm{AA}} between the ii-th and (i+1)(i+1)-th characters of ss.
  2. Choose ii such that 1i<s1 \leq i < |s|, sis_{i} = A, si+1s_{i+1} = B and insert cABc_{\mathrm{AB}} between the ii-th and (i+1)(i+1)-th characters of ss.
  3. Choose ii such that 1i<s1 \leq i < |s|, sis_{i} = B, si+1s_{i+1} = A and insert cBAc_{\mathrm{BA}} between the ii-th and (i+1)(i+1)-th characters of ss.
  4. Choose ii such that 1i<s1 \leq i < |s|, sis_{i} = B, si+1s_{i+1} = B and insert cBBc_{\mathrm{BB}} between the ii-th and (i+1)(i+1)-th characters of ss.

Find the number, modulo (109+7)(10^9+7), of strings that can be ss when Snuke has done the operations so that the length of ss becomes NN.

Constraints

  • 2N10002 \leq N \leq 1000
  • Each of cAAc_{\mathrm{AA}}, cABc_{\mathrm{AB}}, cBAc_{\mathrm{BA}}, and cBBc_{\mathrm{BB}} is A or B.

Input

Input is given from Standard Input in the following format:

NN

cAAc_{\mathrm{AA}}

cABc_{\mathrm{AB}}

cBAc_{\mathrm{BA}}

cBBc_{\mathrm{BB}}

Output

Print the number, modulo (109+7)(10^9+7), of strings that can be ss when Snuke has done the operations so that the length of ss becomes NN.

4
A
B
B
A
2
  • There are two strings that can be ss when Snuke is done: ABAB and ABBB.
1000
B
B
B
B
1
  • There is just one string that can be ss when Snuke is done.