Longest Repeating SubstringMedium

Longest Repeating Substring

MediumPractice library · +20 XPstringssuffix arraylcp array

Given a string S, find the length of the longest substring that appears at least twice. The two occurrences may overlap.

Input

A single line containing the string S.

Output

A single integer representing the length of the longest repeating substring.

Constraints

1 <= |S| <= 200000

Time limit 2 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
banana
Output
3

The longest repeating substring is 'ana' with length 3.

Example 2

Input
aaaaa
Output
4

The longest repeating substring is 'aaaa' with length 4.

Hints