#P15659. [ICPC 2025 Jakarta R] Mugen E
[ICPC 2025 Jakarta R] Mugen E
题目描述
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 .
输入格式
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 the limit .
ab
2
a
b
748683265
ab
4
aaa
abab
baba
bbb
1
提示
It can be shown that .
It can be shown that .