Archaeologist Minwoo discovered a very long inscription on the wall of an ancient temple. The inscription is a single string of lowercase English letters.
To understand the grammar and core vocabulary of this ancient language, Minwoo wants to find the length of the longest substring that appears at least twice in the inscription.
The two occurrences may overlap. For example, if the inscription is aaaa, the substring aaa appears starting at indices 0 and 1 — the occurrences overlap, but they still count as two appearances, so the answer is 3.
Given the length $N$ of the inscription and the string $S$, write a program that finds the length of the longest substring appearing at least twice.
Input
The first line contains the length $N$ of the inscription ($1 \le N \le 200,000$). The second line contains the inscription string $S$ of length $N$, consisting only of lowercase English letters, with no spaces.
Output
Print the length of the longest substring that appears at least twice. If no substring appears two or more times, print 0.
Constraints
$1 \le N \le 200,000$
$S$ consists only of lowercase English letters.
Example 1
11 bananafgban
3
Example 2
4 aaaa
3
Example 3
3 abc
0
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.