n = int(input())
s = str(input())

def z_algorithm(s):
    n = len(s)
    Z = [0]*n
    Z[0] = n
    i = 1
    j = 0
    while i < n:
        while i+j < n and s[j] == s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+Z[k] < j:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

ans = 0
for i in range(n):
    t = s[i:]
    z = z_algorithm(t)
    for j in range(len(z)):
        if z[j] <= j:
            ans = max(ans, z[j])
print(ans) n = int(input()) n int(input()) int input() input s = str(input()) s str(input()) str input() input def z_algorithm(s):
    n = len(s)
    Z = [0]*n
    Z[0] = n
    i = 1
    j = 0
    while i < n:
        while i+j < n and s[j] == s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+Z[k] < j:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z z_algorithm n = len(s) n len(s) len s Z = [0]*n Z [0]*n [0] 0 n Z[0] = n Z[0] Z 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[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+Z[k] < j:
            Z[i+k] = Z[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[i] = j Z[i] Z 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[k] < j:
            Z[i+k] = Z[k]
            k += 1
         i+k < n and k+Z[k] < j i+k < n i+k i k n k+Z[k] < j k+Z[k] k Z[k] Z k j Z[i+k] = Z[k] Z[i+k] Z i+k i k Z[k] Z k k += 1 k 1 i += k i k j -= k j k return Z Z s s ans = 0 ans 0 for i in range(n):
    t = s[i:]
    z = z_algorithm(t)
    for j in range(len(z)):
        if z[j] <= j:
            ans = max(ans, z[j]) i range(n) range n t = s[i:] t s[i:] s i: i z = z_algorithm(t) z z_algorithm(t) z_algorithm t for j in range(len(z)):
        if z[j] <= j:
            ans = max(ans, z[j]) j range(len(z)) range len(z) len z if z[j] <= j:
            ans = max(ans, z[j]) z[j] <= j z[j] z j j ans = max(ans, z[j]) ans max(ans, z[j]) max ans z[j] z j print(ans) print ans ans = max(ans, z[j]) max(ans, z[j]) ans ans = 0 0 ans z = z_algorithm(t) z_algorithm(t) z s = str(input()) str(input()) s t = s[i:] s[i:] t n = int(input()) int(input()) n def z_algorithm(s):
    n = len(s)
    Z = [0]*n
    Z[0] = n
    i = 1
    j = 0
    while i < n:
        while i+j < n and s[j] == s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+Z[k] < j:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z def z_algorithm(s):
    n = len(s)
    Z = [0]*n
    Z[0] = n
    i = 1
    j = 0
    while i < n:
        while i+j < n and s[j] == s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+Z[k] < j:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z z_algorithm
n = int(input())
s = str(input())

def z_algorithm(s):
    n = len(s)
    Z = [0]*n
    Z[0] = n
    i = 1
    j = 0
    while i < n:
        while i+j < n and s[j] == s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+Z[k] < j:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

ans = 0
for i in range(n):
    t = s[i:]
    z = z_algorithm(t)
    for j in range(len(z)):
        if z[j] <= j:
            ans = max(ans, z[j])
print(ans)
