Longest Repeated Substring
You are given a string s of lowercase English letters. Find the longest substring of s
that occurs at least twice. The two occurrences are allowed to overlap.
If several substrings share the longest length, output the one whose first (leftmost)
occurrence starts earliest in s. If no substring occurs twice (all characters are
distinct), there is no answer.
Input
The first line contains the string s (1 ≤ |s| ≤ 2·10^5), consisting only of lowercase
English letters.
Output
If some substring occurs at least twice, print two lines: the length of the longest such substring, and then the substring itself (the one whose leftmost occurrence starts earliest among all substrings achieving that length).
If no substring occurs twice, print a single line containing 0.
Notes
In the first example, s = banana. The substring ana occurs at positions 1 and 3
(0-indexed), overlapping in the middle a, and no longer substring repeats, so the answer
is 3 and ana.
In the second example every character of s is distinct, so the answer is 0.