n=int(eval(input()))

s=eval(input())

ans=0

tmp=0

for i in range(n-1):

  for j in range(i+2,n+1):

    if j-i>ans:

      if s[i:j] in s[j:]:

        tmp=j-i

      else:

        ans=max(tmp,ans)

        break

ans=max(tmp,ans)

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

s=eval(input())

ans=0

i=0

j=1

while i<n and j<=n:

  if s[i:j] in s[j:n]:

    ans=max(j-i,ans)

    j+=1

  else:

    i+=1

print(ans)
n = int(eval(input()))
s = eval(input())
ans = 0
tmp = 0
for i in range(n - 1):
    for j in range(i + 2, n + 1):
        if j - i > ans:
            if s[i:j] in s[j:]:
                tmp = j - i
            else:
                ans = max(tmp, ans)
                break
ans = max(tmp, ans)
print(ans)

n = int(eval(input()))
s = eval(input())
ans = 0
i = 0
j = 1
while i < n and j <= n:
    if s[i:j] in s[j:n]:
        ans = max(j - i, ans)
        j += 1
    else:
        i += 1
print(ans)

-tmp = 0 -for i in range(n - 1): -    for j in range(i + 2, n + 1): -        if j - i > ans: -            if s[i:j] in s[j:]: -                tmp = j - i -            else: -                ans = max(tmp, ans) -                break -ans = max(tmp, ans) +i = 0 +j = 1 +while i < n and j <= n: +    if s[i:j] in s[j:n]: +        ans = max(j - i, ans) +        j += 1 +    else: +        i += 1