n = int(input())
s = input()
dp = [[0]*5005 for _ in range(5005)]
for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if s[i]!=s[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        now = min(dp[i][j], j-i)
        ans = max(ans, now)
print(ans) n = int(input()) n int(input()) int input() input s = input() s input() input [0]*5005 for _ in range(5005) for _ in range(5005) _ range(5005) range 5005 for _ in range(5005) [0]*5005 [0] 0 5005 dp = [[0]*5005 for _ in range(5005)] dp [[0]*5005 for _ in range(5005)] for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if s[i]!=s[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i+1][j+1] + 1 i range(n)[::-1] (n) range n ::-1 -1 for j in range(n)[::-1]:
        if s[i]!=s[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i+1][j+1] + 1 j range(n)[::-1] (n) range n ::-1 -1 if s[i]!=s[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i+1][j+1] + 1 s[i]!=s[j] s[i] s i s[j] s j dp[i][j] = 0 dp[i][j] [i] dp i j 0 dp[i][j] = dp[i+1][j+1] + 1 dp[i][j] [i] dp i j dp[i+1][j+1] + 1 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 1 ans = 0 ans 0 for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        now = min(dp[i][j], j-i)
        ans = max(ans, now) i range(n) range n for j in range(n):
        if i >= j:
            continue
        now = min(dp[i][j], j-i)
        ans = max(ans, now) j range(n) range n if i >= j:
            continue
         i >= j i j continue now = min(dp[i][j], j-i) now min(dp[i][j], j-i) min dp[i][j] [i] dp i j j-i j i ans = max(ans, now) ans max(ans, now) max ans now print(ans) print ans dp = [[0]*5005 for _ in range(5005)] [[0]*5005 for _ in range(5005)] dp now = min(dp[i][j], j-i) min(dp[i][j], j-i) now s = input() input() s n = int(input()) int(input()) n ans = max(ans, now) max(ans, now) ans ans = 0 0 ans
n = int(input())
s = input()
dp = [[0]*5005 for _ in range(5005)]
for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if s[i]!=s[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        now = min(dp[i][j], j-i)
        ans = max(ans, now)
print(ans)