#P7758. [COCI 2012/2013 #3] HERKABE
[COCI 2012/2013 #3] HERKABE
Description
This time, teacher Herkabe wants his ranking list to be pleasing to the eye as well, so he decided that names with the same prefix must be adjacent on the list. Therefore, he made the following rule: for any two names on the list that share a common prefix, all names between them in the ranking should also have this prefix.
Now, given the names of students, find how many different ranking lists teacher Herkabe can make that satisfy the rule above. Since the result may be very large, you only need to output the answer modulo .
Input Format
The input has lines.
The first line contains an integer , the number of students.
The next lines each contain a string, the name of a student.
Output Format
Output one line containing the number of different ranking lists teacher Herkabe can make, modulo .
3
IVO
JASNA
JOSIPA
4
5
MARICA
MARTA
MATO
MARA
MARTINA
24
4
A
AA
AAA
AAAA
8
Hint
Constraints
There are test points in total. The constraints for each test point are shown in the table below.
| Test Point ID | |
|---|---|
For all testdata, each string has length in , contains only uppercase English letters, and all names are guaranteed to be distinct.
Source
This problem is from COCI 2012-2013 CONTEST 3 T5 HERKABE. According to the original testdata settings, the full score is points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5
京公网安备 11011102002149号