#P6456. [COCI 2006/2007 #5] DVAPUT

[COCI 2006/2007 #5] DVAPUT

Problem Description

Given a string of length LL, you need to find the longest substring that appears at least twice in the string (at different positions). Output its length.

Input Format

The first line contains an integer LL, representing the length of the string.

The second line contains a string of length LL.

Output Format

Output one line containing one integer, representing the length of this longest substring.

11
sabcabcfabc
3
18
trutrutiktiktappop
4
6
abcdef
0

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that 1L2×1051 \le L \le 2 \times 10^5, and the input string consists only of lowercase letters.

Notes

This problem is translated from COCI2006-2007 CONTEST #5 T6 DVAPUT.

Translated by ChatGPT 5