LCS - Longest Common Substring

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 simple, for two given strings, find the length of the longest common substring of them.

Here common substring means a substring of two or more strings.

Input

The input contains exactly two lines, each line consists of no more than 250000 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

Output:
3

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
2013-07-17 07:47:20 jimmy
O(N*log(N)^2) will result in TLE.

Last edit: 2014-04-09 12:01:26
2013-03-15 09:07:25 luyuncheng
why I use DC3 TLE who use DC3 AC?could you please talk to me? luyuncheng@sina.com
2013-03-03 03:49:24 Julio [UFSCar]
My DC3 got TLE. Optimizing a little more...
2013-02-06 19:02:09 aristofanis
I don't understand, why is O(N+M) giving me TLE?
2012-11-29 23:48:18 manish sharma
dynamic programming will not work it costs around O(n*m) ...........try suffix tree that will work...complexity O(n+m).

http://en.wikipedia.org/wiki/Longest_common_substring_problem

use the above link
2011-07-17 04:32:18 ymGXX
DC3 can AC....
nlogn TLE....
2011-07-17 04:32:18 [Rampage] Blue.Mary
Stranger, stranger! It's just a constant-optimization problem, and some more...
2011-07-17 04:32:18 যোবায়ের
it gave me "time limit exceeded #0"
what does it mean by #0 ?
2011-07-17 04:32:18 Tony Beta Lambda
Are we expected to implement Suffix Array or Suffix Tree?


Jin Bin: Suffix Automaton was expected.

Last edit: 2010-11-09 05:51:31
2011-07-17 04:32:18 Seshadri R
Do the strings contain any whitespace? I mean, would using scanf or cin produce any unpleasant surprises?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.