n = int(input())
s = input()

dp = [[0]*(n+1) for _ in range(n+1)]


for i in reversed(range(n-1)):
    for j in reversed(range(i+1, n)):
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1]+1


ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        x = min(dp[i][j], j-i)
        if ans < x:
            ans = x
print(ans) n = int(input()) n int(input()) int input() input s = input() s input() input [0]*(n+1) for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [0]*(n+1) [0] 0 n+1 n 1 dp = [[0]*(n+1) for _ in range(n+1)] dp [[0]*(n+1) for _ in range(n+1)] for i in reversed(range(n-1)):
    for j in reversed(range(i+1, n)):
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1]+1 i reversed(range(n-1)) reversed range(n-1) range n-1 n 1 for j in reversed(range(i+1, n)):
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1]+1 j reversed(range(i+1, n)) reversed range(i+1, n) range i+1 i 1 n if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1]+1 s[i] == s[j] s[i] s i s[j] s j 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-1):
    for j in range(i+1, n):
        x = min(dp[i][j], j-i)
        if ans < x:
            ans = x i range(n-1) range n-1 n 1 for j in range(i+1, n):
        x = min(dp[i][j], j-i)
        if ans < x:
            ans = x j range(i+1, n) range i+1 i 1 n x = min(dp[i][j], j-i) x min(dp[i][j], j-i) min dp[i][j] [i] dp i j j-i j i if ans < x:
            ans = x ans < x ans x ans = x ans x print(ans) print ans x = min(dp[i][j], j-i) min(dp[i][j], j-i) x n = int(input()) int(input()) n ans = x x ans s = input() input() s dp = [[0]*(n+1) for _ in range(n+1)] [[0]*(n+1) for _ in range(n+1)] dp ans = 0 0 ans
n = int(input())
s = input()

dp = [[0]*(n+1) for _ in range(n+1)]


for i in reversed(range(n-1)):
    for j in reversed(range(i+1, n)):
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1]+1


ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        x = min(dp[i][j], j-i)
        if ans < x:
            ans = x
print(ans)
