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

s = list(s)
s.reverse()
import copy
ans = 0
for i in range(n):
    if i != 0:
        s.pop()
    t = copy.copy(s)
    t.reverse()
    t = ''.join(t)
    Z = z_algorithm(t)
    for i, z in enumerate(Z):
        ans = max(ans, min(i, z))
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 s = list(s) s list(s) list s s.reverse() s.reverse s reverse import copy copy ans = 0 ans 0 for i in range(n):
    if i != 0:
        s.pop()
    t = copy.copy(s)
    t.reverse()
    t = ''.join(t)
    Z = z_algorithm(t)
    for i, z in enumerate(Z):
        ans = max(ans, min(i, z)) i range(n) range n if i != 0:
        s.pop()
     i != 0 i 0 s.pop() s.pop s pop t = copy.copy(s) t copy.copy(s) copy.copy copy copy s t.reverse() t.reverse t reverse t = ''.join(t) t ''.join(t) ''.join '' join t Z = z_algorithm(t) Z z_algorithm(t) z_algorithm t for i, z in enumerate(Z):
        ans = max(ans, min(i, z)) i z enumerate(Z) enumerate Z ans = max(ans, min(i, z)) ans max(ans, min(i, z)) max ans min(i, z) min i z print(ans) print ans Z = z_algorithm(t) z_algorithm(t) Z n = int(input()) int(input()) n s = str(input()) str(input()) s 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 s = list(s) list(s) s ans = max(ans, min(i, z)) max(ans, min(i, z)) ans ans = 0 0 ans t = ''.join(t) ''.join(t) t t = copy.copy(s) copy.copy(s) t
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

s = list(s)
s.reverse()
import copy
ans = 0
for i in range(n):
    if i != 0:
        s.pop()
    t = copy.copy(s)
    t.reverse()
    t = ''.join(t)
    Z = z_algorithm(t)
    for i, z in enumerate(Z):
        ans = max(ans, min(i, z))
print(ans)
