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
2020-08-04 15:51:03
Suffix automaton worked super quick for me
2020-08-02 10:06:04 Lê Thanh Phú
Suffix Array O(nlog^2(n)) AC 0.53s
2020-07-07 06:35:02
No need for suffix tree, suffix array is enough to solve this problem, also no need for memory optimization in LCP, it get AC easily.. goodluck O(n log n:)
2020-07-03 10:06:31
dcmm lũ ox chó
2019-12-31 08:07:27
finally AC using suffix automaton.
2019-10-13 20:58:35 yaswanth
Got TLE with Suffix array with storing temp results (partial ordering array). Had to change it to get AC. Too strict of a time limit.
2019-09-24 12:51:06
NLogN suffix array works with cpp but TLE with Java
2019-07-26 13:30:09
its so bad that suffix array in O(nlog^2n) is giving tle
2019-07-24 18:42:47
oh ye
2019-07-24 18:41:31
ye
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.