REPTTS - Repetitions

A sequence of words over alphabet [‘a’ ..’z’] is given. The length of longest word occurring as a coherent fragment in every word given is to be found.

Input

In the first line there is an integer n, where 1 <= n <= 5 is the number of words. In each of the next n lines there is one word formed from small letters of English alphabet [‘a’ .. ’z’]. The length of each word is at least 1, but not greater than 2000.

Output

The output should consist of exactly one line containing a single integer equal to the length of the longest word occurring as the coherent fragment in every word given.

Example

Input:
3
abcb
bca
acbc

Output:
2

Added by:Krzysztof Lewko
Date:2011-07-13
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:VII POI

hide comments
2011-09-13 14:52:28 Oleg
Yes, seems its easy version of LCS2. Moved to Tutorials.

Last edit: 2011-07-15 09:22:38
2011-09-13 14:52:28 Siarhei Kulik
Is it the same as LCS2 but with lower constraints?
2011-09-13 14:52:28 Krzysztof Lewko
@Kashyap, yes
2011-09-13 14:52:28 Kashyap Krishnakumar
What does a coherent fragment mean? a substring?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.