PDP-23 (2011) - Camp seniors - 1 (toponyms)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

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 (A, B, C, ..., Z, a, b, c, ..., z) 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 m characters of a toponym are called "prefixes" of length m. For example, the string "Gerop" is a prefix of length 5 of the toponym "Geropotamos."

The similarity degree Ls(T) of a set of toponyms T is the length of the longest common prefix of all the toponyms in T. For example, for the set T = {"Geroplatanos", "Geropotamos", "Gerovasiliotika"}, the similarity degree is Ls(T) = 4 because the longest common prefix is "Gero."

The complexity degree Lc(T) of a set T consisting of k toponyms is defined as

\displaystyle Lc(T) = k \times Ls(T)

For example, for the set T = {"Geroplatanos", "Geropotamos", "Gerovasiliotika"}, the complexity degree is Lc(T) = 3 \times 4 = 12.

Write a program that, for each given set of toponyms S, finds the subset T \subseteq S with the maximum complexity degree.

Input

The first line of input contains the number of toponyms N. Each of the next N 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

2 \le N \le 1.000.000.
The length of each toponym does not exceed 20.000 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

There are no comments at the moment.