#P10047. [CCPC 2023 北京市赛] 勿蹖宠物
[CCPC 2023 北京市赛] 勿蹖宠物
Problem Description
Ene likes palindromes.
Ene now has some words. She wants to choose some words and concatenate them end to end to form a palindrome string with length exactly . Each word can be chosen multiple times, or not chosen at all.
Ene wants to know the number of ways to do this. Ene considers two ways different if and only if the number of occurrences of each word is different, or their arrangement order is different. Note that multiple different ways may produce the same palindrome string. Since the answer may be very large, you need to output the answer modulo .
Input Format
The first line contains two positive integers , representing the number of words and the required length of the palindrome string. It is guaranteed that , .
The next lines each contain a string , representing a word. It is guaranteed that , . The input words contain only lowercase letters and are pairwise distinct.
Output Format
Output a non-negative integer, representing the number of ways to form a palindrome string modulo .
7 9
cats
eel
eve
evil
lee
olive
stack
5
2 2
a
aa
2
6 12
aa
aab
no
on
pets
step
43
Hint
[Sample Explanation 1]
There are the following five ways:
stackcatseviloliveeeleveleeleeeveeeleveeveeve
[Sample Explanation 2]
There are the following two ways:
aaaa
Translated by ChatGPT 5