#Z-Algorithm
#文字列が与えられた時、各 i について「S と S[i:] の最長共通接頭辞の長さ」を記録した配列 A を O(len(S)) で構築するアルゴリズム
#s : 文字列
#あとで要復習！
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

n = int(input())
S = input()
max_ = 0
for i in range(n):
    k = S[i:len(S)]
    li = z_algorithm(k)
    for j in range(len(li)):
        if li[j] < j+1:
            max_ = max(max_, li[j])
print(max_) 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 n = int(input()) n int(input()) int input() input S = input() S input() input max_ = 0 max_ 0 for i in range(n):
    k = S[i:len(S)]
    li = z_algorithm(k)
    for j in range(len(li)):
        if li[j] < j+1:
            max_ = max(max_, li[j]) i range(n) range n k = S[i:len(S)] k S[i:len(S)] S i:len(S) i len(S) len S li = z_algorithm(k) li z_algorithm(k) z_algorithm k for j in range(len(li)):
        if li[j] < j+1:
            max_ = max(max_, li[j]) j range(len(li)) range len(li) len li if li[j] < j+1:
            max_ = max(max_, li[j]) li[j] < j+1 li[j] li j j+1 j 1 max_ = max(max_, li[j]) max_ max(max_, li[j]) max max_ li[j] li j print(max_) print max_ S = input() input() S k = S[i:len(S)] S[i:len(S)] k max_ = 0 0 max_ li = z_algorithm(k) z_algorithm(k) li n = int(input()) int(input()) n 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 max_ = max(max_, li[j]) max(max_, li[j]) max_
#Z-Algorithm
#文字列が与えられた時、各 i について「S と S[i:] の最長共通接頭辞の長さ」を記録した配列 A を O(len(S)) で構築するアルゴリズム
#s : 文字列
#あとで要復習！
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

n = int(input())
S = input()
max_ = 0
for i in range(n):
    k = S[i:len(S)]
    li = z_algorithm(k)
    for j in range(len(li)):
        if li[j] < j+1:
            max_ = max(max_, li[j])
print(max_)