atcoder#ABC246F. [ABC246F] typewriter
[ABC246F] typewriter
Score : points
Problem Statement
We have a typewriter with rows. The keys in the -th row from the top can type the characters in a string .
Let us use this keyboard to enter a string, as follows.
- First, choose an integer .
- Then, start with an empty string and only use the keys in the -th row from the top to enter a string of length exactly .
How many strings of length can be entered in this way? Since the answer can be enormous, print it modulo .
Constraints
- and are integers.
- is a (not necessarily contiguous) non-empty subsequence of
abcdefghijklmnopqrstuvwxyz
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2 2
ab
ac
7
We can enter seven strings: aa
, ab
, ac
, ba
, bb
, ca
, cc
.
4 3
abcdefg
hijklmnop
qrstuv
wxyz
1352
5 1000000000
abc
acde
cefg
abcfh
dghi
346462871
Be sure to print the answer modulo .