#Lutece2422. Nico~Nico~Ni~ (Ⅲ)
Nico~Nico~Ni~ (Ⅲ)
Migrated from Lutece 2422 Nico~Nico~Ni~ (Ⅲ)
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
这次的 鬼畜视频 可以用一个仅包含小写英文字母的字符串 来表示。
定义一个字符串 的鬼畜度为 在 中的出现次数除以 的长度。
作为一名计数菌,你将进行 次计数。每次计数你都会选择两个正整数 ,并计算 的所有子串中字典序在 之间的子串的鬼畜度之和。
Input
第一行包含一个仅由小写英文字母构成的字符串 。
第二行包含一个正整数 ,表示计数的次数。
接下来有 行,其中第 行包含两个正整数 。
Output
输出 行,第 行一个整数 ,表示第 次计数的答案。
设你计算的鬼畜度之和可以用既约分数 表示,你需要输出它模 的结果,即输出 ,其中 表示 在模 意义下的逆元。
Samples
niconiconi
2
2 3
10 45
3
92460351
Constraints
$\displaystyle 1 \leq L_i \leq R_i \leq \frac{n (n+1)}{2} \ \ (1 \leq i \leq n)$
Resources
2020 UESTC ICPC Training for String and Search Algorithm