logo AlgoBeat OnlineJudge
登录 注册

#215713. [ICPC 2025 Jakarta R] Mugen E

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 .

样例

样例输入 1

ab
2
a
b

样例输出 1

748683265

样例输入 2

ab
4
aaa
abab
baba
bbb

样例输出 2

1

数据范围与提示

It can be shown that .

It can be shown that .