#ARC131F. [ARC131F] ARC Stamp

[ARC131F] ARC Stamp

Score : 10001000 points

Problem Statement

On a string SS consisting of A, R, and C, we did the following operation at most KK times: choose three consecutive characters and overwrite them with ARC. The result is the string TT.

How many strings are there that could be the initial string SS? Find this count modulo 998244353998244353.

Constraints

  • 3T50003 \leq |T| \leq 5000
  • 0K100000 \leq K \leq 10000
  • TT is a string consisting of A, R, and C.

Input

Input is given from Standard Input in the following format:

TT

KK

Output

Print the answer.

ARCCARC
1
53

Below are some examples of the initial string SS from which we can get the string TT = ARCCARC with at most 11 operation.

  • SS = ARCCARC: we can choose to do nothing to get ARCCARC.
  • SS = CRACARC: we can choose the 11-st, 22-nd, 33-rd characters and overwrite them with ARC to get ARCCARC.
  • SS = ARCCCCC: we can choose the 55-th, 66-th, 77-th characters and overwrite them with ARC to get ARCCARC.

There are many other strings that could be SS, for a total of 5353.

ARARCRCA
5
2187

If the intial string SS is AAAAAAAA, one way to get TT = ARARCRCA with at most 55 operations is as follows.

  • Step 11: choose the 33-rd, 44-th, 55-th characters and overwrite them with ARC to get the string AAARCAAA.
  • Step 22: choose the 55-th, 66-th, 77-th characters and overwrite them with ARC to get the string AAARARCA.
  • Step 33: choose the 11-st, 22-nd, 33-rd characters and overwrite them with ARC to get the string ARCRARCA.
  • Step 44: choose the 33-rd, 44-th, 55-th characters and overwrite them with ARC to get the string ARARCRCA.

There are many other strings that could be SS, for a total of 21872187.

AARCRRARCC
0
1

We can get TT = AARCRRARCC with 00 operations in only one case in which S=TS = T from the beginning, or SS = AARCRRARCC.

AAAAARRRRRCCCCC
131
1

In this case, there is just one string that could be SS: AAAAARRRRRCCCCC.

CAARCACRAAARARARCRCRARCARARCRRARC
9
797833187

There are 320236026147320236026147 strings that could be SS, so print this count modulo 998244353998244353, which is 797833187797833187.