def zarg(N, S):
    Z = [0] * N
    Z[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        i += k
        j -= k
    M = 0
    for i in range(1,N):
        M = max(M, min(Z[i], i))
    return M

N = int(input())
S = input()
ans = 0
for i in range(N):
    s = S[i:]
    ans = max(ans, zarg(N-i, s))
print(ans) def zarg(N, S):
    Z = [0] * N
    Z[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        i += k
        j -= k
    M = 0
    for i in range(1,N):
        M = max(M, min(Z[i], i))
    return M zarg Z = [0] * N Z [0] * N [0] 0 N Z[0] = N Z[0] Z 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[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k + Z[k] < j:
            Z[i + k] = Z[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[i] = j Z[i] Z i j if j == 0:
            i += 1
            continue
         j == 0 j 0 i += 1 i 1 continue k = 1 k 1 while k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
         k + Z[k] < j k + Z[k] k Z[k] Z k j Z[i + k] = Z[k] Z[i + k] Z i + k i k Z[k] Z k k += 1 k 1 i += k i k j -= k j k M = 0 M 0 for i in range(1,N):
        M = max(M, min(Z[i], i))
     i range(1,N) range 1 N M = max(M, min(Z[i], i)) M max(M, min(Z[i], i)) max M min(Z[i], i) min Z[i] Z i i return M M N N S S N = int(input()) N int(input()) int input() input S = input() S input() input ans = 0 ans 0 for i in range(N):
    s = S[i:]
    ans = max(ans, zarg(N-i, s)) i range(N) range N s = S[i:] s S[i:] S i: i ans = max(ans, zarg(N-i, s)) ans max(ans, zarg(N-i, s)) max ans zarg(N-i, s) zarg N-i N i s print(ans) print ans ans = 0 0 ans def zarg(N, S):
    Z = [0] * N
    Z[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        i += k
        j -= k
    M = 0
    for i in range(1,N):
        M = max(M, min(Z[i], i))
    return M def zarg(N, S):
    Z = [0] * N
    Z[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        i += k
        j -= k
    M = 0
    for i in range(1,N):
        M = max(M, min(Z[i], i))
    return M zarg S = input() input() S N = int(input()) int(input()) N ans = max(ans, zarg(N-i, s)) max(ans, zarg(N-i, s)) ans s = S[i:] S[i:] s
def zarg(N, S):
    Z = [0] * N
    Z[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        i += k
        j -= k
    M = 0
    for i in range(1,N):
        M = max(M, min(Z[i], i))
    return M

N = int(input())
S = input()
ans = 0
for i in range(N):
    s = S[i:]
    ans = max(ans, zarg(N-i, s))
print(ans)