Jason discovered that alarms can sing one of the n+1 tunes, which have the accompanying construction: let si (0≤i≤n) be the I-th tune and t be a line of length n, then, at that point, for each i
Correct answer will be upvoted else Multiple Downvoted. Computer science.
Jason discovered that alarms can sing one of the n+1 tunes, which have the accompanying construction: let si (0≤i≤n) be the I-th tune and t be a line of length n, then, at that point, for each i<n: si+1=sitisi. All in all i+1-st tune is the connection of I-th tune, I-th letter (0-recorded) of t and the I-th melody.
Luckily, he likewise knows s0 and t. Jason considers how frequently a mariner's name is referenced in a specific tune. Answer q inquiries: given the mariner's name (w) and the file of a tune (I) output the number of events of w in si as a substring. As this number can be very huge, output its remaining portion modulo 109+7.
Input
In the main line of input there are two integers n, q ( 1≤n,q≤105) implying that there are n+1 tunes and q questions. In the following two lines strings s0 and t follow (1≤|s0|≤100,|t|=n).
Next q lines depict the questions; every one contains an integer k (0≤k≤n), the record of the melody sung by the alarms, and a non-void string w, which is the name of a mariner. All strings in this issue comprise just of lowercase English letters, and the amount of lengths of mariners' names doesn't surpass 106.
Output
Output q lines, I-th of them ought to contain the rest of 109+7 of the number of events of w in sk.
Step by step
Solved in 4 steps with 1 images