A subsequence of a string of characters s is a string of characters t with the property that there exist two indices i and j with 0β€iβ€j<β£sβ£ such that t=siβsi+1βsi+2β...sjββ.
For a tuple of strings (s0β,s1β,s2β,...,sKβ1β) we define f(s0β,s1β,s2β,...,sKβ1β) as the lexicographically smallest1 string that can be obtained through the following procedure:
- For each string siβ, choose a nonempty substring tiβ of it;
- Concatenate t0β,t1β,t2β,...,tKβ1β, the resulting string being the outcome of the procedure.
1 A string a0βa1ββ¦anβ1ββ is lexicographically smaller than another string b0βb1ββ¦bmβ1ββ if and only if:
- There exists an index i (0β€i<min(n,m)) for which a0βa1ββ¦aiβ1ββ=b0βb1ββ¦biβ1ββ and aiβ<biβ; or
- n<m and a0βa1ββ¦anβ1ββ=b0βb1ββ¦bnβ1ββ.
Requirement
You are given a natural number N, a string of length N denoted w, a natural number K, and a sequence of K nonzero natural numbers l0β,l1β,l2β,...,lKβ1β. Count how many tuples of K strings, (s0β,s1β,s2β,...,sKβ1β) satisfy the following conditions:
- All strings contain only lowercase letters of the English alphabet
- β£siββ£=liβ, β1β€iβ€K
- f(s0β,s1β,s2β,...,sKβ1β)=w
Since this number can be large, output its remainder modulo 998Β 244Β 353.
Implementation Details
You must implement a single function:
int solve(int N, int K, std::string w, std::vector<int> l);
which receives as parameters:
- N, the number of characters in the string w
- K, the number of strings in a tuple
- The string w (indexed from 0)
- l, representing the lengths of the strings (indexed from 0)
The solve function will be called exactly once.
Constraints
- 1β€Kβ€Nβ€200
- 1β€liββ€200, 0β€iβ€Nβ1
- The string w consists only of lowercase letters of the English alphabet
- We denote by wiβ the i-th character of the string w
| # |
Score |
Constraints |
| 1 |
7 |
1β€Kβ€Nβ€7, β0Kβ1βliββ€8 and w contains only the characters a, b, c, d |
| 2 |
8 |
1β€Kβ€Nβ€25 and liβ=3, βΒ 0β€i<N |
| 3 |
11 |
K=2 |
| 4 |
14 |
1β€Kβ€Nβ€120, 1β€liββ€120 and wiββ€wi+1β,βΒ 0β€i<Nβ1 (the string w is non-decreasing) |
| 5 |
23 |
1β€Kβ€Nβ€90 and 1β€liββ€90, βΒ 0β€i<N |
| 6 |
21 |
1β€Kβ€Nβ€150 and 1β€liββ€150, βΒ 0β€i<N |
| 7 |
16 |
No additional restrictions. |
Example 1
input
4 3
babz
1 2 1
output
1
Explanation
For the first example, the only valid tuple is ("b", "ab", "z").
Example 2
input
4 3
babz
1 3 1
output
26
Example 3
input
6 4
abcbzz
3 3 3 3
output
1849