N = int(eval(input()))

S = eval(input())

r = 0

i = j = 0

while j < N:

  t = S[i:j]

  if t in S[j:]:

    r = max(r, j-i)

    j += 1

  else:

    i += 1

print(r)  

N = int(eval(input()))

S = eval(input())

def check(l):

  D = {}

  for i in range(N-l+1):

    s = S[i:i+l]

    if s not in D:

      D[s] = i

      continue

    if D[s]+l <= i:

      return True

  return False

a = 1

b = N

while a < b:

  i = (a + b)//2

  if not check(i):

    b = i

  else:

    if a == i:

      break

    a = i

r = b-1

print(r)

N = int(eval(input()))
S = eval(input())
r = 0
i = j = 0
while j < N:
    t = S[i:j]
    if t in S[j:]:
        r = max(r, j - i)
        j += 1
    else:
        i += 1
print(r)

N = int(eval(input()))
S = eval(input())


def check(l):
    D = {}
    for i in range(N - l + 1):
        s = S[i : i + l]
        if s not in D:
            D[s] = i
            continue
        if D[s] + l <= i:
            return True
    return False


a = 1
b = N
while a < b:
    i = (a + b) // 2
    if not check(i):
        b = i
    else:
        if a == i:
            break
        a = i
r = b - 1
print(r)

-r = 0 -i = j = 0 -while j < N: -    t = S[i:j] -    if t in S[j:]: -        r = max(r, j - i) -        j += 1 + + +def check(l): +    D = {} +    for i in range(N - l + 1): +        s = S[i : i + l] +        if s not in D: +            D[s] = i +            continue +        if D[s] + l <= i: +            return True +    return False + + +a = 1 +b = N +while a < b: +    i = (a + b) // 2 +    if not check(i): +        b = i -        i += 1 +        if a == i: +            break +        a = i +r = b - 1