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
2024-08-21 02:43:20
Suffix array barely passed, had to do a lot of changes to my template
2023-12-25 09:46:17
Suffix Automaton O(n) 0.06s AC
2023-09-27 07:38:43
hash O(nlogn) TLE?
2023-08-27 15:36:29
O(nlogn) suffix array TLE, too strict time limit?
2022-11-23 07:42:29
A good problem for practicing suffix array.
My O(n log n) solution got TLE.How can I optimize my solution?
Update:Now it gets WA...
Update:Now it passed!My radix sort was wrong XD

Last edit: 2022-11-23 08:24:10
2022-05-27 13:26:45
TLE TLE TLE TLE.... bc gaand maar liya is question ne to
2022-05-24 17:49:35
Suffix Automaton O(n) AC 0.27s

Last edit: 2022-05-27 13:12:15
2021-05-13 10:18:33
TLE TLE TLE TLE.... bc gaand maar liya is question ne to
2021-05-08 11:19:16
SuffixAutoMaton O(n) AC 0.04s
2021-02-23 13:59:03
Prefix hash O(nlog^2n) with vector + sorting passed in 0.77s


Last edit: 2021-03-03 23:46:40
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.