TWICE - Twice

Given a string S, find the longest substring that appears at least twice in S (occurrences may overlap).

Input

The first line contains an integer L (1 ≤ L ≤ 200000), the length of S.

The second line contains the string S, consisting of exactly L lowercase letters ('a'-'z').

Output

Output the length of the longest substring that appears at least twice in S. If there is no such substring, output 0.

Example

Input:
11
sabcabcfabc

Output:
3
Input:
18
trutrutiktiktappop

Output:
4

Added by:Lovro Puzar
Date:2009-08-21
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Own problem

hide comments
2012-09-05 17:32:24 Ajey Golsangi
Nice problem.
2012-02-25 22:59:20 Buda IM (retired)
Suffix array is not needed to solve this problem
2010-12-27 17:14:08 Nikhil Garg
Too bad - I don't know O(N) construction of suffix tree yet :(
2009-08-24 14:52:50 Lovro Puzar
> is substring of length 1 is also considered??

Sure.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.