#P5028. Longest Common Substring Among Attacks

    ID: 18266 Type: Default 1000ms 256MiB

Longest Common Substring Among Attacks

Longest Common Substring Among Attacks

In this problem, the Dark Lord launches several attacks represented by strings consisting solely of lowercase letters. For any two attacks, Little Square can choose their longest common substring and eliminate that portion. Now Little Square wants to know the maximum length of the longest common substring among any two attacks.

More formally, given a list of attack strings, find the maximum length of the longest common substring between any pair of strings.

Note: A substring is a contiguous sequence of characters within a string. For example, the longest common substring of "abcde" and "cdefg" is "cde" which has length 3.

inputFormat

The first line contains a single integer n (n ≥ 2) denoting the number of attack strings.
The following n lines each contain a non-empty string consisting of only lowercase English letters.

outputFormat

Output a single integer, which is the maximum length of the longest common substring among any two different attack strings. If no common substring exists, output 0.

sample

2
abcde
cdefg
3