LCS2 - Longest Common Substring II

A string is finite sequence of characters over a non-empty finite set Σ.

In this problem, Σ is the set of lowercase letters.

Substring, also called factor, is a consecutive sequence of characters occurrences at least once in a string.

Now your task is a bit harder, for some given strings, find the length of the longest common substring of them.

Here common substring means a substring of all the considered strings.

Input

The input contains at most 10 lines, each line consists of no more than 100000 lowercase letters, representing a string.

Output

The length of the longest common substring. If such string doesn't exist, print "0" instead.

Example

Input:
alsdfkjfjkdsal
fdjskalajfkdsla
aaaajfaaaa

Output:
2

Notice: new testcases added


Added by:Bin Jin
Date:2007-09-24
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 CPP

hide comments
2015-12-18 00:18:21 caoyiyuan
Alaways get WA on #10 sad...
2015-12-14 07:09:40 duyixian
Alaways get WA on #4
2015-08-21 19:54:16 (Tjandra Satria Gunawan)(曾毅昆)
getting TLE :( seems that time limit is very strict for Ukkonen algo. I should learn more efficient O(n) algo than Ukkonen like McCreight algo, but maybe next time :p
2015-01-26 15:37:57 adamant
Finally AC with an unusual trick with suffix automaton. TL is so strict :(
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.