def Z_algo(S):
    L = len(S)
    lcp = [0]*L
    i = 1
    j = 0
    lcp[0] = L
    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 i + k < L and k + lcp[k] < j:
            lcp[i+k] = lcp[k]
            k += 1
        i += k
        j -= k
    return lcp

def max2(x,y):
    return x if x > y else y

def min2(x,y):
    return x if x < y else y

res = 0
N = int(input())
S = input()
for i in range(N):
    lcp = Z_algo(S[i:])
    for j, s in enumerate(lcp):
        temp = min2(s, j)
        res = max2(res, temp)
print(res) def Z_algo(S):
    L = len(S)
    lcp = [0]*L
    i = 1
    j = 0
    lcp[0] = L
    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 i + k < L and k + lcp[k] < j:
            lcp[i+k] = lcp[k]
            k += 1
        i += k
        j -= k
    return lcp Z_algo L = len(S) L len(S) len S lcp = [0]*L lcp [0]*L [0] 0 L i = 1 i 1 j = 0 j 0 lcp[0] = L lcp[0] lcp 0 L 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 i + k < L and k + lcp[k] < j:
            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 i + k < L and k + lcp[k] < j:
            lcp[i+k] = lcp[k]
            k += 1
         i + k < L and k + lcp[k] < j i + k < L i + k i k L k + lcp[k] < j k + lcp[k] k lcp[k] lcp k j 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 def max2(x,y):
    return x if x > y else y max2 return x if x > y else y x if x > y else y x > y x y x y x x y y def min2(x,y):
    return x if x < y else y min2 return x if x < y else y x if x < y else y x < y x y x y x x y y res = 0 res 0 N = int(input()) N int(input()) int input() input S = input() S input() input for i in range(N):
    lcp = Z_algo(S[i:])
    for j, s in enumerate(lcp):
        temp = min2(s, j)
        res = max2(res, temp) i range(N) range N lcp = Z_algo(S[i:]) lcp Z_algo(S[i:]) Z_algo S[i:] S i: i for j, s in enumerate(lcp):
        temp = min2(s, j)
        res = max2(res, temp) j s enumerate(lcp) enumerate lcp temp = min2(s, j) temp min2(s, j) min2 s j res = max2(res, temp) res max2(res, temp) max2 res temp print(res) print res def Z_algo(S):
    L = len(S)
    lcp = [0]*L
    i = 1
    j = 0
    lcp[0] = L
    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 i + k < L and k + lcp[k] < j:
            lcp[i+k] = lcp[k]
            k += 1
        i += k
        j -= k
    return lcp def Z_algo(S):
    L = len(S)
    lcp = [0]*L
    i = 1
    j = 0
    lcp[0] = L
    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 i + k < L and k + lcp[k] < j:
            lcp[i+k] = lcp[k]
            k += 1
        i += k
        j -= k
    return lcp Z_algo def max2(x,y):
    return x if x > y else y def max2(x,y):
    return x if x > y else y max2 lcp = Z_algo(S[i:]) Z_algo(S[i:]) lcp S = input() input() S def min2(x,y):
    return x if x < y else y def min2(x,y):
    return x if x < y else y min2 temp = min2(s, j) min2(s, j) temp res = 0 0 res N = int(input()) int(input()) N res = max2(res, temp) max2(res, temp) res
def Z_algo(S):
    L = len(S)
    lcp = [0]*L
    i = 1
    j = 0
    lcp[0] = L
    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 i + k < L and k + lcp[k] < j:
            lcp[i+k] = lcp[k]
            k += 1
        i += k
        j -= k
    return lcp

def max2(x,y):
    return x if x > y else y

def min2(x,y):
    return x if x < y else y

res = 0
N = int(input())
S = input()
for i in range(N):
    lcp = Z_algo(S[i:])
    for j, s in enumerate(lcp):
        temp = min2(s, j)
        res = max2(res, temp)
print(res)