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
2016-01-25 14:13:26 Dhawal Harkawat
After this, try -> http://www.spoj.com/problems/LCS2/


Last edit: 2016-01-25 14:14:04
2015-11-16 17:27:56 hanif
is it possible to solve this problem with rolling hash technique??
2015-08-21 17:53:02 (Tjandra Satria Gunawan)(曾毅昆)
Optimized Suffix Array -> TLE
Unoptomized Ukkonen -> AC (it's hard for me, need 1 day to understand the concept + 1 day to implement & debug it)
I'm tired but satisfied with this problem ;-)
2015-03-14 19:37:04 Omer Farukh
Is the answer for given testcase correct ?
I am getting 8 as answer
2015-01-28 12:14:40 Dhruv Mullick
nlogn approach gives TLE

Last edit: 2015-01-28 12:15:05
2014-10-16 22:11:06 Gaurav Kumar Verma
Suffix Automation got AC in C++ but got TLE in JAVA, i dont understand y :(
2014-03-21 18:16:58 zicowa
geting TLE using suffix array O(nlogn) approach
2014-03-20 06:12:57 Terence
AC using O(N) suffix array!
2014-03-17 11:13:21 knb_dtu
Suffix Automation gets AC:)
2014-01-16 15:55:33 Chandan Mittal
O(NlogN) also TLE

finally!! Suffix Automaton got AC :)

Last edit: 2014-01-18 23:25:00
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.