luogu#P7942. 「Wdcfr-1」CONsecutive and CONcat (easy version)
「Wdcfr-1」CONsecutive and CONcat (easy version)
Problem Description
In easy version, It is guaranteed that any string in array contains at least two different letters.
Lily White is playing with strings. Being a yousei, she is not capable of complex speech. Thus, she likes strings that only contain one kind of letter, she calls such strings of length a "-CON string". For example, qqqq is a "-CON string", while aaab is not any type of "CON string".
Lily White composed an array . It contains strings of length that she will use to herald spring. For each permutation of , let us denote current permutation as . Lily White concatenates all the string in array in the order of into a string of length .
As she likes -CON strings, she wants to know the sum of the number of "-CON string" in all non-empty substrings of composed by all permutations. Since the answer may be enormous, just print the answer taken modulo (a large prime).
Input Format
The first line contains three integers .
Then lines follow, each line contains a string of length . The string in the-th line represents .
Output Format
Print a single integer - the answer taken modulo .
3 3 4
aab
baa
baa
4
3 3 2
xyz
qaq
aba
0
Hint
Explanation
Sample #1
- For permutation , the formed is
aabbaabaa, none on the non-empty substring in this string are "-CON string". - For permutation , the formed is
aabbaabaa, none on the non-empty substring in this string are "-CON string". - For permutation , the formed is
baaaabbaa, this string has one substringaaaawhich is a "-CON string". - For permutation , the formed is
baabaaaab, this string has one substringaaaawhich is a "-CON string". - For permutation , the formed is
baaaabbaa, this string has one substringaaaawhich is a "-CON string". - For permutation , the formed is
baabaaaab, this string has one substringaaaawhich is a "-CON string".
In summary, the answer is .
Sample #2
In all of the full permutation of length , there will be six different : xyzqaqaba, xyzabaqaq, qaqxyzaba, qaqabaxyz, abaqaqxyz, and abaxyzqaq. None of these has a non-empty substrings which is a "-CON string". So the answer is .
Constraints
. contains only lowercase English letters.
In easy version, we ensure that any string in array contains at least two different letters.