#P15659. [ICPC 2025 Jakarta R] Mugen E
[ICPC 2025 Jakarta R] Mugen E
Description
You are given strings of lowercase Latin letters. You are also given a string .
Define a function , where is an integer, as the following.
- Initially, you have an empty string .
- For times, choose a string uniformly at random among , and append that string to .
- Let be the expected value of the number of occurrences of in as a substring. Then, .
It can be proven that exists and can be written as a rational number . Find .
Input Format
The first line contains the string () consisting of lowercase Latin letters.
The second line contains an integer (.
Each of the next lines contains () consisting of lowercase Latin letters.
The sum of does not exceed .
Output Format
Output the limit .
ab
2
a
b
748683265
ab
4
aaa
abab
baba
bbb
1
Hint
It can be shown that .
It can be shown that .
京公网安备 11011102002149号