N=int(input())
S=input()
ans=0

def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg

ans=0  
for i in range(N):
  d=S[i:]
  D=Z_algorithm(d)
  for j in range(N-i):
    ans=max(ans,min(j,D[j]))
print(ans) N=int(input()) N int(input()) int input() input S=input() S input() input ans=0 ans 0 def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg Z_algorithm N = len(s) N len(s) len s Z_alg = [0]*N Z_alg [0]*N [0] 0 N Z_alg[0] = N Z_alg[0] Z_alg 0 N i = 1 i 1 j = 0 j 0 while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
     i < N i N while i+j < N and s[j] == s[i+j]:
            j += 1
         i+j < N and s[j] == s[i+j] i+j < N i+j i j N s[j] == s[i+j] s[j] s j s[i+j] s i+j i j j += 1 j 1 Z_alg[i] = j Z_alg[i] Z_alg i j if j == 0:
            i += 1
            continue
         j == 0 j 0 i += 1 i 1 continue k = 1 k 1 while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
         i+k < N and k + Z_alg[k]<j i+k < N i+k i k N k + Z_alg[k]<j k + Z_alg[k] k Z_alg[k] Z_alg k j Z_alg[i+k] = Z_alg[k] Z_alg[i+k] Z_alg i+k i k Z_alg[k] Z_alg k k += 1 k 1 i += k i k j -= k j k return Z_alg Z_alg s s ans=0 ans 0 for i in range(N):
  d=S[i:]
  D=Z_algorithm(d)
  for j in range(N-i):
    ans=max(ans,min(j,D[j])) i range(N) range N d=S[i:] d S[i:] S i: i D=Z_algorithm(d) D Z_algorithm(d) Z_algorithm d for j in range(N-i):
    ans=max(ans,min(j,D[j])) j range(N-i) range N-i N i ans=max(ans,min(j,D[j])) ans max(ans,min(j,D[j])) max ans min(j,D[j]) min j D[j] D j print(ans) print ans S=input() input() S ans=0 0 ans d=S[i:] S[i:] d ans=0 0 ans def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg Z_algorithm D=Z_algorithm(d) Z_algorithm(d) D N=int(input()) int(input()) N ans=max(ans,min(j,D[j])) max(ans,min(j,D[j])) ans
N=int(input())
S=input()
ans=0

def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg

ans=0  
for i in range(N):
  d=S[i:]
  D=Z_algorithm(d)
  for j in range(N-i):
    ans=max(ans,min(j,D[j]))
print(ans)