# suffix array
# z-algorithm
# rolling-hash
# dp
n = int(input())
s = input()

# z-algorithm
# i左端
# j iからの距離
# k i-i+jの間を進みながら比較
ans = 0
for num in range(n - 1):
    S = s[num:]
    A = [0] * (n - num)
    A[0] = n - num
    i = 1
    j = 0
    while i < n - num:
        while i + j < n - num and S[j] == S[i + j]:
            j += 1
        A[i] = j
        ans = max(ans, min(i, j))
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < n - num and k + A[k] < j:
            A[i + k] = A[k]
            ans = max(ans, min(k, A[k]))
            k += 1
        i += k
        j -= k
print(ans) n = int(input()) n int(input()) int input() input s = input() s input() input ans = 0 ans 0 for num in range(n - 1):
    S = s[num:]
    A = [0] * (n - num)
    A[0] = n - num
    i = 1
    j = 0
    while i < n - num:
        while i + j < n - num and S[j] == S[i + j]:
            j += 1
        A[i] = j
        ans = max(ans, min(i, j))
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < n - num and k + A[k] < j:
            A[i + k] = A[k]
            ans = max(ans, min(k, A[k]))
            k += 1
        i += k
        j -= k num range(n - 1) range n - 1 n 1 S = s[num:] S s[num:] s num: num A = [0] * (n - num) A [0] * (n - num) [0] 0 n - num n num A[0] = n - num A[0] A 0 n - num n num i = 1 i 1 j = 0 j 0 while i < n - num:
        while i + j < n - num and S[j] == S[i + j]:
            j += 1
        A[i] = j
        ans = max(ans, min(i, j))
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < n - num and k + A[k] < j:
            A[i + k] = A[k]
            ans = max(ans, min(k, A[k]))
            k += 1
        i += k
        j -= k i < n - num i n - num n num while i + j < n - num and S[j] == S[i + j]:
            j += 1
         i + j < n - num and S[j] == S[i + j] i + j < n - num i + j i j n - num n num S[j] == S[i + j] S[j] S j S[i + j] S i + j i j j += 1 j 1 A[i] = j A[i] A i j ans = max(ans, min(i, j)) ans max(ans, min(i, j)) max ans min(i, j) min 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 - num and k + A[k] < j:
            A[i + k] = A[k]
            ans = max(ans, min(k, A[k]))
            k += 1
         i + k < n - num and k + A[k] < j i + k < n - num i + k i k n - num n num k + A[k] < j k + A[k] k A[k] A k j A[i + k] = A[k] A[i + k] A i + k i k A[k] A k ans = max(ans, min(k, A[k])) ans max(ans, min(k, A[k])) max ans min(k, A[k]) min k A[k] A k k += 1 k 1 i += k i k j -= k j k print(ans) print ans i = 1 1 i s = input() input() s ans = max(ans, min(k, A[k])) max(ans, min(k, A[k])) ans S = s[num:] s[num:] S i += 1 1 i i += k k i j += 1 1 j n = int(input()) int(input()) n A = [0] * (n - num) [0] * (n - num) A k = 1 1 k j -= k k j ans = max(ans, min(i, j)) max(ans, min(i, j)) ans ans = 0 0 ans j = 0 0 j k += 1 1 k
# suffix array
# z-algorithm
# rolling-hash
# dp
n = int(input())
s = input()

# z-algorithm
# i左端
# j iからの距離
# k i-i+jの間を進みながら比較
ans = 0
for num in range(n - 1):
    S = s[num:]
    A = [0] * (n - num)
    A[0] = n - num
    i = 1
    j = 0
    while i < n - num:
        while i + j < n - num and S[j] == S[i + j]:
            j += 1
        A[i] = j
        ans = max(ans, min(i, j))
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < n - num and k + A[k] < j:
            A[i + k] = A[k]
            ans = max(ans, min(k, A[k]))
            k += 1
        i += k
        j -= k
print(ans)
