atcoder#ARC108D. [ARC108D] AB
[ARC108D] AB
Score : points
Problem Statement
Given are an integer and four characters , , , and .
Here, it is guaranteed that each of those four characters is A
or B
.
Snuke has a string , which is initially AB
.
Let denote the length of . Snuke can do the four kinds of operations below zero or more times in any order:
- Choose such that , =
A
, =A
and insert between the -th and -th characters of . - Choose such that , =
A
, =B
and insert between the -th and -th characters of . - Choose such that , =
B
, =A
and insert between the -th and -th characters of . - Choose such that , =
B
, =B
and insert between the -th and -th characters of .
Find the number, modulo , of strings that can be when Snuke has done the operations so that the length of becomes .
Constraints
- Each of , , , and is
A
orB
.
Input
Input is given from Standard Input in the following format:
Output
Print the number, modulo , of strings that can be when Snuke has done the operations so that the length of becomes .
4
A
B
B
A
2
- There are two strings that can be when Snuke is done:
ABAB
andABBB
.
1000
B
B
B
B
1
- There is just one string that can be when Snuke is done.