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


hide comments
dad3zz: 2016-12-20 01:29:20

totziens' Suffix Automaton is necessary!

totziens: 2016-10-01 10:00:55

Suffix Automaton is necessary!

Augusto: 2016-08-31 01:41:12

"Here common substring means a substring of two or more strings." The problem is kind of obvious but I think that statement might be confusing, we're asked for the length of the longest common substring, common means common to ALL the strings in the input :)

AC with suffix automaton, such a beautiful DS :3

sxysxyspoj: 2016-08-18 07:40:23

WA at #10.......

flaze: 2016-07-30 15:52:28

Well... It seems easy to get WA on #10...

[Rampage] Blue.Mary: 2016-03-11 07:30:11

My program uses hash and get AC.

liuguangzhe: 2016-03-11 02:38:03

Is suffix automaton necessary?Or suffix tree and suffix array are also Ok?And what about HASH?

sigma_poet: 2016-01-16 12:36:39

always get wa on #10... sad ....cao yi yuan do you know me ? we've ever lived in the same dormitory in Peking 80 school......曹奕远

sigma_poet: 2016-01-16 12:29:57

get wa on #0

caoyiyuan: 2015-12-18 00:18:21

Alaways get WA on #10 sad...


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