
# 長さnの文字列Sについて，各iに対しSとS[i:-1]の最長共通接頭辞(LCP)の長さを求める
def Z_algorithm(S): # O(n)
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    LCP[0] = l = n
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        LCP[i] = j
        k = 1
        while l-i > k < j - LCP[k]:
            LCP[i+k] = LCP[k]
            k += 1
        i += k
        j -= k
    return LCP # LCP:list[int,...] (LCP[i]はSとS[i:-1]の最長共通接頭辞の長さ)



N = int(input())
S = input()
ans = 0
for i in range(N):
    lcp = Z_algorithm(S[i:])
    for j in range(len(lcp)):
        if lcp[j]<=j:
            ans = max(ans,lcp[j])
print(ans) def Z_algorithm(S): # O(n)
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    LCP[0] = l = n
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        LCP[i] = j
        k = 1
        while l-i > k < j - LCP[k]:
            LCP[i+k] = LCP[k]
            k += 1
        i += k
        j -= k
    return LCP # LCP:list[int,...] (LCP[i]はSとS[i:-1]の最長共通接頭辞の長さ) Z_algorithm n = len(S) n len(S) len S LCP = [0]*n LCP [0]*n [0] 0 n i = 1 i 1 j = 0 j 0 LCP[0] = l = n LCP[0] LCP 0 n = l = n l n while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        LCP[i] = j
        k = 1
        while l-i > k < j - LCP[k]:
            LCP[i+k] = LCP[k]
            k += 1
        i += k
        j -= k
     i < l i l while i+j < l and S[j] == S[i+j]:
            j += 1
         i+j < l and S[j] == S[i+j] i+j < l i+j i j l S[j] == S[i+j] S[j] S j S[i+j] S i+j i j j += 1 j 1 if not j:
            i += 1
            continue
         not j j i += 1 i 1 continue LCP[i] = j LCP[i] LCP i j k = 1 k 1 while l-i > k < j - LCP[k]:
            LCP[i+k] = LCP[k]
            k += 1
         l-i > k < j - LCP[k] l-i > k l-i l i k j - LCP[k] j LCP[k] LCP k LCP[i+k] = LCP[k] LCP[i+k] LCP i+k i k LCP[k] LCP k k += 1 k 1 i += k i k j -= k j k return LCP LCP 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):
    lcp = Z_algorithm(S[i:])
    for j in range(len(lcp)):
        if lcp[j]<=j:
            ans = max(ans,lcp[j]) i range(N) range N lcp = Z_algorithm(S[i:]) lcp Z_algorithm(S[i:]) Z_algorithm S[i:] S i: i for j in range(len(lcp)):
        if lcp[j]<=j:
            ans = max(ans,lcp[j]) j range(len(lcp)) range len(lcp) len lcp if lcp[j]<=j:
            ans = max(ans,lcp[j]) lcp[j]<=j lcp[j] lcp j j ans = max(ans,lcp[j]) ans max(ans,lcp[j]) max ans lcp[j] lcp j print(ans) print ans ans = 0 0 ans ans = max(ans,lcp[j]) max(ans,lcp[j]) ans N = int(input()) int(input()) N S = input() input() S lcp = Z_algorithm(S[i:]) Z_algorithm(S[i:]) lcp def Z_algorithm(S): # O(n)
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    LCP[0] = l = n
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        LCP[i] = j
        k = 1
        while l-i > k < j - LCP[k]:
            LCP[i+k] = LCP[k]
            k += 1
        i += k
        j -= k
    return LCP # LCP:list[int,...] (LCP[i]はSとS[i:-1]の最長共通接頭辞の長さ) def Z_algorithm(S): # O(n)
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    LCP[0] = l = n
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        LCP[i] = j
        k = 1
        while l-i > k < j - LCP[k]:
            LCP[i+k] = LCP[k]
            k += 1
        i += k
        j -= k
    return LCP # LCP:list[int,...] (LCP[i]はSとS[i:-1]の最長共通接頭辞の長さ) Z_algorithm

# 長さnの文字列Sについて，各iに対しSとS[i:-1]の最長共通接頭辞(LCP)の長さを求める
def Z_algorithm(S): # O(n)
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    LCP[0] = l = n
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        LCP[i] = j
        k = 1
        while l-i > k < j - LCP[k]:
            LCP[i+k] = LCP[k]
            k += 1
        i += k
        j -= k
    return LCP # LCP:list[int,...] (LCP[i]はSとS[i:-1]の最長共通接頭辞の長さ)



N = int(input())
S = input()
ans = 0
for i in range(N):
    lcp = Z_algorithm(S[i:])
    for j in range(len(lcp)):
        if lcp[j]<=j:
            ans = max(ans,lcp[j])
print(ans)
