def Z_Algorithm(S):
    N = len(S)
    Z = [0]*N
    Z[0] = N
    
    i = 1   #左
    j = 0   #差分

    while i < N:
        while i + j < N and S[j] == S[j + i]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1   # 差分
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        
        i += k
        j -= k
    
    return Z

def calc(S):
    N = len(S)
    Z = Z_Algorithm(S)

    res = 0
    for i in range(N):
        res = max(res, min(Z[i], i))
    
    return res

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

res = 0

for i in range(N):
    res = max(res, calc(S[i:]))

print(res) def Z_Algorithm(S):
    N = len(S)
    Z = [0]*N
    Z[0] = N
    
    i = 1   #左
    j = 0   #差分

    while i < N:
        while i + j < N and S[j] == S[j + i]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1   # 差分
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        
        i += k
        j -= k
    
    return Z Z_Algorithm N = len(S) N len(S) len S 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[j + i]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1   # 差分
        while k < j and 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[j + i]:
            j += 1
         i + j < N and S[j] == S[j + i] i + j < N i + j i j N S[j] == S[j + i] S[j] S j S[j + i] S j + i j i 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 < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        
         k < j and k + Z[k] < j k < j k j 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 return Z Z S S def calc(S):
    N = len(S)
    Z = Z_Algorithm(S)

    res = 0
    for i in range(N):
        res = max(res, min(Z[i], i))
    
    return res calc N = len(S) N len(S) len S Z = Z_Algorithm(S) Z Z_Algorithm(S) Z_Algorithm S res = 0 res 0 for i in range(N):
        res = max(res, min(Z[i], i))
    
     i range(N) range N res = max(res, min(Z[i], i)) res max(res, min(Z[i], i)) max res min(Z[i], i) min Z[i] Z i i return res res S S N = int(input()) N int(input()) int input() input S = input() S input() input res = 0 res 0 for i in range(N):
    res = max(res, calc(S[i:])) i range(N) range N res = max(res, calc(S[i:])) res max(res, calc(S[i:])) max res calc(S[i:]) calc S[i:] S i: i print(res) print res S = input() input() S N = int(input()) int(input()) N res = 0 0 res def calc(S):
    N = len(S)
    Z = Z_Algorithm(S)

    res = 0
    for i in range(N):
        res = max(res, min(Z[i], i))
    
    return res def calc(S):
    N = len(S)
    Z = Z_Algorithm(S)

    res = 0
    for i in range(N):
        res = max(res, min(Z[i], i))
    
    return res calc def Z_Algorithm(S):
    N = len(S)
    Z = [0]*N
    Z[0] = N
    
    i = 1   #左
    j = 0   #差分

    while i < N:
        while i + j < N and S[j] == S[j + i]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1   # 差分
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        
        i += k
        j -= k
    
    return Z def Z_Algorithm(S):
    N = len(S)
    Z = [0]*N
    Z[0] = N
    
    i = 1   #左
    j = 0   #差分

    while i < N:
        while i + j < N and S[j] == S[j + i]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1   # 差分
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        
        i += k
        j -= k
    
    return Z Z_Algorithm res = max(res, calc(S[i:])) max(res, calc(S[i:])) res
def Z_Algorithm(S):
    N = len(S)
    Z = [0]*N
    Z[0] = N
    
    i = 1   #左
    j = 0   #差分

    while i < N:
        while i + j < N and S[j] == S[j + i]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1   # 差分
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        
        i += k
        j -= k
    
    return Z

def calc(S):
    N = len(S)
    Z = Z_Algorithm(S)

    res = 0
    for i in range(N):
        res = max(res, min(Z[i], i))
    
    return res

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

res = 0

for i in range(N):
    res = max(res, calc(S[i:]))

print(res)