n = int(eval(input()))

s = eval(input())

j = 1

result = [0]

for i in range(n):

    while (j < n-1) and (s[i:j] in s[:i]+"0"+s[j:]):

        j += 1

    result.append(j-i-1)

print((max(result)))
n = int(eval(input()))

s = eval(input())

j = 1

result = []

for i in range(n):

    while (j < n-1) and (s[i:j] in s[:i]+"0"+s[j:]):

        j += 1

    result.append(j-i-1)

print((max(result)))
n = int(eval(input()))
s = eval(input())
j = 1
result = [0]
for i in range(n):
    while (j < n - 1) and (s[i:j] in s[:i] + "0" + s[j:]):
        j += 1
    result.append(j - i - 1)
print((max(result)))

n = int(eval(input()))
s = eval(input())
j = 1
result = []
for i in range(n):
    while (j < n - 1) and (s[i:j] in s[:i] + "0" + s[j:]):
        j += 1
    result.append(j - i - 1)
print((max(result)))

-result = [0] +result = []