Problem list
Log in
#r03519 · Online Judge > GoldOJ

Archaeologist

Platinum IV 2.0 s 256 MB

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

Input
11
bananafgban
Output
3

Example 2

Input
4
aaaa
Output
3

Example 3

Input
3
abc
Output
0
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 2 Submissions 10 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code