n=int(eval(input()))

s=list(eval(input()))

f=0

b=-1

for d in range(1,n):

  c=0

  b=-1

  for i in range(n-d):

    if c>=d:

      break

    if s[i]==s[i+d]:

      if b==-1:b=i

      c+=1

      f=max(f,c)

    else:

      c=0

      b=-1

print(f)

n=int(eval(input()))

s=list(eval(input()))

f=0

b=-1

for d in range(1,n):

  c=0

  b=-1

  for i in range(n-d):

    if s[i]==s[i+d] and c<d:

      if b==-1:b=i

      c+=1

      f=max(f,c)

      if c>=d:

        break

    else:

      c=0

      b=-1

print(f)

n = int(eval(input()))
s = list(eval(input()))
f = 0
b = -1
for d in range(1, n):
    c = 0
    b = -1
    for i in range(n - d):
        if c >= d:
            break
        if s[i] == s[i + d]:
            if b == -1:
                b = i
            c += 1
            f = max(f, c)
        else:
            c = 0
            b = -1
print(f)

n = int(eval(input()))
s = list(eval(input()))
f = 0
b = -1
for d in range(1, n):
    c = 0
    b = -1
    for i in range(n - d):
        if s[i] == s[i + d] and c < d:
            if b == -1:
                b = i
            c += 1
            f = max(f, c)
            if c >= d:
                break
        else:
            c = 0
            b = -1
print(f)

-        if c >= d: -            break -        if s[i] == s[i + d]: +        if s[i] == s[i + d] and c < d: +            if c >= d: +                break