def z_al(s):
    le = len(s)
    res = [0 for i in range(le)]
    i, j = 1, 0
    while i < le:
        while i + j < le and s[i + j] == s[j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < le and res[k] + k < j:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res
n = int(input())
s = input()
ans = 0
for i in range(n):
    s2 = s[i:]
    res = z_al(s2)
    for j in range(len(s2)):
        ans = max(ans, min(res[j], j))
print(ans) def z_al(s):
    le = len(s)
    res = [0 for i in range(le)]
    i, j = 1, 0
    while i < le:
        while i + j < le and s[i + j] == s[j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < le and res[k] + k < j:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res z_al le = len(s) le len(s) len s 0 for i in range(le) for i in range(le) i range(le) range le for i in range(le) 0 res = [0 for i in range(le)] res [0 for i in range(le)] i, j = 1, 0 i 1 j 0 while i < le:
        while i + j < le and s[i + j] == s[j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < le and res[k] + k < j:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
     i < le i le while i + j < le and s[i + j] == s[j]:
            j += 1
         i + j < le and s[i + j] == s[j] i + j < le i + j i j le s[i + j] == s[j] s[i + j] s i + j i j s[j] s j j += 1 j 1 res[i] = j res[i] res i j if j == 0:
            i += 1
            continue
         j == 0 j 0 i += 1 i 1 continue k = 1 k 1 while i + k < le and res[k] + k < j:
            res[i + k] = res[k]
            k += 1
         i + k < le and res[k] + k < j i + k < le i + k i k le res[k] + k < j res[k] + k res[k] res k k j res[i + k] = res[k] res[i + k] res i + k i k res[k] res k k += 1 k 1 i += k i k j -= k j k return res res 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):
    s2 = s[i:]
    res = z_al(s2)
    for j in range(len(s2)):
        ans = max(ans, min(res[j], j)) i range(n) range n s2 = s[i:] s2 s[i:] s i: i res = z_al(s2) res z_al(s2) z_al s2 for j in range(len(s2)):
        ans = max(ans, min(res[j], j)) j range(len(s2)) range len(s2) len s2 ans = max(ans, min(res[j], j)) ans max(ans, min(res[j], j)) max ans min(res[j], j) min res[j] res j j print(ans) print ans n = int(input()) int(input()) n ans = 0 0 ans res = z_al(s2) z_al(s2) res s2 = s[i:] s[i:] s2 def z_al(s):
    le = len(s)
    res = [0 for i in range(le)]
    i, j = 1, 0
    while i < le:
        while i + j < le and s[i + j] == s[j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < le and res[k] + k < j:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res def z_al(s):
    le = len(s)
    res = [0 for i in range(le)]
    i, j = 1, 0
    while i < le:
        while i + j < le and s[i + j] == s[j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < le and res[k] + k < j:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res z_al s = input() input() s ans = max(ans, min(res[j], j)) max(ans, min(res[j], j)) ans
def z_al(s):
    le = len(s)
    res = [0 for i in range(le)]
    i, j = 1, 0
    while i < le:
        while i + j < le and s[i + j] == s[j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < le and res[k] + k < j:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res
n = int(input())
s = input()
ans = 0
for i in range(n):
    s2 = s[i:]
    res = z_al(s2)
    for j in range(len(s2)):
        ans = max(ans, min(res[j], j))
print(ans)
