N = int(eval(input()))

S = eval(input())



dp = [[0] * (N+1) for i in range(N+1)]



for i in range(N-1,-1,-1):

    for j in range(N-1,-1,-1):

        # print(i,j)

        if S[i] == S[j]:

            dp[i][j] = dp[i+1][j+1] + 1 



# print(dp)

ans = 0

for i in range(N):

    for j in range(N):

       val = min(abs(i-j),dp[i][j])

       ans = max(val,ans)



print(ans) 
N = int(eval(input()))

S = eval(input())



dp = [[0] * (N+1) for i in range(N+1)]



for i in range(N-1,-1,-1):

    for j in range(N-1,i-1,-1):

        # print(i,j)

        if S[i] == S[j]:

            dp[i][j] = dp[i+1][j+1] + 1 



# print(dp)

ans = 0

for i in range(N):

    for j in range(i+1,N):

       val = min(abs(i-j),dp[i][j])

       ans = max(val,ans)



print(ans) 
N = int(eval(input()))
S = eval(input())
dp = [[0] * (N + 1) for i in range(N + 1)]
for i in range(N - 1, -1, -1):
    for j in range(N - 1, -1, -1):
        # print(i,j)
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
# print(dp)
ans = 0
for i in range(N):
    for j in range(N):
        val = min(abs(i - j), dp[i][j])
        ans = max(val, ans)
print(ans)

N = int(eval(input()))
S = eval(input())
dp = [[0] * (N + 1) for i in range(N + 1)]
for i in range(N - 1, -1, -1):
    for j in range(N - 1, i - 1, -1):
        # print(i,j)
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
# print(dp)
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        val = min(abs(i - j), dp[i][j])
        ans = max(val, ans)
print(ans)

-    for j in range(N - 1, -1, -1): +    for j in range(N - 1, i - 1, -1): -    for j in range(N): +    for j in range(i + 1, N):