N = int(eval(input()))

S = eval(input())

r = 0

ans = 0

for i in range(N):

    while True:

        if S.rfind(S[i : r + 1]) >= r + 1:

            r += 1

            ans = max(ans, r - i)

        else:

            break

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

S = eval(input())

l = 0

k = 1

for i in range(N - 1):

    while True:

        if S[i : i + k] in S[i + k :]:

            k += 1

        else:

            break

    l = max(l, k - 1)

print(l)
N = int(eval(input()))
S = eval(input())
r = 0
ans = 0
for i in range(N):
    while True:
        if S.rfind(S[i : r + 1]) >= r + 1:
            r += 1
            ans = max(ans, r - i)
        else:
            break
print(ans)

N = int(eval(input()))
S = eval(input())
l = 0
k = 1
for i in range(N - 1):
    while True:
        if S[i : i + k] in S[i + k :]:
            k += 1
        else:
            break
    l = max(l, k - 1)
print(l)

-r = 0 -ans = 0 -for i in range(N): +l = 0 +k = 1 +for i in range(N - 1): -        if S.rfind(S[i : r + 1]) >= r + 1: -            r += 1 -            ans = max(ans, r - i) +        if S[i : i + k] in S[i + k :]: +            k += 1 -print(ans) +    l = max(l, k - 1) +print(l)