n = int(eval(input()))

s = eval(input())



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



for i in reversed(list(range(n))):

    for j in reversed(list(range(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(eval(input()))

s = eval(input())



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





for i in reversed(list(range(n-1))):

    for j in reversed(list(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(eval(input()))
s = eval(input())
dp = [[0] * (n + 1) for _ in range(n + 1)]
for i in reversed(list(range(n))):
    for j in reversed(list(range(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(eval(input()))
s = eval(input())
dp = [[0] * (n + 1) for _ in range(n + 1)]
for i in reversed(list(range(n - 1))):
    for j in reversed(list(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)

-for i in reversed(list(range(n))): -    for j in reversed(list(range(n))): +for i in reversed(list(range(n - 1))): +    for j in reversed(list(range(i + 1, n))):