from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1; j = 0
    A[0] = l = N
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

n = inp()
s = input()
res = 0
for i in range(n-1):
    a = z_algo(s[i:])
    ln = n-i
    for j,x in enumerate(a):
        tmp = min(j,x)
        res = max(res, tmp)
print(res) from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions sys bisect math itertools fractions from decimal import Decimal sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 INF = float('inf') INF float('inf') float 'inf' def inp(): return int(sys.stdin.readline()) inp def inpl(): return list(map(int, sys.stdin.readline().split())) inpl def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1; j = 0
    A[0] = l = N
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A z_algo N = len(S) N len(S) len S A = [0] * N A [0] * N [0] 0 N i = 1 i 1 j = 0 j 0 A[0] = l = N A[0] A 0 N = l = N l N while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[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 A[i] = j A[i] A i j k = 1 k 1 while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
         l-i > k < j - A[k] l-i > k l-i l i k j - A[k] j A[k] A k A[i+k] = A[k] A[i+k] A i+k i k A[k] A k k += 1 k 1 i += k i k j -= k j k return A A S S n = inp() n inp() inp s = input() s input() input res = 0 res 0 for i in range(n-1):
    a = z_algo(s[i:])
    ln = n-i
    for j,x in enumerate(a):
        tmp = min(j,x)
        res = max(res, tmp) i range(n-1) range n-1 n 1 a = z_algo(s[i:]) a z_algo(s[i:]) z_algo s[i:] s i: i ln = n-i ln n-i n i for j,x in enumerate(a):
        tmp = min(j,x)
        res = max(res, tmp) j x enumerate(a) enumerate a tmp = min(j,x) tmp min(j,x) min j x res = max(res, tmp) res max(res, tmp) max res tmp print(res) print res INF = float('inf') float('inf') INF def inp(): return int(sys.stdin.readline()) def inp(): return int(sys.stdin.readline()) inp mod = 10**9+7 10**9+7 mod res = max(res, tmp) max(res, tmp) res res = 0 0 res ln = n-i n-i ln def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl(): return list(map(int, sys.stdin.readline().split())) inpl tmp = min(j,x) min(j,x) tmp def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1; j = 0
    A[0] = l = N
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1; j = 0
    A[0] = l = N
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A z_algo s = input() input() s a = z_algo(s[i:]) z_algo(s[i:]) a n = inp() inp() n
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1; j = 0
    A[0] = l = N
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

n = inp()
s = input()
res = 0
for i in range(n-1):
    a = z_algo(s[i:])
    ln = n-i
    for j,x in enumerate(a):
        tmp = min(j,x)
        res = max(res, tmp)
print(res)