#P8617. Longest Repeated Substring

    ID: 21783 Type: Default 1000ms 256MiB

Longest Repeated Substring

Longest Repeated Substring

Given a string \(S\), find the length of the longest substring \(T\) such that \(T\) appears at least twice in \(S\). The occurrences of \(T\) may overlap. This secret message hidden in \(T\) is something only a true friend can decipher!

Note: If no such substring exists, output 0.

Hint: A suffix automaton can be used to solve this problem efficiently.

inputFormat

The input consists of a single line containing the string \(S\).

\(S\) is a non-empty string that may be very long.

outputFormat

Output one integer representing the length of the longest substring that appears at least twice in \(S\). If there is no such substring, output 0.

sample

abab
2