Knowledge
Time limit1sMemory limit512 MB
Count strings of length x reachable from s by inserting or deleting the blocks aa, bbb, and ababab, modulo 998244353.
- Level
Hard9 of 10
- Topics
- String, Combinatorics, Dynamic programming, Math
- Solved
- No attempts yet
Problem
You have a string consisting of lowercase English letters “a” and “b”.
You can make zero or more operations in any order. Here are the possible operations:
- Delete “aa” from any place of the string.
- Delete “bbb” from any place of the string.
- Delete “ababab” from any place of the string.
- Add “aa” to any place of the string.
- Add “bbb” to any place of the string.
- Add “ababab” to any place of the string.
Your goal is to calculate the number of strings of length that can be obtained by such operations. As the answer can be very large, find it modulo 998 244 353.
Input
The first line of the input contains one integer : the length of the string ().
The second line contains a string of length consisting of lowercase English letters “a” and “b”.
The third line contains one integer (), the length of the string you need to obtain.
Output
Print one integer: the number of strings of length that can be obtained from string by making the operations described above, taken modulo 998 244 353.