405210: GYM101845 G Generating Texts
Description
Lucko is a greedy boy that is looking for ways to gain some money, one easy way he has found is to invest in bets on different lotteries, but he knows that the probability of winning a lottery is really low, for this reason he decides to play on a new lottery called UN-lotto.
To play UN-lotto one chooses a string of length m, then the lottery generates a string of length n (n ≥ m) randomly, both strings are formed only by lower-case letters from the english alphabet. You win if the string you have chosen is a subsequence of the generated text by UN-lotto.
Formally, for a string s = s1s2...sn we say that sa1sa2...sam is a subsequence of s of length m if 1 ≤ a1 < a2 < ... < am ≤ n. For example, suppose that n = 4 and m = 3 and Lucko chooses the string abc, some of the winning generated strings for him would be abcb, abbc and abzc, and some of the losing generated strings would be acba, azbz and zzzz
Good news for Lucko, information about this lottery has been leaked:
- The text is generated taking each letter randomly from a probability distribution.
- The selection of the letter for each position in the text is independent.
- The probability distribution of the letters was also leaked.
Lucko has already chosen his string to play UN-lotto, help him using the leaked information to tell him which is his probability P / Q of winning. As Lucko only likes low integer numbers calculate the probability modulo 109 + 7, i.e., calculate
InputThe first line of input contains 2 numbers n and m (1 ≤ m ≤ n ≤ 5000) — the length of the string generated by UN-lotto and the length of the string chosen by Lucko respectively.
The second line of input contains s — the string chosen by Lucko.
Next 26 lines contains each a pair of integers separated by spaces, i.e. the i-th line contains pi, qi, where corresponds to the probability of taking the i-th letter, being a the first letter, b the second letter and so on. For every i = 1, ..., 26, 0 ≤ pi ≤ 1000, 1 ≤ qi ≤ 1000 and pi / qi is an irreducible fraction.
It is guaranteed that .
OutputOutput one integer — the probability modulo 109 + 7 of Lucko winning UN-lotto with the string s.
ExamplesInput5 1Output
a
1 1
0 1
... 24 more lines ...
1Input
5 3Output
aaa
1 2
1 2
0 1
... 23 more lines ...
500000004