#arc108d. [arc108_d]AB

[arc108_d]AB

Problem Statement

Given are an integer NN and four characters cmathrmAAc_{\\mathrm{AA}}, cmathrmABc_{\\mathrm{AB}}, cmathrmBAc_{\\mathrm{BA}}, and cmathrmBBc_{\\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 1leqi<s1 \\leq i < |s|, sis_{i} = A, si+1s_{i+1} = A and insert cmathrmAAc_{\\mathrm{AA}} between the ii-th and (i+1)(i+1)-th characters of ss.
  2. Choose ii such that 1leqi<s1 \\leq i < |s|, sis_{i} = A, si+1s_{i+1} = B and insert cmathrmABc_{\\mathrm{AB}} between the ii-th and (i+1)(i+1)-th characters of ss.
  3. Choose ii such that 1leqi<s1 \\leq i < |s|, sis_{i} = B, si+1s_{i+1} = A and insert cmathrmBAc_{\\mathrm{BA}} between the ii-th and (i+1)(i+1)-th characters of ss.
  4. Choose ii such that 1leqi<s1 \\leq i < |s|, sis_{i} = B, si+1s_{i+1} = B and insert cmathrmBBc_{\\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

  • 2leqNleq10002 \\leq N \\leq 1000
  • Each of cmathrmAAc_{\\mathrm{AA}}, cmathrmABc_{\\mathrm{AB}}, cmathrmBAc_{\\mathrm{BA}}, and cmathrmBBc_{\\mathrm{BB}} is A or B.

Input

Input is given from Standard Input in the following format:

NN cmathrmAAc_{\\mathrm{AA}} cmathrmABc_{\\mathrm{AB}} cmathrmBAc_{\\mathrm{BA}} cmathrmBBc_{\\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.


Sample Input 1

4
A
B
B
A

Sample Output 1

2
  • There are two strings that can be ss when Snuke is done: ABAB and ABBB.

Sample Input 2

1000
B
B
B
B

Sample Output 2

1
  • There is just one string that can be ss when Snuke is done.