atcoder#ABC268G. [ABC268G] Random Student ID
[ABC268G] Random Student ID
Score : points
Problem Statement
Takahashi Elementary School has new students. For , the name of the -th new student is (which is a string consisting of lowercase English letters). The names of the new students are distinct.
The students will be assigned a student ID in ascending lexicographical order of their names. However, instead of the ordinary order of lowercase English letters where a
is the minimum and z
is the maximum, we use the following order:
- First, Principal Takahashi chooses a string from the permutations of the string
abcdefghijklmnopqrstuvwxyz
of length , uniformly at random. - The lowercase English characters that occur earlier in are considered smaller.
For each of the students, find the expected value, modulo , of the student ID assigned (see Notes).
What is the lexicographical order?
A string is said to be lexicographically smaller than a string if one of the following 1. and 2. holds. Here, and denote the lengths of and , respectively.
- and .
- There exists an integer satisfying the following two conditions:
- is a smaller character than .
Notes
We can prove that the sought expected value is always a rational number. Moreover, under the Constraints of this problem, when the value is represented as by two coprime integers and , we can prove that there is a unique integer such that and . Find such .
Constraints
- is an integer.
- is a string of length at least consisting of lowercase English letters.
- The sum of lengths of the given strings is at most .
Input
Input is given from Standard Input in the following format:
Output
Print lines. For each , the -th line should contain the expected value, modulo , of the student ID assigned to Student .
3
a
aa
ab
1
499122179
499122179
The expected value of the student ID assigned to Student is ; the expected values of the student ID assigned to Student and are .
Note that the answer should be printed modulo . For example, the sought expected value for Student and is , and we have , so should be printed.
3
a
aa
aaa
1
2
3