TOPONYMS (BOI 2007)
A toponym is the name of a city, village, river, mountain, etc. Often, one encounters toponyms that look very similar. For example, "Angelokastro Corinthias" and "Angelokastro Aitoloakarnanias," or "Geropotamos" and "Geroplatanos."
Toponyms are represented by strings consisting of uppercase and lowercase letters of the Latin alphabet (, , , , , , , , , ) and spaces. However, two or more consecutive spaces cannot appear, and there are no spaces at the beginning or end of the toponyms. The strings consisting of the first characters of a toponym are called "prefixes" of length . For example, the string "Gerop" is a prefix of length of the toponym "Geropotamos."
The similarity degree of a set of toponyms is the length of the longest common prefix of all the toponyms in . For example, for the set {"Geroplatanos", "Geropotamos", "Gerovasiliotika"}, the similarity degree is because the longest common prefix is "Gero."
The complexity degree of a set consisting of toponyms is defined as
For example, for the set {"Geroplatanos", "Geropotamos", "Gerovasiliotika"}, the complexity degree is .
Write a program that, for each given set of toponyms , finds the subset with the maximum complexity degree.
Input
The first line of input contains the number of toponyms . Each of the next lines contains a toponym, which is a string consisting of letters and spaces, following the constraints mentioned for the use of spaces.
Output
The output should consist of a single line containing exactly one integer, the maximum complexity degree that any subset of the toponyms can have.
Constraints
.
The length of each toponym does not exceed characters.
The total size of the input file does not exceed 10 MB.
Execution time limit: 2 sec.
Maximum available memory: 64 MB.
Example of Input - Output
STDIN (toponyms.in)
7
Jora de Sus
Orhei
Jora de Mijloc
Joreni
Jora de Jos
Japca
Orheiul Vechi
STDOUT (toponyms.out)
24
Comments